Skip to content

Commit 637c5ef

Browse files
committed
examples with upstream v24.0.01 changes
1 parent 705c6f0 commit 637c5ef

File tree

3 files changed

+88
-69
lines changed

3 files changed

+88
-69
lines changed

examples/capture.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ bufferDimensions = BufferDimensions(width, height)
2929

3030
bufferSize = bufferDimensions.padded_bytes_per_row * bufferDimensions.height
3131

32+
outputBufferLabel = "OutputBuffer"
3233
outputBuffer = wgpuDeviceCreateBuffer(
3334
gpuDevice.internal[],
3435
cStruct(
3536
WGPUBufferDescriptor;
3637
nextInChain = C_NULL,
37-
label = WGPUCore.toCString("Output Buffer"),
38-
usage = WGPUBufferUsage_MapRead | WGPUBufferUsage_CopyDst,
38+
label = WGPUStringView(pointer(outputBufferLabel), length(outputBufferLabel)),
39+
usage = WGPUBufferUsage(WGPUBufferUsage_MapRead | WGPUBufferUsage_CopyDst),
3940
size = bufferSize,
4041
mappedAtCreation = false,
4142
) |> ptr
@@ -57,13 +58,13 @@ texture = wgpuDeviceCreateTexture(
5758
cStruct(
5859
WGPUTextureDescriptor;
5960
nextInChain = C_NULL,
60-
label = C_NULL,
61+
label = WGPUStringView(C_NULL, 0),
6162
size = textureExtent |> ptr |> unsafe_load,
6263
mipLevelCount = 1,
6364
sampleCount = 1,
6465
dimension = WGPUTextureDimension_2D,
6566
format = WGPUTextureFormat_RGBA8UnormSrgb,
66-
usage = WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_CopySrc,
67+
usage = WGPUTextureUsage(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_CopySrc),
6768
) |> ptr
6869
)
6970

@@ -115,20 +116,20 @@ wgpuRenderPassEncoderRelease(renderPass)
115116
wgpuCommandEncoderCopyTextureToBuffer(
116117
encoder,
117118
cStruct(
118-
WGPUImageCopyTexture;
119+
WGPUTexelCopyTextureInfo;
119120
texture = texture,
120121
mipLevel = 0,
121122
origin = WGPUOrigin3D(0, 0, 0),
122123
) |> ptr,
123124
cStruct(
124-
WGPUImageCopyBuffer;
125+
WGPUTexelCopyBufferInfo;
125126
buffer = outputBuffer,
126127
layout = cStruct(
127-
WGPUTextureDataLayout;
128+
WGPUTexelCopyBufferLayout;
128129
offset = 0,
129130
bytesPerRow = bufferDimensions.padded_bytes_per_row,
130131
rowsPerImage = WGPU_COPY_STRIDE_UNDEFINED,
131-
) |> ptr |> unsafe_load,
132+
) |> concrete,
132133
) |> ptr,
133134
textureExtent |> ptr,
134135
)
@@ -146,16 +147,19 @@ cmdBuffer = wgpuCommandEncoderFinish(
146147
wgpuQueueSubmit(queue, 1, Ref(cmdBuffer))
147148

148149
## MapAsync
149-
asyncstatus = Ref(WGPUBufferMapAsyncStatus(3))
150+
asyncstatus = Ref(WGPUMapAsyncStatus(3))
150151

151-
function readBufferMap(status::WGPUBufferMapAsyncStatus, userData)
152+
function readBufferMap(status::WGPUMapAsyncStatus, userData)
152153
asyncstatus[] = status
153154
return nothing
154155
end
155156

156-
readbuffermap = @cfunction(readBufferMap, Cvoid, (WGPUBufferMapAsyncStatus, Ptr{Cvoid}))
157+
readbuffermap = @cfunction(readBufferMap, Cvoid, (WGPUMapAsyncStatus, Ptr{Cvoid}))
158+
bufferMapCallbackInfo = CStruct(WGPUBufferMapCallbackInfo)
159+
bufferMapCallbackInfo.callback = readbuffermap
157160

158-
wgpuBufferMapAsync(outputBuffer, WGPUMapMode_Read, 0, bufferSize, readbuffermap, C_NULL)
161+
162+
wgpuBufferMapAsync(outputBuffer, WGPUMapMode_Read, 0, bufferSize, bufferMapCallbackInfo |> concrete)
159163

160164
print(asyncstatus[])
161165

examples/compute.jl

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,69 +27,80 @@ shader = wgpuDeviceCreateShaderModule(
2727
)
2828

2929
## StagingBuffer
30+
stagingLabel = "StagingBuffer"
3031

3132
stagingBuffer = 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"
4445
storageBuffer = 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
5891
bindGroupLayout = 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"
8899
bindGroup = 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"
122134
compute = 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"
131143
computePipeline = 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"
146158
encoder = 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"
156169
computePass = 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

197210
function readBufferMap(
198-
status::WGPUBufferMapAsyncStatus,
211+
status::WGPUMapAsyncStatus,
199212
userData)
200213
asyncstatus[] = status
201214
return nothing
202215
end
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

208223
print(asyncstatus[])
209224

examples/triangle.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Images
66
using Debugger
77
using WGPUCanvas
88

9-
WGPUCore.SetLogLevel(WGPULogLevel_Debug)
9+
WGPUCore.SetLogLevel(WGPULogLevel_Trace)
1010

1111
shaderSource = Vector{UInt8}(
1212
"""

0 commit comments

Comments
 (0)