@@ -33,15 +33,17 @@ using ValidateComposites = spvtest::ValidateBase<bool>;
3333std::string GenerateShaderCode (
3434 const std::string& body,
3535 const std::string& capabilities_and_extensions = " " ,
36- const std::string& execution_model = " Fragment" ) {
36+ const std::string& execution_model = " Fragment" ,
37+ const std::string& extra_types = " " ,
38+ const std::string& memory_model = " Logical GLSL450" ) {
3739 std::ostringstream ss;
3840 ss << R"(
3941OpCapability Shader
4042OpCapability Float64
4143)" ;
4244
4345 ss << capabilities_and_extensions;
44- ss << " OpMemoryModel Logical GLSL450 \n " ;
46+ ss << " OpMemoryModel " << memory_model << " \n " ;
4547 ss << " OpEntryPoint " << execution_model << " %main \" main\"\n " ;
4648 if (execution_model == " Fragment" ) {
4749 ss << " OpExecutionMode %main OriginUpperLeft\n " ;
@@ -93,7 +95,11 @@ OpCapability Float64
9395
9496%ptr_big_struct = OpTypePointer Uniform %big_struct
9597%var_big_struct = OpVariable %ptr_big_struct Uniform
98+ )" ;
99+
100+ ss << extra_types;
96101
102+ ss << R"(
97103%main = OpFunction %void None %func
98104%main_entry = OpLabel
99105)" ;
@@ -536,6 +542,201 @@ TEST_F(ValidateComposites, CompositeConstructStructWrongConstituent) {
536542 " corresponding member type of Result Type struct" ));
537543}
538544
545+ TEST_F (ValidateComposites, CompositeConstructReplicateVectorGood) {
546+ const std::string body = R"(
547+ %val1 = OpCompositeConstructReplicateEXT %f32vec4 %f32_0
548+ )" ;
549+
550+ CompileSuccessfully (
551+ GenerateShaderCode (body,
552+ " OpCapability ReplicatedCompositesEXT\n OpExtension "
553+ " \" SPV_EXT_replicated_composites\"\n " )
554+ .c_str ());
555+ ASSERT_EQ (SPV_SUCCESS, ValidateInstructions ());
556+ }
557+
558+ TEST_F (ValidateComposites, CompositeConstructReplicateMatrixGood) {
559+ const std::string body = R"(
560+ %val1 = OpCompositeConstructReplicateEXT %f32mat22 %f32vec2_01
561+ )" ;
562+
563+ CompileSuccessfully (
564+ GenerateShaderCode (body,
565+ " OpCapability ReplicatedCompositesEXT\n OpExtension "
566+ " \" SPV_EXT_replicated_composites\"\n " ,
567+ " Fragment" )
568+ .c_str ());
569+ ASSERT_EQ (SPV_SUCCESS, ValidateInstructions ());
570+ }
571+
572+ TEST_F (ValidateComposites, CompositeConstructReplicateArrayGood) {
573+ const std::string body = R"(
574+ %val1 = OpCompositeConstructReplicateEXT %f32vec2arr3 %f32vec2_12
575+ )" ;
576+
577+ CompileSuccessfully (
578+ GenerateShaderCode (body,
579+ " OpCapability ReplicatedCompositesEXT\n OpExtension "
580+ " \" SPV_EXT_replicated_composites\"\n " )
581+ .c_str ());
582+ ASSERT_EQ (SPV_SUCCESS, ValidateInstructions ());
583+ }
584+
585+ TEST_F (ValidateComposites, CompositeConstructReplicateStructGood) {
586+ const std::string copy_types = R"(
587+ %f32struct = OpTypeStruct %f32 %f32 %f32
588+ )" ;
589+
590+ const std::string body = R"(
591+ %val1 = OpCompositeConstructReplicateEXT %f32struct %f32_0
592+ )" ;
593+
594+ CompileSuccessfully (
595+ GenerateShaderCode (body,
596+ " OpCapability ReplicatedCompositesEXT\n OpExtension "
597+ " \" SPV_EXT_replicated_composites\"\n " ,
598+ " Fragment" , copy_types)
599+ .c_str ());
600+ ASSERT_EQ (SPV_SUCCESS, ValidateInstructions ());
601+ }
602+
603+ TEST_F (ValidateComposites, CompositeConstructReplicateCoopMatGood) {
604+ const std::string extra_types = R"(
605+ %u32_8 = OpConstant %u32 8
606+ %u32_16 = OpConstant %u32 16
607+ %subgroup = OpConstant %u32 3
608+ %useA = OpConstant %u32 0
609+ %f32mat_nv = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_8 %u32_8
610+ %f32mat_khr = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_16 %u32_16 %useA
611+ )" ;
612+
613+ const std::string body = R"(
614+ %val1 = OpCompositeConstructReplicateEXT %f32mat_nv %f32_0
615+ %val2 = OpCompositeConstructReplicateEXT %f32mat_khr %f32_0
616+ )" ;
617+
618+ CompileSuccessfully (
619+ GenerateShaderCode (body,
620+ " OpCapability ReplicatedCompositesEXT\n "
621+ " OpCapability CooperativeMatrixNV\n "
622+ " OpCapability CooperativeMatrixKHR\n "
623+ " OpCapability VulkanMemoryModel\n "
624+ " OpCapability Float16\n "
625+ " OpExtension \" SPV_EXT_replicated_composites\"\n "
626+ " OpExtension \" SPV_NV_cooperative_matrix\"\n "
627+ " OpExtension \" SPV_KHR_cooperative_matrix\"\n "
628+ " OpExtension \" SPV_KHR_vulkan_memory_model\"\n " ,
629+ " Fragment" , extra_types, " Logical Vulkan" )
630+ .c_str (),
631+ SPV_ENV_UNIVERSAL_1_3);
632+ ASSERT_EQ (SPV_SUCCESS, ValidateInstructions (SPV_ENV_UNIVERSAL_1_3));
633+ }
634+
635+ TEST_F (ValidateComposites, CompositeConstructReplicateTensorGood) {
636+ const std::string extra_types = R"(
637+ %arr = OpTypeArray %u32 %u32_1
638+ %c_arr = OpConstantNull %arr
639+ %tensor = OpTypeTensorARM %f32 %u32_1 %c_arr
640+ )" ;
641+
642+ const std::string body = R"(
643+ %val1 = OpCompositeConstructReplicateEXT %tensor %f32_0
644+ )" ;
645+
646+ CompileSuccessfully (
647+ GenerateShaderCode (body,
648+ " OpCapability ReplicatedCompositesEXT\n OpCapability "
649+ " TensorsARM\n OpExtension "
650+ " \" SPV_EXT_replicated_composites\"\n OpExtension "
651+ " \" SPV_ARM_tensors\"\n " ,
652+ " Fragment" , extra_types)
653+ .c_str ());
654+ ASSERT_EQ (SPV_SUCCESS, ValidateInstructions ());
655+ }
656+
657+ TEST_F (ValidateComposites, CompositeConstructReplicateCoopMatWrongOperand) {
658+ const std::string extra_types = R"(
659+ %u32_8 = OpConstant %u32 8
660+ %subgroup = OpConstant %u32 3
661+ %f32mat_nv = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_8 %u32_8
662+ )" ;
663+
664+ const std::string body = R"(
665+ %val1 = OpCompositeConstructReplicateEXT %f32mat_nv %u32_0
666+ )" ;
667+
668+ CompileSuccessfully (
669+ GenerateShaderCode (body,
670+ " OpCapability ReplicatedCompositesEXT\n "
671+ " OpCapability CooperativeMatrixNV\n "
672+ " OpCapability Float16\n "
673+ " OpExtension \" SPV_EXT_replicated_composites\"\n "
674+ " OpExtension \" SPV_NV_cooperative_matrix\"\n " ,
675+ " Fragment" , extra_types)
676+ .c_str ());
677+ ASSERT_EQ (SPV_ERROR_INVALID_DATA, ValidateInstructions ());
678+ EXPECT_THAT (
679+ getDiagnosticString (),
680+ HasSubstr (
681+ " Expected Value type to be equal to the result's element type" ));
682+ }
683+
684+ TEST_F (ValidateComposites, CompositeConstructReplicateTensorWrongOperand) {
685+ const std::string extra_types = R"(
686+ %tensor = OpTypeTensorARM %f32
687+ )" ;
688+
689+ const std::string body = R"(
690+ %val1 = OpCompositeConstructReplicateEXT %tensor %u32_0
691+ )" ;
692+
693+ CompileSuccessfully (
694+ GenerateShaderCode (body,
695+ " OpCapability ReplicatedCompositesEXT\n OpCapability "
696+ " TensorsARM\n OpExtension "
697+ " \" SPV_EXT_replicated_composites\"\n OpExtension "
698+ " \" SPV_ARM_tensors\"\n " ,
699+ " Fragment" , extra_types)
700+ .c_str ());
701+ ASSERT_EQ (SPV_ERROR_INVALID_DATA, ValidateInstructions ());
702+ EXPECT_THAT (
703+ getDiagnosticString (),
704+ HasSubstr (
705+ " Expected Value type to be equal to the result's element type" ));
706+ }
707+
708+ TEST_F (ValidateComposites, CompositeConstructReplicateWrongOperandType) {
709+ const std::string body = R"(
710+ %val1 = OpCompositeConstructReplicateEXT %f32vec4 %u32_0
711+ )" ;
712+
713+ CompileSuccessfully (
714+ GenerateShaderCode (body,
715+ " OpCapability ReplicatedCompositesEXT\n OpExtension "
716+ " \" SPV_EXT_replicated_composites\"\n " )
717+ .c_str ());
718+ ASSERT_EQ (SPV_ERROR_INVALID_DATA, ValidateInstructions ());
719+ EXPECT_THAT (
720+ getDiagnosticString (),
721+ HasSubstr (
722+ " Expected Value type to be equal to the result's element type" ));
723+ }
724+
725+ TEST_F (ValidateComposites, CompositeConstructReplicateNotComposite) {
726+ const std::string body = R"(
727+ %val1 = OpCompositeConstructReplicateEXT %f32 %f32_0
728+ )" ;
729+
730+ CompileSuccessfully (
731+ GenerateShaderCode (body,
732+ " OpCapability ReplicatedCompositesEXT\n OpExtension "
733+ " \" SPV_EXT_replicated_composites\"\n " )
734+ .c_str ());
735+ ASSERT_EQ (SPV_ERROR_INVALID_DATA, ValidateInstructions ());
736+ EXPECT_THAT (getDiagnosticString (),
737+ HasSubstr (" Expected Result Type to be a composite type" ));
738+ }
739+
539740TEST_F (ValidateComposites, CopyObjectSuccess) {
540741 const std::string body = R"(
541742%val1 = OpCopyObject %f32 %f32_0
0 commit comments