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.
|
// It returns a value.
|
||||||
ast::Expression* value = call_expr;
|
ast::Expression* value = call_expr;
|
||||||
|
|
||||||
// If necessary, convert the result to the signedness of the instruction
|
// The result type, derived from the SPIR-V 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* result_type = parser_impl_.ConvertType(inst.type_id());
|
auto* result_type = parser_impl_.ConvertType(inst.type_id());
|
||||||
auto* result_component_type = result_type;
|
auto* result_component_type = result_type;
|
||||||
if (auto* result_vector_type = result_type->As<ast::type::Vector>()) {
|
if (auto* result_vector_type = result_type->As<ast::type::Vector>()) {
|
||||||
result_component_type = result_vector_type->type();
|
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 =
|
auto* spirv_image_type =
|
||||||
parser_impl_.GetSpirvTypeForHandleMemoryObjectDeclaration(*image);
|
parser_impl_.GetSpirvTypeForHandleMemoryObjectDeclaration(*image);
|
||||||
if (!spirv_image_type || (spirv_image_type->opcode() != SpvOpTypeImage)) {
|
if (!spirv_image_type || (spirv_image_type->opcode() != SpvOpTypeImage)) {
|
||||||
|
|
|
@ -1751,13 +1751,19 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
none
|
none
|
||||||
__vec_4__f32
|
__vec_4__f32
|
||||||
{
|
{
|
||||||
Call[not set]{
|
TypeConstructor[not set]{
|
||||||
Identifier[not set]{textureSample}
|
__vec_4__f32
|
||||||
(
|
Call[not set]{
|
||||||
Identifier[not set]{x_20}
|
Identifier[not set]{textureSample}
|
||||||
Identifier[not set]{x_10}
|
(
|
||||||
Identifier[not set]{coords12}
|
Identifier[not set]{x_20}
|
||||||
)
|
Identifier[not set]{x_10}
|
||||||
|
Identifier[not set]{coords12}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1768,14 +1774,20 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
none
|
none
|
||||||
__vec_4__f32
|
__vec_4__f32
|
||||||
{
|
{
|
||||||
Call[not set]{
|
TypeConstructor[not set]{
|
||||||
Identifier[not set]{textureSampleCompare}
|
__vec_4__f32
|
||||||
(
|
Call[not set]{
|
||||||
Identifier[not set]{x_20}
|
Identifier[not set]{textureSampleCompare}
|
||||||
Identifier[not set]{x_30}
|
(
|
||||||
Identifier[not set]{coords12}
|
Identifier[not set]{x_20}
|
||||||
ScalarConstructor[not set]{0.200000}
|
Identifier[not set]{x_30}
|
||||||
)
|
Identifier[not set]{coords12}
|
||||||
|
ScalarConstructor[not set]{0.200000}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1809,14 +1821,20 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
__depth_texture_2d
|
__depth_texture_2d
|
||||||
})",
|
})",
|
||||||
R"(
|
R"(
|
||||||
Call[not set]{
|
TypeConstructor[not set]{
|
||||||
Identifier[not set]{textureSampleCompare}
|
__vec_4__f32
|
||||||
(
|
Call[not set]{
|
||||||
Identifier[not set]{x_20}
|
Identifier[not set]{textureSampleCompare}
|
||||||
Identifier[not set]{x_10}
|
(
|
||||||
Identifier[not set]{coords12}
|
Identifier[not set]{x_20}
|
||||||
ScalarConstructor[not set]{0.200000}
|
Identifier[not set]{x_10}
|
||||||
)
|
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
|
// ImageSampleDrefImplicitLod - arrayed
|
||||||
ImageAccessCase{"%float 2D 0 1 0 1 Unknown",
|
ImageAccessCase{"%float 2D 0 1 0 1 Unknown",
|
||||||
|
@ -1842,24 +1860,30 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
__depth_texture_2d_array
|
__depth_texture_2d_array
|
||||||
})",
|
})",
|
||||||
R"(
|
R"(
|
||||||
Call[not set]{
|
TypeConstructor[not set]{
|
||||||
Identifier[not set]{textureSampleCompare}
|
__vec_4__f32
|
||||||
(
|
Call[not set]{
|
||||||
Identifier[not set]{x_20}
|
Identifier[not set]{textureSampleCompare}
|
||||||
Identifier[not set]{x_10}
|
(
|
||||||
MemberAccessor[not set]{
|
Identifier[not set]{x_20}
|
||||||
Identifier[not set]{coords123}
|
Identifier[not set]{x_10}
|
||||||
Identifier[not set]{xy}
|
|
||||||
}
|
|
||||||
TypeConstructor[not set]{
|
|
||||||
__i32
|
|
||||||
MemberAccessor[not set]{
|
MemberAccessor[not set]{
|
||||||
Identifier[not set]{coords123}
|
Identifier[not set]{coords123}
|
||||||
Identifier[not set]{z}
|
Identifier[not set]{xy}
|
||||||
}
|
}
|
||||||
}
|
TypeConstructor[not set]{
|
||||||
ScalarConstructor[not set]{0.200000}
|
__i32
|
||||||
)
|
MemberAccessor[not set]{
|
||||||
|
Identifier[not set]{coords123}
|
||||||
|
Identifier[not set]{z}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ScalarConstructor[not set]{0.200000}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
})"},
|
})"},
|
||||||
// ImageSampleDrefImplicitLod with ConstOffset
|
// ImageSampleDrefImplicitLod with ConstOffset
|
||||||
ImageAccessCase{
|
ImageAccessCase{
|
||||||
|
@ -1886,15 +1910,21 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
__depth_texture_2d
|
__depth_texture_2d
|
||||||
})",
|
})",
|
||||||
R"(
|
R"(
|
||||||
Call[not set]{
|
TypeConstructor[not set]{
|
||||||
Identifier[not set]{textureSampleCompare}
|
__vec_4__f32
|
||||||
(
|
Call[not set]{
|
||||||
Identifier[not set]{x_20}
|
Identifier[not set]{textureSampleCompare}
|
||||||
Identifier[not set]{x_10}
|
(
|
||||||
Identifier[not set]{coords12}
|
Identifier[not set]{x_20}
|
||||||
ScalarConstructor[not set]{0.200000}
|
Identifier[not set]{x_10}
|
||||||
Identifier[not set]{offsets2d}
|
Identifier[not set]{coords12}
|
||||||
)
|
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
|
// ImageSampleDrefImplicitLod arrayed with ConstOffset
|
||||||
ImageAccessCase{
|
ImageAccessCase{
|
||||||
|
@ -1921,25 +1951,31 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
__depth_texture_2d_array
|
__depth_texture_2d_array
|
||||||
})",
|
})",
|
||||||
R"(
|
R"(
|
||||||
Call[not set]{
|
TypeConstructor[not set]{
|
||||||
Identifier[not set]{textureSampleCompare}
|
__vec_4__f32
|
||||||
(
|
Call[not set]{
|
||||||
Identifier[not set]{x_20}
|
Identifier[not set]{textureSampleCompare}
|
||||||
Identifier[not set]{x_10}
|
(
|
||||||
MemberAccessor[not set]{
|
Identifier[not set]{x_20}
|
||||||
Identifier[not set]{coords123}
|
Identifier[not set]{x_10}
|
||||||
Identifier[not set]{xy}
|
|
||||||
}
|
|
||||||
TypeConstructor[not set]{
|
|
||||||
__i32
|
|
||||||
MemberAccessor[not set]{
|
MemberAccessor[not set]{
|
||||||
Identifier[not set]{coords123}
|
Identifier[not set]{coords123}
|
||||||
Identifier[not set]{z}
|
Identifier[not set]{xy}
|
||||||
}
|
}
|
||||||
}
|
TypeConstructor[not set]{
|
||||||
ScalarConstructor[not set]{0.200000}
|
__i32
|
||||||
Identifier[not set]{offsets2d}
|
MemberAccessor[not set]{
|
||||||
)
|
Identifier[not set]{coords123}
|
||||||
|
Identifier[not set]{z}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
@ -2471,17 +2507,23 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
__depth_texture_2d
|
__depth_texture_2d
|
||||||
})",
|
})",
|
||||||
R"(
|
R"(
|
||||||
Call[not set]{
|
TypeConstructor[not set]{
|
||||||
Identifier[not set]{textureSampleLevel}
|
__vec_4__f32
|
||||||
(
|
Call[not set]{
|
||||||
Identifier[not set]{x_20}
|
Identifier[not set]{textureSampleLevel}
|
||||||
Identifier[not set]{x_10}
|
(
|
||||||
Identifier[not set]{vf12}
|
Identifier[not set]{x_20}
|
||||||
TypeConstructor[not set]{
|
Identifier[not set]{x_10}
|
||||||
__i32
|
Identifier[not set]{vf12}
|
||||||
Identifier[not set]{f1}
|
TypeConstructor[not set]{
|
||||||
}
|
__i32
|
||||||
)
|
Identifier[not set]{f1}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
|
ScalarConstructor[not set]{0.000000}
|
||||||
})"}}));
|
})"}}));
|
||||||
|
|
||||||
using SpvParserTest_ImageAccessTest =
|
using SpvParserTest_ImageAccessTest =
|
||||||
|
|
Loading…
Reference in New Issue