Skip to content

Commit 195335a

Browse files
Firestar99fee1-dead
authored andcommitted
allow zst entry params in input and output positions
1 parent 7ad4c4d commit 195335a

File tree

3 files changed

+98
-28
lines changed

3 files changed

+98
-28
lines changed

crates/rustc_codegen_spirv/src/codegen_cx/entry.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> CodegenCx<'tcx> {
8787
};
8888
for (arg_abi, hir_param) in fn_abi.args.iter().zip(hir_params) {
8989
match arg_abi.mode {
90-
PassMode::Direct(_) => {}
90+
PassMode::Direct(_) | PassMode::Ignore => {}
9191
PassMode::Pair(..) => {
9292
// FIXME(eddyb) implement `ScalarPair` `Input`s, or change
9393
// the `FnAbi` readjustment to only use `PassMode::Pair` for
@@ -103,16 +103,6 @@ impl<'tcx> CodegenCx<'tcx> {
103103
);
104104
}
105105
}
106-
// FIXME(eddyb) support these (by just ignoring them) - if there
107-
// is any validation concern, it should be done on the types.
108-
PassMode::Ignore => self.tcx.dcx().span_fatal(
109-
hir_param.ty_span,
110-
format!(
111-
"entry point parameter type not yet supported \
112-
(`{}` has size `0`)",
113-
arg_abi.layout.ty
114-
),
115-
),
116106
_ => span_bug!(
117107
hir_param.ty_span,
118108
"query hooks should've made this `PassMode` impossible: {:#?}",
@@ -674,28 +664,37 @@ impl<'tcx> CodegenCx<'tcx> {
674664
// starting from the `value_ptr` pointing to a `value_spirv_type`
675665
// (e.g. `Input` doesn't use indirection, so we have to load from it).
676666
if let ty::Ref(..) = entry_arg_abi.layout.ty.kind() {
677-
call_args.push(value_ptr.unwrap());
678667
match entry_arg_abi.mode {
679-
PassMode::Direct(_) => assert_eq!(value_len, None),
680-
PassMode::Pair(..) => call_args.push(value_len.unwrap()),
668+
PassMode::Direct(_) => {
669+
assert_eq!(value_len, None);
670+
call_args.push(value_ptr.unwrap());
671+
}
672+
PassMode::Pair(..) => call_args.extend([value_ptr.unwrap(), value_len.unwrap()]),
673+
PassMode::Ignore => (),
681674
_ => unreachable!(),
682675
}
683676
} else {
684-
assert_matches!(entry_arg_abi.mode, PassMode::Direct(_));
685-
686-
let value = match storage_class {
687-
Ok(_) => {
688-
assert_eq!(storage_class, Ok(StorageClass::Input));
689-
bx.load(
690-
entry_arg_abi.layout.spirv_type(hir_param.ty_span, bx),
691-
value_ptr.unwrap(),
692-
entry_arg_abi.layout.align.abi,
693-
)
677+
match entry_arg_abi.mode {
678+
PassMode::Ignore => {}
679+
PassMode::Direct(_) => {
680+
let value = match storage_class {
681+
Ok(_) => {
682+
assert_eq!(storage_class, Ok(StorageClass::Input));
683+
bx.load(
684+
entry_arg_abi.layout.spirv_type(hir_param.ty_span, bx),
685+
value_ptr.unwrap(),
686+
entry_arg_abi.layout.align.abi,
687+
)
688+
}
689+
Err(SpecConstant { .. }) => {
690+
spec_const_id.unwrap().with_type(value_spirv_type)
691+
}
692+
};
693+
call_args.push(value);
694+
assert_eq!(value_len, None);
694695
}
695-
Err(SpecConstant { .. }) => spec_const_id.unwrap().with_type(value_spirv_type),
696-
};
697-
call_args.push(value);
698-
assert_eq!(value_len, None);
696+
_ => unreachable!(),
697+
}
699698
}
700699

701700
// FIXME(eddyb) check whether the storage class is compatible with the
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// build-pass
2+
// compile-flags: -C llvm-args=--disassemble
3+
// normalize-stderr-test "OpSource .*\n" -> ""
4+
// normalize-stderr-test "OpLine .*\n" -> ""
5+
// normalize-stderr-test "%\d+ = OpString .*\n" -> ""
6+
// normalize-stderr-test "(^|\n); .*" -> ""
7+
// normalize-stderr-test "OpCapability VulkanMemoryModel\n" -> ""
8+
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
9+
// ignore-spv1.0
10+
// ignore-spv1.1
11+
// ignore-spv1.2
12+
// ignore-spv1.3
13+
// ignore-vulkan1.0
14+
// ignore-vulkan1.1
15+
16+
use spirv_std::glam::*;
17+
use spirv_std::{Image, spirv};
18+
19+
#[spirv(vertex)]
20+
pub fn main(in1: (), in2: u32, out1: &mut [f32; 3], out2: &mut (), out3: &mut f32) {
21+
*out1 = Default::default();
22+
*out2 = Default::default();
23+
*out3 = in2 as f32;
24+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
OpCapability Shader
3+
OpMemoryModel Logical Simple
4+
OpEntryPoint Vertex %1 "main" %2 %3 %4
5+
OpName %2 "in2"
6+
OpName %3 "out1"
7+
OpName %4 "out3"
8+
OpName %7 "<[f32; 3] as core::default::Default>::default"
9+
OpDecorate %2 Location 0
10+
OpDecorate %8 ArrayStride 4
11+
OpDecorate %3 Location 0
12+
OpDecorate %4 Location 3
13+
%9 = OpTypeInt 32 0
14+
%10 = OpTypePointer Input %9
15+
%11 = OpTypeFloat 32
16+
%12 = OpConstant %9 3
17+
%13 = OpTypeArray %11 %12
18+
%14 = OpTypePointer Output %13
19+
%15 = OpTypePointer Output %11
20+
%16 = OpTypeVoid
21+
%17 = OpTypeFunction %16
22+
%2 = OpVariable %10 Input
23+
%8 = OpTypeArray %11 %12
24+
%18 = OpTypeFunction %8
25+
%19 = OpConstant %11 0
26+
%3 = OpVariable %14 Output
27+
%4 = OpVariable %15 Output
28+
%1 = OpFunction %16 None %17
29+
%20 = OpLabel
30+
%21 = OpLoad %9 %2
31+
%22 = OpFunctionCall %8 %7
32+
%23 = OpCompositeExtract %11 %22 0
33+
%24 = OpCompositeExtract %11 %22 1
34+
%25 = OpCompositeExtract %11 %22 2
35+
%26 = OpCompositeConstruct %13 %23 %24 %25
36+
OpStore %3 %26
37+
%27 = OpConvertUToF %11 %21
38+
OpStore %4 %27
39+
OpNoLine
40+
OpReturn
41+
OpFunctionEnd
42+
%7 = OpFunction %8 None %18
43+
%28 = OpLabel
44+
%29 = OpCompositeConstruct %8 %19 %19 %19
45+
OpNoLine
46+
OpReturnValue %29
47+
OpFunctionEnd

0 commit comments

Comments
 (0)