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 9084ebd..671211e 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) @@ -49,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 3e3470d..718d4d7 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) @@ -36,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..1f7c4dc 100644 --- a/src/adapter.jl +++ b/src/adapter.jl @@ -40,7 +40,11 @@ function requestAdapter(; backendType = getDefaultBackendType() adapterOptions = cStruct(WGPURequestAdapterOptions) - adapterOptions.compatibleSurface = C_NULL + if (typeof(canvas) == FallbackCanvas) || (canvas == nothing) + adapterOptions.compatibleSurface = C_NULL + else + adapterOptions.compatibleSurface = canvas.surfaceRef[] + end adapterOptions.powerPreference = powerPreference adapterOptions.forceFallbackAdapter = false diff --git a/src/device.jl b/src/device.jl index fdcd149..71bbfa9 100644 --- a/src/device.jl +++ b/src/device.jl @@ -122,8 +122,11 @@ function requestDevice( ) end -function getDefaultDevice(; backendType = getDefaultBackendType()) - adapter = WGPUCore.requestAdapter() +function getDefaultDevice(canvas; backendType = getDefaultBackendType()) + adapter = WGPUCore.requestAdapter(;canvas=canvas) device = requestDevice(adapter) + if canvas != nothing + canvas.device = device + end return device end 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,