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

bevy_render: load .spv assets #1104

Merged
merged 3 commits into from
Dec 24, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix wasm compilation
  • Loading branch information
jakobhellermann committed Dec 20, 2020
commit 553638c14efe4df796d3ec7aa452496051bc54c1
7 changes: 6 additions & 1 deletion crates/bevy_render/src/shader/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use bevy_asset::{AssetEvent, AssetLoader, Assets, Handle, LoadContext, LoadedAss
use bevy_ecs::{Local, Res, ResMut};
use bevy_reflect::TypeUuid;
use bevy_utils::{tracing::error, BoxedFuture};
use spirv_reflect::{types::ReflectShaderStageFlags, ShaderModule};
use std::marker::Copy;
use thiserror::Error;

Expand Down Expand Up @@ -146,7 +145,10 @@ impl Shader {
Shader { stage, source }
}

#[cfg(not(target_arch = "wasm32"))]
pub fn from_spirv(spirv: &[u8]) -> Result<Shader, ShaderError> {
use spirv_reflect::{types::ReflectShaderStageFlags, ShaderModule};

let module = ShaderModule::load_u8_data(spirv)
.map_err(|msg| ShaderError::Compilation(msg.to_string()))?;
let stage = match module.get_shader_stage() {
Expand Down Expand Up @@ -259,7 +261,10 @@ impl AssetLoader for ShaderLoader {
let shader = match ext {
"vert" => Shader::from_glsl(ShaderStage::Vertex, std::str::from_utf8(bytes)?),
"frag" => Shader::from_glsl(ShaderStage::Fragment, std::str::from_utf8(bytes)?),
#[cfg(not(target_arch = "wasm32"))]
"spv" => Shader::from_spirv(bytes)?,
#[cfg(target_arch = "wasm32")]
"spv" => panic!("cannot load .spv file on wasm"),
_ => panic!("unhandled extension: {}", ext),
};

Expand Down