spirv-reader: Support depth-reference sampling

Bug: tint:109
Change-Id: I1e1dcd7c0724124a3a29e94e65856a07c54dd998
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34005
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
This commit is contained in:
David Neto 2020-11-26 16:39:32 +00:00 committed by Commit Bot service account
parent ddaf59016b
commit 77e3318b39
2 changed files with 99 additions and 11 deletions

View File

@ -3654,6 +3654,7 @@ bool FunctionEmitter::EmitSampledImageAccess(
// TODO(dneto): For arrayed access, split off the array layer. // TODO(dneto): For arrayed access, split off the array layer.
params.push_back(MakeOperand(inst, 1).expr); params.push_back(MakeOperand(inst, 1).expr);
uint32_t arg_index = 2; uint32_t arg_index = 2;
const auto num_args = inst.NumInOperands();
std::string builtin_name; std::string builtin_name;
switch (inst.opcode()) { switch (inst.opcode()) {
@ -3661,6 +3662,18 @@ bool FunctionEmitter::EmitSampledImageAccess(
case SpvOpImageSampleExplicitLod: case SpvOpImageSampleExplicitLod:
builtin_name = "textureSample"; builtin_name = "textureSample";
break; break;
case SpvOpImageSampleDrefImplicitLod:
case SpvOpImageSampleDrefExplicitLod:
builtin_name = "textureSampleCompare";
if (arg_index < num_args) {
params.push_back(MakeOperand(inst, arg_index).expr);
arg_index++;
} else {
return Fail()
<< "image depth-compare instruction is missing a Dref operand: "
<< inst.PrettyPrint();
}
break;
case SpvOpImageGather: case SpvOpImageGather:
case SpvOpImageDrefGather: case SpvOpImageDrefGather:
return Fail() << " image gather is not yet supported"; return Fail() << " image gather is not yet supported";
@ -3672,7 +3685,6 @@ bool FunctionEmitter::EmitSampledImageAccess(
// Loop over the image operands, looking for extra operands to the builtin. // Loop over the image operands, looking for extra operands to the builtin.
// Except we uroll the loop. // Except we uroll the loop.
const auto num_args = inst.NumInOperands();
uint32_t image_operands_mask = 0; uint32_t image_operands_mask = 0;
if (arg_index < num_args) { if (arg_index < num_args) {
image_operands_mask = inst.GetSingleWordInOperand(arg_index); image_operands_mask = inst.GetSingleWordInOperand(arg_index);

View File

@ -1195,6 +1195,8 @@ TEST_P(SpvParserTest_DeclHandle_SampledImage, Variable) {
OpDecorate %20 DescriptorSet 2 OpDecorate %20 DescriptorSet 2
OpDecorate %20 Binding 1 OpDecorate %20 Binding 1
)" + CommonTypes() + R"( )" + CommonTypes() + R"(
; Vulkan ignores the "depth" parameter on OpTypeImage.
; So this image type can serve for both regular sampling and depth-compare.
%si_ty = OpTypeSampledImage %f_texture_2d %si_ty = OpTypeSampledImage %f_texture_2d
%coords = OpConstantNull %v2float %coords = OpConstantNull %v2float
@ -1453,19 +1455,93 @@ INSTANTIATE_TEST_SUITE_P(
)); ));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
DISABLED_ImageSampleDrefImplicitLod, ImageSampleDrefImplicitLod,
SpvParserTest_DeclHandle_SampledImage, SpvParserTest_DeclHandle_SampledImage,
::testing::ValuesIn(std::vector<DeclSampledImageCase>{ ::testing::Values(
// TODO(dneto): ImageSampleDrefImplicitLod // ImageSampleDrefImplicitLod
// TODO(dneto): ImageSampleDrefImplicitLod with ConstOffset (signed and DeclSampledImageCase{"%result = OpImageSampleDrefImplicitLod "
// unsigned) "%v4float %sampled_image %coords %depth",
// TODO(dneto): ImageSampleDrefImplicitLod with Bias R"(
// TODO(dneto): ImageSampleDrefImplicitLod with Biase and ConstOffset DecoratedVariable{
// (signed and unsigned) Decorations{
})); SetDecoration{0}
BindingDecoration{0}
}
x_10
uniform_constant
__sampler_comparison
}
DecoratedVariable{
Decorations{
SetDecoration{2}
BindingDecoration{1}
}
x_20
uniform_constant
__depth_texture_2d
})",
R"(
Call[not set]{
Identifier[not set]{textureSampleCompare}
(
Identifier[not set]{x_20}
Identifier[not set]{x_10}
TypeConstructor[not set]{
__vec_2__f32
ScalarConstructor[not set]{0.000000}
ScalarConstructor[not set]{0.000000}
}
ScalarConstructor[not set]{0.200000}
)
})"},
// ImageSampleDrefImplicitLod with ConstOffset
DeclSampledImageCase{
"%result = OpImageSampleDrefImplicitLod %v4float "
"%sampled_image %coords %depth ConstOffset %offsets2d",
R"(
DecoratedVariable{
Decorations{
SetDecoration{0}
BindingDecoration{0}
}
x_10
uniform_constant
__sampler_comparison
}
DecoratedVariable{
Decorations{
SetDecoration{2}
BindingDecoration{1}
}
x_20
uniform_constant
__depth_texture_2d
})",
R"(
Call[not set]{
Identifier[not set]{textureSampleCompare}
(
Identifier[not set]{x_20}
Identifier[not set]{x_10}
TypeConstructor[not set]{
__vec_2__f32
ScalarConstructor[not set]{0.000000}
ScalarConstructor[not set]{0.000000}
}
ScalarConstructor[not set]{0.200000}
TypeConstructor[not set]{
__vec_2__i32
ScalarConstructor[not set]{3}
ScalarConstructor[not set]{4}
}
)
})"}
));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
DisabledimageSampleExplicitLod, ImageSampleExplicitLod,
SpvParserTest_DeclHandle_SampledImage, SpvParserTest_DeclHandle_SampledImage,
::testing::Values( ::testing::Values(