Skip to content

Commit d135c3b

Browse files
author
Mike Solomon
committed
Scaffolds internal functions for command encoding
1 parent 94a3378 commit d135c3b

12 files changed

Lines changed: 368 additions & 65 deletions

spago.dhall

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ to generate this file without the comments in this block.
1313
{ name = "webgpu"
1414
, dependencies =
1515
[ "arraybuffer-types"
16-
, "arrays"
1716
, "effect"
1817
, "foreign"
1918
, "foreign-object"
@@ -22,7 +21,6 @@ to generate this file without the comments in this block.
2221
, "ordered-collections"
2322
, "prelude"
2423
, "record"
25-
, "tuples"
2624
, "unsafe-coerce"
2725
, "web-html"
2826
, "web-promise"

src/Web/GPU/GPUColor.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Web.GPU.GPUColor
2+
( gpuColorDict
3+
, gpuColorRGBA
4+
) where
5+
6+
import Unsafe.Coerce (unsafeCoerce)
7+
import Web.GPU.Internal.Types (GPUColor)
8+
9+
gpuColorRGBA :: Number -> Number -> Number -> Number -> GPUColor
10+
gpuColorRGBA r g b a = unsafeCoerce [ r, g, b, a ]
11+
12+
gpuColorDict :: { r :: Number, g :: Number, b :: Number, a :: Number } -> GPUColor
13+
gpuColorDict rgba = unsafeCoerce rgba

src/Web/GPU/GPUCommandEncoder.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Web/GPU/GPUCommandEncoder.purs

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
module Web.GPU.GPUCommandEncoder where
2+
3+
import Prelude
4+
5+
import Effect (Effect)
6+
import Web.GPU.GPUComputePassTimestampLocation (GPUComputePassTimestampLocation)
7+
import Web.GPU.GPULoadOp (GPULoadOp)
8+
import Web.GPU.GPURenderPassTimestampLocation (GPURenderPassTimestampLocation)
9+
import Web.GPU.GPUStoreOp (GPUStoreOp)
10+
import Web.GPU.GPUTextureAspect (GPUTextureAspect)
11+
import Web.GPU.Internal.ConvertibleOptions (class ConvertOption, class ConvertOptionsWithDefaults, convertOptionsWithDefaults)
12+
import Web.GPU.Internal.Types (GPUBuffer, GPUColor, GPUCommandBuffer, GPUCommandEncoder, GPUComputePassEncoder, GPUExtent3D, GPUOrigin3D, GPUQuerySet, GPURenderPassEncoder, GPUTexture, GPUTextureView)
13+
import Web.GPU.Internal.Undefinable (Undefinable, defined, undefined)
14+
import Web.GPU.Internal.Unsigned (GPUSize32, GPUSize64, GPUStencilValue, GPUIntegerCoordinate)
15+
16+
-- todo
17+
-- convertible options on GPURenderPassDescriptor
18+
19+
type GPURenderPassTimestampWrite =
20+
{ querySet :: GPUQuerySet
21+
, queryIndex :: GPUSize32
22+
, location :: GPURenderPassTimestampLocation
23+
}
24+
25+
type GPURenderPassTimestampWrites = Array GPURenderPassTimestampWrite
26+
27+
type GPURenderPassDescriptorOptional :: forall k. k -> Row Type
28+
type GPURenderPassDescriptorOptional gpuRenderPassDepthStencilAttachment =
29+
( depthStencilAttachment :: Undefinable gpuRenderPassDepthStencilAttachment
30+
, occlusionQuerySet :: Undefinable GPUQuerySet
31+
, timestampWrites :: Undefinable GPURenderPassTimestampWrites
32+
, maxDrawCount :: Undefinable GPUSize64
33+
)
34+
35+
type GPURenderPassColorAttachmentOptional =
36+
( resolveTarget :: Undefinable GPUTextureView
37+
, clearValue :: Undefinable GPUColor
38+
)
39+
40+
type GPURenderPassColorAttachment =
41+
( view :: GPUTextureView
42+
, loadOp :: GPULoadOp
43+
, storeOp :: GPUStoreOp
44+
| GPURenderPassColorAttachmentOptional
45+
)
46+
47+
defaultGPURenderPassColorAttachmentOptions :: { | GPURenderPassColorAttachmentOptional }
48+
defaultGPURenderPassColorAttachmentOptions =
49+
{ resolveTarget: undefined
50+
, clearValue: undefined
51+
}
52+
53+
data RenderPassColorAttachment = RenderPassColorAttachment
54+
55+
instance ConvertOption RenderPassColorAttachment "resolveTarget" GPUTextureView (Undefinable GPUTextureView) where
56+
convertOption _ _ = defined
57+
58+
instance ConvertOption RenderPassColorAttachment "clearValue" GPUColor (Undefinable GPUColor) where
59+
convertOption _ _ = defined
60+
61+
gpuRenderPassColorAttachment
62+
:: forall provided
63+
. ConvertOptionsWithDefaults RenderPassColorAttachment { | GPURenderPassColorAttachmentOptional } { | provided } { | GPURenderPassColorAttachment }
64+
=> { | provided }
65+
-> { | GPURenderPassColorAttachment }
66+
67+
gpuRenderPassColorAttachment provided = all
68+
where
69+
all :: { | GPURenderPassColorAttachment }
70+
all = convertOptionsWithDefaults RenderPassColorAttachment defaultGPURenderPassColorAttachmentOptions provided
71+
72+
type GPURenderPassDepthStencilAttachmentOptional =
73+
( depthClearValue :: Undefinable Number
74+
, depthReadOnly :: Undefinable Boolean
75+
, stencilClearValue :: Undefinable GPUStencilValue
76+
, stencilReadOnly :: Undefinable Boolean
77+
)
78+
79+
type GPURenderPassDepthStencilAttachment =
80+
( view :: GPUTextureView
81+
, depthLoadOp :: GPULoadOp
82+
, depthStoreOp :: GPUStoreOp
83+
, stencilLoadOp :: GPULoadOp
84+
, stencilStoreOp :: GPUStoreOp
85+
| GPURenderPassDepthStencilAttachmentOptional
86+
)
87+
88+
type GPURenderPassDescriptor :: forall k. k -> Row Type
89+
type GPURenderPassDescriptor gpuRenderPassDepthStencilAttachment =
90+
( colorAttachments :: Array { | GPURenderPassColorAttachment }
91+
| GPURenderPassDescriptorOptional gpuRenderPassDepthStencilAttachment
92+
)
93+
94+
type GPUComputePassTimestampWrite =
95+
{ querySet :: GPUQuerySet
96+
, queryIndex :: GPUSize32
97+
, location :: GPUComputePassTimestampLocation
98+
}
99+
100+
type GPUComputePassTimestampWrites = Array GPUComputePassTimestampWrite
101+
type GPUComputePassDescriptorOptional =
102+
( timestampWrites :: Undefinable GPUComputePassTimestampWrites
103+
)
104+
105+
type GPUComputePassDescriptor =
106+
(
107+
| GPUComputePassDescriptorOptional
108+
)
109+
110+
foreign import beginRenderPassImpl :: GPUCommandEncoder -> { | GPURenderPassDescriptor GPURenderPassDepthStencilAttachment } -> Effect GPURenderPassEncoder
111+
foreign import beginComputePassImpl :: GPUCommandEncoder -> { | GPUComputePassDescriptor } -> GPUComputePassEncoder
112+
foreign import copyBufferToBufferImpl
113+
:: GPUCommandEncoder
114+
-> GPUBuffer
115+
-> GPUSize64
116+
-> GPUBuffer
117+
-> GPUSize64
118+
-> GPUSize64
119+
-> Effect Unit
120+
121+
type GPUImageCopyBufferOptional =
122+
( offset :: GPUSize64
123+
, bytesPerRow :: GPUSize32
124+
, rowsPerImage :: GPUSize32
125+
)
126+
127+
type GPUImageCopyBuffer =
128+
( buffer :: GPUBuffer
129+
| GPUImageCopyBufferOptional
130+
)
131+
132+
type GPUImageCopyTextureOptional =
133+
( mipLevel :: GPUIntegerCoordinate
134+
, origin :: GPUOrigin3D
135+
, aspect :: GPUTextureAspect
136+
)
137+
138+
type GPUImageCopyTexture =
139+
( texture :: GPUTexture
140+
| GPUImageCopyTextureOptional
141+
)
142+
143+
foreign import copyBufferToTextureImpl
144+
:: GPUCommandEncoder
145+
-> { | GPUImageCopyBuffer }
146+
-> { | GPUImageCopyTexture }
147+
-> GPUExtent3D
148+
-> Effect Unit
149+
150+
foreign import copyTextureToBufferImpl
151+
:: GPUCommandEncoder
152+
-> { | GPUImageCopyTexture }
153+
-> { | GPUImageCopyBuffer }
154+
-> GPUExtent3D
155+
-> Effect Unit
156+
157+
foreign import copyTextureToTextureImpl
158+
:: GPUCommandEncoder
159+
-> { | GPUImageCopyTexture }
160+
-> { | GPUImageCopyTexture }
161+
-> GPUExtent3D
162+
-> Effect Unit
163+
164+
foreign import clearBufferImpl
165+
:: GPUCommandEncoder
166+
-> GPUBuffer
167+
-> Effect Unit
168+
169+
foreign import clearBufferWithOffsetImpl
170+
:: GPUCommandEncoder
171+
-> GPUBuffer
172+
-> GPUSize64
173+
-> Effect Unit
174+
175+
foreign import clearBufferWithSizeImpl
176+
:: GPUCommandEncoder
177+
-> GPUBuffer
178+
-> GPUSize64
179+
-> Effect Unit
180+
181+
foreign import clearBufferWithOffsetAndSizeImpl
182+
:: GPUCommandEncoder
183+
-> GPUBuffer
184+
-> GPUSize64
185+
-> GPUSize64
186+
-> Effect Unit
187+
188+
foreign import writeTimestampImpl :: GPUCommandEncoder -> GPUQuerySet -> GPUSize32 -> Effect Unit
189+
190+
foreign import resolveQuerySetImpl
191+
:: GPUCommandEncoder
192+
-> GPUQuerySet
193+
-> GPUSize32
194+
-> GPUSize32
195+
-> GPUBuffer
196+
-> GPUSize64
197+
-> Effect Unit
198+
199+
foreign import finishImpl :: GPUCommandEncoder -> Effect GPUCommandBuffer
200+
201+
foreign import pushDebugGroupImpl :: GPUCommandEncoder -> String -> Effect Unit
202+
foreign import popDebugGroupImpl :: GPUCommandEncoder -> Effect Unit
203+
foreign import insertDebugMarkerImpl :: GPUCommandEncoder -> String -> Effect Unit
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Web.GPU.GPUComputePassTimestampLocation
2+
( GPUComputePassTimestampLocation
3+
, beginning
4+
, end
5+
) where
6+
7+
import Prelude
8+
9+
newtype GPUComputePassTimestampLocation = GPUComputePassTimestampLocation String
10+
11+
derive instance Eq GPUComputePassTimestampLocation
12+
derive instance Ord GPUComputePassTimestampLocation
13+
derive newtype instance Show GPUComputePassTimestampLocation
14+
15+
beginning :: GPUComputePassTimestampLocation
16+
beginning = GPUComputePassTimestampLocation "beginning"
17+
18+
end :: GPUComputePassTimestampLocation
19+
end = GPUComputePassTimestampLocation "end"
20+

src/Web/GPU/GPUDevice.purs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import Web.GPU.GPUBufferUsage (GPUBufferUsage)
5757
import Web.GPU.GPUColorWrite (GPUColorWrite)
5858
import Web.GPU.GPUCompareFunction (GPUCompareFunction)
5959
import Web.GPU.GPUCullMode (GPUCullMode)
60-
import Web.GPU.GPUExtent3D (class AsGPUExtent3D, asGPUExtent3D)
6160
import Web.GPU.GPUFeatureName (GPUFeatureName)
6261
import Web.GPU.GPUFilterMode (GPUFilterMode)
6362
import Web.GPU.GPUFrontFace (GPUFrontFace)
@@ -78,7 +77,7 @@ import Web.GPU.GPUTextureViewDimension (GPUTextureViewDimension)
7877
import Web.GPU.GPUVertexFormat (GPUVertexFormat)
7978
import Web.GPU.GPUVertexStepMode (GPUVertexStepMode)
8079
import Web.GPU.Internal.ConvertibleOptions (class ConvertOption, class ConvertOptionsWithDefaults, convertOptionsWithDefaults)
81-
import Web.GPU.Internal.Types (GPUBindGroup, GPUBindGroupEntry, GPUBindGroupLayout, GPUBindGroupLayoutEntry, GPUBuffer, GPUCommandEncoder, GPUComputePipeline, GPUDevice, GPUExternalTexture, GPUPipelineLayout, GPUQuerySet, GPUQueue, GPURenderPipeline, GPUSampler, GPUShaderModule, GPUShaderModuleCompilationHint, GPUTexture)
80+
import Web.GPU.Internal.Types (GPUBindGroup, GPUBindGroupEntry, GPUBindGroupLayout, GPUBindGroupLayoutEntry, GPUBuffer, GPUCommandEncoder, GPUComputePipeline, GPUDevice, GPUExtent3D, GPUExternalTexture, GPUPipelineLayout, GPUQuerySet, GPUQueue, GPURenderPipeline, GPUSampler, GPUShaderModule, GPUShaderModuleCompilationHint, GPUTexture)
8281
import Web.GPU.Internal.Undefinable (Undefinable, defined, undefined)
8382
import Web.GPU.Internal.Unsigned (GPUDepthBias, GPUIntegerCoordinate, GPUSampleMask, GPUSize32, GPUSize64, GPUStencilValue, UnsignedShort, GPUIndex32)
8483
import Web.GPU.PredefinedColorSpace (PredefinedColorSpace)
@@ -160,8 +159,8 @@ type GPUTextureDescriptorOptional =
160159
, label :: Undefinable String
161160
)
162161

163-
type GPUTextureDescriptor gpuExtent3D =
164-
( size :: gpuExtent3D
162+
type GPUTextureDescriptor =
163+
( size :: GPUExtent3D
165164
, usage :: GPUTextureUsage
166165
, format :: GPUTextureFormat
167166
| GPUTextureDescriptorOptional
@@ -178,9 +177,6 @@ defaultGPUTextureDescriptorOptions =
178177

179178
data TextureDescriptor = TextureDescriptor
180179

181-
instance AsGPUExtent3D gpuExtent3DProvided gpuExtent3D => ConvertOption TextureDescriptor "size" gpuExtent3DProvided gpuExtent3D where
182-
convertOption _ _ = asGPUExtent3D
183-
184180
instance ConvertOption TextureDescriptor "mipLevelCount" GPUIntegerCoordinate (Undefinable GPUIntegerCoordinate) where
185181
convertOption _ _ = defined
186182

@@ -196,17 +192,17 @@ instance ConvertOption TextureDescriptor "viewFormats" (Array GPUTextureFormat)
196192
instance ConvertOption TextureDescriptor "label" String (Undefinable String) where
197193
convertOption _ _ = defined
198194

199-
foreign import createTextureImpl :: forall gpuExtent3D. GPUDevice -> { | GPUTextureDescriptor gpuExtent3D } -> Effect GPUTexture
195+
foreign import createTextureImpl :: GPUDevice -> { | GPUTextureDescriptor } -> Effect GPUTexture
200196

201197
createTexture
202-
:: forall provided gpuExtent3D
203-
. ConvertOptionsWithDefaults TextureDescriptor { | GPUTextureDescriptorOptional } { | provided } { | GPUTextureDescriptor gpuExtent3D }
198+
:: forall provided
199+
. ConvertOptionsWithDefaults TextureDescriptor { | GPUTextureDescriptorOptional } { | provided } { | GPUTextureDescriptor }
204200
=> GPUDevice
205201
-> { | provided }
206202
-> Effect GPUTexture
207203
createTexture gpuDevice provided = createTextureImpl gpuDevice all
208204
where
209-
all :: { | GPUTextureDescriptor gpuExtent3D }
205+
all :: { | GPUTextureDescriptor }
210206
all = convertOptionsWithDefaults
211207
TextureDescriptor
212208
defaultGPUTextureDescriptorOptions

0 commit comments

Comments
 (0)