-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
730378d
commit 05ed24b
Showing
4 changed files
with
94 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use naga::{ | ||
back::glsl::{Options, PipelineOptions}, | ||
proc::BoundsCheckPolicies, | ||
valid::ModuleInfo, | ||
}; | ||
|
||
use super::error::TranslateError; | ||
|
||
pub struct Glsl {} | ||
|
||
impl Glsl { | ||
pub fn from_wgsl(src: impl AsRef<str>) {} | ||
} | ||
|
||
pub fn write_glsl( | ||
module: &naga::Module, | ||
info: &ModuleInfo, | ||
shader_stage: naga::ShaderStage, | ||
entry_point: &str, | ||
) -> Result<String, TranslateError> { | ||
let mut glsl = String::new(); | ||
let options = Options::default(); | ||
let pipeline_options = PipelineOptions { | ||
shader_stage, | ||
entry_point: entry_point.into(), | ||
multiview: None, | ||
}; | ||
|
||
let mut writer = naga::back::glsl::Writer::new( | ||
&mut glsl, | ||
module, | ||
info, | ||
&options, | ||
&pipeline_options, | ||
BoundsCheckPolicies::default(), | ||
) | ||
.map_err(TranslateError::BackendGlsl)?; | ||
writer.write().map_err(TranslateError::BackendGlsl)?; | ||
Ok(glsl) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::write_glsl; | ||
|
||
#[test] | ||
fn test_wgsl_to_glsl_translation() { | ||
let wgsl = " | ||
@fragment | ||
fn fs_main() -> @location(0) vec4<f32> { | ||
return vec4<f32>(1.0, 0.0, 0.0, 1.0); | ||
} | ||
"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters