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

Expose SPIRV_SHADER_PASSTHROUGH native feature. #436

Merged
merged 1 commit into from
Oct 14, 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
9 changes: 8 additions & 1 deletion ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,9 +1187,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 @@ -1264,7 +1264,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
Loading