Skip to content

Commit

Permalink
update wgpu to current trunk (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajveermalviya authored Oct 24, 2023
1 parent 24e00f4 commit c373595
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 122 deletions.
206 changes: 125 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

35 changes: 24 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ crate-type = ["lib", "cdylib", "staticlib"]
[features]
default = ["wgsl", "spirv", "glsl", "trace"]

angle = ["wgc/angle"]
# Enables the GLES backend on Windows & macOS
angle = ["wgc/gles"]
# Enables the Vulkan backend on macOS & iOS
vulkan-portability = ["wgc/vulkan"]
wgsl = ["wgc/wgsl"]
spirv = ["naga/spv-in"]
Expand All @@ -30,40 +32,51 @@ trace = ["wgc/trace"]
[dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "9a76c483da4891fb7046c579e36d7c54bdb0b251"
rev = "dd9b282c72a696ffaee100b69e7c8e37668e6149"
version = "0.17"
features = ["raw-window-handle", "gles"]
features = ["raw-window-handle"]

# We want the wgpu-core Metal backend on macOS and iOS.
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "9a76c483da4891fb7046c579e36d7c54bdb0b251"
rev = "dd9b282c72a696ffaee100b69e7c8e37668e6149"
version = "0.17"
features = ["metal"]

# We want the wgpu-core Direct3D backends and OpenGL (via WGL) on Windows.
[target.'cfg(windows)'.dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "9a76c483da4891fb7046c579e36d7c54bdb0b251"
rev = "dd9b282c72a696ffaee100b69e7c8e37668e6149"
version = "0.17"
features = ["dx11", "dx12"]
features = ["dx11", "dx12", "gles"]

[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
# We want the wgpu-core Vulkan backend on Unix (but not emscripten, macOS, iOS) and Windows.
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "9a76c483da4891fb7046c579e36d7c54bdb0b251"
rev = "dd9b282c72a696ffaee100b69e7c8e37668e6149"
version = "0.17"
features = ["vulkan"]

# We want the wgpu-core GLES backend on Unix (but not macOS, iOS).
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "dd9b282c72a696ffaee100b69e7c8e37668e6149"
version = "0.17"
features = ["gles"]

[dependencies.wgt]
package = "wgpu-types"
git = "https://github.com/gfx-rs/wgpu"
rev = "9a76c483da4891fb7046c579e36d7c54bdb0b251"
rev = "dd9b282c72a696ffaee100b69e7c8e37668e6149"
version = "0.17"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "df8107b7"
rev = "e25280df9316434ef7752970016d01a3aede3f17"
version = "0.13.0"

[dependencies]
Expand All @@ -75,7 +88,7 @@ parking_lot = "0.12"
smallvec = "1"

[build-dependencies]
bindgen = "0.66"
bindgen = "0.68"

[workspace]
resolver = "2"
2 changes: 1 addition & 1 deletion examples/capture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include_directories(${CMAKE_SOURCE_DIR}/../ffi)
include_directories(${CMAKE_SOURCE_DIR}/framework)

if (WIN32)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
set(OS_LIBRARIES "-lm -ldl")
elseif(APPLE)
Expand Down
2 changes: 1 addition & 1 deletion examples/compute/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include_directories(${CMAKE_SOURCE_DIR}/../ffi)
include_directories(${CMAKE_SOURCE_DIR}/framework)

if (WIN32)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
set(OS_LIBRARIES "-lm -ldl")
elseif(APPLE)
Expand Down
2 changes: 1 addition & 1 deletion examples/enumerate_adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include_directories(${CMAKE_SOURCE_DIR}/../ffi)
include_directories(${CMAKE_SOURCE_DIR}/framework)

if (WIN32)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
set(OS_LIBRARIES "-lm -ldl")
elseif(APPLE)
Expand Down
2 changes: 1 addition & 1 deletion examples/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif()
include_directories(${CMAKE_SOURCE_DIR}/../ffi)

if (WIN32)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
set(OS_LIBRARIES "-lm -ldl")
elseif(APPLE)
Expand Down
2 changes: 1 addition & 1 deletion examples/texture_arrays/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include_directories(${DEP_GLFW_DIR}/include)

if (WIN32)
add_definitions(-DWGPU_TARGET_WINDOWS)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
add_definitions(-DWGPU_TARGET_LINUX_X11)
set(OS_LIBRARIES "-lm -ldl")
Expand Down
2 changes: 1 addition & 1 deletion examples/triangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include_directories(${DEP_GLFW_DIR}/include)

if (WIN32)
add_definitions(-DWGPU_TARGET_WINDOWS)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll)
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32)
elseif(UNIX AND NOT APPLE)
add_definitions(-DWGPU_TARGET_LINUX_X11)
set(OS_LIBRARIES "-lm -ldl")
Expand Down
27 changes: 21 additions & 6 deletions ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,30 @@ typedef enum WGPULogLevel {
} WGPULogLevel;

typedef enum WGPUInstanceBackend {
WGPUInstanceBackend_Vulkan = 1 << 1,
WGPUInstanceBackend_GL = 1 << 5,
WGPUInstanceBackend_All = 0x00000000,
WGPUInstanceBackend_Vulkan = 1 << 0,
WGPUInstanceBackend_GL = 1 << 1,
WGPUInstanceBackend_Metal = 1 << 2,
WGPUInstanceBackend_DX12 = 1 << 3,
WGPUInstanceBackend_DX11 = 1 << 4,
WGPUInstanceBackend_BrowserWebGPU = 1 << 6,
WGPUInstanceBackend_BrowserWebGPU = 1 << 5,
WGPUInstanceBackend_Primary = WGPUInstanceBackend_Vulkan | WGPUInstanceBackend_Metal |
WGPUInstanceBackend_DX12 |
WGPUInstanceBackend_BrowserWebGPU,
WGPUInstanceBackend_Secondary = WGPUInstanceBackend_GL | WGPUInstanceBackend_DX11,
WGPUInstanceBackend_None = 0x00000000,
WGPUInstanceBackend_Force32 = 0x7FFFFFFF
} WGPUInstanceBackend;
typedef WGPUFlags WGPUInstanceBackendFlags;

typedef enum WGPUInstanceFlag {
WGPUInstanceFlag_Default = 0x00000000,
WGPUInstanceFlag_Debug = 1 << 0,
WGPUInstanceFlag_Validation = 1 << 1,
WGPUInstanceFlag_DiscardHalLabels = 1 << 2,
WGPUInstanceFlag_Force32 = 0x7FFFFFFF
} WGPUInstanceFlag;
typedef WGPUFlags WGPUInstanceFlags;

typedef enum WGPUDx12Compiler {
WGPUDx12Compiler_Undefined = 0x00000000,
WGPUDx12Compiler_Fxc = 0x00000001,
Expand All @@ -71,6 +80,7 @@ typedef enum WGPUGles3MinorVersion {
typedef struct WGPUInstanceExtras {
WGPUChainedStruct chain;
WGPUInstanceBackendFlags backends;
WGPUInstanceFlags flags;
WGPUDx12Compiler dx12ShaderCompiler;
WGPUGles3MinorVersion gles3MinorVersion;
const char * dxilPath;
Expand All @@ -82,14 +92,19 @@ typedef struct WGPUDeviceExtras {
const char * tracePath;
} WGPUDeviceExtras;

typedef struct WGPUNativeLimits {
uint32_t maxPushConstantSize;
uint32_t maxNonSamplerBindings;
} WGPUNativeLimits;

typedef struct WGPURequiredLimitsExtras {
WGPUChainedStruct chain;
uint32_t maxPushConstantSize;
WGPUNativeLimits limits;
} WGPURequiredLimitsExtras;

typedef struct WGPUSupportedLimitsExtras {
WGPUChainedStructOut chain;
uint32_t maxPushConstantSize;
WGPUNativeLimits limits;
} WGPUSupportedLimitsExtras;

typedef struct WGPUPushConstantRange {
Expand Down
66 changes: 48 additions & 18 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub fn map_origin3d(native: &native::WGPUOrigin3D) -> wgt::Origin3d {

#[inline]
pub fn map_instance_backend_flags(flags: native::WGPUInstanceBackend) -> wgt::Backends {
let mut result: wgt::Backends = wgt::Backends::empty();
let mut result = wgt::Backends::empty();
if (flags & native::WGPUInstanceBackend_BrowserWebGPU) != 0 {
result |= wgt::Backends::BROWSER_WEBGPU;
}
Expand All @@ -267,6 +267,21 @@ pub fn map_instance_backend_flags(flags: native::WGPUInstanceBackend) -> wgt::Ba
result
}

#[inline]
pub fn map_instance_flags(flags: native::WGPUInstanceFlag) -> wgt::InstanceFlags {
let mut result = wgt::InstanceFlags::empty();
if (flags & native::WGPUInstanceFlag_Debug) != 0 {
result.insert(wgt::InstanceFlags::DEBUG);
}
if (flags & native::WGPUInstanceFlag_Validation) != 0 {
result.insert(wgt::InstanceFlags::VALIDATION);
}
if (flags & native::WGPUInstanceFlag_DiscardHalLabels) != 0 {
result.insert(wgt::InstanceFlags::DISCARD_HAL_LABELS);
}
result
}

#[inline]
pub fn map_instance_descriptor(
_base: &native::WGPUInstanceDescriptor,
Expand All @@ -283,9 +298,16 @@ pub fn map_instance_descriptor(
};

wgt::InstanceDescriptor {
backends: map_instance_backend_flags(extras.backends as native::WGPUInstanceBackend),
backends: match extras.backends as native::WGPUInstanceBackend {
native::WGPUInstanceBackend_All => wgt::Backends::all(),
backends => map_instance_backend_flags(backends),
},
dx12_shader_compiler,
gles_minor_version: map_gles3_minor_version(extras.gles3MinorVersion),
flags: match extras.flags as native::WGPUInstanceFlag {
native::WGPUInstanceFlag_Default => wgt::InstanceFlags::default(),
flags => map_instance_flags(flags),
},
}
} else {
wgt::InstanceDescriptor::default()
Expand Down Expand Up @@ -388,12 +410,12 @@ pub fn write_limits_struct(
limits.maxUniformBuffersPerShaderStage = wgt_limits.max_uniform_buffers_per_shader_stage;
limits.maxUniformBufferBindingSize = wgt_limits.max_uniform_buffer_binding_size as _;
limits.maxStorageBufferBindingSize = wgt_limits.max_storage_buffer_binding_size as _;
limits.minUniformBufferOffsetAlignment = wgt_limits.min_uniform_buffer_offset_alignment;
limits.minStorageBufferOffsetAlignment = wgt_limits.min_storage_buffer_offset_alignment;
limits.maxVertexBuffers = wgt_limits.max_vertex_buffers;
limits.maxBufferSize = wgt_limits.max_buffer_size;
limits.maxVertexAttributes = wgt_limits.max_vertex_attributes;
limits.maxVertexBufferArrayStride = wgt_limits.max_vertex_buffer_array_stride;
limits.minUniformBufferOffsetAlignment = wgt_limits.min_uniform_buffer_offset_alignment;
limits.minStorageBufferOffsetAlignment = wgt_limits.min_storage_buffer_offset_alignment;
limits.maxInterStageShaderComponents = wgt_limits.max_inter_stage_shader_components;
// TODO: not yet in wgt
// limits.maxInterStageShaderVariables = wgt_limits.max_inter_stage_shader_variables;
Expand All @@ -409,19 +431,22 @@ pub fn write_limits_struct(
limits.maxComputeWorkgroupsPerDimension = wgt_limits.max_compute_workgroups_per_dimension;
supported_limits.limits = limits;

if !supported_limits.nextInChain.is_null() {
unsafe {
match unsafe { supported_limits.nextInChain.as_ref() } {
Some(native::WGPUChainedStructOut {
sType: native::WGPUSType_SupportedLimitsExtras,
..
}) => unsafe {
let extras = std::mem::transmute::<
*mut native::WGPUChainedStructOut,
*mut native::WGPUSupportedLimitsExtras,
>(supported_limits.nextInChain);

(*extras).chain.next = std::ptr::null_mut();
(*extras).chain.sType = native::WGPUSType_SupportedLimitsExtras;

(*extras).maxPushConstantSize = wgt_limits.max_push_constant_size;
}
}
(*extras).limits = native::WGPUNativeLimits {
maxPushConstantSize: wgt_limits.max_push_constant_size,
maxNonSamplerBindings: wgt_limits.max_non_sampler_bindings,
};
},
_ => {}
};
}

#[inline]
Expand Down Expand Up @@ -509,8 +534,7 @@ pub fn map_required_limits(
}
// TODO: not yet in wgt
// if limits.maxInterStageShaderVariables != native::WGPU_LIMIT_U32_UNDEFINED {
// wgt_limits.max_inter_stage_shader_variables =
// limits.maxInterStageShaderVariables;
// wgt_limits.max_inter_stage_shader_variables = limits.maxInterStageShaderVariables;
// }
// TODO: not yet in wgt
// if limits.maxColorAttachments != native::WGPU_LIMIT_U32_UNDEFINED {
Expand Down Expand Up @@ -539,8 +563,12 @@ pub fn map_required_limits(
wgt_limits.max_compute_workgroups_per_dimension = limits.maxComputeWorkgroupsPerDimension;
}
if let Some(extras) = extras {
if extras.maxPushConstantSize != native::WGPU_LIMIT_U32_UNDEFINED {
wgt_limits.max_push_constant_size = extras.maxPushConstantSize;
let limits = extras.limits;
if limits.maxPushConstantSize != native::WGPU_LIMIT_U32_UNDEFINED {
wgt_limits.max_push_constant_size = limits.maxPushConstantSize;
}
if limits.maxNonSamplerBindings != native::WGPU_LIMIT_U32_UNDEFINED {
wgt_limits.max_non_sampler_bindings = limits.maxNonSamplerBindings;
}
}
wgt_limits
Expand Down Expand Up @@ -815,6 +843,7 @@ pub fn to_native_texture_format(rs_type: wgt::TextureFormat) -> Option<native::W
wgt::TextureFormat::Rg16Snorm => None,
wgt::TextureFormat::Rgba16Unorm => None,
wgt::TextureFormat::Rgba16Snorm => None,
wgt::TextureFormat::Rgb10a2Uint => None,
wgt::TextureFormat::Astc { block:_, channel: AstcChannel::Hdr } => None,

wgt::TextureFormat::R8Unorm => Some(native::WGPUTextureFormat_R8Unorm),
Expand Down Expand Up @@ -985,7 +1014,7 @@ pub fn write_global_report(
windows,
all(
unix,
not(target_arch = "emscripten"),
not(target_os = "emscripten"),
not(target_os = "ios"),
not(target_os = "macos")
)
Expand Down Expand Up @@ -1013,6 +1042,7 @@ pub fn write_global_report(
}
}

#[cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))]
if let Some(gl) = report.gl {
native_report.gl = map_hub_report(gl);
native_report.backendType = native::WGPUBackendType_OpenGL;
Expand Down

0 comments on commit c373595

Please sign in to comment.