spv-out: support version 1.4 (#2230)

* spv-out: support version 1.4

* Extract SPV version numner from the comment
This commit is contained in:
Dzmitry Malyshau
2023-02-01 03:24:05 -08:00
committed by GitHub
parent 6be394dac3
commit 16be1a9237
7 changed files with 66 additions and 2 deletions

View File

@@ -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

View File

@@ -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!");
}
}

View File

@@ -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.
//

View File

@@ -0,0 +1,5 @@
(
spv: (
version: (1, 4),
),
)

7
tests/in/sprite.wgsl Normal file
View File

@@ -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);
}

View File

@@ -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

View File

@@ -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() {