@@ -280,6 +280,56 @@ TEST_F(SplitCombinedImageSamplerPassTest,
280280 EXPECT_EQ (status, Pass::Status::SuccessWithChange) << disasm;
281281}
282282
283+ TEST_F (SplitCombinedImageSamplerPassTest, Combined_SynthesizeVarNames) {
284+ // Also tests binding info is copied to both variables.
285+ const std::string kTest = Preamble () +
286+ R"(
287+ OpName %orig_var "orig_var"
288+ OpDecorate %orig_var DescriptorSet 0
289+ OpDecorate %orig_var Binding 0
290+
291+ ; The combined image variable is replaced by an image variable and a sampler variable.
292+
293+ ; CHECK: OpCapability
294+ ; The original name is deleted
295+ ; CHECK-NOT: OpName %orig_var "
296+ ; CHECK: OpName %orig_var_image "orig_var_image"
297+ ; CHECK: OpName %orig_var_sampler "orig_var_sampler"
298+ ; CHECK-NOT: OpName %orig_var "
299+
300+ ; CHECK: OpDecorate %orig_var_image DescriptorSet 0
301+ ; CHECK: OpDecorate %orig_var_sampler DescriptorSet 0
302+ ; CHECK: OpDecorate %orig_var_image Binding 0
303+ ; CHECK: OpDecorate %orig_var_sampler Binding 0
304+
305+ ; CHECK: %10 = OpTypeImage %
306+ ; CHECK: %[[image_ptr_ty:\w+]] = OpTypePointer UniformConstant %10
307+ ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
308+ ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
309+
310+
311+ ; CHECK-NOT: %orig_var = OpVariable
312+ ; CHECK-DAG: %orig_var_sampler = OpVariable %[[sampler_ptr_ty]] UniformConstant
313+ ; CHECK-DAG: %orig_var_image = OpVariable %[[image_ptr_ty]] UniformConstant
314+ ; CHECK: = OpFunction
315+
316+ )" + BasicTypes () + R"(
317+ %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
318+ %11 = OpTypeSampledImage %10
319+ %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
320+
321+ %orig_var = OpVariable %_ptr_UniformConstant_11 UniformConstant
322+ %main = OpFunction %void None %voidfn
323+ %main_0 = OpLabel
324+ %101 = OpLoad %11 %orig_var
325+ OpReturn
326+ OpFunctionEnd
327+ )" ;
328+ auto [disasm, status] = SinglePassRunAndMatch<SplitCombinedImageSamplerPass>(
329+ kTest , /* do_validation= */ true );
330+ EXPECT_EQ (status, Pass::Status::SuccessWithChange) << disasm;
331+ }
332+
283333TEST_P (SplitCombinedImageSamplerPassTypeCaseTest, Combined_RemapLoad) {
284334 // Also tests binding info is copied to both variables.
285335 const std::string kTest = Preamble () +
@@ -313,7 +363,6 @@ TEST_P(SplitCombinedImageSamplerPassTypeCaseTest, Combined_RemapLoad) {
313363 ; CHECK: %[[s:\d+]] = OpLoad %[[sampler_ty]] %[[sampler_var]]
314364 ; CHECK: %combined = OpSampledImage %11 %[[im]] %[[s]]
315365
316- %bool = OpTypeBool ; location marker
317366)" + BasicTypes () +
318367 " %10 = " + GetParam ().image_type_decl + R"(
319368 %11 = OpTypeSampledImage %10
@@ -621,28 +670,18 @@ std::vector<EntryPointRemapCase> EntryPointInterfaceCases() {
621670 return std::vector<EntryPointRemapCase>{
622671 {SPV_ENV_VULKAN_1_0, " %in_var %out_var" , " %in_var %out_var" },
623672 {SPV_ENV_VULKAN_1_4, " %combined_var" ,
624- " %[[image_var: \\ d+]] %[[sampler_var: \\ d+]] " },
673+ " %combined_var_image %combined_var_sampler " },
625674 {SPV_ENV_VULKAN_1_4, " %combined_var %in_var %out_var" ,
626- " %[[image_var: \\ d+]] %in_var %out_var %[[sampler_var: \\ d+]] " },
675+ " %combined_var_image %in_var %out_var %combined_var_sampler " },
627676 {SPV_ENV_VULKAN_1_4, " %in_var %combined_var %out_var" ,
628- " %in_var %[[image_var: \\ d+]] %out_var %[[sampler_var: \\ d+]] " },
677+ " %in_var %combined_var_image %out_var %combined_var_sampler " },
629678 {SPV_ENV_VULKAN_1_4, " %in_var %out_var %combined_var" ,
630- " %in_var %out_var %[[image_var: \\ d+]] %[[sampler_var: \\ d+]] " },
679+ " %in_var %out_var %combined_var_image %combined_var_sampler " },
631680 };
632681}
633682
634683TEST_P (SplitCombinedImageSamplerPassEntryPointRemapTest,
635684 EntryPoint_Combined_UsedInShader) {
636- const bool combined_var_in_interface =
637- std::string (GetParam ().initial_interface ).find (" %combined_var" ) !=
638- std::string::npos;
639- // If the combined var is listed in the entry point, then the entry point
640- // interface will give the pattern match definition of the sampler var ID.
641- // Otherwise it's defined at the assignment.
642- const std::string sampler_var_def =
643- combined_var_in_interface ? " %[[sampler_var]]" : " %[[sampler_var:\\ d+]]" ;
644- const std::string image_var_def =
645- combined_var_in_interface ? " %[[image_var]]" : " %[[image_var:\\ d+]]" ;
646685 const std::string kTest = PreambleFragment (GetParam ().initial_interface ) +
647686 R"(
648687 OpName %combined "combined"
@@ -669,10 +708,8 @@ TEST_P(SplitCombinedImageSamplerPassEntryPointRemapTest,
669708 ; CHECK: %[[sampler_ty:\d+]] = OpTypeSampler
670709 ; CHECK: %[[sampler_ptr_ty:\w+]] = OpTypePointer UniformConstant %[[sampler_ty]]
671710 ; The combined image variable is replaced by an image variable and a sampler variable.
672- ; CHECK-DAG: )" + sampler_var_def +
673- R"( = OpVariable %[[sampler_ptr_ty]] UniformConstant
674- ; CHECK-DAG: )" + image_var_def +
675- R"( = OpVariable %[[image_ptr_ty]] UniformConstant
711+ ; CHECK-DAG: %combined_var_sampler = OpVariable %[[sampler_ptr_ty]] UniformConstant
712+ ; CHECK-DAG: %combined_var_image = OpVariable %[[image_ptr_ty]] UniformConstant
676713 ; CHECK: = OpFunction
677714
678715 %bool = OpTypeBool
@@ -772,8 +809,8 @@ TEST_P(SplitCombinedImageSamplerPassEntryPointRemapTest,
772809 ; CHECK-NOT: %combined_var
773810 ; CHECK: OpExecutionMode %main OriginUpperLeft
774811
775- ; All traces of the variable disappear
776- ; CHECK-NOT: combined_var
812+ ; The variable disappears.
813+ ; CHECK-NOT: % combined_var =
777814 ; CHECK: OpFunctionEnd
778815 OpName %combined_var "combined_var"
779816 OpName %in_var "in_var"
0 commit comments