replace glsl_to_spirv with shaderc
This commit is contained in:
parent
35705dfad2
commit
50722089ef
@ -10,7 +10,6 @@ legion_transform = { path = "src/transform" }
|
||||
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "4a0da16fe6764c4e1dc918a31cbd7467d404df51"}
|
||||
glam = "0.8.4"
|
||||
winit = "0.20.0-alpha6"
|
||||
glsl-to-spirv = "0.1"
|
||||
zerocopy = "0.2"
|
||||
log = "0.4"
|
||||
env_logger = "0.7"
|
||||
@ -21,6 +20,7 @@ serde_json = "1.0"
|
||||
uuid = { version = "0.8", features = ["v4"] }
|
||||
erased-serde = "0.3"
|
||||
type-uuid = "0.1"
|
||||
shaderc = "0.6"
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
@ -22,9 +22,9 @@ impl ForwardPipeline {
|
||||
|
||||
impl Pipeline for ForwardPipeline {
|
||||
fn initialize(&mut self, render_graph: &mut RenderGraphData, _: &mut World) {
|
||||
let vs_bytes = shader::load_glsl(include_str!("forward.vert"), shader::ShaderStage::Vertex);
|
||||
let vs_bytes = shader::glsl_to_spirv(include_str!("forward.vert"), shader::ShaderStage::Vertex);
|
||||
let fs_bytes =
|
||||
shader::load_glsl(include_str!("forward.frag"), shader::ShaderStage::Fragment);
|
||||
shader::glsl_to_spirv(include_str!("forward.frag"), shader::ShaderStage::Fragment);
|
||||
|
||||
let bind_group_layout =
|
||||
render_graph
|
||||
|
@ -136,11 +136,11 @@ impl ForwardInstancedPipeline {
|
||||
|
||||
impl Pipeline for ForwardInstancedPipeline {
|
||||
fn initialize(&mut self, render_graph: &mut RenderGraphData, world: &mut World) {
|
||||
let vs_bytes = shader::load_glsl(
|
||||
let vs_bytes = shader::glsl_to_spirv(
|
||||
include_str!("forward_instanced.vert"),
|
||||
shader::ShaderStage::Vertex,
|
||||
);
|
||||
let fs_bytes = shader::load_glsl(
|
||||
let fs_bytes = shader::glsl_to_spirv(
|
||||
include_str!("forward_instanced.frag"),
|
||||
shader::ShaderStage::Fragment,
|
||||
);
|
||||
|
@ -20,11 +20,11 @@ impl ForwardShadowPassNew {
|
||||
|
||||
impl Pipeline for ForwardShadowPassNew {
|
||||
fn initialize(&mut self, render_graph: &mut RenderGraphData, _world: &mut World) {
|
||||
let vs_bytes = shader::load_glsl(
|
||||
let vs_bytes = shader::glsl_to_spirv(
|
||||
include_str!("forward_shadow.vert"),
|
||||
shader::ShaderStage::Vertex,
|
||||
);
|
||||
let fs_bytes = shader::load_glsl(
|
||||
let fs_bytes = shader::glsl_to_spirv(
|
||||
include_str!("forward_shadow.frag"),
|
||||
shader::ShaderStage::Fragment,
|
||||
);
|
||||
|
@ -102,9 +102,9 @@ impl Pipeline for ShadowPipeline {
|
||||
let vertex_buffer_descriptor = get_vertex_buffer_descriptor();
|
||||
|
||||
// Create the render pipeline
|
||||
let vs_bytes = shader::load_glsl(include_str!("shadow.vert"), shader::ShaderStage::Vertex);
|
||||
let vs_bytes = shader::glsl_to_spirv(include_str!("shadow.vert"), shader::ShaderStage::Vertex);
|
||||
let fs_bytes =
|
||||
shader::load_glsl(include_str!("shadow.frag"), shader::ShaderStage::Fragment);
|
||||
shader::glsl_to_spirv(include_str!("shadow.frag"), shader::ShaderStage::Fragment);
|
||||
let vs_module = render_graph.device.create_shader_module(&vs_bytes);
|
||||
let fs_module = render_graph.device.create_shader_module(&fs_bytes);
|
||||
|
||||
|
@ -95,8 +95,8 @@ impl UiPipeline {
|
||||
|
||||
impl Pipeline for UiPipeline {
|
||||
fn initialize(&mut self, render_graph: &mut RenderGraphData, world: &mut World) {
|
||||
let vs_bytes = shader::load_glsl(include_str!("ui.vert"), shader::ShaderStage::Vertex);
|
||||
let fs_bytes = shader::load_glsl(include_str!("ui.frag"), shader::ShaderStage::Fragment);
|
||||
let vs_bytes = shader::glsl_to_spirv(include_str!("ui.vert"), shader::ShaderStage::Vertex);
|
||||
let fs_bytes = shader::glsl_to_spirv(include_str!("ui.frag"), shader::ShaderStage::Fragment);
|
||||
|
||||
let bind_group_layout =
|
||||
render_graph
|
||||
|
@ -5,12 +5,27 @@ pub enum ShaderStage {
|
||||
Compute,
|
||||
}
|
||||
|
||||
pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec<u32> {
|
||||
let ty = match stage {
|
||||
ShaderStage::Vertex => glsl_to_spirv::ShaderType::Vertex,
|
||||
ShaderStage::Fragment => glsl_to_spirv::ShaderType::Fragment,
|
||||
ShaderStage::Compute => glsl_to_spirv::ShaderType::Compute,
|
||||
};
|
||||
|
||||
wgpu::read_spirv(glsl_to_spirv::compile(&code, ty).unwrap()).unwrap()
|
||||
impl Into<shaderc::ShaderKind> for ShaderStage {
|
||||
fn into(self) -> shaderc::ShaderKind {
|
||||
match self {
|
||||
ShaderStage::Vertex => shaderc::ShaderKind::Vertex,
|
||||
ShaderStage::Fragment => shaderc::ShaderKind::Fragment,
|
||||
ShaderStage::Compute => shaderc::ShaderKind::Compute,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn glsl_to_spirv(glsl_source: &str, stage: ShaderStage) -> Vec<u32> {
|
||||
let shader_kind: shaderc::ShaderKind = stage.into();
|
||||
let mut compiler = shaderc::Compiler::new().unwrap();
|
||||
let options = shaderc::CompileOptions::new().unwrap();
|
||||
// options.add_macro_definition("EP", Some("main"));
|
||||
let binary_result = compiler.compile_into_spirv(
|
||||
glsl_source, shader_kind,
|
||||
"shader.glsl", "main", Some(&options)).unwrap();
|
||||
|
||||
// let text_result = compiler.compile_into_spirv_assembly(
|
||||
// glsl_source, shader_kind,
|
||||
// "shader.glsl", "main", Some(&options)).unwrap();
|
||||
binary_result.as_binary().into()
|
||||
}
|
Loading…
Reference in New Issue
Block a user