@@ -27,69 +27,80 @@ shader = wgpuDeviceCreateShaderModule(
2727)
2828
2929# # StagingBuffer
30+ stagingLabel = " StagingBuffer"
3031
3132stagingBuffer = wgpuDeviceCreateBuffer (
32- device. internal[],
33- cStruct (
34- WGPUBufferDescriptor;
35- nextInChain = C_NULL ,
36- label = toCString ( " StagingBuffer " ),
37- usage = WGPUBufferUsage_MapRead | WGPUBufferUsage_CopyDst,
38- size = sizeof (numbers),
39- mappedAtCreation = false
40- ) |> ptr
41- )
33+ device. internal[],
34+ cStruct (
35+ WGPUBufferDescriptor;
36+ nextInChain = C_NULL ,
37+ label = WGPUStringView ( pointer (stagingLabel), length (stagingLabel) ),
38+ usage = ( WGPUBufferUsage_MapRead | WGPUBufferUsage_CopyDst) |> WGPUBufferUsage ,
39+ size = sizeof (numbers),
40+ mappedAtCreation = false
41+ ) |> ptr
42+ )
4243# # StorageBuffer
43-
44+ storageLabel = " StorageBuffer "
4445storageBuffer = wgpuDeviceCreateBuffer (
45- device. internal[],
46- cStruct (
47- WGPUBufferDescriptor;
48- nextInChain = C_NULL ,
49- label = toCString (" StorageBuffer" ),
50- usage = WGPUBufferUsage_Storage | WGPUBufferUsage_CopyDst | WGPUBufferUsage_CopySrc,
51- size = sizeof (numbers),
52- mappedAtCreation = false
53- ) |> ptr
54- )
46+ device. internal[],
47+ cStruct (
48+ WGPUBufferDescriptor;
49+ nextInChain = C_NULL ,
50+ label = WGPUStringView (pointer (storageLabel), length (storageLabel)),
51+ usage = WGPUBufferUsage ( WGPUBufferUsage_Storage | WGPUBufferUsage_CopyDst | WGPUBufferUsage_CopySrc ),
52+ size = sizeof (numbers),
53+ mappedAtCreation = false
54+ ) |> ptr
55+ )
56+
57+ entries = WGPUBindGroupLayoutEntry[]
58+
59+ entry = WGPUBindGroupLayoutEntry |> CStruct
60+
61+
62+ entries = cStruct (
63+ WGPUBindGroupLayoutEntry;
64+ nextInChain = C_NULL ,
65+ binding = 0 ,
66+ visibility = WGPUShaderStage_Compute,
67+ buffer = cStruct (
68+ WGPUBufferBindingLayout;
69+ type= WGPUBufferBindingType_Storage
70+ ) |> concrete,
71+ sampler = cStruct (
72+ WGPUSamplerBindingLayout;
73+ ) |> concrete,
74+ texture = cStruct (
75+ WGPUTextureBindingLayout;
76+ ) |> concrete,
77+ storageTexture = cStruct (
78+ WGPUStorageTextureBindingLayout;
79+ ) |> concrete
80+ )
5581
82+ bglayoutDescLabel = " Bind Group Layout"
83+ layoutdesc = cStruct (
84+ WGPUBindGroupLayoutDescriptor;
85+ label = WGPUStringView (pointer (bglayoutDescLabel), length (bglayoutDescLabel)),
86+ entries = entries |> ptr,
87+ entryCount = 1
88+ )
5689
5790# # BindGroupLayout
5891bindGroupLayout = wgpuDeviceCreateBindGroupLayout (
5992 device. internal[],
60- cStruct (
61- WGPUBindGroupLayoutDescriptor;
62- label = toCString (" Bind Group Layout" ),
63- entries = cStruct (
64- WGPUBindGroupLayoutEntry;
65- nextInChain = C_NULL ,
66- binding = 0 ,
67- visibility = WGPUShaderStage_Compute,
68- buffer = cStruct (
69- WGPUBufferBindingLayout;
70- type= WGPUBufferBindingType_Storage
71- ) |> concrete,
72- sampler = cStruct (
73- WGPUSamplerBindingLayout;
74- ) |> concrete,
75- texture = cStruct (
76- WGPUTextureBindingLayout;
77- ) |> concrete,
78- storageTexture = cStruct (
79- WGPUStorageTextureBindingLayout;
80- ) |> concrete
81- ) |> ptr,
82- entryCount = 1
83- ) |> ptr
93+ layoutdesc |> ptr
8494)
8595
8696# # BindGroup
8797
98+ bgLabel = " Bind Group"
8899bindGroup = wgpuDeviceCreateBindGroup (
89100 device. internal[],
90101 cStruct (
91102 WGPUBindGroupDescriptor;
92- label = toCString ( " Bind Group " ),
103+ label = WGPUStringView ( pointer (bgLabel), length (bgLabel) ),
93104 layout = bindGroupLayout,
94105 entries = cStruct (
95106 WGPUBindGroupEntry;
@@ -119,15 +130,16 @@ pipelineLayout = wgpuDeviceCreatePipelineLayout(
119130
120131# # TODO fix
121132
133+ computeLabel = " compute main"
122134compute = cStruct (
123135 WGPUProgrammableStageDescriptor;
124136 _module = shader,
125- entryPoint = toCString ( " main " )
137+ entryPoint = WGPUStringView ( pointer (computeLabel), length (computeLabel) )
126138) |> concrete
127139
128140
129141# # compute pipeline
130-
142+ computePipelineLabel = " main "
131143computePipeline = wgpuDeviceCreateComputePipeline (
132144 device. internal[],
133145 cStruct (
@@ -136,28 +148,29 @@ computePipeline = wgpuDeviceCreateComputePipeline(
136148 compute = cStruct (
137149 WGPUProgrammableStageDescriptor;
138150 _module = shader,
139- entryPoint = toCString ( " main " )
151+ entryPoint = WGPUStringView ( pointer (computePipelineLabel), length (computePipelineLabel) )
140152 ) |> concrete
141153 ) |> ptr
142154)
143155
144156# # encoder
145-
157+ cmdEncoderLabel = " Command Encoder "
146158encoder = wgpuDeviceCreateCommandEncoder (
147159 device. internal[],
148160 cStruct (
149161 WGPUCommandEncoderDescriptor;
150- label = toCString ( " Command Encoder " )
162+ label = WGPUStringView ( pointer (cmdEncoderLabel), length (cmdEncoderLabel) )
151163 ) |> ptr
152164 )
153165
154166
155167# # computePass
168+ computePassLabel = " Compute Pass"
156169computePass = wgpuCommandEncoderBeginComputePass (
157170 encoder,
158171 cStruct (
159172 WGPUComputePassDescriptor;
160- label = toCString ( " Compute Pass " )
173+ label = WGPUStringView ( pointer (computePassLabel), length (computePassLabel) )
161174 ) |> ptr
162175)
163176
@@ -192,18 +205,20 @@ wgpuQueueSubmit(queue, 1, Ref(cmdBuffer))
192205
193206# # MapAsync
194207
195- asyncstatus = Ref (WGPUBufferMapAsyncStatus (3 ))
208+ asyncstatus = Ref (WGPUMapAsyncStatus (3 ))
196209
197210function readBufferMap (
198- status:: WGPUBufferMapAsyncStatus ,
211+ status:: WGPUMapAsyncStatus ,
199212 userData)
200213 asyncstatus[] = status
201214 return nothing
202215end
203216
204- readbuffermap = @cfunction (readBufferMap, Cvoid, (WGPUBufferMapAsyncStatus, Ptr{Cvoid}))
217+ readbuffermap = @cfunction (readBufferMap, Cvoid, (WGPUMapAsyncStatus, Ptr{Cvoid}))
218+ readBufferMapInfo = WGPUBufferMapCallbackInfo |> CStruct
219+ readBufferMapInfo. callback = readbuffermap
205220
206- wgpuBufferMapAsync (stagingBuffer, WGPUMapMode_Read, 0 , sizeof (numbers), readbuffermap, C_NULL )
221+ wgpuBufferMapAsync (stagingBuffer, WGPUMapMode_Read, 0 , sizeof (numbers), readBufferMapInfo |> concrete )
207222
208223print (asyncstatus[])
209224
0 commit comments