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

spirv-val: Add VK_KHR_maintenance8 support #5951

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetSkipBlockLayout(
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetAllowLocalSizeId(
spv_validator_options options, bool val);

// Allow Offset (in addition to ConstOffset) for texture operations.
// Was added for VK_KHR_maintenance8
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetAllowOffsetTextureOperand(
spv_validator_options options, bool val);

// Whether friendly names should be used in validation error messages.
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetFriendlyNames(
spv_validator_options options, bool val);
Expand Down
6 changes: 6 additions & 0 deletions include/spirv-tools/libspirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ class SPIRV_TOOLS_EXPORT ValidatorOptions {
spvValidatorOptionsSetAllowLocalSizeId(options_, val);
}

// Allow Offset (in addition to ConstOffset) for texture
// operations. Was added for VK_KHR_maintenance8
void SetAllowOffsetTextureOperand(bool val) {
spvValidatorOptionsSetAllowOffsetTextureOperand(options_, val);
}

// Records whether or not the validator should relax the rules on pointer
// usage in logical addressing mode.
//
Expand Down
5 changes: 5 additions & 0 deletions source/spirv_validator_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ void spvValidatorOptionsSetAllowLocalSizeId(spv_validator_options options,
options->allow_localsizeid = val;
}

void spvValidatorOptionsSetAllowOffsetTextureOperand(
spv_validator_options options, bool val) {
options->allow_offset_texture_operand = val;
}

void spvValidatorOptionsSetFriendlyNames(spv_validator_options options,
bool val) {
options->use_friendly_names = val;
Expand Down
2 changes: 2 additions & 0 deletions source/spirv_validator_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct spv_validator_options_t {
workgroup_scalar_block_layout(false),
skip_block_layout(false),
allow_localsizeid(false),
allow_offset_texture_operand(false),
before_hlsl_legalization(false),
use_friendly_names(true) {}

Expand All @@ -60,6 +61,7 @@ struct spv_validator_options_t {
bool workgroup_scalar_block_layout;
bool skip_block_layout;
bool allow_localsizeid;
bool allow_offset_texture_operand;
bool before_hlsl_legalization;
bool use_friendly_names;
};
Expand Down
4 changes: 2 additions & 2 deletions source/val/validate_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,13 @@ spv_result_t ValidateImageOperands(ValidationState_t& _,
}

if (!_.options()->before_hlsl_legalization &&
spvIsVulkanEnv(_.context()->target_env)) {
spvIsVulkanEnv(_.context()->target_env) &&
!_.options()->allow_offset_texture_operand) {
if (opcode != spv::Op::OpImageGather &&
opcode != spv::Op::OpImageDrefGather &&
opcode != spv::Op::OpImageSparseGather &&
opcode != spv::Op::OpImageSparseDrefGather) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< _.VkErrorID(4663)
<< "Image Operand Offset can only be used with "
"OpImage*Gather operations";
}
Expand Down
2 changes: 0 additions & 2 deletions source/val/validation_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,8 +2264,6 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
return VUID_WRAP(VUID-StandaloneSpirv-OpImageTexelPointer-04658);
case 4659:
return VUID_WRAP(VUID-StandaloneSpirv-OpImageQuerySizeLod-04659);
case 4663:
return VUID_WRAP(VUID-StandaloneSpirv-Offset-04663);
case 4664:
return VUID_WRAP(VUID-StandaloneSpirv-OpImageGather-04664);
case 4667:
Expand Down
17 changes: 15 additions & 2 deletions test/val/val_image_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>

#include "gmock/gmock.h"
#include "spirv-tools/libspirv.h"
#include "test/unit_spirv.h"
#include "test/val/val_fixtures.h"

Expand Down Expand Up @@ -2144,13 +2145,25 @@ TEST_F(ValidateImage, SampleImplicitLodVulkanOffsetWrongSize) {
CompileSuccessfully(
GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-Offset-04663"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Image Operand Offset can only be used with "
"OpImage*Gather operations"));
}

TEST_F(ValidateImage, SampleImplicitLodVulkanOffsetMaintenance8) {
const std::string body = R"(
%img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
%sampler = OpLoad %type_sampler %uniform_sampler
%simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
%res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec2_01
)";

CompileSuccessfully(
GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
spvValidatorOptionsSetAllowOffsetTextureOperand(getValidatorOptions(), true);
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
}

TEST_F(ValidateImage, SampleImplicitLodVulkanOffsetWrongBeforeLegalization) {
const std::string body = R"(
%img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
Expand Down
4 changes: 4 additions & 0 deletions tools/val/val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ NOTE: The validator is a work in progress.
members.
--allow-localsizeid Allow use of the LocalSizeId decoration where it would otherwise not
be allowed by the target environment.
--allow-offset-texture-operand Allow use of the Offset texture operands where it would otherwise not
be allowed by the target environment.
--before-hlsl-legalization Allows code patterns that are intended to be
fixed by spirv-opt's legalization passes.
--version Display validator version information.
Expand Down Expand Up @@ -161,6 +163,8 @@ int main(int argc, char** argv) {
options.SetSkipBlockLayout(true);
} else if (0 == strcmp(cur_arg, "--allow-localsizeid")) {
options.SetAllowLocalSizeId(true);
} else if (0 == strcmp(cur_arg, "--allow-offset-texture-operand")) {
options.SetAllowOffsetTextureOperand(true);
} else if (0 == strcmp(cur_arg, "--relax-struct-store")) {
options.SetRelaxStructStore(true);
} else if (0 == cur_arg[1]) {
Expand Down
Loading