spirv-reader: builtin conversions for sample_mask_in, sample_mask_out
Enum conversion of builtins depends on storage class. Bug: tint:471 Change-Id: I0b93c26139f72c70786b9b70f1016e62e1df62f4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40122 Commit-Queue: David Neto <dneto@google.com> Auto-Submit: David Neto <dneto@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
77f4f0280d
commit
ef6eefdc8f
|
@ -66,7 +66,7 @@ ast::StorageClass EnumConverter::ToStorageClass(const SpvStorageClass sc) {
|
||||||
return ast::StorageClass::kNone;
|
return ast::StorageClass::kNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::Builtin EnumConverter::ToBuiltin(SpvBuiltIn b) {
|
ast::Builtin EnumConverter::ToBuiltin(SpvBuiltIn b, ast::StorageClass sc) {
|
||||||
switch (b) {
|
switch (b) {
|
||||||
case SpvBuiltInPosition:
|
case SpvBuiltInPosition:
|
||||||
return ast::Builtin::kPosition;
|
return ast::Builtin::kPosition;
|
||||||
|
@ -88,6 +88,9 @@ ast::Builtin EnumConverter::ToBuiltin(SpvBuiltIn b) {
|
||||||
return ast::Builtin::kGlobalInvocationId;
|
return ast::Builtin::kGlobalInvocationId;
|
||||||
case SpvBuiltInSampleId:
|
case SpvBuiltInSampleId:
|
||||||
return ast::Builtin::kSampleId;
|
return ast::Builtin::kSampleId;
|
||||||
|
case SpvBuiltInSampleMask:
|
||||||
|
return sc == ast::StorageClass::kInput ? ast::Builtin::kSampleMaskIn
|
||||||
|
: ast::Builtin::kSampleMaskOut;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,9 @@ class EnumConverter {
|
||||||
/// Converts a SPIR-V Builtin value a Tint Builtin.
|
/// Converts a SPIR-V Builtin value a Tint Builtin.
|
||||||
/// On failure, logs an error and returns kNone
|
/// On failure, logs an error and returns kNone
|
||||||
/// @param b the SPIR-V builtin
|
/// @param b the SPIR-V builtin
|
||||||
|
/// @param sc the Tint storage class
|
||||||
/// @returns a Tint AST builtin
|
/// @returns a Tint AST builtin
|
||||||
ast::Builtin ToBuiltin(SpvBuiltIn b);
|
ast::Builtin ToBuiltin(SpvBuiltIn b, ast::StorageClass sc);
|
||||||
|
|
||||||
/// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension.
|
/// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension.
|
||||||
/// On failure, logs an error and returns kNone
|
/// On failure, logs an error and returns kNone
|
||||||
|
|
|
@ -165,11 +165,12 @@ INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
|
||||||
|
|
||||||
struct BuiltinCase {
|
struct BuiltinCase {
|
||||||
SpvBuiltIn builtin;
|
SpvBuiltIn builtin;
|
||||||
|
ast::StorageClass sc;
|
||||||
bool expect_success;
|
bool expect_success;
|
||||||
ast::Builtin expected;
|
ast::Builtin expected;
|
||||||
};
|
};
|
||||||
inline std::ostream& operator<<(std::ostream& out, BuiltinCase bc) {
|
inline std::ostream& operator<<(std::ostream& out, BuiltinCase bc) {
|
||||||
out << "BuiltinCase{ SpvBuiltIn:" << int(bc.builtin)
|
out << "BuiltinCase{ SpvBuiltIn:" << int(bc.builtin) << " sc:" << int(bc.sc)
|
||||||
<< " expect_success?:" << int(bc.expect_success)
|
<< " expect_success?:" << int(bc.expect_success)
|
||||||
<< " expected:" << int(bc.expected) << "}";
|
<< " expected:" << int(bc.expected) << "}";
|
||||||
return out;
|
return out;
|
||||||
|
@ -194,7 +195,7 @@ class SpvBuiltinTest : public testing::TestWithParam<BuiltinCase> {
|
||||||
TEST_P(SpvBuiltinTest, Samples) {
|
TEST_P(SpvBuiltinTest, Samples) {
|
||||||
const auto params = GetParam();
|
const auto params = GetParam();
|
||||||
|
|
||||||
const auto result = converter_.ToBuiltin(params.builtin);
|
const auto result = converter_.ToBuiltin(params.builtin, params.sc);
|
||||||
EXPECT_EQ(success_, params.expect_success);
|
EXPECT_EQ(success_, params.expect_success);
|
||||||
if (params.expect_success) {
|
if (params.expect_success) {
|
||||||
EXPECT_EQ(result, params.expected);
|
EXPECT_EQ(result, params.expected);
|
||||||
|
@ -206,29 +207,49 @@ TEST_P(SpvBuiltinTest, Samples) {
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
EnumConverterGood,
|
EnumConverterGood_Input,
|
||||||
SpvBuiltinTest,
|
SpvBuiltinTest,
|
||||||
testing::Values(
|
testing::Values(
|
||||||
BuiltinCase{SpvBuiltInPosition, true, ast::Builtin::kPosition},
|
BuiltinCase{SpvBuiltInPosition, ast::StorageClass::kInput, true,
|
||||||
BuiltinCase{SpvBuiltInVertexIndex, true, ast::Builtin::kVertexIndex},
|
ast::Builtin::kPosition},
|
||||||
BuiltinCase{SpvBuiltInInstanceIndex, true,
|
BuiltinCase{SpvBuiltInInstanceIndex, ast::StorageClass::kInput, true,
|
||||||
ast::Builtin::kInstanceIndex},
|
ast::Builtin::kInstanceIndex},
|
||||||
BuiltinCase{SpvBuiltInFrontFacing, true, ast::Builtin::kFrontFacing},
|
BuiltinCase{SpvBuiltInFrontFacing, ast::StorageClass::kInput, true,
|
||||||
BuiltinCase{SpvBuiltInFragCoord, true, ast::Builtin::kFragCoord},
|
ast::Builtin::kFrontFacing},
|
||||||
BuiltinCase{SpvBuiltInFragDepth, true, ast::Builtin::kFragDepth},
|
BuiltinCase{SpvBuiltInFragCoord, ast::StorageClass::kInput, true,
|
||||||
BuiltinCase{SpvBuiltInLocalInvocationId, true,
|
ast::Builtin::kFragCoord},
|
||||||
ast::Builtin::kLocalInvocationId},
|
BuiltinCase{SpvBuiltInLocalInvocationId, ast::StorageClass::kInput,
|
||||||
BuiltinCase{SpvBuiltInLocalInvocationIndex, true,
|
true, ast::Builtin::kLocalInvocationId},
|
||||||
ast::Builtin::kLocalInvocationIndex},
|
BuiltinCase{SpvBuiltInLocalInvocationIndex, ast::StorageClass::kInput,
|
||||||
BuiltinCase{SpvBuiltInGlobalInvocationId, true,
|
true, ast::Builtin::kLocalInvocationIndex},
|
||||||
ast::Builtin::kGlobalInvocationId}));
|
BuiltinCase{SpvBuiltInGlobalInvocationId, ast::StorageClass::kInput,
|
||||||
|
true, ast::Builtin::kGlobalInvocationId},
|
||||||
|
BuiltinCase{SpvBuiltInSampleId, ast::StorageClass::kInput, true,
|
||||||
|
ast::Builtin::kSampleId},
|
||||||
|
BuiltinCase{SpvBuiltInSampleMask, ast::StorageClass::kInput, true,
|
||||||
|
ast::Builtin::kSampleMaskIn}));
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
EnumConverterGood_Output,
|
||||||
|
SpvBuiltinTest,
|
||||||
|
testing::Values(BuiltinCase{SpvBuiltInPosition, ast::StorageClass::kOutput,
|
||||||
|
true, ast::Builtin::kPosition},
|
||||||
|
BuiltinCase{SpvBuiltInFragDepth, ast::StorageClass::kOutput,
|
||||||
|
true, ast::Builtin::kFragDepth},
|
||||||
|
BuiltinCase{SpvBuiltInSampleMask,
|
||||||
|
ast::StorageClass::kOutput, true,
|
||||||
|
ast::Builtin::kSampleMaskOut}));
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
EnumConverterBad,
|
EnumConverterBad,
|
||||||
SpvBuiltinTest,
|
SpvBuiltinTest,
|
||||||
testing::Values(
|
testing::Values(
|
||||||
BuiltinCase{static_cast<SpvBuiltIn>(9999), false, ast::Builtin::kNone},
|
BuiltinCase{static_cast<SpvBuiltIn>(9999), ast::StorageClass::kInput,
|
||||||
BuiltinCase{SpvBuiltInNumWorkgroups, false, ast::Builtin::kNone}));
|
false, ast::Builtin::kNone},
|
||||||
|
BuiltinCase{static_cast<SpvBuiltIn>(9999), ast::StorageClass::kOutput,
|
||||||
|
false, ast::Builtin::kNone},
|
||||||
|
BuiltinCase{SpvBuiltInNumWorkgroups, ast::StorageClass::kInput, false,
|
||||||
|
ast::Builtin::kNone}));
|
||||||
|
|
||||||
// Dim
|
// Dim
|
||||||
|
|
||||||
|
|
|
@ -1280,7 +1280,7 @@ ast::Variable* ParserImpl::MakeVariable(
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto ast_builtin = enum_converter_.ToBuiltin(spv_builtin);
|
auto ast_builtin = enum_converter_.ToBuiltin(spv_builtin, sc);
|
||||||
if (ast_builtin == ast::Builtin::kNone) {
|
if (ast_builtin == ast::Builtin::kNone) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue