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

Implement SPIR-V passthrough #8131

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ bevy_gizmos = ["bevy_internal/bevy_gizmos", "bevy_color"]
# Provides a collection of developer tools
bevy_dev_tools = ["bevy_internal/bevy_dev_tools"]

# Enable passthrough loading for SPIR-V shaders (Only supported on Vulkan, shader capabilities and extensions must agree with the platform implementation)
spirv_shader_passthrough = ["bevy_internal/spirv_shader_passthrough"]

# Tracing support, saving a file in Chrome Tracing format
trace_chrome = ["trace", "bevy_internal/trace_chrome"]

Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ ktx2 = ["bevy_render/ktx2"]
zlib = ["bevy_render/zlib"]
zstd = ["bevy_render/zstd"]

# Enable SPIR-V passthrough
spirv_shader_passthrough = ["bevy_render/spirv_shader_passthrough"]

# Include tonemapping LUT KTX2 files.
tonemapping_luts = ["bevy_core_pipeline/tonemapping_luts"]

Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ shader_format_spirv = ["wgpu/spirv", "naga/spv-in", "naga/spv-out"]
zlib = ["flate2"]
zstd = ["ruzstd"]

# Enable SPIR-V shader passthrough
spirv_shader_passthrough = []

trace = ["profiling"]
tracing-tracy = []
ci_limits = []
Expand Down
22 changes: 22 additions & 0 deletions crates/bevy_render/src/renderer/render_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ impl RenderDevice {
/// Creates a [`ShaderModule`](wgpu::ShaderModule) from either SPIR-V or WGSL source code.
#[inline]
pub fn create_shader_module(&self, desc: wgpu::ShaderModuleDescriptor) -> wgpu::ShaderModule {
#[cfg(feature = "spirv_shader_passthrough")]
match &desc.source {
wgpu::ShaderSource::SpirV(source)
if self
.features()
.contains(wgpu::Features::SPIRV_SHADER_PASSTHROUGH) =>
{
// SAFETY:
// This call passes binary data to the backend as-is and can potentially result in a driver crash or bogus behaviour.
// No attempt is made to ensure that data is valid SPIR-V.
unsafe {
self.device
.create_shader_module_spirv(&wgpu::ShaderModuleDescriptorSpirV {
label: desc.label,
source: source.clone(),
})
}
}
_ => self.device.create_shader_module(desc),
}

#[cfg(not(feature = "spirv_shader_passthrough"))]
self.device.create_shader_module(desc)
}

Expand Down
1 change: 1 addition & 0 deletions docs/cargo_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The default feature set enables most of the expected features of a game engine,
|pnm|PNM image format support, includes pam, pbm, pgm and ppm|
|reflect_functions|Enable function reflection|
|serialize|Enable serialization support through serde|
|spirv_shader_passthrough|Enable passthrough loading for SPIR-V shaders (Only supported on Vulkan, shader capabilities and extensions must agree with the platform implementation)|
|shader_format_glsl|Enable support for shaders in GLSL|
|shader_format_spirv|Enable support for shaders in SPIR-V|
|symphonia-aac|AAC audio format support (through symphonia)|
Expand Down
Loading