spirv-reader: Support GLSL.std.450 FindSMsb
Fixed: tint:1058 Change-Id: Ifdc2ee9c54d18e1efe6b908991e8eb1b8c6a6de4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104903 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: David Neto <dneto@google.com> Auto-Submit: David Neto <dneto@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
042711b2b1
commit
cc0c67bce8
|
@ -329,6 +329,8 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) {
|
||||||
return "faceForward";
|
return "faceForward";
|
||||||
case GLSLstd450FindILsb:
|
case GLSLstd450FindILsb:
|
||||||
return "firstTrailingBit";
|
return "firstTrailingBit";
|
||||||
|
case GLSLstd450FindSMsb:
|
||||||
|
return "firstLeadingBit";
|
||||||
case GLSLstd450FindUMsb:
|
case GLSLstd450FindUMsb:
|
||||||
return "firstLeadingBit";
|
return "firstLeadingBit";
|
||||||
case GLSLstd450Floor:
|
case GLSLstd450Floor:
|
||||||
|
@ -431,8 +433,6 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) {
|
||||||
case GLSLstd450PackDouble2x32:
|
case GLSLstd450PackDouble2x32:
|
||||||
case GLSLstd450UnpackDouble2x32:
|
case GLSLstd450UnpackDouble2x32:
|
||||||
|
|
||||||
case GLSLstd450FindSMsb:
|
|
||||||
|
|
||||||
case GLSLstd450InterpolateAtCentroid:
|
case GLSLstd450InterpolateAtCentroid:
|
||||||
case GLSLstd450InterpolateAtSample:
|
case GLSLstd450InterpolateAtSample:
|
||||||
case GLSLstd450InterpolateAtOffset:
|
case GLSLstd450InterpolateAtOffset:
|
||||||
|
|
|
@ -583,7 +583,8 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) {
|
||||||
INSTANTIATE_TEST_SUITE_P(Samples,
|
INSTANTIATE_TEST_SUITE_P(Samples,
|
||||||
SpvParserTest_GlslStd450_Inting_Inting,
|
SpvParserTest_GlslStd450_Inting_Inting,
|
||||||
::testing::Values(GlslStd450Case{"SAbs", "abs"},
|
::testing::Values(GlslStd450Case{"SAbs", "abs"},
|
||||||
GlslStd450Case{"FindILsb", "firstTrailingBit"}));
|
GlslStd450Case{"FindILsb", "firstTrailingBit"},
|
||||||
|
GlslStd450Case{"FindSMsb", "firstLeadingBit"}));
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(Samples,
|
INSTANTIATE_TEST_SUITE_P(Samples,
|
||||||
SpvParserTest_GlslStd450_Inting_IntingInting,
|
SpvParserTest_GlslStd450_Inting_IntingInting,
|
||||||
|
@ -978,6 +979,56 @@ let x_4 : vec2<i32> = bitcast<vec2<i32>>(firstTrailingBit(v2u1));)"))
|
||||||
<< body;
|
<< body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvParserTest, RectifyOperandsAndResult_FindSMsb) {
|
||||||
|
// Check signedness conversion of arguments and results.
|
||||||
|
// SPIR-V signed arg -> keep it
|
||||||
|
// signed result -> keep it
|
||||||
|
// unsigned result -> cast result to unsigned
|
||||||
|
//
|
||||||
|
// SPIR-V unsigned arg -> cast it to signed
|
||||||
|
// signed result -> keept it
|
||||||
|
// unsigned result -> cast result to unsigned
|
||||||
|
const auto assembly = Preamble() + R"(
|
||||||
|
; signed arg
|
||||||
|
; signed result
|
||||||
|
%1 = OpExtInst %int %glsl FindSMsb %i1
|
||||||
|
%2 = OpExtInst %v2int %glsl FindSMsb %v2i1
|
||||||
|
|
||||||
|
; signed arg
|
||||||
|
; unsigned result
|
||||||
|
%3 = OpExtInst %uint %glsl FindSMsb %i1
|
||||||
|
%4 = OpExtInst %v2uint %glsl FindSMsb %v2i1
|
||||||
|
|
||||||
|
; unsigned arg
|
||||||
|
; signed result
|
||||||
|
%5 = OpExtInst %int %glsl FindSMsb %u1
|
||||||
|
%6 = OpExtInst %v2int %glsl FindSMsb %v2u1
|
||||||
|
|
||||||
|
; unsigned arg
|
||||||
|
; unsigned result
|
||||||
|
%7 = OpExtInst %uint %glsl FindSMsb %u1
|
||||||
|
%8 = OpExtInst %v2uint %glsl FindSMsb %v2u1
|
||||||
|
OpReturn
|
||||||
|
OpFunctionEnd
|
||||||
|
)";
|
||||||
|
auto p = parser(test::Assemble(assembly));
|
||||||
|
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||||
|
auto fe = p->function_emitter(100);
|
||||||
|
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||||
|
auto ast_body = fe.ast_body();
|
||||||
|
const auto body = test::ToString(p->program(), ast_body);
|
||||||
|
EXPECT_THAT(body, HasSubstr(R"(
|
||||||
|
let x_1 : i32 = firstLeadingBit(i1);
|
||||||
|
let x_2 : vec2<i32> = firstLeadingBit(v2i1);
|
||||||
|
let x_3 : u32 = bitcast<u32>(firstLeadingBit(i1));
|
||||||
|
let x_4 : vec2<u32> = bitcast<vec2<u32>>(firstLeadingBit(v2i1));
|
||||||
|
let x_5 : i32 = firstLeadingBit(bitcast<i32>(u1));
|
||||||
|
let x_6 : vec2<i32> = firstLeadingBit(bitcast<vec2<i32>>(v2u1));
|
||||||
|
let x_7 : u32 = bitcast<u32>(firstLeadingBit(bitcast<i32>(u1)));
|
||||||
|
let x_8 : vec2<u32> = bitcast<vec2<u32>>(firstLeadingBit(bitcast<vec2<i32>>(v2u1)));
|
||||||
|
)")) << body;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SpvParserTest, RectifyOperandsAndResult_FindUMsb) {
|
TEST_F(SpvParserTest, RectifyOperandsAndResult_FindUMsb) {
|
||||||
// Check signedness conversion of arguments and results.
|
// Check signedness conversion of arguments and results.
|
||||||
// SPIR-V signed arg -> cast arg to unsigned
|
// SPIR-V signed arg -> cast arg to unsigned
|
||||||
|
|
|
@ -117,6 +117,7 @@ bool AssumesSignedOperands(GLSLstd450 extended_opcode) {
|
||||||
case GLSLstd450SMin:
|
case GLSLstd450SMin:
|
||||||
case GLSLstd450SMax:
|
case GLSLstd450SMax:
|
||||||
case GLSLstd450SClamp:
|
case GLSLstd450SClamp:
|
||||||
|
case GLSLstd450FindSMsb:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -223,8 +224,8 @@ bool AssumesResultSignednessMatchesFirstOperand(GLSLstd450 extended_opcode) {
|
||||||
case GLSLstd450UMax:
|
case GLSLstd450UMax:
|
||||||
case GLSLstd450UClamp:
|
case GLSLstd450UClamp:
|
||||||
case GLSLstd450FindILsb:
|
case GLSLstd450FindILsb:
|
||||||
|
case GLSLstd450FindSMsb:
|
||||||
case GLSLstd450FindUMsb:
|
case GLSLstd450FindUMsb:
|
||||||
// TODO(dneto): FindSMsb?
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue