Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up stream #2

Merged
merged 7 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/capture.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion examples/cube.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Rotations
using WGPUNative
using GLFW
using StaticArrays
using WGPUCanvas

WGPUCore.SetLogLevel(WGPULogLevel_Debug)

Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion examples/image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using WGPUCore
using LinearAlgebra
using Rotations
using WGPUNative
using WGPUCanvas
using GLFW
using StaticArrays
using Images
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion examples/saveTriangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using WGPUCore
using GLFW

using WGPUNative
using WGPUCanvas
using Images
using Debugger

Expand Down Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion examples/triangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using GLFW
using WGPUNative
using Images
using Debugger
using WGPUCanvas

WGPUCore.SetLogLevel(WGPULogLevel_Debug)

Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions examples/triangleOffscreen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using GLFW
using WGPUNative
using Images
using Debugger
using WGPUCanvas

WGPUCore.SetLogLevel(WGPULogLevel_Debug)

Expand Down
6 changes: 5 additions & 1 deletion src/adapter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions src/device.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/bufferCopyTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

canvas = WGPUCore.getCanvas();

gpuDevice = WGPUCore.getDefaultDevice()
gpuDevice = WGPUCore.getDefaultDevice(canvas)

# GC.gc()

Expand Down
4 changes: 2 additions & 2 deletions test/fragmentStateTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -65,4 +65,4 @@ fs = unsafe_load(fstate.internal[] |> ptr)

Test.@testset "FragmentState" begin
Test.@test unsafe_string(fs.entryPoint) == "fs_main"
end
end
2 changes: 1 addition & 1 deletion test/renderpipelineTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/setVertexBufferTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ vertexData =
) .|> Float32

canvas = WGPUCore.getCanvas()
gpuDevice = WGPUCore.getDefaultDevice()
gpuDevice = WGPUCore.getDefaultDevice(canvas)

(vertexBuffer, tmpData) = WGPUCore.createBufferWithData(
gpuDevice,
Expand Down
Loading