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

Fix shader import hot reloading on windows #10502

Merged
merged 3 commits into from
Nov 11, 2023
Merged
Changes from 2 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
34 changes: 14 additions & 20 deletions crates/bevy_render/src/render_resource/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,30 +259,24 @@ impl AssetLoader for ShaderLoader {
) -> BoxedFuture<'a, Result<Shader, Self::Error>> {
Box::pin(async move {
let ext = load_context.path().extension().unwrap().to_str().unwrap();

let path = load_context.asset_path().to_string();
// On windows, the path will inconsistently use \ or /.
// TODO: remove this once AssetPath forces cross-platform "slash" consistency. See #10511
let path = path.replace("\\", "/");
cart marked this conversation as resolved.
Show resolved Hide resolved
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let mut shader = match ext {
"spv" => Shader::from_spirv(bytes, load_context.path().to_string_lossy()),
"wgsl" => Shader::from_wgsl(
String::from_utf8(bytes)?,
load_context.path().to_string_lossy(),
),
"vert" => Shader::from_glsl(
String::from_utf8(bytes)?,
naga::ShaderStage::Vertex,
load_context.path().to_string_lossy(),
),
"frag" => Shader::from_glsl(
String::from_utf8(bytes)?,
naga::ShaderStage::Fragment,
load_context.path().to_string_lossy(),
),
"comp" => Shader::from_glsl(
String::from_utf8(bytes)?,
naga::ShaderStage::Compute,
load_context.path().to_string_lossy(),
),
"wgsl" => Shader::from_wgsl(String::from_utf8(bytes)?, path),
"vert" => {
Shader::from_glsl(String::from_utf8(bytes)?, naga::ShaderStage::Vertex, path)
}
"frag" => {
Shader::from_glsl(String::from_utf8(bytes)?, naga::ShaderStage::Fragment, path)
}
"comp" => {
Shader::from_glsl(String::from_utf8(bytes)?, naga::ShaderStage::Compute, path)
}
_ => panic!("unhandled extension: {ext}"),
};

Expand Down
Loading