@@ -29,8 +29,8 @@ namespace spvtools {
2929namespace opt {
3030namespace {
3131
32- using ::testing::Eq;
3332using spvtest::MakeInstruction;
33+ using ::testing::Eq;
3434using DescriptorTypeTest = PassTest<::testing::Test>;
3535using OpaqueTypeTest = PassTest<::testing::Test>;
3636using GetBaseTest = PassTest<::testing::Test>;
@@ -347,7 +347,7 @@ TEST_F(DescriptorTypeTest, StorageImage) {
347347 EXPECT_FALSE (type->IsVulkanStorageTexelBuffer ());
348348 EXPECT_FALSE (type->IsVulkanStorageBuffer ());
349349 EXPECT_FALSE (type->IsVulkanUniformBuffer ());
350- EXPECT_FALSE (type->IsVulkanReadOnlyStorageBuffer ());
350+ EXPECT_FALSE (type->IsVulkanStorageBufferNonWriteable ());
351351
352352 Instruction* variable = context->get_def_use_mgr ()->GetDef (3 );
353353 EXPECT_FALSE (variable->IsReadOnlyPointer ());
@@ -388,7 +388,7 @@ TEST_F(DescriptorTypeTest, SampledImage) {
388388 EXPECT_FALSE (type->IsVulkanStorageTexelBuffer ());
389389 EXPECT_FALSE (type->IsVulkanStorageBuffer ());
390390 EXPECT_FALSE (type->IsVulkanUniformBuffer ());
391- EXPECT_FALSE (type->IsVulkanReadOnlyStorageBuffer ());
391+ EXPECT_FALSE (type->IsVulkanStorageBufferNonWriteable ());
392392
393393 Instruction* variable = context->get_def_use_mgr ()->GetDef (3 );
394394 EXPECT_TRUE (variable->IsReadOnlyPointer ());
@@ -429,7 +429,7 @@ TEST_F(DescriptorTypeTest, StorageTexelBuffer) {
429429 EXPECT_TRUE (type->IsVulkanStorageTexelBuffer ());
430430 EXPECT_FALSE (type->IsVulkanStorageBuffer ());
431431 EXPECT_FALSE (type->IsVulkanUniformBuffer ());
432- EXPECT_FALSE (type->IsVulkanReadOnlyStorageBuffer ());
432+ EXPECT_FALSE (type->IsVulkanStorageBufferNonWriteable ());
433433
434434 Instruction* variable = context->get_def_use_mgr ()->GetDef (3 );
435435 EXPECT_FALSE (variable->IsReadOnlyPointer ());
@@ -473,7 +473,7 @@ TEST_F(DescriptorTypeTest, StorageBuffer) {
473473 EXPECT_FALSE (type->IsVulkanStorageTexelBuffer ());
474474 EXPECT_TRUE (type->IsVulkanStorageBuffer ());
475475 EXPECT_FALSE (type->IsVulkanUniformBuffer ());
476- EXPECT_FALSE (type->IsVulkanReadOnlyStorageBuffer ());
476+ EXPECT_FALSE (type->IsVulkanStorageBufferNonWriteable ());
477477
478478 Instruction* variable = context->get_def_use_mgr ()->GetDef (3 );
479479 EXPECT_FALSE (variable->IsReadOnlyPointer ());
@@ -490,35 +490,40 @@ TEST_F(DescriptorTypeTest, ReadOnlyStorageBuffer) {
490490 OpEntryPoint Fragment %2 "main"
491491 OpExecutionMode %2 OriginUpperLeft
492492 OpSource GLSL 430
493- OpName %3 "myStorageImage"
494493 OpDecorate %3 DescriptorSet 0
495494 OpDecorate %3 Binding 0
496- OpDecorate %9 BufferBlock
497- OpDecorate %9 NonWritable
498- %4 = OpTypeVoid
499- %5 = OpTypeFunction %4
500- %6 = OpTypeFloat 32
501- %7 = OpTypeVector %6 4
502- %8 = OpTypeRuntimeArray %7
503- %9 = OpTypeStruct %8
504- %10 = OpTypePointer Uniform %9
505- %3 = OpVariable %10 Uniform
506- %2 = OpFunction %4 None %5
507- %11 = OpLabel
508- %12 = OpCopyObject %8 %3
495+ OpDecorate %4 BufferBlock
496+ OpDecorate %4 NonWritable
497+ OpDecorate %5 DescriptorSet 0
498+ OpDecorate %5 Binding 1
499+ OpDecorate %6 BufferBlock
500+ %7 = OpTypeVoid
501+ %8 = OpTypeFunction %7
502+ %9 = OpTypeFloat 32
503+ %10 = OpTypeVector %9 4
504+ %11 = OpTypeRuntimeArray %10
505+ %4 = OpTypeStruct %11
506+ %6 = OpTypeStruct %11
507+ %12 = OpTypePointer Uniform %4
508+ %13 = OpTypePointer Uniform %6
509+ %3 = OpVariable %12 Uniform
510+ %5 = OpVariable %13 Uniform
511+ %2 = OpFunction %7 None %8
512+ %14 = OpLabel
513+ %15 = OpCopyObject %11 %3
509514 OpReturn
510515 OpFunctionEnd
511516)" ;
512517
513518 std::unique_ptr<IRContext> context =
514519 BuildModule (SPV_ENV_UNIVERSAL_1_2, nullptr , text);
515- Instruction* type = context->get_def_use_mgr ()->GetDef (10 );
520+ Instruction* type = context->get_def_use_mgr ()->GetDef (12 );
516521 EXPECT_FALSE (type->IsVulkanStorageImage ());
517522 EXPECT_FALSE (type->IsVulkanSampledImage ());
518523 EXPECT_FALSE (type->IsVulkanStorageTexelBuffer ());
519524 EXPECT_TRUE (type->IsVulkanStorageBuffer ());
520525 EXPECT_FALSE (type->IsVulkanUniformBuffer ());
521- EXPECT_TRUE (type->IsVulkanReadOnlyStorageBuffer ());
526+ EXPECT_TRUE (type->IsVulkanStorageBufferNonWriteable ());
522527
523528 Instruction* variable = context->get_def_use_mgr ()->GetDef (3 );
524529 EXPECT_TRUE (variable->IsReadOnlyPointer ());
@@ -527,6 +532,47 @@ TEST_F(DescriptorTypeTest, ReadOnlyStorageBuffer) {
527532 EXPECT_FALSE (object_copy->IsReadOnlyPointer ());
528533}
529534
535+ TEST_F (DescriptorTypeTest, AliasedNotReadOnlyStorageBuffer) {
536+ const std::string text = R"(
537+ OpCapability Shader
538+ %1 = OpExtInstImport "GLSL.std.450"
539+ OpMemoryModel Logical GLSL450
540+ OpEntryPoint Fragment %2 "main"
541+ OpExecutionMode %2 OriginUpperLeft
542+ OpSource GLSL 430
543+ OpDecorate %3 DescriptorSet 0
544+ OpDecorate %3 Binding 0
545+ OpDecorate %4 BufferBlock
546+ OpDecorate %4 NonWritable
547+ OpDecorate %5 DescriptorSet 0
548+ OpDecorate %5 Binding 0
549+ OpDecorate %6 BufferBlock
550+ %7 = OpTypeVoid
551+ %8 = OpTypeFunction %7
552+ %9 = OpTypeFloat 32
553+ %10 = OpTypeVector %9 4
554+ %11 = OpTypeRuntimeArray %10
555+ %4 = OpTypeStruct %11
556+ %6 = OpTypeStruct %11
557+ %12 = OpTypePointer Uniform %4
558+ %13 = OpTypePointer Uniform %6
559+ %3 = OpVariable %12 Uniform
560+ %5 = OpVariable %13 Uniform
561+ %2 = OpFunction %7 None %8
562+ %14 = OpLabel
563+ %15 = OpCopyObject %11 %3
564+ OpReturn
565+ OpFunctionEnd
566+ )" ;
567+
568+ std::unique_ptr<IRContext> context =
569+ BuildModule (SPV_ENV_UNIVERSAL_1_2, nullptr , text);
570+ Instruction* variable_readonly = context->get_def_use_mgr ()->GetDef (3 );
571+ EXPECT_FALSE (variable_readonly->IsReadOnlyPointer ());
572+ Instruction* variable_writeonly = context->get_def_use_mgr ()->GetDef (5 );
573+ EXPECT_FALSE (variable_readonly->IsReadOnlyPointer ());
574+ }
575+
530576TEST_F (DescriptorTypeTest, UniformBuffer) {
531577 const std::string text = R"(
532578 OpCapability Shader
@@ -562,7 +608,7 @@ TEST_F(DescriptorTypeTest, UniformBuffer) {
562608 EXPECT_FALSE (type->IsVulkanStorageTexelBuffer ());
563609 EXPECT_FALSE (type->IsVulkanStorageBuffer ());
564610 EXPECT_TRUE (type->IsVulkanUniformBuffer ());
565- EXPECT_FALSE (type->IsVulkanReadOnlyStorageBuffer ());
611+ EXPECT_FALSE (type->IsVulkanStorageBufferNonWriteable ());
566612
567613 Instruction* variable = context->get_def_use_mgr ()->GetDef (3 );
568614 EXPECT_TRUE (variable->IsReadOnlyPointer ());
0 commit comments