diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 28a51f62..2cfb8de0 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -43,7 +43,7 @@ typedef enum WGPUNativeFeature { // WGPUNativeFeature_PolygonModePoint = 0x00030014, // WGPUNativeFeature_ConservativeRasterization = 0x00030015, // WGPUNativeFeature_ClearTexture = 0x00030016, - // WGPUNativeFeature_SpirvShaderPassthrough = 0x00030017, + WGPUNativeFeature_SpirvShaderPassthrough = 0x00030017, // WGPUNativeFeature_Multiview = 0x00030018, WGPUNativeFeature_VertexAttribute64bit = 0x00030019, WGPUNativeFeature_TextureFormatNv12 = 0x0003001A, @@ -182,6 +182,12 @@ typedef struct WGPUShaderModuleGLSLDescriptor { WGPUShaderDefine * defines; } WGPUShaderModuleGLSLDescriptor; +typedef struct WGPUShaderModuleDescriptorSpirV { + char const * label; + uint32_t sourceSize; + uint32_t const * source; +} WGPUShaderModuleDescriptorSpirV; + typedef struct WGPURegistryReport { size_t numAllocated; size_t numKeptFromUser; @@ -274,6 +280,7 @@ WGPUSubmissionIndex wgpuQueueSubmitForIndex(WGPUQueue queue, size_t commandCount // Returns true if the queue is empty, or false if there are more queue submissions still in flight. WGPUBool wgpuDevicePoll(WGPUDevice device, WGPUBool wait, WGPU_NULLABLE WGPUWrappedSubmissionIndex const * wrappedSubmissionIndex); +WGPUShaderModule wgpuDeviceCreateShaderModuleSpirV(WGPUDevice device, WGPUShaderModuleDescriptorSpirV const * descriptor); void wgpuSetLogCallback(WGPULogCallback callback, void * userdata); diff --git a/src/conv.rs b/src/conv.rs index 9ac434ba..a0710adc 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -1187,9 +1187,9 @@ pub fn features_to_native(features: wgt::Features) -> Vec Option { // native::WGPUNativeFeature_PolygonModePoint => Some(Features::POLYGON_MODE_POINT), // native::WGPUNativeFeature_ConservativeRasterization => Some(Features::CONSERVATIVE_RASTERIZATION), // native::WGPUNativeFeature_ClearTexture => Some(Features::CLEAR_TEXTURE), - // native::WGPUNativeFeature_SpirvShaderPassthrough => Some(Features::SPIRV_SHADER_PASSTHROUGH), + native::WGPUNativeFeature_SpirvShaderPassthrough => Some(Features::SPIRV_SHADER_PASSTHROUGH), // native::WGPUNativeFeature_Multiview => Some(Features::MULTIVIEW), native::WGPUNativeFeature_VertexAttribute64bit => Some(Features::VERTEX_ATTRIBUTE_64BIT), native::WGPUNativeFeature_TextureFormatNv12 => Some(Features::TEXTURE_FORMAT_NV12), diff --git a/src/lib.rs b/src/lib.rs index 7aae51a2..22613e64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4230,6 +4230,42 @@ pub unsafe extern "C" fn wgpuDevicePoll( } } +#[no_mangle] +pub unsafe extern "C" fn wgpuDeviceCreateShaderModuleSpirV( + device: native::WGPUDevice, + descriptor: Option<&native::WGPUShaderModuleDescriptorSpirV>, +) -> native::WGPUShaderModule { + let (device_id, context, error_sink) = { + let device = device.as_ref().expect("invalid device"); + (device.id, &device.context, &device.error_sink) + }; + let descriptor = descriptor.expect("invalid descriptor"); + + let desc = wgc::pipeline::ShaderModuleDescriptor { + label: ptr_into_label(descriptor.label), + shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() }, + }; + + let source = Cow::Borrowed(make_slice( + descriptor.source, + descriptor.sourceSize as usize, + )); + let (shader_module_id, error) = gfx_select!(device_id => context.device_create_shader_module_spirv(device_id, &desc, source, None)); + if let Some(cause) = error { + handle_error( + error_sink, + cause, + desc.label, + "wgpuDeviceCreateShaderModuleSpirV", + ); + } + + Arc::into_raw(Arc::new(WGPUShaderModuleImpl { + context: context.clone(), + id: Some(shader_module_id), + })) +} + #[no_mangle] pub unsafe extern "C" fn wgpuRenderPassEncoderSetPushConstants( pass: native::WGPURenderPassEncoder,