From a06213f67c59716564e8c62e64b0716f33f25382 Mon Sep 17 00:00:00 2001 From: Arhik Date: Thu, 22 Feb 2024 06:00:00 +0530 Subject: [PATCH 1/5] include WGPUCanvas dependency --- examples/cube.jl | 1 + examples/triangle.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/cube.jl b/examples/cube.jl index 9084ebd..625a96a 100644 --- a/examples/cube.jl +++ b/examples/cube.jl @@ -4,6 +4,7 @@ using Rotations using WGPUNative using GLFW using StaticArrays +using WGPUCanvas WGPUCore.SetLogLevel(WGPULogLevel_Debug) diff --git a/examples/triangle.jl b/examples/triangle.jl index 3e3470d..5f5040c 100644 --- a/examples/triangle.jl +++ b/examples/triangle.jl @@ -4,6 +4,7 @@ using GLFW using WGPUNative using Images using Debugger +using WGPUCanvas WGPUCore.SetLogLevel(WGPULogLevel_Debug) From 5c502babe5a4b293099c56cd8b4fd2c2a55bdc2f Mon Sep 17 00:00:00 2001 From: Arhik Date: Fri, 1 Mar 2024 15:32:47 +0530 Subject: [PATCH 2/5] update to wgpu-native v0.19.1.1 --- examples/capture.jl | 4 +++- examples/cube.jl | 2 +- examples/image.jl | 3 ++- examples/saveTriangle.jl | 3 ++- examples/triangle.jl | 2 +- examples/triangleOffscreen.jl | 1 + src/adapter.jl | 2 +- src/device.jl | 5 +++-- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/capture.jl b/examples/capture.jl index 1c6c09f..aa5b0a5 100644 --- a/examples/capture.jl +++ b/examples/capture.jl @@ -1,7 +1,9 @@ ## Load WGPU using WGPUCore using WGPUNative -adapter = WGPUCore.requestAdapter() +using WGPUCanvas +canvas = WGPUCore.getCanvas(:GLFW) +adapter = WGPUCore.requestAdapter(canvas=canvas) gpuDevice = WGPUCore.requestDevice(adapter) width, height = (200, 200) diff --git a/examples/cube.jl b/examples/cube.jl index 625a96a..671211e 100644 --- a/examples/cube.jl +++ b/examples/cube.jl @@ -50,7 +50,7 @@ shaderSource = Vector{UInt8}( ); canvas = WGPUCore.getCanvas(:GLFW) -gpuDevice = WGPUCore.getDefaultDevice() +gpuDevice = WGPUCore.getDefaultDevice(canvas) canvas.device = gpuDevice shadercode = WGPUCore.loadWGSL(shaderSource); cshader = diff --git a/examples/image.jl b/examples/image.jl index b202cab..bd413e5 100644 --- a/examples/image.jl +++ b/examples/image.jl @@ -2,6 +2,7 @@ using WGPUCore using LinearAlgebra using Rotations using WGPUNative +using WGPUCanvas using GLFW using StaticArrays using Images @@ -51,7 +52,7 @@ shaderSource = Vector{UInt8}( ); canvas = WGPUCore.getCanvas(:GLFW) -gpuDevice = WGPUCore.getDefaultDevice() +gpuDevice = WGPUCore.getDefaultDevice(canvas) shadercode = WGPUCore.loadWGSL(shaderSource); cshader = Ref(WGPUCore.createShaderModule(gpuDevice, "shadercode", shadercode.shaderModuleDesc, nothing, nothing)); diff --git a/examples/saveTriangle.jl b/examples/saveTriangle.jl index c92bdfa..49a5ecc 100644 --- a/examples/saveTriangle.jl +++ b/examples/saveTriangle.jl @@ -3,6 +3,7 @@ using WGPUCore using GLFW using WGPUNative +using WGPUCanvas using Images using Debugger @@ -38,7 +39,7 @@ shaderSource = Vector{UInt8}( ); canvas = WGPUCore.getCanvas(:GLFW); -gpuDevice = WGPUCore.getDefaultDevice(); +gpuDevice = WGPUCore.getDefaultDevice(canvas); shadercode = WGPUCore.loadWGSL(shaderSource); cshader = Ref(WGPUCore.createShaderModule(gpuDevice, "shadercode", shadercode.shaderModuleDesc, nothing, nothing)); diff --git a/examples/triangle.jl b/examples/triangle.jl index 5f5040c..718d4d7 100644 --- a/examples/triangle.jl +++ b/examples/triangle.jl @@ -37,7 +37,7 @@ shaderSource = Vector{UInt8}( ); canvas = WGPUCore.getCanvas(:GLFW); -gpuDevice = WGPUCore.getDefaultDevice(); +gpuDevice = WGPUCore.getDefaultDevice(canvas); shadercode = WGPUCore.loadWGSL(shaderSource); cshader = Ref(WGPUCore.createShaderModule(gpuDevice, "shadercode", shadercode.shaderModuleDesc, nothing, nothing)); diff --git a/examples/triangleOffscreen.jl b/examples/triangleOffscreen.jl index 6d37e79..bb0a8f4 100644 --- a/examples/triangleOffscreen.jl +++ b/examples/triangleOffscreen.jl @@ -5,6 +5,7 @@ using GLFW using WGPUNative using Images using Debugger +using WGPUCanvas WGPUCore.SetLogLevel(WGPULogLevel_Debug) diff --git a/src/adapter.jl b/src/adapter.jl index d5dbb18..17a5736 100644 --- a/src/adapter.jl +++ b/src/adapter.jl @@ -40,7 +40,7 @@ function requestAdapter(; backendType = getDefaultBackendType() adapterOptions = cStruct(WGPURequestAdapterOptions) - adapterOptions.compatibleSurface = C_NULL + adapterOptions.compatibleSurface = canvas.surfaceRef[] adapterOptions.powerPreference = powerPreference adapterOptions.forceFallbackAdapter = false diff --git a/src/device.jl b/src/device.jl index fdcd149..b6a90c5 100644 --- a/src/device.jl +++ b/src/device.jl @@ -122,8 +122,9 @@ function requestDevice( ) end -function getDefaultDevice(; backendType = getDefaultBackendType()) - adapter = WGPUCore.requestAdapter() +function getDefaultDevice(canvas; backendType = getDefaultBackendType()) + adapter = WGPUCore.requestAdapter(;canvas=canvas) device = requestDevice(adapter) + canvas.device = device return device end From cc9b291956fc89537a429318d667d551ca3bdf79 Mon Sep 17 00:00:00 2001 From: Arhik Date: Fri, 1 Mar 2024 16:40:34 +0530 Subject: [PATCH 3/5] update to v0.19.1.1 --- src/adapter.jl | 6 +++++- test/bufferCopyTest.jl | 2 +- test/fragmentStateTest.jl | 4 ++-- test/renderpipelineTest.jl | 2 +- test/setVertexBufferTest.jl | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/adapter.jl b/src/adapter.jl index 17a5736..8e1c9c8 100644 --- a/src/adapter.jl +++ b/src/adapter.jl @@ -40,7 +40,11 @@ function requestAdapter(; backendType = getDefaultBackendType() adapterOptions = cStruct(WGPURequestAdapterOptions) - adapterOptions.compatibleSurface = canvas.surfaceRef[] + if (typeof(canvas) == FallbackCanvas) || (typeof(canvas) == nothing) + adapterOptions.compatibleSurface = C_NULL + else + adapterOptions.compatibleSurface = canvas.surfaceRef[] + end adapterOptions.powerPreference = powerPreference adapterOptions.forceFallbackAdapter = false diff --git a/test/bufferCopyTest.jl b/test/bufferCopyTest.jl index 57d2498..727eabe 100644 --- a/test/bufferCopyTest.jl +++ b/test/bufferCopyTest.jl @@ -16,7 +16,7 @@ end canvas = WGPUCore.getCanvas(); -gpuDevice = WGPUCore.getDefaultDevice() +gpuDevice = WGPUCore.getDefaultDevice(canvas) # GC.gc() diff --git a/test/fragmentStateTest.jl b/test/fragmentStateTest.jl index 439a362..dfe8d98 100644 --- a/test/fragmentStateTest.jl +++ b/test/fragmentStateTest.jl @@ -35,7 +35,7 @@ shaderSource = Vector{UInt8}( ); canvas = WGPUCore.getCanvas(); -gpuDevice = WGPUCore.getDefaultDevice(); +gpuDevice = WGPUCore.getDefaultDevice(canvas); shaderinfo = WGPUCore.loadWGSL(shaderSource); cshader = Ref(WGPUCore.createShaderModule(gpuDevice, "shadercode", shaderinfo.shaderModuleDesc, nothing, nothing)); @@ -65,4 +65,4 @@ fs = unsafe_load(fstate.internal[] |> ptr) Test.@testset "FragmentState" begin Test.@test unsafe_string(fs.entryPoint) == "fs_main" -end \ No newline at end of file +end diff --git a/test/renderpipelineTest.jl b/test/renderpipelineTest.jl index 487983e..c2e3a39 100644 --- a/test/renderpipelineTest.jl +++ b/test/renderpipelineTest.jl @@ -37,7 +37,7 @@ shaderSource = """, ) canvas = WGPUCore.getCanvas(); -gpuDevice = WGPUCore.getDefaultDevice(); +gpuDevice = WGPUCore.getDefaultDevice(canvas); shaderInfo = WGPUCore.loadWGSL(shaderSource); cshader = WGPUCore.createShaderModule(gpuDevice, "shadercode", shaderInfo.shaderModuleDesc, nothing, nothing); cshaderRef = cshader |> Ref diff --git a/test/setVertexBufferTest.jl b/test/setVertexBufferTest.jl index 7dc5da6..e6ab37c 100644 --- a/test/setVertexBufferTest.jl +++ b/test/setVertexBufferTest.jl @@ -38,7 +38,7 @@ vertexData = ) .|> Float32 canvas = WGPUCore.getCanvas() -gpuDevice = WGPUCore.getDefaultDevice() +gpuDevice = WGPUCore.getDefaultDevice(canvas) (vertexBuffer, tmpData) = WGPUCore.createBufferWithData( gpuDevice, From ce092440fa72e624754e912c9ec5b1222be92207 Mon Sep 17 00:00:00 2001 From: Arhik Date: Fri, 1 Mar 2024 17:48:27 +0530 Subject: [PATCH 4/5] Update adapter.jl --- src/adapter.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapter.jl b/src/adapter.jl index 8e1c9c8..1f7c4dc 100644 --- a/src/adapter.jl +++ b/src/adapter.jl @@ -40,7 +40,7 @@ function requestAdapter(; backendType = getDefaultBackendType() adapterOptions = cStruct(WGPURequestAdapterOptions) - if (typeof(canvas) == FallbackCanvas) || (typeof(canvas) == nothing) + if (typeof(canvas) == FallbackCanvas) || (canvas == nothing) adapterOptions.compatibleSurface = C_NULL else adapterOptions.compatibleSurface = canvas.surfaceRef[] From b160525956b878dedefc34c684bad455c7d166a3 Mon Sep 17 00:00:00 2001 From: Arhik Date: Fri, 1 Mar 2024 17:54:13 +0530 Subject: [PATCH 5/5] Update device.jl Consider `nothing` backend for example `WGPUCompute` doesnot have GUI backend. --- src/device.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/device.jl b/src/device.jl index b6a90c5..71bbfa9 100644 --- a/src/device.jl +++ b/src/device.jl @@ -125,6 +125,8 @@ end function getDefaultDevice(canvas; backendType = getDefaultBackendType()) adapter = WGPUCore.requestAdapter(;canvas=canvas) device = requestDevice(adapter) - canvas.device = device + if canvas != nothing + canvas.device = device + end return device end