Skip to content

Commit

Permalink
Expose spirv shader passthrough feature. (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
MineBill authored Oct 14, 2024
1 parent 7b039f3 commit 7c87e99
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
9 changes: 8 additions & 1 deletion ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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,
Expand Down Expand Up @@ -185,6 +185,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;
Expand Down Expand Up @@ -277,6 +283,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);

Expand Down
8 changes: 4 additions & 4 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,9 @@ pub fn features_to_native(features: wgt::Features) -> Vec<native::WGPUFeatureNam
// if features.contains(wgt::Features::CLEAR_TEXTURE) {
// temp.push(native::WGPUNativeFeature_ClearTexture);
// }
// if features.contains(wgt::Features::SPIRV_SHADER_PASSTHROUGH) {
// temp.push(native::WGPUNativeFeature_SpirvShaderPassthrough);
// }
if features.contains(wgt::Features::SPIRV_SHADER_PASSTHROUGH) {
temp.push(native::WGPUNativeFeature_SpirvShaderPassthrough);
}
// if features.contains(wgt::Features::MULTIVIEW) {
// temp.push(native::WGPUNativeFeature_Multiview);
// }
Expand Down Expand Up @@ -1275,7 +1275,7 @@ pub fn map_feature(feature: native::WGPUFeatureName) -> Option<wgt::Features> {
// 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),
Expand Down
36 changes: 36 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7c87e99

Please sign in to comment.