Allow WorkgroupSize on variables for Kernels (#4627)

* Update tests
This commit is contained in:
alan-baker 2021-11-10 15:06:39 -05:00 committed by GitHub
parent 352a411278
commit b014238e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 9 deletions

View File

@ -266,7 +266,8 @@ spv_result_t ValidateDecorationTarget(ValidationState_t& _, SpvDecoration dec,
<< "BuiltIns can only target variables, structure members or "
"constants";
}
if (inst->GetOperandAs<SpvBuiltIn>(2) == SpvBuiltInWorkgroupSize) {
if (_.HasCapability(SpvCapabilityShader) &&
inst->GetOperandAs<SpvBuiltIn>(2) == SpvBuiltInWorkgroupSize) {
if (!spvOpcodeIsConstant(target->opcode())) {
return fail() << "must be a constant for WorkgroupSize";
}

View File

@ -32,6 +32,40 @@ using ::testing::Eq;
using ::testing::HasSubstr;
using ::testing::Values;
using DecorationTest = spvtest::ValidateBase<bool>;
TEST_F(DecorationTest, WorkgroupSizeShader) {
const std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
OpDecorate %ones BuiltIn WorkgroupSize
%int = OpTypeInt 32 0
%int3 = OpTypeVector %int 3
%int_1 = OpConstant %int 1
%ones = OpConstantComposite %int3 %int_1 %int_1 %int_1
)";
CompileSuccessfully(text);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(DecorationTest, WorkgroupSizeKernel) {
const std::string text = R"(
OpCapability Kernel
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %var BuiltIn WorkgroupSize
%int = OpTypeInt 32 0
%int3 = OpTypeVector %int 3
%ptr = OpTypePointer Input %int3
%var = OpVariable %ptr Input
)";
CompileSuccessfully(text);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}
using MemberOnlyDecorations = spvtest::ValidateBase<std::string>;
TEST_P(MemberOnlyDecorations, MemberDecoration) {

View File

@ -1700,14 +1700,6 @@ std::make_pair(std::string(kOpenCLMemoryModel) +
"%ptr = OpTypePointer Input %intt\n"
"%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
AllCapabilities()),
std::make_pair(std::string(kOpenCLMemoryModel) +
"OpEntryPoint Kernel %func \"compute\" \n" +
"OpDecorate %ones BuiltIn WorkgroupSize\n"
"%intt = OpTypeInt 32 0\n"
"%int3 = OpTypeVector %intt 3\n"
"%int_1 = OpConstant %intt 1\n"
"%ones = OpConstantComposite %int3 %int_1 %int_1 %int_1\n" + std::string(kVoidFVoid),
AllCapabilities()),
std::make_pair(std::string(kOpenCLMemoryModel) +
"OpEntryPoint Kernel %func \"compute\" \n" +
"OpDecorate %var BuiltIn WorkgroupId\n"