spirv-reader: fix arity for depth texture builtins
Texture buitins on depth textures always result in scalar f32. Corresponding operations in SPIR-V always result in vec4<f32>. When translating to Tint AST, wrap the generated texture builtin in a type constructor to vec4, with the builtin result as the x component. Fixed: tint:411 Change-Id: Idf26a1cbc7e875bc8a97bf3c0b342c0220c6d4b7 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35900 Auto-Submit: David Neto <dneto@google.com> Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
a57f842be9
commit
d1469c60c1
|
@ -4145,14 +4145,31 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
|
|||
// It returns a value.
|
||||
ast::Expression* value = call_expr;
|
||||
|
||||
// If necessary, convert the result to the signedness of the instruction
|
||||
// result type. Compare the SPIR-V image's sampled component type with the
|
||||
// component of the result type of the SPIR-V instruction.
|
||||
// The result type, derived from the SPIR-V instruction.
|
||||
auto* result_type = parser_impl_.ConvertType(inst.type_id());
|
||||
auto* result_component_type = result_type;
|
||||
if (auto* result_vector_type = result_type->As<ast::type::Vector>()) {
|
||||
result_component_type = result_vector_type->type();
|
||||
}
|
||||
|
||||
// Convert the arity of the result when operating on depth textures.
|
||||
// SPIR-V operations on depth textures always result in 4-element vectors.
|
||||
// But WGSL operations on depth textures always result in a f32 scalar.
|
||||
// Construct a 4-element vector with the result from the builtin in the
|
||||
// first component.
|
||||
if (texture_type->Is<ast::type::DepthTexture>()) {
|
||||
value = create<ast::TypeConstructorExpression>(
|
||||
Source{},
|
||||
result_type, // a vec4
|
||||
ast::ExpressionList{
|
||||
value, parser_impl_.MakeNullValue(result_component_type),
|
||||
parser_impl_.MakeNullValue(result_component_type),
|
||||
parser_impl_.MakeNullValue(result_component_type)});
|
||||
}
|
||||
|
||||
// If necessary, convert the result to the signedness of the instruction
|
||||
// result type. Compare the SPIR-V image's sampled component type with the
|
||||
// component of the result type of the SPIR-V instruction.
|
||||
auto* spirv_image_type =
|
||||
parser_impl_.GetSpirvTypeForHandleMemoryObjectDeclaration(*image);
|
||||
if (!spirv_image_type || (spirv_image_type->opcode() != SpvOpTypeImage)) {
|
||||
|
|
|
@ -1751,6 +1751,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
none
|
||||
__vec_4__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
Call[not set]{
|
||||
Identifier[not set]{textureSample}
|
||||
(
|
||||
|
@ -1759,6 +1761,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
Identifier[not set]{coords12}
|
||||
)
|
||||
}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1768,6 +1774,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
none
|
||||
__vec_4__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
Call[not set]{
|
||||
Identifier[not set]{textureSampleCompare}
|
||||
(
|
||||
|
@ -1777,6 +1785,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
ScalarConstructor[not set]{0.200000}
|
||||
)
|
||||
}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"}));
|
||||
|
@ -1809,6 +1821,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
__depth_texture_2d
|
||||
})",
|
||||
R"(
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
Call[not set]{
|
||||
Identifier[not set]{textureSampleCompare}
|
||||
(
|
||||
|
@ -1817,6 +1831,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
Identifier[not set]{coords12}
|
||||
ScalarConstructor[not set]{0.200000}
|
||||
)
|
||||
}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
})"},
|
||||
// ImageSampleDrefImplicitLod - arrayed
|
||||
ImageAccessCase{"%float 2D 0 1 0 1 Unknown",
|
||||
|
@ -1842,6 +1860,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
__depth_texture_2d_array
|
||||
})",
|
||||
R"(
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
Call[not set]{
|
||||
Identifier[not set]{textureSampleCompare}
|
||||
(
|
||||
|
@ -1860,6 +1880,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
}
|
||||
ScalarConstructor[not set]{0.200000}
|
||||
)
|
||||
}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
})"},
|
||||
// ImageSampleDrefImplicitLod with ConstOffset
|
||||
ImageAccessCase{
|
||||
|
@ -1886,6 +1910,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
__depth_texture_2d
|
||||
})",
|
||||
R"(
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
Call[not set]{
|
||||
Identifier[not set]{textureSampleCompare}
|
||||
(
|
||||
|
@ -1895,6 +1921,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
ScalarConstructor[not set]{0.200000}
|
||||
Identifier[not set]{offsets2d}
|
||||
)
|
||||
}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
})"},
|
||||
// ImageSampleDrefImplicitLod arrayed with ConstOffset
|
||||
ImageAccessCase{
|
||||
|
@ -1921,6 +1951,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
__depth_texture_2d_array
|
||||
})",
|
||||
R"(
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
Call[not set]{
|
||||
Identifier[not set]{textureSampleCompare}
|
||||
(
|
||||
|
@ -1940,6 +1972,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
ScalarConstructor[not set]{0.200000}
|
||||
Identifier[not set]{offsets2d}
|
||||
)
|
||||
}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
})"}));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
@ -2471,6 +2507,8 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
__depth_texture_2d
|
||||
})",
|
||||
R"(
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
Call[not set]{
|
||||
Identifier[not set]{textureSampleLevel}
|
||||
(
|
||||
|
@ -2482,6 +2520,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
Identifier[not set]{f1}
|
||||
}
|
||||
)
|
||||
}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
})"}}));
|
||||
|
||||
using SpvParserTest_ImageAccessTest =
|
||||
|
|
Loading…
Reference in New Issue