Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arrayed storage images for NonWritable decoration #2358

Merged
merged 2 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions source/val/validate_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,23 @@ spv_result_t ValidateTypeStruct(ValidationState_t& _, const Instruction* inst) {

spv_result_t ValidateTypePointer(ValidationState_t& _,
const Instruction* inst) {
const auto type_id = inst->GetOperandAs<uint32_t>(2);
const auto type = _.FindDef(type_id);
auto type_id = inst->GetOperandAs<uint32_t>(2);
auto type = _.FindDef(type_id);
if (!type || !spvOpcodeGeneratesType(type->opcode())) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpTypePointer Type <id> '" << _.getIdName(type_id)
<< "' is not a type.";
}
// See if this points to a storage image.
if (type->opcode() == SpvOpTypeImage) {
const auto storage_class = inst->GetOperandAs<uint32_t>(1);
if (storage_class == SpvStorageClassUniformConstant) {
const auto storage_class = inst->GetOperandAs<SpvStorageClass>(1);
if (storage_class == SpvStorageClassUniformConstant) {
// Unpack an optional level of arraying.
if (type->opcode() == SpvOpTypeArray ||
type->opcode() == SpvOpTypeRuntimeArray) {
type_id = type->GetOperandAs<uint32_t>(1);
type = _.FindDef(type_id);
}
if (type->opcode() == SpvOpTypeImage) {
const auto sampled = type->GetOperandAs<uint32_t>(6);
// 2 indicates this image is known to be be used without a sampler, i.e.
// a storage image.
Expand Down
24 changes: 24 additions & 0 deletions test/val/val_decoration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5517,6 +5517,8 @@ std::string ShaderWithNonWritableTarget(const std::string& target,

return std::string(R"(
OpCapability Shader
OpCapability RuntimeDescriptorArrayEXT
OpExtension "SPV_EXT_descriptor_indexing"
OpExtension "SPV_KHR_storage_buffer_storage_class"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main"
Expand Down Expand Up @@ -5546,6 +5548,8 @@ std::string ShaderWithNonWritableTarget(const std::string& target,
%void_fn = OpTypeFunction %void
%float = OpTypeFloat 32
%float_0 = OpConstant %float 0
%int = OpTypeInt 32 0
%int_2 = OpConstant %int 2
%struct_b = OpTypeStruct %float
%struct_bb = OpTypeStruct %float
%rtarr = OpTypeRuntimeArray %float
Expand All @@ -5555,6 +5559,8 @@ std::string ShaderWithNonWritableTarget(const std::string& target,
%imstor = OpTypeImage %float 2D 0 0 0 2 R32f
; sampled image
%imsam = OpTypeImage %float 2D 0 0 0 1 R32f
%array_imstor = OpTypeArray %imstor %int_2
%rta_imstor = OpTypeRuntimeArray %imstor

%_ptr_Uniform_stb = OpTypePointer Uniform %struct_b
%_ptr_Uniform_stbb = OpTypePointer Uniform %struct_bb
Expand All @@ -5565,6 +5571,8 @@ std::string ShaderWithNonWritableTarget(const std::string& target,
%_ptr_Function = OpTypePointer Function %float
%_ptr_imstor = OpTypePointer UniformConstant %imstor
%_ptr_imsam = OpTypePointer UniformConstant %imsam
%_ptr_array_imstor = OpTypePointer UniformConstant %array_imstor
%_ptr_rta_imstor = OpTypePointer UniformConstant %rta_imstor

%extra_fn = OpTypeFunction %void %float %_ptr_Private %_ptr_imstor

Expand All @@ -5576,6 +5584,8 @@ std::string ShaderWithNonWritableTarget(const std::string& target,
%var_priv = OpVariable %_ptr_Private Private
%var_imstor = OpVariable %_ptr_imstor UniformConstant
%var_imsam = OpVariable %_ptr_imsam UniformConstant
%var_array_imstor = OpVariable %_ptr_array_imstor UniformConstant
%var_rta_imstor = OpVariable %_ptr_rta_imstor UniformConstant

%helper = OpFunction %void None %extra_fn
%param_f = OpFunctionParameter %float
Expand Down Expand Up @@ -5754,6 +5764,20 @@ TEST_F(ValidateDecorations, NonWritableVarFunctionBad) {
"buffer\n %var_func"));
}

TEST_F(ValidateDecorations, NonWritableArrayGood) {
std::string spirv = ShaderWithNonWritableTarget("%var_array_imstor");

CompileSuccessfully(spirv);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}

TEST_F(ValidateDecorations, NonWritableRuntimeArrayGood) {
std::string spirv = ShaderWithNonWritableTarget("%var_rta_imstor");

CompileSuccessfully(spirv);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}

TEST_P(ValidateWebGPUCombineDecorationResult, Decorate) {
const char* const decoration = std::get<0>(GetParam());
const TestResult& test_result = std::get<1>(GetParam());
Expand Down