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

Allow SPIR-V shaders to process when shader defs are present #7772

Merged
merged 2 commits into from
Mar 19, 2023
Merged
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
7 changes: 1 addition & 6 deletions crates/bevy_render/src/render_resource/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ pub enum ProcessShaderError {
"Not enough '# endif' lines. Each if statement should be followed by an endif statement."
)]
NotEnoughEndIfs,
#[error("This Shader's format does not support processing shader defs.")]
ShaderFormatDoesNotSupportShaderDefs,
#[error("This Shader's format does not support imports.")]
ShaderFormatDoesNotSupportImports,
#[error("Unresolved import: {0:?}.")]
Expand Down Expand Up @@ -477,10 +475,7 @@ impl ShaderProcessor {
Source::Wgsl(source) => source.deref(),
Source::Glsl(source, _stage) => source.deref(),
Source::SpirV(source) => {
if shader_defs_unique.is_empty() {
return Ok(ProcessedShader::SpirV(source.clone()));
}
return Err(ProcessShaderError::ShaderFormatDoesNotSupportShaderDefs);
return Ok(ProcessedShader::SpirV(source.clone()));
Comment on lines -480 to +478
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it makes sense to log a message saying something like "loaded a SpirV shader, it will ignore shader defs"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have thought that would be implicit, or something that would belong documentation-side if anything; the processor is either interested in SPIR-V or not, so my initial feeling is that it would end up filling the log with obvious statements in a project that makes extensive use of the format.

However, @superdump suggested an alternate approach on Discord that seems less intrusive; keeping the hard error, but giving Material implementors the opportunity to clear out all built-in shader defs at specialization time.

Currently NO_*_SUPPORT and SIXTEEN_BYTE_ALIGNMENTget injected after the fact and create the hard error situation this PR aims to remedy, so moving them earlier in the pipeline would avoid breaking the processor's existing assumptions while simultaneously allowing Material the control it needs for the use-case.

I was planning to open another pull to that effect anyway, so will take a swing at it and see where things go from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New PR: #7903

}
};

Expand Down