Skip to content

Commit c2ebb31

Browse files
committed
src changes for upstream v24.0.0.1
1 parent a98599d commit c2ebb31

File tree

8 files changed

+108
-97
lines changed

8 files changed

+108
-97
lines changed

src/WGPUCore.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function createTexture(
7070

7171
textureDesc = cStruct(
7272
WGPUTextureDescriptor;
73-
label = toCString(label),
73+
label = toWGPUString(label),
7474
size = textureExtent |> concrete,
7575
mipLevelCount = mipLevelCount,
7676
sampleCount = sampleCount,
@@ -121,7 +121,7 @@ function createView(gpuTexture::GPUTexture; dimension = nothing)
121121
viewDescriptor =
122122
cStruct(
123123
WGPUTextureViewDescriptor;
124-
label = toCString(gpuTexture.label),
124+
label = toWGPUString(gpuTexture.label),
125125
format = gpuTexture.texInfo["format"],
126126
dimension = dimension,
127127
aspect = WGPUTextureAspect_All,
@@ -167,7 +167,7 @@ function createSampler(
167167
)
168168
desc = cStruct(
169169
WGPUSamplerDescriptor;
170-
label = toCString(label),
170+
label = toWGPUString(label),
171171
addressModeU = addressModeU,
172172
addressModeV = addressModeV,
173173
addressModeW = addressModeW,
@@ -365,7 +365,7 @@ function createBindGroupLayout(gpuDevice, label, entries)
365365
if count > 0
366366
bindGroupLayoutDesc = cStruct(
367367
WGPUBindGroupLayoutDescriptor;
368-
label = toCString(label),
368+
label = toWGPUString(label),
369369
entries = count == 0 ? C_NULL : entries.cEntries |> pointer, # assuming array of entries
370370
entryCount = count,
371371
)
@@ -421,7 +421,7 @@ function createBindGroup(label, gpuDevice, bindingLayout, entries)
421421
if bindingLayout.internal[] != C_NULL && count > 0
422422
bindGroupDesc = GC.@preserve label cStruct(
423423
WGPUBindGroupDescriptor;
424-
label = toCString(label),
424+
label = toWGPUString(label),
425425
layout = bindingLayout.internal[],
426426
entries = count == 0 ? C_NULL : entries.cEntries |> pointer,
427427
entryCount = count,
@@ -479,7 +479,7 @@ function createPipelineLayout(gpuDevice, label, bindingLayouts, bindings)
479479
end
480480
pipelineDescriptor = GC.@preserve bindGroupLayoutArray label cStruct(
481481
WGPUPipelineLayoutDescriptor;
482-
label = toCString(label),
482+
label = toWGPUString(label),
483483
bindGroupLayouts = layoutCount == 0 ? C_NULL : bindGroupLayoutArray |> pointer,
484484
bindGroupLayoutCount = layoutCount,
485485
)
@@ -515,15 +515,15 @@ function createComputeStage(shaderModule, entryPoint::String)
515515
computeStage = cStruct(
516516
WGPUProgrammableStageDescriptor;
517517
_module = shaderModule.internal[],
518-
entryPoint = toCString(entryPoint),
518+
entryPoint = toWGPUString(entryPoint),
519519
)
520520
return ComputeStage(computeStage, entryPoint)
521521
end
522522

523523
function createComputePipeline(gpuDevice, label, pipelinelayout, computeStage)
524524
desc = cStruct(
525525
WGPUComputePipelineDescriptor;
526-
label = toCString(label),
526+
label = toWGPUString(label),
527527
layout = pipelinelayout.internal[],
528528
compute = computeStage.internal |> concrete,
529529
)
@@ -622,7 +622,7 @@ function createEntry(::Type{GPUVertexState}; args...)
622622
aRef = GC.@preserve entryPointArg bufferDescArrayPtr cStruct(
623623
WGPUVertexState;
624624
_module = shaderInternal[],
625-
entryPoint = toCString(entryPointArg),
625+
entryPoint = toWGPUString(entryPointArg),
626626
buffers = length(buffers) == 0 ? C_NULL : bufferDescArrayPtr,
627627
bufferCount = length(buffers),
628628
)
@@ -786,7 +786,7 @@ function createEntry(::Type{GPUFragmentState}; args...)
786786
aref = GC.@preserve entryPointArg ctargets shader cStruct(
787787
WGPUFragmentState;
788788
_module = shader.internal[],
789-
entryPoint = toCString(entryPointArg),
789+
entryPoint = toWGPUString(entryPointArg),
790790
targets = ctargets,
791791
targetCount = targetsLen,
792792
)
@@ -841,7 +841,7 @@ function createRenderPipeline(
841841

842842
pipelineDesc = GC.@preserve vertexState primitiveState depthStencilState multiSampleState fragmentState label cStruct(
843843
WGPURenderPipelineDescriptor;
844-
label = toCString(label),
844+
label = toWGPUString(label),
845845
layout = pipelinelayout.internal[],
846846
vertex = vertexState[] |> concrete,
847847
primitive = primitiveState[] |> concrete,
@@ -1002,7 +1002,7 @@ end
10021002
function createCommandEncoder(gpuDevice, label)
10031003
cmdEncDesc = GC.@preserve label cStruct(
10041004
WGPUCommandEncoderDescriptor;
1005-
label = toCString(label),
1005+
label = toWGPUString(label),
10061006
)
10071007
commandEncoder =
10081008
wgpuDeviceCreateCommandEncoder(
@@ -1019,7 +1019,7 @@ function beginComputePass(
10191019
)
10201020
desc =
10211021
GC.@preserve label cStruct(
1022-
WGPUComputePassDescriptor; label = toCString(label)
1022+
WGPUComputePassDescriptor; label = toWGPUString(label)
10231023
)
10241024
computePass = wgpuCommandEncoderBeginComputePass(cmdEncoder.internal[], desc |> ptr) |> Ref
10251025
GPUComputePassEncoder(label, computePass, cmdEncoder, desc)
@@ -1044,7 +1044,7 @@ function beginRenderPass(
10441044
# Both color and depth attachments requires pointer
10451045
desc = GC.@preserve label cStruct(
10461046
WGPURenderPassDescriptor;
1047-
label = toCString(label),
1047+
label = toWGPUString(label),
10481048
colorAttachments = let ca = colorAttachmentsIn
10491049
length(ca.internal[]) > 0 ? ca.internal[] : C_NULL
10501050
end,
@@ -1098,16 +1098,16 @@ function copyBufferToTexture(
10981098
cOrigin = cStruct(WGPUOrigin3D; origin...)
10991099
cDestination =
11001100
cStruct(
1101-
WGPUImageCopyTexture;
1101+
WGPUTexelCopyTextureInfo;
11021102
texture = source[:texture].internal[],
11031103
mipLevel = get(source, :mipLevel, 0),
11041104
origin = cOrigin |> concrete,
11051105
aspect = getEnum(WGPUTextureAspect, "All"),
11061106
)
1107-
texLayout = cStruct(WGPUTextureDataLayout; destination[:layout]...)
1107+
texLayout = cStruct(WGPUTexelCopyBufferLayout; destination[:layout]...)
11081108
cSource =
11091109
cStruct(
1110-
WGPUImageCopyBuffer;
1110+
WGPUTexelCopyBufferInfo;
11111111
buffer = destination[:buffer].internal[],
11121112
layout = texLayout |> concrete,
11131113
)
@@ -1136,19 +1136,19 @@ function copyTextureToBuffer(
11361136
cOrigin = cStruct(WGPUOrigin3D; origin...)
11371137
cSource =
11381138
cStruct(
1139-
WGPUImageCopyTexture;
1139+
WGPUTexelCopyTextureInfo;
11401140
texture = source[:texture].internal[],
11411141
mipLevel = get(source, :mipLevel, 0),
11421142
origin = cOrigin |> concrete,
11431143
aspect = getEnum(WGPUTextureAspect, "All"),
11441144
)
11451145
textureLayout = cStruct(
1146-
WGPUTextureDataLayout;
1146+
WGPUTexelCopyBufferLayout;
11471147
destination[:layout]..., # should document these obscure
11481148
)
11491149
cDestination =
11501150
cStruct(
1151-
WGPUImageCopyBuffer;
1151+
WGPUTexelCopyBufferInfo;
11521152
buffer = destination[:buffer].internal[],
11531153
layout = textureLayout |> concrete,
11541154
)
@@ -1173,7 +1173,7 @@ function copyTextureToTexture(
11731173

11741174
cSource =
11751175
cStruct(
1176-
WGPUImageCopyTexture;
1176+
WGPUTexelCopyTextureInfo;
11771177
texture = source[:texture].internal[],
11781178
mipLevel = get(source, :mipLevel, 0),
11791179
origin = cOrigin1 |> concrete,
@@ -1185,7 +1185,7 @@ function copyTextureToTexture(
11851185

11861186
cDestination =
11871187
cStruct(
1188-
WGPUImageCopyTexture;
1188+
WGPUTexelCopyTextureInfo;
11891189
texture = destination[:texture].internal[],
11901190
mipLevel = get(destination, :mipLevel, 0),
11911191
origin = cOrigin2 |> concrete,
@@ -1203,7 +1203,7 @@ function copyTextureToTexture(
12031203
end
12041204

12051205
function finish(cmdEncoder::GPUCommandEncoder; label = " CMD ENCODER COMMAND BUFFER ")
1206-
desc = cStruct(WGPUCommandBufferDescriptor; label = toCString(label))
1206+
desc = cStruct(WGPUCommandBufferDescriptor; label = toWGPUString(label))
12071207
cmdEncoderFinish = wgpuCommandEncoderFinish(
12081208
cmdEncoder.internal[],
12091209
desc |> ptr,
@@ -1431,7 +1431,7 @@ function writeTexture(queue::GPUQueue; args...)
14311431

14321432
destination =
14331433
cStruct(
1434-
WGPUImageCopyTexture;
1434+
WGPUTexelCopyTextureInfo;
14351435
texture = texture.internal[],
14361436
mipLevel = mipLevel,
14371437
origin = cOrigin[],
@@ -1443,7 +1443,7 @@ function writeTexture(queue::GPUQueue; args...)
14431443
end
14441444
cDataLayout =
14451445
cStruct(
1446-
WGPUTextureDataLayout;
1446+
WGPUTexelCopyBufferLayout;
14471447
offset = offset,
14481448
bytesPerRow = bytesPerRow,
14491449
rowsPerImage = rowsPerImage,

src/adapter.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ function getAdapterCallback(adapter::Ref{WGPUAdapter})
1515
function request_adapter_callback(
1616
status::WGPURequestAdapterStatus,
1717
returnAdapter::WGPUAdapter,
18-
message::Ptr{Cchar},
18+
message::WGPUStringView,
1919
userData::Ptr{Cvoid},
2020
)
2121
global adapter
2222
# @debug status
2323
if status == WGPURequestAdapterStatus_Success
2424
adapter[] = returnAdapter
2525
elseif message != C_NULL
26-
@error unsafe_string(message)
26+
@error unsafe_string(message.data, message.length)
2727
end
2828
return nothing
2929
end
@@ -51,17 +51,21 @@ function requestAdapter(;
5151
requestAdapterCallback = @cfunction(
5252
getAdapterCallback(adapter),
5353
Cvoid,
54-
(WGPURequestAdapterStatus, WGPUAdapter, Ptr{Cchar}, Ptr{Cvoid})
54+
(WGPURequestAdapterStatus, WGPUAdapter, WGPUStringView, Ptr{Cvoid})
5555
)
5656

57+
callbackInfo = WGPURequestAdapterCallbackInfo |> CStruct
58+
callbackInfo.nextInChain = C_NULL
59+
callbackInfo.userdata1 = adapter[]
60+
callbackInfo.callback = requestAdapterCallback
61+
5762
## request adapter
5863
instance = getWGPUInstance()
5964

6065
wgpuInstanceRequestAdapter(
6166
instance[],
62-
adapterOptions |> ptr,
63-
requestAdapterCallback,
64-
C_NULL
67+
C_NULL,
68+
callbackInfo |> concrete,
6569
)
6670

6771
@assert adapter[] != C_NULL
@@ -70,8 +74,10 @@ function requestAdapter(;
7074

7175
wgpuAdapterGetInfo(adapter[], infos |> ptr)
7276

73-
supportedLimits = cStruct(WGPUSupportedLimits)
74-
cLimits = supportedLimits.limits
77+
nativeLimits = WGPUNativeLimits |> CStruct
78+
79+
supportedLimits = cStruct(WGPULimits)
80+
supportedLimits.nextInChain = nativeLimits.chain.next
7581

7682
wgpuAdapterGetLimits(adapter[], supportedLimits |> ptr)
7783

@@ -80,7 +86,7 @@ function requestAdapter(;
8086
"WGPU",
8187
features,
8288
adapter,
83-
cLimits,
89+
nativeLimits,
8490
supportedLimits,
8591
infos,
8692
adapterOptions,

src/buffer.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,38 @@ mutable struct GPUBuffer <: Droppable
88
desc::Any
99
end
1010

11-
asyncstatus = Ref(WGPUBufferMapAsyncStatus(3))
11+
asyncstatus = Ref(WGPUMapAsyncStatus(3))
1212

13-
function bufferCallback(status::WGPUBufferMapAsyncStatus, userData)
13+
function bufferCallback(status::WGPUMapAsyncStatus, userData)
1414
asyncstatus[] = status
1515
return nothing
1616
end
1717

1818
function mapRead(gpuBuffer::GPUBuffer)
1919
bufferSize = gpuBuffer.size
2020
buffercallback =
21-
@cfunction(bufferCallback, Cvoid, (WGPUBufferMapAsyncStatus, Ptr{Cvoid}))
21+
@cfunction(bufferCallback, Cvoid, (WGPUMapAsyncStatus, Ptr{Cvoid}))
2222
# Prepare
2323
data = convert(Ptr{UInt8}, Libc.malloc(bufferSize))
24+
25+
buffercallbackInfo = WGPUBufferMapCallbackInfo |> CStruct
26+
buffercallbackInfo.callback = buffercallback
27+
2428
wgpuBufferMapAsync(
2529
gpuBuffer.internal[],
2630
WGPUMapMode_Read,
2731
0,
2832
bufferSize,
29-
buffercallback,
30-
C_NULL,
33+
buffercallbackInfo |> concrete,
3134
)
3235
wgpuDevicePoll(gpuBuffer.device.internal[], true, C_NULL)
3336

34-
if asyncstatus[] != WGPUBufferMapAsyncStatus_Success
37+
if asyncstatus[] != WGPUMapAsyncStatus_Success
3538
@error "Couldn't read buffer data : $asyncstatus"
36-
asyncstatus[] = WGPUBufferMapAsyncStatus(3)
39+
asyncstatus[] = WGPUMapAsyncStatus(3)
3740
end
3841

39-
asyncstatus[] = WGPUBufferMapAsyncStatus(0)
42+
asyncstatus[] = WGPUMapAsyncStatus(0)
4043

4144
src_ptr =
4245
convert(Ptr{UInt8}, wgpuBufferGetMappedRange(gpuBuffer.internal[], 0, bufferSize))
@@ -51,24 +54,26 @@ function mapWrite(gpuBuffer::GPUBuffer, data)
5154
bufferSize = gpuBuffer.size
5255
@assert sizeof(data) == bufferSize
5356
buffercallback =
54-
@cfunction(bufferCallback, Cvoid, (WGPUBufferMapAsyncStatus, Ptr{Cvoid}))
57+
@cfunction(bufferCallback, Cvoid, (WGPUMapAsyncStatus, Ptr{Cvoid}))
58+
59+
buffercallbackInfo = WGPUBufferMapCallbackInfo |> CStruct
60+
buffercallbackInfo.callback = buffercallback
5561

5662
wgpuBufferMapAsync(
5763
gpuBuffer.internal,
5864
WGPUMapMode_Write,
5965
0,
6066
bufferSize,
61-
buffercallback,
62-
C_NULL,
67+
buffercallbackInfo |> concrete,
6368
)
6469
wgpuDevicePoll(gpuBuffer.device.internal, true)
6570

66-
if asyncstatus[] != WGPUBufferMapAsyncStatus_Success
71+
if asyncstatus[] != WGPUMapAsyncStatus_Success
6772
@error "Couldn't write buffer data: $asyncstatus"
68-
asyncstatus[] = WGPUBufferMapAsyncStatus(3)
73+
asyncstatus[] = WGPUMapAsyncStatus(3)
6974
end
7075

71-
asyncstatus[] = WGPUBufferMapAsyncStatus(0)
76+
asyncstatus[] = WGPUMapAsyncStatus(0)
7277

7378
src_ptr = wgpuBufferGetMappedRange(gpuBuffer.internal[], 0, bufferSize)
7479
src_ptr = convert(Ptr{UInt8}, src_ptr)
@@ -80,7 +85,7 @@ function mapWrite(gpuBuffer::GPUBuffer, data)
8085
end
8186

8287
function createBuffer(label, gpuDevice, bufSize, usage, mappedAtCreation)
83-
labelPtr = toCString(label)
88+
labelPtr = toWGPUString(label)
8489
desc = cStruct(
8590
WGPUBufferDescriptor;
8691
label = labelPtr,

src/canvas.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function getContext(gpuCanvas::FallbackCanvas)
101101
nothing, # currentTexture::Any
102102
nothing, # currentTextureView::Any
103103
nothing, # format::WGPUTextureFormat
104-
getEnum(WGPUTextureUsage, ["RenderAttachment"]), # usage::WGPUTextureUsage
104+
WGPUTextureUsage_RenderAttachment, # usage::WGPUTextureUsage
105105
nothing, # compositingAlphaMode::Any
106106
nothing, # size::Any
107107
(500, 500), # physicalSize::Any
@@ -179,7 +179,7 @@ function createNewTextureMaybe(canvasCntxt::GPUCanvasContextOffscreen)
179179
1,
180180
getEnum(WGPUTextureDimension, "2D"),
181181
canvasCntxt.format,
182-
canvasCntxt.usage | getEnum(WGPUTextureUsage, "CopySrc"),
182+
(canvasCntxt.usage | WGPUTextureUsage_CopySrc) |> WGPUTextureUsage,
183183
)
184184
canvasCntxt.currentTextureView = WGPUCore.createView(canvasCntxt.currentTexture)
185185
end

0 commit comments

Comments
 (0)