Skip to content

Commit

Permalink
[hlsl-out] Validate all entry points in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon-F authored and kvark committed Jul 20, 2021
1 parent f3c7537 commit 3c98cc5
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 64 deletions.
24 changes: 17 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,27 @@ validate-wgsl: $(SNAPSHOTS_BASE_OUT)/wgsl/*.wgsl
cargo run $${file}; \
done

validate-hlsl: SHELL:=/bin/bash # required because config files uses arrays
validate-hlsl: $(SNAPSHOTS_BASE_OUT)/hlsl/*.hlsl
@set -e && for file in $^ ; do \
DXC_PARAMS="-Wno-parentheses-equality -Zi -Qembed_debug"; \
echo "Validating" $${file#"$(SNAPSHOTS_BASE_OUT)/"}; \
config="$$(dirname $${file})/$$(basename $${file}).config"; \
vertex=""\
fragment="" \
compute="" \
. $${config}; \
DXC_PARAMS="-Wno-parentheses-equality -Zi -Qembed_debug"; \
[ ! -z "$${vertex}" ] && echo "Vertex Stage:" && dxc $${file} -T $${vertex} -E $${vertex_name} $${DXC_PARAMS} > /dev/null; \
[ ! -z "$${fragment}" ] && echo "Fragment Stage:" && dxc $${file} -T $${fragment} -E $${fragment_name} $${DXC_PARAMS} > /dev/null; \
[ ! -z "$${compute}" ] && echo "Compute Stage:" && dxc $${file} -T $${compute} -E $${compute_name} $${DXC_PARAMS} > /dev/null; \
for (( i=0; i<$${#vertex[@]}; i++ )); do \
name=`echo $${vertex[i]} | cut -d \: -f 1`; \
profile=`echo $${vertex[i]} | cut -d \: -f 2`; \
(set -x; dxc $${file} -T $${profile} -E $${name} $${DXC_PARAMS} > /dev/null); \
done; \
for (( i=0; i<$${#fragment[@]}; i++ )); do \
name=`echo $${fragment[i]} | cut -d \: -f 1`; \
profile=`echo $${fragment[i]} | cut -d \: -f 2`; \
(set -x; dxc $${file} -T $${profile} -E $${name} $${DXC_PARAMS} > /dev/null); \
done; \
for (( i=0; i<$${#compute[@]}; i++ )); do \
name=`echo $${compute[i]} | cut -d \: -f 1`; \
profile=`echo $${compute[i]} | cut -d \: -f 2`; \
(set -x; dxc $${file} -T $${profile} -E $${name} $${DXC_PARAMS} > /dev/null); \
done; \
echo "======================"; \
done
5 changes: 3 additions & 2 deletions tests/out/hlsl/control-flow.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
compute=cs_5_0
compute_name=main
vertex=()
fragment=()
compute=(main:cs_5_0 )
5 changes: 3 additions & 2 deletions tests/out/hlsl/empty.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
compute=cs_5_0
compute_name=main
vertex=()
fragment=()
compute=(main:cs_5_0 )
5 changes: 3 additions & 2 deletions tests/out/hlsl/globals.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
compute=cs_5_0
compute_name=main
vertex=()
fragment=()
compute=(main:cs_5_0 )
11 changes: 3 additions & 8 deletions tests/out/hlsl/image.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
compute=cs_5_0
compute_name=main
vertex=vs_5_0
vertex_name=queries
fragment=ps_5_0
fragment_name=sample1
fragment=ps_5_0
fragment_name=sample_comparison
vertex=(queries:vs_5_0 )
fragment=(sample1:ps_5_0 sample_comparison:ps_5_0 )
compute=(main:cs_5_0 )
9 changes: 3 additions & 6 deletions tests/out/hlsl/interface.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
vertex=vs_5_0
vertex_name=vertex
fragment=ps_5_0
fragment_name=fragment
compute=cs_5_0
compute_name=compute
vertex=(vertex:vs_5_0 )
fragment=(fragment:ps_5_0 )
compute=(compute:cs_5_0 )
7 changes: 3 additions & 4 deletions tests/out/hlsl/interpolate.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
vertex=vs_5_0
vertex_name=main
fragment=ps_5_0
fragment_name=main1
vertex=(main:vs_5_0 )
fragment=(main1:ps_5_0 )
compute=()
5 changes: 3 additions & 2 deletions tests/out/hlsl/operators.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
compute=cs_5_0
compute_name=main
vertex=()
fragment=()
compute=(main:cs_5_0 )
5 changes: 3 additions & 2 deletions tests/out/hlsl/quad-vert.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vertex=vs_5_0
vertex_name=main
vertex=(main:vs_5_0 )
fragment=()
compute=()
9 changes: 3 additions & 6 deletions tests/out/hlsl/quad.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
vertex=vs_5_0
vertex_name=main
fragment=ps_5_0
fragment_name=main1
fragment=ps_5_0
fragment_name=fs_extra
vertex=(main:vs_5_0 )
fragment=(main1:ps_5_0 fs_extra:ps_5_0 )
compute=()
5 changes: 3 additions & 2 deletions tests/out/hlsl/shadow.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fragment=ps_5_0
fragment_name=fs_main
vertex=()
fragment=(fs_main:ps_5_0 )
compute=()
7 changes: 3 additions & 4 deletions tests/out/hlsl/skybox.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
vertex=vs_5_1
vertex_name=vs_main
fragment=ps_5_1
fragment_name=fs_main
vertex=(vs_main:vs_5_1 )
fragment=(fs_main:ps_5_1 )
compute=()
5 changes: 3 additions & 2 deletions tests/out/hlsl/standard.hlsl.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fragment=ps_5_0
fragment_name=derivatives
vertex=()
fragment=(derivatives:ps_5_0 )
compute=()
58 changes: 43 additions & 15 deletions tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,55 @@ fn write_output_hlsl(
// This file contains an info about profiles (shader stages) contains inside generated shader
// This info will be passed to dxc
let mut config_str = String::new();
let mut vertex_str = String::from("vertex=(");
let mut fragment_str = String::from("fragment=(");
let mut compute_str = String::from("compute=(");
for (index, ep) in module.entry_points.iter().enumerate() {
let name = match reflection_info.entry_point_names[index] {
Ok(ref name) => name,
Err(_) => continue,
};
let stage_str = match ep.stage {
naga::ShaderStage::Vertex => "vertex",
naga::ShaderStage::Fragment => "fragment",
naga::ShaderStage::Compute => "compute",
};
writeln!(
config_str,
"{}={}_{}\n{}_name={}",
stage_str,
ep.stage.to_hlsl_str(),
options.shader_model.to_str(),
stage_str,
name,
)
.unwrap();
match ep.stage {
naga::ShaderStage::Vertex => {
write!(
vertex_str,
"{}:{}_{} ",
name,
ep.stage.to_hlsl_str(),
options.shader_model.to_str(),
)
.unwrap();
}
naga::ShaderStage::Fragment => {
write!(
fragment_str,
"{}:{}_{} ",
name,
ep.stage.to_hlsl_str(),
options.shader_model.to_str(),
)
.unwrap();
}
naga::ShaderStage::Compute => {
write!(
compute_str,
"{}:{}_{} ",
name,
ep.stage.to_hlsl_str(),
options.shader_model.to_str(),
)
.unwrap();
}
}
}

writeln!(
config_str,
"{})\n{})\n{})",
vertex_str, fragment_str, compute_str
)
.unwrap();

fs::write(
destination.join(format!("hlsl/{}.hlsl.config", file_name)),
config_str,
Expand Down

0 comments on commit 3c98cc5

Please sign in to comment.