Skip to content

Commit 02d0b98

Browse files
authored
Merge pull request JuliaWGPU#3 from arhik/main
update to v0.19.1.1 upstream version
2 parents 6ae1b75 + aaf3b37 commit 02d0b98

File tree

3 files changed

+98
-45
lines changed

3 files changed

+98
-45
lines changed

src/glfwWindows.jl

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function WGPUCore.getContext(gpuCanvas::GLFWWinCanvas)
122122
gpuCanvas.device, # device::Any
123123
WGPUTextureFormat_R8Unorm, # format::WGPUTextureFormat
124124
WGPUCore.getEnum(WGPUTextureUsage, ["RenderAttachment", "CopySrc"]), # usage::WGPUTextureUsage
125-
nothing, # compositingAlphaMode::Any
125+
WGPUCompositeAlphaMode_Premultiplied, # compositingAlphaMode::Any
126126
nothing, # size::Any
127127
gpuCanvas.size, # physicalSize::Any
128128
nothing, # pixelRatio::Any
@@ -190,51 +190,67 @@ function WGPUCore.getCurrentTexture(cntxt::GPUCanvasContext)
190190
# if cntxt.device.internal[] == C_NULL
191191
# @error "context must be configured before request for texture"
192192
# end
193+
canvas = cntxt.canvasRef[]
194+
surface = canvas.surfaceRef[]
195+
surfaceTexture = cStruct(WGPUSurfaceTexture;)
193196
if cntxt.currentTexture == nothing
194-
createNativeSwapChainMaybe(cntxt)
195-
id = wgpuSwapChainGetCurrentTextureView(cntxt.internal[]) |> Ref
197+
configureSurface(cntxt)
198+
wgpuSurfaceGetCurrentTexture(surface, surfaceTexture|>ptr)
196199
size = (cntxt.surfaceSize..., 1)
200+
currentTexture = wgpuTextureCreateView(surfaceTexture.texture, C_NULL) |> Ref
197201
cntxt.currentTexture =
198-
WGPUCore.GPUTextureView("swap chain", id, cntxt.device, nothing, size, nothing |> Ref)
202+
WGPUCore.GPUTextureView("swap chain", currentTexture, cntxt.device, nothing, size, nothing |> Ref)
199203
end
200204
return cntxt.currentTexture
201205
end
202206

203207
function WGPUCore.present(cntxt::GPUCanvasContext)
204-
if cntxt.internal[] != C_NULL && cntxt.currentTexture.internal[] != C_NULL
205-
wgpuSwapChainPresent(cntxt.internal[])
208+
canvas = cntxt.canvasRef[]
209+
if cntxt.currentTexture.internal[] != C_NULL
210+
wgpuSurfacePresent(canvas.surfaceRef[])
206211
end
207212
WGPUCore.destroy(cntxt.currentTexture)
208213
cntxt.currentTexture = nothing
209214
end
210215

211-
function createNativeSwapChainMaybe(canvasCntxt::GPUCanvasContext)
216+
function configureSurface(canvasCntxt::GPUCanvasContext)
212217
canvas = canvasCntxt.canvasRef[]
213218
pSize = canvasCntxt.physicalSize
214219
if pSize == canvasCntxt.surfaceSize
215220
return
216221
end
217222
canvasCntxt.surfaceSize = pSize
218223
canvasCntxt.usage = WGPUCore.getEnum(WGPUTextureUsage, ["RenderAttachment", "CopySrc"])
219-
presentMode = WGPUPresentMode_Immediate # TODO hardcoded (for other options ref https://docs.rs/wgpu/latest/wgpu/enum.PresentMode.html)
220-
swapChain =
224+
presentMode = WGPUPresentMode_Fifo # TODO hardcoded (for other options ref https://docs.rs/wgpu/latest/wgpu/enum.PresentMode.html)
225+
surfaceCapabilities = cStruct(WGPUSurfaceCapabilities;)
226+
227+
wgpuSurfaceGetCapabilities(
228+
canvas.surfaceRef[],
229+
canvas.device.internal[],
230+
surfaceCapabilities |> ptr
231+
)
232+
233+
surfaceConfiguration =
221234
cStruct(
222-
WGPUSwapChainDescriptor;
235+
WGPUSurfaceConfiguration;
236+
device = canvasCntxt.device.internal[],
223237
usage = canvasCntxt.usage,
224238
format = canvasCntxt.format,
239+
viewFormatCount = 1,
240+
viewFormats = [canvasCntxt.format] |> pointer,
241+
alphaMode = WGPUCompositeAlphaMode_Opaque,
225242
width = max(1, pSize[1]),
226243
height = max(1, pSize[2]),
227244
presentMode = presentMode,
245+
nextInChain = C_NULL,
228246
)
229247
if canvasCntxt.surfaceId == nothing
230248
canvasCntxt.surfaceId = getSurfaceIdFromCanvas(canvas)
231249
end
232-
canvasCntxt.internal =
233-
wgpuDeviceCreateSwapChain(
234-
canvasCntxt.device.internal[],
235-
canvasCntxt.surfaceId,
236-
swapChain |> ptr,
237-
) |> Ref
250+
wgpuSurfaceConfigure(
251+
canvas.surfaceRef[],
252+
surfaceConfiguration |> ptr,
253+
)
238254
end
239255

240256
function WGPUCore.destroyWindow(canvas::GLFWWinCanvas)

src/linuxglfw.jl

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,30 @@ function WGPUCore.getCurrentTexture(cntxt::GPUCanvasContext)
197197
# if cntxt.device.internal[] == C_NULL
198198
# @error "context must be configured before request for texture"
199199
# end
200+
canvas = cntxt.canvasRef[]
201+
surface = canvas.surfaceRef[]
202+
surfaceTexture = cStruct(WGPUSurfaceTexture;)
200203
if cntxt.currentTexture == nothing
201-
createNativeSwapChainMaybe(cntxt)
202-
id = wgpuSwapChainGetCurrentTextureView(cntxt.internal[]) |> Ref
204+
configureSurface(cntxt)
205+
wgpuSurfaceGetCurrentTexture(surface, surfaceTexture |> ptr)
203206
size = (cntxt.surfaceSize..., 1)
207+
currentTexture = wgpuTextureCreateView(surfaceTexture.texture, C_NULL) |> Ref
204208
cntxt.currentTexture =
205-
WGPUCore.GPUTextureView("swap chain", id, cntxt.device, nothing, size, nothing |> Ref)
209+
WGPUCore.GPUTextureView("swap chain", currentTexture, cntxt.device, nothing, size, nothing |> Ref)
206210
end
207211
return cntxt.currentTexture
208212
end
209213

210214
function WGPUCore.present(cntxt::GPUCanvasContext)
211-
if cntxt.internal[] != C_NULL && cntxt.currentTexture.internal[] != C_NULL
212-
wgpuSwapChainPresent(cntxt.internal[])
215+
canvas = cntxt.canvasRef[]
216+
if cntxt.currentTexture.internal[] != C_NULL
217+
wgpuSurfacePresent(canvas.surfaceRef[])
213218
end
214219
WGPUCore.destroy(cntxt.currentTexture)
215220
cntxt.currentTexture = nothing
216221
end
217222

218-
function createNativeSwapChainMaybe(canvasCntxt::GPUCanvasContext)
223+
function configureSurface(canvasCntxt::GPUCanvasContext)
219224
canvas = canvasCntxt.canvasRef[]
220225
pSize = canvasCntxt.physicalSize
221226
if pSize == canvasCntxt.surfaceSize
@@ -224,24 +229,36 @@ function createNativeSwapChainMaybe(canvasCntxt::GPUCanvasContext)
224229
canvasCntxt.surfaceSize = pSize
225230
canvasCntxt.usage = WGPUCore.getEnum(WGPUTextureUsage, ["RenderAttachment", "CopySrc"])
226231
presentMode = WGPUPresentMode_Fifo
227-
swapChain =
232+
233+
surfaceCapabilities = cStruct(WGPUSurfaceCapabilities;)
234+
235+
wgpuSurfaceGetCapabilities(
236+
canvas.surfaceRef[],
237+
canvas.device.internal[],
238+
surfaceCapabilities |> ptr
239+
)
240+
241+
surfaceConfiguration =
228242
cStruct(
229-
WGPUSwapChainDescriptor;
243+
WGPUSurfaceConfiguration;
244+
device = canvasCntxt.device.internal[],
230245
usage = canvasCntxt.usage,
231246
format = canvasCntxt.format,
247+
viewFormatCount = 1,
248+
viewFormats = [canvasCntxt.format] |> pointer,
249+
alphaMode = WGPUCompositeAlphaMode_Opaque,
232250
width = max(1, pSize[1]),
233251
height = max(1, pSize[2]),
234252
presentMode = presentMode,
253+
nextInChain = C_NULL,
235254
)
236255
if canvasCntxt.surfaceId == nothing
237256
canvasCntxt.surfaceId = getSurfaceIdFromCanvas(canvas)
238257
end
239-
canvasCntxt.internal =
240-
wgpuDeviceCreateSwapChain(
241-
canvasCntxt.device.internal[],
242-
canvasCntxt.surfaceId,
243-
swapChain |> ptr,
244-
) |> Ref
258+
wgpuSurfaceConfigure(
259+
canvas.surfaceRef[],
260+
surfaceConfiguration |> ptr,
261+
)
245262
end
246263

247264
function WGPUCore.destroyWindow(canvas::GLFWLinuxCanvas)

src/metalglfw.jl

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function WGPUCore.getContext(gpuCanvas::GLFWMacCanvas)
158158
gpuCanvas.device, # device::Any
159159
WGPUTextureFormat(0), # format::WGPUTextureFormat
160160
WGPUTextureUsage_RenderAttachment, # usage::WGPUTextureUsage
161-
nothing, # compositingAlphaMode::Any
161+
WGPUCompositeAlphaMode_Premultiplied, # compositingAlphaMode::Any
162162
nothing, # size::Any
163163
gpuCanvas.size, # physicalSize::Any
164164
nothing, # pixelRatio::Any
@@ -186,6 +186,7 @@ function WGPUCore.configure(
186186
canvasContext.usage = usage
187187
canvasContext.compositingAlphaMode = compositingAlphaMode
188188
canvasContext.size = size
189+
189190
end
190191

191192
function WGPUCore.unconfigure(canvasContext::GPUCanvasContext)
@@ -227,25 +228,30 @@ function WGPUCore.getCurrentTexture(cntxt::GPUCanvasContext)
227228
# if cntxt.device.internal[] == C_NULL
228229
# @error "context must be configured before request for texture"
229230
# end
231+
canvas = cntxt.canvasRef[]
232+
surface = canvas.surfaceRef[]
233+
surfaceTexture = cStruct(WGPUSurfaceTexture;)
230234
if cntxt.currentTexture == nothing
231-
createNativeSwapChainMaybe(cntxt)
232-
id = wgpuSwapChainGetCurrentTextureView(cntxt.internal[]) |> Ref
235+
configureSurface(cntxt)
236+
wgpuSurfaceGetCurrentTexture(surface, surfaceTexture|>ptr)
233237
size = (cntxt.surfaceSize..., 1)
238+
currentTexture = wgpuTextureCreateView(surfaceTexture.texture, C_NULL) |> Ref
234239
cntxt.currentTexture =
235-
WGPUCore.GPUTextureView("swap chain", id, cntxt.device, nothing, size, nothing |> Ref)
240+
WGPUCore.GPUTextureView("swap chain", currentTexture, cntxt.device, nothing, size, nothing |> Ref)
236241
end
237242
return cntxt.currentTexture
238243
end
239244

240245
function WGPUCore.present(cntxt::GPUCanvasContext)
241-
if cntxt.internal[] != C_NULL && cntxt.currentTexture.internal[] != C_NULL
242-
wgpuSwapChainPresent(cntxt.internal[])
246+
canvas = cntxt.canvasRef[]
247+
if cntxt.currentTexture.internal[] != C_NULL
248+
wgpuSurfacePresent(canvas.surfaceRef[])
243249
end
244250
WGPUCore.destroy(cntxt.currentTexture)
245251
cntxt.currentTexture = nothing
246252
end
247253

248-
function createNativeSwapChainMaybe(canvasCntxt::GPUCanvasContext)
254+
function configureSurface(canvasCntxt::GPUCanvasContext)
249255
canvas = canvasCntxt.canvasRef[]
250256
pSize = canvasCntxt.physicalSize
251257
if pSize == canvasCntxt.surfaceSize
@@ -254,24 +260,38 @@ function createNativeSwapChainMaybe(canvasCntxt::GPUCanvasContext)
254260
canvasCntxt.surfaceSize = pSize
255261
canvasCntxt.usage = WGPUTextureUsage_RenderAttachment
256262
presentMode = WGPUPresentMode_Fifo
257-
swapChain =
263+
264+
surfaceCapabilities = cStruct(
265+
WGPUSurfaceCapabilities;
266+
)
267+
268+
wgpuSurfaceGetCapabilities(
269+
canvas.surfaceRef[],
270+
canvas.device.internal[],
271+
surfaceCapabilities |> ptr
272+
)
273+
274+
surfaceConfiguration =
258275
cStruct(
259-
WGPUSwapChainDescriptor;
276+
WGPUSurfaceConfiguration;
277+
device = canvasCntxt.device.internal[],
260278
usage = canvasCntxt.usage,
261279
format = canvasCntxt.format,
280+
viewFormatCount=1,
281+
viewFormats = [canvasCntxt.format] |> pointer,
282+
alphaMode=WGPUCompositeAlphaMode_Opaque,
262283
width = max(1, pSize[1]),
263284
height = max(1, pSize[2]),
264285
presentMode = presentMode,
286+
nextInChain=C_NULL
265287
)
266288
if canvasCntxt.surfaceId == nothing
267289
canvasCntxt.surfaceId = getSurfaceIdFromCanvas(canvas)
268290
end
269-
canvasCntxt.internal =
270-
wgpuDeviceCreateSwapChain(
271-
canvasCntxt.device.internal[],
272-
canvasCntxt.surfaceId,
273-
swapChain |> ptr,
274-
) |> Ref
291+
wgpuSurfaceConfigure(
292+
canvas.surfaceRef[],
293+
surfaceConfiguration |> ptr,
294+
)
275295
end
276296

277297
function WGPUCore.destroyWindow(canvas::GLFWMacCanvas)

0 commit comments

Comments
 (0)