Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
spv-out: support version 1.4 (#2230)
Browse files Browse the repository at this point in the history
* spv-out: support version 1.4

* Extract SPV version numner from the comment
  • Loading branch information
kvark authored Feb 1, 2023
1 parent 6be394d commit 16be1a9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ bench:
validate-spv: $(SNAPSHOTS_BASE_OUT)/spv/*.spvasm
@set -e && for file in $^ ; do \
echo "Validating" $${file#"$(SNAPSHOTS_BASE_OUT)/"}; \
cat $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \
version_line=$$(head -2 $${file} | tail -1); \
version=$${version_line#"; Version: "};\
cat $${file} | spirv-as --target-env spv$${version} -o - | spirv-val; \
done

validate-msl: $(SNAPSHOTS_BASE_OUT)/msl/*.msl
Expand Down
2 changes: 1 addition & 1 deletion src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4221,7 +4221,7 @@ fn test_stack_size() {
let stack_size = addresses_end - addresses_start;
// check the size (in debug only)
// last observed macOS value: 19152 (CI)
if !(9500..=20000).contains(&stack_size) {
if !(9000..=20000).contains(&stack_size) {
panic!("`put_block` stack size {stack_size} has changed!");
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ impl Writer {
}

let mut gv = self.global_variables[handle.index()].clone();
if let Some(ref mut iface) = interface {
// Have to include global variables in the interface
if self.physical_layout.version >= 0x10400 {
iface.varying_ids.push(gv.var_id);
}
}

// Handle globals are pre-emitted and should be loaded automatically.
//
Expand Down
5 changes: 5 additions & 0 deletions tests/in/sprite.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(
spv: (
version: (1, 4),
),
)
7 changes: 7 additions & 0 deletions tests/in/sprite.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@group(0) @binding(0) var u_texture : texture_2d<f32>;
@group(0) @binding(1) var u_sampler : sampler;

@fragment
fn main(@location(0) uv : vec2<f32>) -> @location(0) vec4<f32> {
return textureSample(u_texture, u_sampler, uv);
}
43 changes: 43 additions & 0 deletions tests/out/spv/sprite.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
; SPIR-V
; Version: 1.4
; Generator: rspirv
; Bound: 26
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %18 "main" %13 %16 %8 %10
OpExecutionMode %18 OriginUpperLeft
OpDecorate %8 DescriptorSet 0
OpDecorate %8 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %10 Binding 1
OpDecorate %13 Location 0
OpDecorate %16 Location 0
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpTypeImage %4 2D 0 0 0 1 Unknown
%5 = OpTypeSampler
%6 = OpTypeVector %4 2
%7 = OpTypeVector %4 4
%9 = OpTypePointer UniformConstant %3
%8 = OpVariable %9 UniformConstant
%11 = OpTypePointer UniformConstant %5
%10 = OpVariable %11 UniformConstant
%14 = OpTypePointer Input %6
%13 = OpVariable %14 Input
%17 = OpTypePointer Output %7
%16 = OpVariable %17 Output
%19 = OpTypeFunction %2
%23 = OpTypeSampledImage %3
%18 = OpFunction %2 None %19
%12 = OpLabel
%15 = OpLoad %6 %13
%20 = OpLoad %3 %8
%21 = OpLoad %5 %10
OpBranch %22
%22 = OpLabel
%24 = OpSampledImage %23 %20 %21
%25 = OpImageSampleImplicitLod %7 %24 %15
OpStore %16 %25
OpReturn
OpFunctionEnd
1 change: 1 addition & 0 deletions tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ fn convert_wgsl() {
"workgroup-var-init",
Targets::WGSL | Targets::GLSL | Targets::SPIRV | Targets::HLSL | Targets::METAL,
),
("sprite", Targets::SPIRV),
];

for &(name, targets) in inputs.iter() {
Expand Down

0 comments on commit 16be1a9

Please sign in to comment.