| // Copyright 2023 The Tint Authors. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "src/tint/lang/core/function.h" |
| #include "src/tint/lang/core/type/depth_multisampled_texture.h" |
| #include "src/tint/lang/spirv/writer/common/helper_test.h" |
| |
| using namespace tint::number_suffixes; // NOLINT |
| |
| namespace tint::spirv::writer { |
| namespace { |
| |
| enum TextureType { |
| kSampledTexture, |
| kMultisampledTexture, |
| kDepthTexture, |
| kDepthMultisampledTexture, |
| kStorageTexture, |
| }; |
| |
| enum SamplerUsage { |
| kNoSampler, |
| kSampler, |
| kComparisonSampler, |
| }; |
| |
| /// A typed argument or result for a texture builtin. |
| struct NameAndType { |
| /// The name. |
| const char* name; |
| /// The vector width of the value (1 means scalar). |
| uint32_t width; |
| /// The element type of the value. |
| TestElementType type; |
| }; |
| |
| /// A parameterized texture builtin function test case. |
| struct TextureBuiltinTestCase { |
| /// The texture type. |
| TextureType texture_type; |
| /// The dimensionality of the texture. |
| type::TextureDimension dim; |
| /// The texel type of the texture. |
| TestElementType texel_type; |
| /// The builtin function arguments. |
| Vector<NameAndType, 4> args; |
| /// The result type. |
| NameAndType result; |
| /// The expected SPIR-V instruction strings. |
| Vector<const char*, 2> instructions; |
| }; |
| |
| template <typename STREAM, typename = traits::EnableIfIsOStream<STREAM>> |
| auto& operator<<(STREAM& out, TextureType type) { |
| switch (type) { |
| case kSampledTexture: |
| out << "SampleTexture"; |
| break; |
| case kMultisampledTexture: |
| out << "MultisampleTexture"; |
| break; |
| case kDepthTexture: |
| out << "DepthTexture"; |
| break; |
| case kDepthMultisampledTexture: |
| out << "DepthMultisampledTexture"; |
| break; |
| case kStorageTexture: |
| out << "StorageTexture"; |
| break; |
| } |
| return out; |
| } |
| |
| std::string PrintCase(testing::TestParamInfo<TextureBuiltinTestCase> cc) { |
| StringStream ss; |
| ss << cc.param.texture_type << cc.param.dim << "_" << cc.param.texel_type; |
| for (const auto& arg : cc.param.args) { |
| ss << "_" << arg.name; |
| } |
| return ss.str(); |
| } |
| |
| class TextureBuiltinTest : public SpirvWriterTestWithParam<TextureBuiltinTestCase> { |
| protected: |
| const type::Texture* MakeTextureType(TextureType type, |
| type::TextureDimension dim, |
| TestElementType texel_type) { |
| switch (type) { |
| case kSampledTexture: |
| return ty.Get<type::SampledTexture>(dim, MakeScalarType(texel_type)); |
| case kMultisampledTexture: |
| return ty.Get<type::MultisampledTexture>(dim, MakeScalarType(texel_type)); |
| case kDepthTexture: |
| return ty.Get<type::DepthTexture>(dim); |
| case kDepthMultisampledTexture: |
| return ty.Get<type::DepthMultisampledTexture>(dim); |
| case kStorageTexture: |
| core::TexelFormat format; |
| switch (texel_type) { |
| case kF32: |
| format = core::TexelFormat::kR32Float; |
| break; |
| case kI32: |
| format = core::TexelFormat::kR32Sint; |
| break; |
| case kU32: |
| format = core::TexelFormat::kR32Uint; |
| break; |
| default: |
| return nullptr; |
| } |
| return ty.Get<type::StorageTexture>(dim, format, core::Access::kWrite, |
| type::StorageTexture::SubtypeFor(format, ty)); |
| } |
| return nullptr; |
| } |
| |
| void Run(enum core::Function function, SamplerUsage sampler) { |
| auto params = GetParam(); |
| |
| auto* result_ty = MakeScalarType(params.result.type); |
| if (function == core::Function::kTextureStore) { |
| result_ty = ty.void_(); |
| } |
| if (params.result.width > 1) { |
| result_ty = ty.vec(result_ty, params.result.width); |
| } |
| |
| Vector<ir::FunctionParam*, 4> func_params; |
| |
| auto* t = b.FunctionParam( |
| "t", MakeTextureType(params.texture_type, params.dim, params.texel_type)); |
| func_params.Push(t); |
| ir::FunctionParam* s = nullptr; |
| if (sampler == kSampler) { |
| s = b.FunctionParam("s", ty.sampler()); |
| func_params.Push(s); |
| } else if (sampler == kComparisonSampler) { |
| s = b.FunctionParam("s", ty.comparison_sampler()); |
| func_params.Push(s); |
| } |
| |
| auto* func = b.Function("foo", result_ty); |
| func->SetParams(std::move(func_params)); |
| |
| b.Append(func->Block(), [&] { |
| uint32_t arg_value = 1; |
| |
| Vector<ir::Value*, 4> args; |
| if (function == core::Function::kTextureGather && |
| params.texture_type != kDepthTexture) { |
| // Special case for textureGather, which has a component argument first. |
| auto* component = MakeScalarValue(kU32, arg_value++); |
| args.Push(component); |
| mod.SetName(component, "component"); |
| } |
| args.Push(t); |
| if (s) { |
| args.Push(s); |
| } |
| |
| for (const auto& arg : params.args) { |
| auto* value = MakeScalarValue(arg.type, arg_value++); |
| if (arg.width > 1) { |
| value = b.Splat(ty.vec(value->Type(), arg.width), value, arg.width); |
| } |
| args.Push(value); |
| mod.SetName(value, arg.name); |
| } |
| auto* result = b.Call(result_ty, function, std::move(args)); |
| if (result_ty->Is<type::Void>()) { |
| b.Return(func); |
| } else { |
| b.Return(func, result); |
| mod.SetName(result, "result"); |
| } |
| }); |
| |
| ASSERT_TRUE(Generate()) << Error() << output_; |
| for (auto& inst : params.instructions) { |
| EXPECT_INST(inst); |
| } |
| } |
| }; |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureSample |
| //////////////////////////////////////////////////////////////// |
| using TextureSample = TextureBuiltinTest; |
| TEST_P(TextureSample, Emit) { |
| Run(core::Function::kTextureSample, kSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureSample, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k1d, |
| /* texel type */ kF32, |
| {{"coord", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coord None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleImplicitLod %v4float %10 %16 None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleImplicitLod %v4float %10 %16 ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"offset", 3, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %12", |
| "OpImageSampleImplicitLod %v4float %10 %15 None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleImplicitLod %v4float %9 %coords None", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleImplicitLod %v4float %9 %coords ConstOffset %offset", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleImplicitLod %v4float %9 %coords None", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "OpImageSampleImplicitLod %v4float %9 %15 None", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "OpImageSampleImplicitLod %v4float %9 %15 ConstOffset %offset", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %11", |
| "OpImageSampleImplicitLod %v4float %9 %15 None", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureSampleBias |
| //////////////////////////////////////////////////////////////// |
| using TextureSampleBias = TextureBuiltinTest; |
| TEST_P(TextureSampleBias, Emit) { |
| Run(core::Function::kTextureSampleBias, kSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureSampleBias, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"bias", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords Bias %bias", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"bias", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords Bias|ConstOffset %bias %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"bias", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleImplicitLod %v4float %10 %16 Bias %bias", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"bias", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleImplicitLod %v4float %10 %16 Bias|ConstOffset %bias %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"bias", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords Bias %bias", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"bias", 1, kF32}, {"offset", 3, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords Bias|ConstOffset %bias %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"bias", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleImplicitLod %v4float %10 %coords Bias %bias", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}, {"bias", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %12", |
| "OpImageSampleImplicitLod %v4float %10 %15 Bias %bias", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureSampleGrad |
| //////////////////////////////////////////////////////////////// |
| using TextureSampleGrad = TextureBuiltinTest; |
| TEST_P(TextureSampleGrad, Emit) { |
| Run(core::Function::kTextureSampleGrad, kSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureSampleGrad, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"ddx", 2, kF32}, {"ddy", 2, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Grad %ddx %ddy", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"ddx", 2, kF32}, {"ddy", 2, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Grad|ConstOffset %ddx %ddy %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"ddx", 2, kF32}, {"ddy", 2, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleExplicitLod %v4float %10 %16 Grad %ddx %ddy", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, |
| {"array_idx", 1, kI32}, |
| {"ddx", 2, kF32}, |
| {"ddy", 2, kF32}, |
| {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleExplicitLod %v4float %10 %16 Grad|ConstOffset %ddx %ddy %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"ddx", 3, kF32}, {"ddy", 3, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Grad %ddx %ddy", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"ddx", 3, kF32}, {"ddy", 3, kF32}, {"offset", 3, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Grad|ConstOffset %ddx %ddy %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"ddx", 3, kF32}, {"ddy", 3, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Grad %ddx %ddy", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}, {"ddx", 3, kF32}, {"ddy", 3, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %12", |
| "OpImageSampleExplicitLod %v4float %10 %15 Grad %ddx %ddy", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureSampleLevel |
| //////////////////////////////////////////////////////////////// |
| using TextureSampleLevel = TextureBuiltinTest; |
| TEST_P(TextureSampleLevel, Emit) { |
| Run(core::Function::kTextureSampleLevel, kSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureSampleLevel, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"lod", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"lod", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Lod|ConstOffset %lod %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"lod", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleExplicitLod %v4float %10 %16 Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"lod", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "OpImageSampleExplicitLod %v4float %10 %16 Lod|ConstOffset %lod %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"lod", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"lod", 1, kF32}, {"offset", 3, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Lod|ConstOffset %lod %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"lod", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "OpImageSampleExplicitLod %v4float %10 %coords Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}, {"lod", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %12", |
| "OpImageSampleExplicitLod %v4float %10 %15 Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"lod", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %lod", |
| "OpImageSampleExplicitLod %v4float %9 %coords Lod %11", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"lod", 1, kI32}, {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %lod", |
| "OpImageSampleExplicitLod %v4float %9 %coords Lod|ConstOffset %11 %offset", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"lod", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "%19 = OpConvertSToF %float %lod", |
| "OpImageSampleExplicitLod %v4float %9 %15 Lod %19", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"lod", 1, kI32}, {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "%19 = OpConvertSToF %float %lod", |
| "OpImageSampleExplicitLod %v4float %9 %15 Lod|ConstOffset %19 %offset", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"lod", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %lod", |
| "OpImageSampleExplicitLod %v4float %9 %coords Lod %11", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}, {"lod", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %11", |
| "%19 = OpConvertSToF %float %lod", |
| "OpImageSampleExplicitLod %v4float %9 %15 Lod %19", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureSampleCompare |
| //////////////////////////////////////////////////////////////// |
| using TextureSampleCompare = TextureBuiltinTest; |
| TEST_P(TextureSampleCompare, Emit) { |
| Run(core::Function::kTextureSampleCompare, kComparisonSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureSampleCompare, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"depth", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleDrefImplicitLod %float %9 %coords %depth", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"depth", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleDrefImplicitLod %float %9 %coords %depth ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"depth", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "OpImageSampleDrefImplicitLod %float %9 %15 %depth", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"depth", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "OpImageSampleDrefImplicitLod %float %9 %15 %depth ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"depth", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleDrefImplicitLod %float %9 %coords %depth", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}, {"depth", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %11", |
| "OpImageSampleDrefImplicitLod %float %9 %15 %depth", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureSampleCompareLevel |
| //////////////////////////////////////////////////////////////// |
| using TextureSampleCompareLevel = TextureBuiltinTest; |
| TEST_P(TextureSampleCompareLevel, Emit) { |
| Run(core::Function::kTextureSampleCompareLevel, kComparisonSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureSampleCompareLevel, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"depth_l0", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleDrefExplicitLod %float %9 %coords %depth_l0 Lod %float_0", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"depth_l0", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleDrefExplicitLod %float %9 %coords %depth_l0 Lod|ConstOffset %float_0 " |
| "%offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"depth_l0", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "OpImageSampleDrefExplicitLod %float %9 %15 %depth_l0 Lod %float_0", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, |
| {"array_idx", 1, kI32}, |
| {"depth_l0", 1, kF32}, |
| {"offset", 2, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v3float %coords %11", |
| "OpImageSampleDrefExplicitLod %float %9 %15 %depth_l0 Lod|ConstOffset %float_0 " |
| "%offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"depth_l0", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "OpImageSampleDrefExplicitLod %float %9 %coords %depth_l0 Lod %float_0", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}, {"depth_l0", 1, kF32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpSampledImage %10 %t %s", |
| "%11 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %11", |
| "OpImageSampleDrefExplicitLod %float %9 %15 %depth_l0 Lod %float_0", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureGather |
| //////////////////////////////////////////////////////////////// |
| using TextureGather = TextureBuiltinTest; |
| TEST_P(TextureGather, Emit) { |
| Run(core::Function::kTextureGather, kSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureGather, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4float %10 %coords %component None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4float %10 %coords %component ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "%result = OpImageGather %v4float %10 %16 %component None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "%result = OpImageGather %v4float %10 %16 %component ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4float %10 %coords %component None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %12", |
| "%result = OpImageGather %v4float %10 %15 %component None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4float %10 %coords %uint_0 None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4float %10 %coords %uint_0 ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4float %10 %coords %uint_0 None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "%result = OpImageGather %v4float %10 %16 %uint_0 None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "%result = OpImageGather %v4float %10 %16 %uint_0 ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %12", |
| "%result = OpImageGather %v4float %10 %15 %uint_0 None", |
| }, |
| }, |
| |
| // Test some textures with integer texel types. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kI32, |
| {{"coords", 2, kF32}}, |
| {"result", 4, kI32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4int %10 %coords %component None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kU32, |
| {{"coords", 2, kF32}}, |
| {"result", 4, kU32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageGather %v4uint %10 %coords %component None", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureGatherCompare |
| //////////////////////////////////////////////////////////////// |
| using TextureGatherCompare = TextureBuiltinTest; |
| TEST_P(TextureGatherCompare, Emit) { |
| Run(core::Function::kTextureGatherCompare, kComparisonSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P( |
| SpirvWriterTest, |
| TextureGatherCompare, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"depth", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageDrefGather %v4float %10 %coords %depth None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"depth", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageDrefGather %v4float %10 %coords %depth ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"depth", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "%result = OpImageDrefGather %v4float %10 %16 %depth None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kF32}, {"array_idx", 1, kI32}, {"depth", 1, kF32}, {"offset", 2, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%16 = OpCompositeConstruct %v3float %coords %12", |
| "%result = OpImageDrefGather %v4float %10 %16 %depth ConstOffset %offset", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"depth", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%result = OpImageDrefGather %v4float %10 %coords %depth None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"coords", 3, kF32}, {"array_idx", 1, kI32}, {"depth", 1, kF32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpSampledImage %11 %t %s", |
| "%12 = OpConvertSToF %float %array_idx", |
| "%15 = OpCompositeConstruct %v4float %coords %12", |
| "%result = OpImageDrefGather %v4float %10 %15 %depth None", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureLoad |
| //////////////////////////////////////////////////////////////// |
| using TextureLoad = TextureBuiltinTest; |
| TEST_P(TextureLoad, Emit) { |
| Run(core::Function::kTextureLoad, kNoSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P(SpirvWriterTest, |
| TextureLoad, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k1d, |
| /* texel type */ kF32, |
| {{"coord", 1, kI32}, {"lod", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "OpImageFetch %v4float %t %coord Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kI32}, {"lod", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "OpImageFetch %v4float %t %coords Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kI32}, {"array_idx", 1, kI32}, {"lod", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "%10 = OpCompositeConstruct %v3int %coords %array_idx", |
| "OpImageFetch %v4float %t %10 Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kI32}, {"lod", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "OpImageFetch %v4float %t %coords Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kMultisampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kI32}, {"sample_idx", 1, kI32}}, |
| {"result", 4, kF32}, |
| { |
| "OpImageFetch %v4float %t %coords Sample %sample_idx", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kI32}, {"lod", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "OpImageFetch %v4float %t %coords Lod %lod", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kI32}, {"array_idx", 1, kI32}, {"lod", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "%9 = OpCompositeConstruct %v3int %coords %array_idx", |
| "OpImageFetch %v4float %t %9 Lod %lod", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthMultisampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 3, kI32}, {"sample_idx", 1, kI32}}, |
| {"result", 1, kF32}, |
| { |
| "OpImageFetch %v4float %t %coords Sample %sample_idx", |
| "%result = OpCompositeExtract %float", |
| }, |
| }, |
| |
| // Test some textures with integer texel types. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kI32, |
| {{"coords", 2, kI32}, {"lod", 1, kI32}}, |
| {"result", 4, kI32}, |
| { |
| "OpImageFetch %v4int %t %coords Lod %lod", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kU32, |
| {{"coords", 2, kI32}, {"lod", 1, kI32}}, |
| {"result", 4, kU32}, |
| { |
| "OpImageFetch %v4uint %t %coords Lod %lod", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureStore |
| //////////////////////////////////////////////////////////////// |
| using TextureStore = TextureBuiltinTest; |
| TEST_P(TextureStore, Emit) { |
| Run(core::Function::kTextureStore, kNoSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P(SpirvWriterTest, |
| TextureStore, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k1d, |
| /* texel type */ kF32, |
| {{"coord", 1, kI32}, {"texel", 4, kF32}}, |
| {}, |
| { |
| "OpImageWrite %t %coord %texel None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"coords", 2, kI32}, {"texel", 4, kF32}}, |
| {}, |
| { |
| "OpImageWrite %t %coords %texel None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"coords", 2, kI32}, {"array_idx", 1, kI32}, {"texel", 4, kF32}}, |
| {}, |
| { |
| "%10 = OpCompositeConstruct %v3int %coords %array_idx", |
| "OpImageWrite %t %10 %texel None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"coords", 3, kI32}, {"texel", 4, kF32}}, |
| {}, |
| { |
| "OpImageWrite %t %coords %texel None", |
| }, |
| }, |
| |
| // Test some textures with integer texel types. |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kI32, |
| {{"coords", 2, kI32}, {"texel", 4, kI32}}, |
| {}, |
| { |
| "OpImageWrite %t %coords %texel None", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kU32, |
| {{"coords", 2, kI32}, {"texel", 4, kU32}}, |
| {}, |
| { |
| "OpImageWrite %t %coords %texel None", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureDimensions |
| //////////////////////////////////////////////////////////////// |
| using TextureDimensions = TextureBuiltinTest; |
| TEST_P(TextureDimensions, Emit) { |
| Run(core::Function::kTextureDimensions, kNoSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P(SpirvWriterTest, |
| TextureDimensions, |
| testing::Values( |
| // 1D implicit Lod. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k1d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| {"%result = OpImageQuerySizeLod %uint %t %uint_0"}, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k1d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| {"%result = OpImageQuerySize %uint %t"}, |
| }, |
| |
| // 1D explicit Lod. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k1d, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 1, kU32}, |
| {"%result = OpImageQuerySizeLod %uint %t %lod"}, |
| }, |
| |
| // 2D implicit Lod. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %uint_0"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %uint_0"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kMultisampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySize %v2uint %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %uint_0"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %uint_0"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthMultisampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySize %v2uint %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySize %v2uint %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySize %v3uint %t", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| |
| // 2D explicit Lod. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %lod"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %lod", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %lod"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %lod", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %lod"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %lod", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| {"%result = OpImageQuerySizeLod %v2uint %t %lod"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 2, kU32}, |
| { |
| "%9 = OpImageQuerySizeLod %v3uint %t %lod", |
| "%result = OpVectorShuffle %v2uint %9 %9 0 1", |
| }, |
| }, |
| |
| // 3D implicit lod. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 3, kU32}, |
| {"%result = OpImageQuerySizeLod %v3uint %t %uint_0"}, |
| }, |
| |
| // 3D explicit lod. |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {{"lod", 1, kU32}}, |
| {"result", 3, kU32}, |
| {"%result = OpImageQuerySizeLod %v3uint %t %lod"}, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureNumLayers |
| //////////////////////////////////////////////////////////////// |
| using TextureNumLayers = TextureBuiltinTest; |
| TEST_P(TextureNumLayers, Emit) { |
| Run(core::Function::kTextureNumLayers, kNoSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P(SpirvWriterTest, |
| TextureNumLayers, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| { |
| "%8 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpCompositeExtract %uint %8 2", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| { |
| "%8 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpCompositeExtract %uint %8 2", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| { |
| "%8 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpCompositeExtract %uint %8 2", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| { |
| "%8 = OpImageQuerySizeLod %v3uint %t %uint_0", |
| "%result = OpCompositeExtract %uint %8 2", |
| }, |
| }, |
| TextureBuiltinTestCase{ |
| kStorageTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| { |
| "%8 = OpImageQuerySize %v3uint %t", |
| "%result = OpCompositeExtract %uint %8 2", |
| }, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureNumLevels |
| //////////////////////////////////////////////////////////////// |
| using TextureNumLevels = TextureBuiltinTest; |
| TEST_P(TextureNumLevels, Emit) { |
| Run(core::Function::kTextureNumLevels, kNoSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P(SpirvWriterTest, |
| TextureNumLevels, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k1d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::k3d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kSampledTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::k2dArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCube, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthTexture, |
| type::TextureDimension::kCubeArray, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kI32}, |
| {"%result = OpImageQueryLevels %int %t"}, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureNumSamples |
| //////////////////////////////////////////////////////////////// |
| using TextureNumSamples = TextureBuiltinTest; |
| TEST_P(TextureNumSamples, Emit) { |
| Run(core::Function::kTextureNumSamples, kNoSampler); |
| } |
| INSTANTIATE_TEST_SUITE_P(SpirvWriterTest, |
| TextureNumSamples, |
| testing::Values( |
| TextureBuiltinTestCase{ |
| kMultisampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| {"%result = OpImageQuerySamples %uint %t"}, |
| }, |
| TextureBuiltinTestCase{ |
| kDepthMultisampledTexture, |
| type::TextureDimension::k2d, |
| /* texel type */ kF32, |
| {}, |
| {"result", 1, kU32}, |
| {"%result = OpImageQuerySamples %uint %t"}, |
| }), |
| PrintCase); |
| |
| //////////////////////////////////////////////////////////////// |
| //// textureSampleBaseClampToEdge |
| //////////////////////////////////////////////////////////////// |
| |
| TEST_F(SpirvWriterTest, TextureSampleBaseClampToEdge_2d_f32) { |
| auto* texture_ty = ty.Get<type::SampledTexture>(type::TextureDimension::k2d, ty.f32()); |
| |
| Vector<ir::FunctionParam*, 4> args; |
| args.Push(b.FunctionParam("texture", texture_ty)); |
| args.Push(b.FunctionParam("sampler", ty.sampler())); |
| args.Push(b.FunctionParam("coords", ty.vec2<f32>())); |
| |
| auto* func = b.Function("foo", ty.vec4<f32>()); |
| func->SetParams(args); |
| b.Append(func->Block(), [&] { |
| auto* result = b.Call(ty.vec4<f32>(), core::Function::kTextureSampleBaseClampToEdge, args); |
| b.Return(func, result); |
| mod.SetName(result, "result"); |
| }); |
| |
| ASSERT_TRUE(Generate()) << Error() << output_; |
| EXPECT_INST("%18 = OpConstantComposite %v2float %float_0_5 %float_0_5"); |
| EXPECT_INST("%21 = OpConstantComposite %v2float %float_1 %float_1"); |
| EXPECT_INST(R"( |
| %12 = OpImageQuerySizeLod %v2uint %texture %uint_0 |
| %16 = OpConvertUToF %v2float %12 |
| %17 = OpFDiv %v2float %18 %16 |
| %20 = OpFSub %v2float %21 %17 |
| %23 = OpExtInst %v2float %24 NClamp %coords %17 %20 |
| %25 = OpSampledImage %26 %texture %sampler |
| %result = OpImageSampleExplicitLod %v4float %25 %23 Lod %float_0 |
| )"); |
| } |
| |
| //////////////////////////////////////////////////////////////// |
| //// Storage textures with bgra8unorm texel formats |
| //////////////////////////////////////////////////////////////// |
| |
| TEST_F(SpirvWriterTest, Bgra8Unorm_textureStore) { |
| auto format = core::TexelFormat::kBgra8Unorm; |
| auto* texture_ty = |
| ty.Get<type::StorageTexture>(type::TextureDimension::k2d, format, core::Access::kWrite, |
| type::StorageTexture::SubtypeFor(format, ty)); |
| |
| auto* texture = b.FunctionParam("texture", texture_ty); |
| auto* coords = b.FunctionParam("coords", ty.vec2<u32>()); |
| auto* value = b.FunctionParam("value", ty.vec4<f32>()); |
| auto* func = b.Function("foo", ty.void_()); |
| func->SetParams({texture, coords, value}); |
| b.Append(func->Block(), [&] { |
| b.Call(ty.void_(), core::Function::kTextureStore, texture, coords, value); |
| b.Return(func); |
| }); |
| |
| ASSERT_TRUE(Generate()) << Error() << output_; |
| EXPECT_INST(R"( |
| %13 = OpVectorShuffle %v4float %value %value 2 1 0 3 |
| OpImageWrite %texture %coords %13 None |
| )"); |
| } |
| |
| } // namespace |
| } // namespace tint::spirv::writer |