GLSL: implement texture sample and store functions.

Change all the texture types to the GLSL equivalents. Note that some
types don't actually exist in GLSL ES, e.g., 1D textures, but this
will be handled later.

Change all the texture functions from HLSL-style to GLSL (e.g.,
texture.Sample(...) -> texture(texture, ...). Note that depth
comparison functions are probably wrong.

Implement writeonly storage texture type and functions.

Samplers are skipped entirely in the GLSL backend, with the assumption
that they will already have been combined into GLSL-style combined
samplers and textures by the client code.

Move the SingleEntryPoint transform above the RemovePhonies pass. This
ensures that texture variables are not optimized out. (Otherwise some
tests produce valid but not very useful results.)

Add the builtin-functions to the GLSL keywords list for renaming.
They're not keywords, but they can't be identifiers either.

Bug: tint:1298, tint:1299

Change-Id: I86c4547fcdd1eba80be98f6c05b939f345fd4c3e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69200
Commit-Queue: Stephen White <senorblanco@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Stephen White 2021-11-15 18:01:54 +00:00 committed by Tint LUCI CQ
parent 6d643deefa
commit bf209ffc9d
5 changed files with 322 additions and 249 deletions

View File

@ -59,6 +59,15 @@ Output Glsl::Run(const Program* in, const DataMap& inputs) {
} }
manager.Add<CanonicalizeEntryPointIO>(); manager.Add<CanonicalizeEntryPointIO>();
manager.Add<InlinePointerLets>(); manager.Add<InlinePointerLets>();
// Running SingleEntryPoint before RemovePhonies prevents variables
// referenced only by phonies from being optimized out. Strictly
// speaking, that optimization isn't incorrect, but it prevents some
// tests (e.g., types/texture/*) from producing useful results.
if (cfg) {
manager.Add<SingleEntryPoint>();
data.Add<SingleEntryPoint::Config>(cfg->entry_point);
}
manager.Add<RemovePhonies>(); manager.Add<RemovePhonies>();
// Simplify cleans up messy `*(&(expr))` expressions from InlinePointerLets. // Simplify cleans up messy `*(&(expr))` expressions from InlinePointerLets.
manager.Add<Simplify>(); manager.Add<Simplify>();
@ -72,10 +81,6 @@ Output Glsl::Run(const Program* in, const DataMap& inputs) {
// variables directly. // variables directly.
data.Add<CanonicalizeEntryPointIO::Config>( data.Add<CanonicalizeEntryPointIO::Config>(
CanonicalizeEntryPointIO::ShaderStyle::kHlsl); CanonicalizeEntryPointIO::ShaderStyle::kHlsl);
if (cfg) {
manager.Add<SingleEntryPoint>();
data.Add<SingleEntryPoint::Config>(cfg->entry_point);
}
auto out = manager.Run(in, data); auto out = manager.Run(in, data);
if (!out.program.IsValid()) { if (!out.program.IsValid()) {
return out; return out;

View File

@ -33,10 +33,35 @@ namespace {
// This list is used for a binary search and must be kept in sorted order. // This list is used for a binary search and must be kept in sorted order.
const char* kReservedKeywordsGLSL[] = { const char* kReservedKeywordsGLSL[] = {
"abs",
"acos",
"acosh",
"active", "active",
"all",
"any",
"asin",
"asinh",
"asm", "asm",
"atan",
"atanh",
"atomicAdd",
"atomicAnd",
"atomicCompSwap",
"atomicCounter",
"atomicCounterDecrement",
"atomicCounterIncrement",
"atomicExchange",
"atomicMax",
"atomicMin",
"atomicOr",
"atomicXor",
"atomic_uint", "atomic_uint",
"attribute", "attribute",
"barrier",
"bitCount",
"bitfieldExtract",
"bitfieldInsert",
"bitfieldReverse",
"bool", "bool",
"break", "break",
"buffer", "buffer",
@ -45,14 +70,24 @@ const char* kReservedKeywordsGLSL[] = {
"bvec4", "bvec4",
"case", "case",
"cast", "cast",
"ceil",
"centroid", "centroid",
"clamp",
"class", "class",
"coherent", "coherent",
"common", "common",
"const", "const",
"continue", "continue",
"cos",
"cosh",
"cross",
"dFdx",
"dFdy",
"default", "default",
"degrees",
"determinant",
"discard", "discard",
"distance",
"dmat2", "dmat2",
"dmat2x2", "dmat2x2",
"dmat2x3", "dmat2x3",
@ -66,23 +101,36 @@ const char* kReservedKeywordsGLSL[] = {
"dmat4x3", "dmat4x3",
"dmat4x4", "dmat4x4",
"do", "do",
"dot",
"double", "double",
"dvec2", "dvec2",
"dvec3", "dvec3",
"dvec4", "dvec4",
"else", "else",
"enum", "enum",
"equal",
"exp",
"exp2",
"extern", "extern",
"external", "external",
"faceforward",
"false", "false",
"filter", "filter",
"findLSB",
"findMSB",
"fixed", "fixed",
"flat", "flat",
"float", "float",
"floatBitsToInt",
"floatBitsToUint",
"floor",
"for", "for",
"fract",
"frexp",
"fvec2", "fvec2",
"fvec3", "fvec3",
"fvec4", "fvec4",
"fwidth",
"gl_BaseInstance", "gl_BaseInstance",
"gl_BaseVertex", "gl_BaseVertex",
"gl_ClipDistance", "gl_ClipDistance",
@ -110,6 +158,9 @@ const char* kReservedKeywordsGLSL[] = {
"gl_WorkGroupID", "gl_WorkGroupID",
"gl_WorkGroupSize", "gl_WorkGroupSize",
"goto", "goto",
"greaterThan",
"greaterThanEqual",
"groupMemoryBarrier",
"half", "half",
"highp", "highp",
"hvec2", "hvec2",
@ -138,13 +189,20 @@ const char* kReservedKeywordsGLSL[] = {
"imageBuffer", "imageBuffer",
"imageCube", "imageCube",
"imageCubeArray", "imageCubeArray",
"imageLoad",
"imageSize",
"imageStore",
"imulExtended",
"in", "in",
"inline", "inline",
"inout", "inout",
"input", "input",
"int", "int",
"intBitsToFloat",
"interface", "interface",
"invariant", "invariant",
"inverse",
"inversesqrt",
"isampler1D", "isampler1D",
"isampler1DArray", "isampler1DArray",
"isampler2D", "isampler2D",
@ -156,10 +214,18 @@ const char* kReservedKeywordsGLSL[] = {
"isamplerBuffer", "isamplerBuffer",
"isamplerCube", "isamplerCube",
"isamplerCubeArray", "isamplerCubeArray",
"isinf",
"isnan",
"ivec2", "ivec2",
"ivec3", "ivec3",
"ivec4", "ivec4",
"layout", "layout",
"ldexp",
"length",
"lessThan",
"lessThanEqual",
"log",
"log2",
"long", "long",
"lowp", "lowp",
"main", "main",
@ -175,21 +241,47 @@ const char* kReservedKeywordsGLSL[] = {
"mat4x2", "mat4x2",
"mat4x3", "mat4x3",
"mat4x4", "mat4x4",
"matrixCompMult",
"max",
"mediump", "mediump",
"memoryBarrier",
"memoryBarrierAtomicCounter",
"memoryBarrierBuffer",
"memoryBarrierImage",
"memoryBarrierShared",
"min",
"mix",
"mod",
"modf",
"namespace", "namespace",
"noinline", "noinline",
"noperspective", "noperspective",
"normalize",
"not",
"notEqual",
"out", "out",
"outerProduct",
"output", "output",
"packHalf2x16",
"packSnorm2x16",
"packSnorm4x8",
"packUnorm2x16",
"packUnorm4x8",
"partition", "partition",
"patch", "patch",
"pow",
"precise", "precise",
"precision", "precision",
"public", "public",
"radians",
"readonly", "readonly",
"reflect",
"refract",
"resource", "resource",
"restrict", "restrict",
"return", "return",
"round",
"roundEven",
"sample", "sample",
"sampler1D", "sampler1D",
"sampler1DArray", "sampler1DArray",
@ -212,17 +304,45 @@ const char* kReservedKeywordsGLSL[] = {
"samplerCubeShadow", "samplerCubeShadow",
"shared", "shared",
"short", "short",
"sign",
"sin",
"sinh",
"sizeof", "sizeof",
"smooth", "smooth",
"smoothstep",
"sqrt",
"static", "static",
"step",
"struct", "struct",
"subroutine", "subroutine",
"superp", "superp",
"switch", "switch",
"tan",
"tanh",
"template", "template",
"texelFetch",
"texelFetchOffset",
"texture",
"textureGather",
"textureGatherOffset",
"textureGrad",
"textureGradOffset",
"textureLod",
"textureLodOffset",
"textureOffset",
"textureProj",
"textureProjGrad",
"textureProjGradOffset",
"textureProjLod",
"textureProjLodOffset",
"textureProjOffset",
"textureSize",
"this", "this",
"transpose",
"true", "true",
"trunc",
"typedef", "typedef",
"uaddCarry",
"uimage1D", "uimage1D",
"uimage1DArray", "uimage1DArray",
"uimage2D", "uimage2D",
@ -235,8 +355,15 @@ const char* kReservedKeywordsGLSL[] = {
"uimageCube", "uimageCube",
"uimageCubeArray", "uimageCubeArray",
"uint", "uint",
"uintBitsToFloat",
"umulExtended",
"uniform", "uniform",
"union", "union",
"unpackHalf2x16",
"unpackSnorm2x16",
"unpackSnorm4x8",
"unpackUnorm2x16",
"unpackUnorm4x8",
"unsigned", "unsigned",
"usampler1D", "usampler1D",
"usampler1DArray", "usampler1DArray",
@ -250,6 +377,7 @@ const char* kReservedKeywordsGLSL[] = {
"usamplerCube", "usamplerCube",
"usamplerCubeArray", "usamplerCubeArray",
"using", "using",
"usubBorrow",
"uvec2", "uvec2",
"uvec3", "uvec3",
"uvec4", "uvec4",

View File

@ -62,32 +62,6 @@ bool last_is_break_or_fallthrough(const ast::BlockStatement* stmts) {
return IsAnyOf<ast::BreakStatement, ast::FallthroughStatement>(stmts->Last()); return IsAnyOf<ast::BreakStatement, ast::FallthroughStatement>(stmts->Last());
} }
const char* image_format_to_rwtexture_type(ast::ImageFormat image_format) {
switch (image_format) {
case ast::ImageFormat::kRgba8Unorm:
case ast::ImageFormat::kRgba8Snorm:
case ast::ImageFormat::kRgba16Float:
case ast::ImageFormat::kR32Float:
case ast::ImageFormat::kRg32Float:
case ast::ImageFormat::kRgba32Float:
return "float4";
case ast::ImageFormat::kRgba8Uint:
case ast::ImageFormat::kRgba16Uint:
case ast::ImageFormat::kR32Uint:
case ast::ImageFormat::kRg32Uint:
case ast::ImageFormat::kRgba32Uint:
return "uint4";
case ast::ImageFormat::kRgba8Sint:
case ast::ImageFormat::kRgba16Sint:
case ast::ImageFormat::kR32Sint:
case ast::ImageFormat::kRg32Sint:
case ast::ImageFormat::kRgba32Sint:
return "int4";
default:
return nullptr;
}
}
} // namespace } // namespace
GeneratorImpl::GeneratorImpl(const Program* program) : TextGenerator(program) {} GeneratorImpl::GeneratorImpl(const Program* program) : TextGenerator(program) {}
@ -1086,7 +1060,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
return false; return false;
} }
} }
out << ");"; out << ")";
return true; return true;
} }
// TODO(senorblanco): determine if this works for array textures // TODO(senorblanco): determine if this works for array textures
@ -1111,9 +1085,6 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
break; break;
} }
if (!EmitExpression(out, texture))
return false;
// If pack_level_in_coords is true, then the mip level will be appended as the // If pack_level_in_coords is true, then the mip level will be appended as the
// last value of the coordinates argument. If the WGSL intrinsic overload does // last value of the coordinates argument. If the WGSL intrinsic overload does
// not have a level parameter and pack_level_in_coords is true, then a zero // not have a level parameter and pack_level_in_coords is true, then a zero
@ -1124,34 +1095,32 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
switch (intrinsic->Type()) { switch (intrinsic->Type()) {
case sem::IntrinsicType::kTextureSample: case sem::IntrinsicType::kTextureSample:
out << ".Sample(";
break;
case sem::IntrinsicType::kTextureSampleBias: case sem::IntrinsicType::kTextureSampleBias:
out << ".SampleBias("; out << "texture(";
break; break;
case sem::IntrinsicType::kTextureSampleLevel: case sem::IntrinsicType::kTextureSampleLevel:
out << ".SampleLevel("; out << "textureLod(";
break; break;
case sem::IntrinsicType::kTextureSampleGrad: case sem::IntrinsicType::kTextureSampleGrad:
out << ".SampleGrad("; out << "textureGrad(";
break; break;
case sem::IntrinsicType::kTextureSampleCompare: case sem::IntrinsicType::kTextureSampleCompare:
out << ".SampleCmp("; out << "texture(";
glsl_ret_width = 1; glsl_ret_width = 1;
break; break;
case sem::IntrinsicType::kTextureSampleCompareLevel: case sem::IntrinsicType::kTextureSampleCompareLevel:
out << ".SampleCmpLevelZero("; out << "texture(";
glsl_ret_width = 1; glsl_ret_width = 1;
break; break;
case sem::IntrinsicType::kTextureLoad: case sem::IntrinsicType::kTextureLoad:
out << ".Load("; out << "texelFetch(";
// Multisampled textures do not support mip-levels. // Multisampled textures do not support mip-levels.
if (!texture_type->Is<sem::MultisampledTexture>()) { if (!texture_type->Is<sem::MultisampledTexture>()) {
pack_level_in_coords = true; pack_level_in_coords = true;
} }
break; break;
case sem::IntrinsicType::kTextureStore: case sem::IntrinsicType::kTextureStore:
out << "["; out << "imageStore(";
break; break;
default: default:
diagnostics_.add_error( diagnostics_.add_error(
@ -1161,11 +1130,10 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
return false; return false;
} }
if (auto* sampler = arg(Usage::kSampler)) { if (!EmitExpression(out, texture))
if (!EmitExpression(out, sampler)) return false;
return false;
out << ", "; out << ", ";
}
auto* param_coords = arg(Usage::kCoords); auto* param_coords = arg(Usage::kCoords);
if (!param_coords) { if (!param_coords) {
@ -1215,8 +1183,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
} }
} }
for (auto usage : {Usage::kDepthRef, Usage::kBias, Usage::kLevel, Usage::kDdx, for (auto usage :
Usage::kDdy, Usage::kSampleIndex, Usage::kOffset}) { {Usage::kDepthRef, Usage::kBias, Usage::kLevel, Usage::kDdx, Usage::kDdy,
Usage::kSampleIndex, Usage::kOffset, Usage::kValue}) {
if (usage == Usage::kLevel && pack_level_in_coords) { if (usage == Usage::kLevel && pack_level_in_coords) {
continue; // mip level already packed in coordinates. continue; // mip level already packed in coordinates.
} }
@ -1228,35 +1197,28 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
} }
} }
if (intrinsic->Type() == sem::IntrinsicType::kTextureStore) { out << ")";
out << "] = ";
if (!EmitExpression(out, arg(Usage::kValue))) {
return false;
}
} else {
out << ")";
// If the intrinsic return type does not match the number of elements of the // If the intrinsic return type does not match the number of elements of the
// GLSL intrinsic, we need to swizzle the expression to generate the correct // GLSL intrinsic, we need to swizzle the expression to generate the correct
// number of components. // number of components.
uint32_t wgsl_ret_width = 1; uint32_t wgsl_ret_width = 1;
if (auto* vec = intrinsic->ReturnType()->As<sem::Vector>()) { if (auto* vec = intrinsic->ReturnType()->As<sem::Vector>()) {
wgsl_ret_width = vec->Width(); wgsl_ret_width = vec->Width();
} }
if (wgsl_ret_width < glsl_ret_width) { if (wgsl_ret_width < glsl_ret_width) {
out << "."; out << ".";
for (uint32_t i = 0; i < wgsl_ret_width; i++) { for (uint32_t i = 0; i < wgsl_ret_width; i++) {
out << "xyz"[i]; out << "xyz"[i];
}
}
if (wgsl_ret_width > glsl_ret_width) {
TINT_ICE(Writer, diagnostics_)
<< "WGSL return width (" << wgsl_ret_width
<< ") is wider than GLSL return width (" << glsl_ret_width << ") for "
<< intrinsic->Type();
return false;
} }
} }
if (wgsl_ret_width > glsl_ret_width) {
TINT_ICE(Writer, diagnostics_)
<< "WGSL return width (" << wgsl_ret_width
<< ") is wider than GLSL return width (" << glsl_ret_width << ") for "
<< intrinsic->Type();
return false;
}
return true; return true;
} }
@ -1671,6 +1633,10 @@ bool GeneratorImpl::EmitHandleVariable(const sem::Variable* var) {
auto name = builder_.Symbols().NameFor(decl->symbol); auto name = builder_.Symbols().NameFor(decl->symbol);
auto* type = var->Type()->UnwrapRef(); auto* type = var->Type()->UnwrapRef();
if (type->As<sem::Sampler>()) {
// GLSL ignores Sampler variables.
return true;
}
if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) { if (!EmitTypeAndName(out, type, var->StorageClass(), var->Access(), name)) {
return false; return false;
} }
@ -2426,12 +2392,8 @@ bool GeneratorImpl::EmitType(std::ostream& out,
<< "Attempting to emit pointer type. These should have been removed " << "Attempting to emit pointer type. These should have been removed "
"with the InlinePointerLets transform"; "with the InlinePointerLets transform";
return false; return false;
} else if (auto* sampler = type->As<sem::Sampler>()) { } else if (type->Is<sem::Sampler>()) {
out << "Sampler"; return false;
if (sampler->IsComparison()) {
out << "Comparison";
}
out << "State";
} else if (auto* str = type->As<sem::Struct>()) { } else if (auto* str = type->As<sem::Struct>()) {
out << StructName(str); out << StructName(str);
} else if (auto* tex = type->As<sem::Texture>()) { } else if (auto* tex = type->As<sem::Texture>()) {
@ -2440,10 +2402,29 @@ bool GeneratorImpl::EmitType(std::ostream& out,
auto* depth_ms = tex->As<sem::DepthMultisampledTexture>(); auto* depth_ms = tex->As<sem::DepthMultisampledTexture>();
auto* sampled = tex->As<sem::SampledTexture>(); auto* sampled = tex->As<sem::SampledTexture>();
if (storage && storage->access() != ast::Access::kRead) { out << "uniform highp ";
out << "RW";
if (sampled || ms) {
auto* subtype =
sampled ? sampled->type() : storage ? storage->type() : ms->type();
if (subtype->Is<sem::F32>()) {
} else if (subtype->Is<sem::I32>()) {
out << "i";
} else if (subtype->Is<sem::U32>()) {
out << "u";
} else {
TINT_ICE(Writer, diagnostics_) << "Unsupported texture type";
return false;
}
}
if (storage) {
if (storage->access() != ast::Access::kRead) {
out << "writeonly ";
}
out << "image";
} else {
out << "sampler";
} }
out << "Texture";
switch (tex->dim()) { switch (tex->dim()) {
case ast::TextureDimension::k1d: case ast::TextureDimension::k1d:
@ -2469,34 +2450,6 @@ bool GeneratorImpl::EmitType(std::ostream& out,
<< "unexpected TextureDimension " << tex->dim(); << "unexpected TextureDimension " << tex->dim();
return false; return false;
} }
if (storage) {
auto* component = image_format_to_rwtexture_type(storage->image_format());
if (component == nullptr) {
TINT_ICE(Writer, diagnostics_)
<< "Unsupported StorageTexture ImageFormat: "
<< static_cast<int>(storage->image_format());
return false;
}
out << "<" << component << ">";
} else if (depth_ms) {
out << "<float4>";
} else if (sampled || ms) {
auto* subtype = sampled ? sampled->type() : ms->type();
out << "<";
if (subtype->Is<sem::F32>()) {
out << "float4";
} else if (subtype->Is<sem::I32>()) {
out << "int4";
} else if (subtype->Is<sem::U32>()) {
out << "uint4";
} else {
TINT_ICE(Writer, diagnostics_)
<< "Unsupported multisampled texture type";
return false;
}
out << ">";
}
} else if (type->Is<sem::U32>()) { } else if (type->Is<sem::U32>()) {
out << "uint"; out << "uint";
} else if (auto* vec = type->As<sem::Vector>()) { } else if (auto* vec = type->As<sem::Vector>()) {

View File

@ -81,151 +81,151 @@ ExpectedResult expected_texture_overload(
case ValidTextureOverload::kNumSamplesMultisampled2d: case ValidTextureOverload::kNumSamplesMultisampled2d:
return {"textureSamples"}; return {"textureSamples"};
case ValidTextureOverload::kSample1dF32: case ValidTextureOverload::kSample1dF32:
return R"(texture.Sample(sampler, 1.0f);)"; return R"(texture(tint_symbol, 1.0f);)";
case ValidTextureOverload::kSample2dF32: case ValidTextureOverload::kSample2dF32:
return R"(texture.Sample(sampler, vec2(1.0f, 2.0f));)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f));)";
case ValidTextureOverload::kSample2dOffsetF32: case ValidTextureOverload::kSample2dOffsetF32:
return R"(texture.Sample(sampler, vec2(1.0f, 2.0f), ivec2(3, 4));)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), ivec2(3, 4));)";
case ValidTextureOverload::kSample2dArrayF32: case ValidTextureOverload::kSample2dArrayF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, float(3)));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(3)));)";
case ValidTextureOverload::kSample2dArrayOffsetF32: case ValidTextureOverload::kSample2dArrayOffsetF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, float(3)), ivec2(4, 5));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(3)), ivec2(4, 5));)";
case ValidTextureOverload::kSample3dF32: case ValidTextureOverload::kSample3dF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, 3.0f));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f));)";
case ValidTextureOverload::kSample3dOffsetF32: case ValidTextureOverload::kSample3dOffsetF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, 3.0f), ivec3(4, 5, 6));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f), ivec3(4, 5, 6));)";
case ValidTextureOverload::kSampleCubeF32: case ValidTextureOverload::kSampleCubeF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, 3.0f));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f));)";
case ValidTextureOverload::kSampleCubeArrayF32: case ValidTextureOverload::kSampleCubeArrayF32:
return R"(texture.Sample(sampler, vec4(1.0f, 2.0f, 3.0f, float(4)));)"; return R"(texture(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(4)));)";
case ValidTextureOverload::kSampleDepth2dF32: case ValidTextureOverload::kSampleDepth2dF32:
return R"(texture.Sample(sampler, vec2(1.0f, 2.0f)).x;)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f)).x;)";
case ValidTextureOverload::kSampleDepth2dOffsetF32: case ValidTextureOverload::kSampleDepth2dOffsetF32:
return R"(texture.Sample(sampler, vec2(1.0f, 2.0f), ivec2(3, 4)).x;)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), ivec2(3, 4)).x;)";
case ValidTextureOverload::kSampleDepth2dArrayF32: case ValidTextureOverload::kSampleDepth2dArrayF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, float(3))).x;)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(3))).x;)";
case ValidTextureOverload::kSampleDepth2dArrayOffsetF32: case ValidTextureOverload::kSampleDepth2dArrayOffsetF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, float(3)), ivec2(4, 5)).x;)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(3)), ivec2(4, 5)).x;)";
case ValidTextureOverload::kSampleDepthCubeF32: case ValidTextureOverload::kSampleDepthCubeF32:
return R"(texture.Sample(sampler, vec3(1.0f, 2.0f, 3.0f)).x;)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f)).x;)";
case ValidTextureOverload::kSampleDepthCubeArrayF32: case ValidTextureOverload::kSampleDepthCubeArrayF32:
return R"(texture.Sample(sampler, vec4(1.0f, 2.0f, 3.0f, float(4))).x;)"; return R"(texture(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(4))).x;)";
case ValidTextureOverload::kSampleBias2dF32: case ValidTextureOverload::kSampleBias2dF32:
return R"(texture.SampleBias(sampler, vec2(1.0f, 2.0f), 3.0f);)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), 3.0f);)";
case ValidTextureOverload::kSampleBias2dOffsetF32: case ValidTextureOverload::kSampleBias2dOffsetF32:
return R"(texture.SampleBias(sampler, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)";
case ValidTextureOverload::kSampleBias2dArrayF32: case ValidTextureOverload::kSampleBias2dArrayF32:
return R"(texture.SampleBias(sampler, vec3(1.0f, 2.0f, float(4)), 3.0f);)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(4)), 3.0f);)";
case ValidTextureOverload::kSampleBias2dArrayOffsetF32: case ValidTextureOverload::kSampleBias2dArrayOffsetF32:
return R"(texture.SampleBias(sampler, vec3(1.0f, 2.0f, float(3)), 4.0f, ivec2(5, 6));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(3)), 4.0f, ivec2(5, 6));)";
case ValidTextureOverload::kSampleBias3dF32: case ValidTextureOverload::kSampleBias3dF32:
return R"(texture.SampleBias(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f);)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f);)";
case ValidTextureOverload::kSampleBias3dOffsetF32: case ValidTextureOverload::kSampleBias3dOffsetF32:
return R"(texture.SampleBias(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f, ivec3(5, 6, 7));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f, ivec3(5, 6, 7));)";
case ValidTextureOverload::kSampleBiasCubeF32: case ValidTextureOverload::kSampleBiasCubeF32:
return R"(texture.SampleBias(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f);)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f);)";
case ValidTextureOverload::kSampleBiasCubeArrayF32: case ValidTextureOverload::kSampleBiasCubeArrayF32:
return R"(texture.SampleBias(sampler, vec4(1.0f, 2.0f, 3.0f, float(3)), 4.0f);)"; return R"(texture(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(3)), 4.0f);)";
case ValidTextureOverload::kSampleLevel2dF32: case ValidTextureOverload::kSampleLevel2dF32:
return R"(texture.SampleLevel(sampler, vec2(1.0f, 2.0f), 3.0f);)"; return R"(textureLod(tint_symbol, vec2(1.0f, 2.0f), 3.0f);)";
case ValidTextureOverload::kSampleLevel2dOffsetF32: case ValidTextureOverload::kSampleLevel2dOffsetF32:
return R"(texture.SampleLevel(sampler, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)"; return R"(textureLod(tint_symbol, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)";
case ValidTextureOverload::kSampleLevel2dArrayF32: case ValidTextureOverload::kSampleLevel2dArrayF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, float(3)), 4.0f);)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, float(3)), 4.0f);)";
case ValidTextureOverload::kSampleLevel2dArrayOffsetF32: case ValidTextureOverload::kSampleLevel2dArrayOffsetF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, float(3)), 4.0f, ivec2(5, 6));)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, float(3)), 4.0f, ivec2(5, 6));)";
case ValidTextureOverload::kSampleLevel3dF32: case ValidTextureOverload::kSampleLevel3dF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f);)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f);)";
case ValidTextureOverload::kSampleLevel3dOffsetF32: case ValidTextureOverload::kSampleLevel3dOffsetF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f, ivec3(5, 6, 7));)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f, ivec3(5, 6, 7));)";
case ValidTextureOverload::kSampleLevelCubeF32: case ValidTextureOverload::kSampleLevelCubeF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f);)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f);)";
case ValidTextureOverload::kSampleLevelCubeArrayF32: case ValidTextureOverload::kSampleLevelCubeArrayF32:
return R"(texture.SampleLevel(sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)"; return R"(textureLod(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)";
case ValidTextureOverload::kSampleLevelDepth2dF32: case ValidTextureOverload::kSampleLevelDepth2dF32:
return R"(texture.SampleLevel(sampler, vec2(1.0f, 2.0f), 3).x;)"; return R"(textureLod(tint_symbol, vec2(1.0f, 2.0f), 3).x;)";
case ValidTextureOverload::kSampleLevelDepth2dOffsetF32: case ValidTextureOverload::kSampleLevelDepth2dOffsetF32:
return R"(texture.SampleLevel(sampler, vec2(1.0f, 2.0f), 3, ivec2(4, 5)).x;)"; return R"(textureLod(tint_symbol, vec2(1.0f, 2.0f), 3, ivec2(4, 5)).x;)";
case ValidTextureOverload::kSampleLevelDepth2dArrayF32: case ValidTextureOverload::kSampleLevelDepth2dArrayF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, float(3)), 4).x;)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, float(3)), 4).x;)";
case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32: case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, float(3)), 4, ivec2(5, 6)).x;)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, float(3)), 4, ivec2(5, 6)).x;)";
case ValidTextureOverload::kSampleLevelDepthCubeF32: case ValidTextureOverload::kSampleLevelDepthCubeF32:
return R"(texture.SampleLevel(sampler, vec3(1.0f, 2.0f, 3.0f), 4).x;)"; return R"(textureLod(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4).x;)";
case ValidTextureOverload::kSampleLevelDepthCubeArrayF32: case ValidTextureOverload::kSampleLevelDepthCubeArrayF32:
return R"(texture.SampleLevel(sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 5).x;)"; return R"(textureLod(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(4)), 5).x;)";
case ValidTextureOverload::kSampleGrad2dF32: case ValidTextureOverload::kSampleGrad2dF32:
return R"(texture.SampleGrad(sampler, vec2(1.0f, 2.0f), vec2(3.0f, 4.0f), vec2(5.0f, 6.0f));)"; return R"(textureGrad(tint_symbol, vec2(1.0f, 2.0f), vec2(3.0f, 4.0f), vec2(5.0f, 6.0f));)";
case ValidTextureOverload::kSampleGrad2dOffsetF32: case ValidTextureOverload::kSampleGrad2dOffsetF32:
return R"(texture.SampleGrad(sampler, vec2(1.0f, 2.0f), vec2(3.0f, 4.0f), vec2(5.0f, 6.0f), ivec2(7, 7));)"; return R"(textureGrad(tint_symbol, vec2(1.0f, 2.0f), vec2(3.0f, 4.0f), vec2(5.0f, 6.0f), ivec2(7, 7));)";
case ValidTextureOverload::kSampleGrad2dArrayF32: case ValidTextureOverload::kSampleGrad2dArrayF32:
return R"(texture.SampleGrad(sampler, vec3(1.0f, 2.0f, float(3)), vec2(4.0f, 5.0f), vec2(6.0f, 7.0f));)"; return R"(textureGrad(tint_symbol, vec3(1.0f, 2.0f, float(3)), vec2(4.0f, 5.0f), vec2(6.0f, 7.0f));)";
case ValidTextureOverload::kSampleGrad2dArrayOffsetF32: case ValidTextureOverload::kSampleGrad2dArrayOffsetF32:
return R"(texture.SampleGrad(sampler, vec3(1.0f, 2.0f, float(3)), vec2(4.0f, 5.0f), vec2(6.0f, 7.0f), ivec2(6, 7));)"; return R"(textureGrad(tint_symbol, vec3(1.0f, 2.0f, float(3)), vec2(4.0f, 5.0f), vec2(6.0f, 7.0f), ivec2(6, 7));)";
case ValidTextureOverload::kSampleGrad3dF32: case ValidTextureOverload::kSampleGrad3dF32:
return R"(texture.SampleGrad(sampler, vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f));)"; return R"(textureGrad(tint_symbol, vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f));)";
case ValidTextureOverload::kSampleGrad3dOffsetF32: case ValidTextureOverload::kSampleGrad3dOffsetF32:
return R"(texture.SampleGrad(sampler, vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f), ivec3(0, 1, 2));)"; return R"(textureGrad(tint_symbol, vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f), ivec3(0, 1, 2));)";
case ValidTextureOverload::kSampleGradCubeF32: case ValidTextureOverload::kSampleGradCubeF32:
return R"(texture.SampleGrad(sampler, vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f));)"; return R"(textureGrad(tint_symbol, vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f));)";
case ValidTextureOverload::kSampleGradCubeArrayF32: case ValidTextureOverload::kSampleGradCubeArrayF32:
return R"(texture.SampleGrad(sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), vec3(5.0f, 6.0f, 7.0f), vec3(8.0f, 9.0f, 10.0f));)"; return R"(textureGrad(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(4)), vec3(5.0f, 6.0f, 7.0f), vec3(8.0f, 9.0f, 10.0f));)";
case ValidTextureOverload::kSampleCompareDepth2dF32: case ValidTextureOverload::kSampleCompareDepth2dF32:
return R"(texture.SampleCmp(sampler, vec2(1.0f, 2.0f), 3.0f);)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), 3.0f);)";
case ValidTextureOverload::kSampleCompareDepth2dOffsetF32: case ValidTextureOverload::kSampleCompareDepth2dOffsetF32:
return R"(texture.SampleCmp(sampler, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)";
case ValidTextureOverload::kSampleCompareDepth2dArrayF32: case ValidTextureOverload::kSampleCompareDepth2dArrayF32:
return R"(texture.SampleCmp(sampler, vec3(1.0f, 2.0f, float(4)), 3.0f);)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(4)), 3.0f);)";
case ValidTextureOverload::kSampleCompareDepth2dArrayOffsetF32: case ValidTextureOverload::kSampleCompareDepth2dArrayOffsetF32:
return R"(texture.SampleCmp(sampler, vec3(1.0f, 2.0f, float(4)), 3.0f, ivec2(5, 6));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(4)), 3.0f, ivec2(5, 6));)";
case ValidTextureOverload::kSampleCompareDepthCubeF32: case ValidTextureOverload::kSampleCompareDepthCubeF32:
return R"(texture.SampleCmp(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f);)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f);)";
case ValidTextureOverload::kSampleCompareDepthCubeArrayF32: case ValidTextureOverload::kSampleCompareDepthCubeArrayF32:
return R"(texture.SampleCmp(sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)"; return R"(texture(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)";
case ValidTextureOverload::kSampleCompareLevelDepth2dF32: case ValidTextureOverload::kSampleCompareLevelDepth2dF32:
return R"(texture.SampleCmpLevelZero(sampler, vec2(1.0f, 2.0f), 3.0f);)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), 3.0f);)";
case ValidTextureOverload::kSampleCompareLevelDepth2dOffsetF32: case ValidTextureOverload::kSampleCompareLevelDepth2dOffsetF32:
return R"(texture.SampleCmpLevelZero(sampler, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)"; return R"(texture(tint_symbol, vec2(1.0f, 2.0f), 3.0f, ivec2(4, 5));)";
case ValidTextureOverload::kSampleCompareLevelDepth2dArrayF32: case ValidTextureOverload::kSampleCompareLevelDepth2dArrayF32:
return R"(texture.SampleCmpLevelZero(sampler, vec3(1.0f, 2.0f, float(4)), 3.0f);)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(4)), 3.0f);)";
case ValidTextureOverload::kSampleCompareLevelDepth2dArrayOffsetF32: case ValidTextureOverload::kSampleCompareLevelDepth2dArrayOffsetF32:
return R"(texture.SampleCmpLevelZero(sampler, vec3(1.0f, 2.0f, float(4)), 3.0f, ivec2(5, 6));)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, float(4)), 3.0f, ivec2(5, 6));)";
case ValidTextureOverload::kSampleCompareLevelDepthCubeF32: case ValidTextureOverload::kSampleCompareLevelDepthCubeF32:
return R"(texture.SampleCmpLevelZero(sampler, vec3(1.0f, 2.0f, 3.0f), 4.0f);)"; return R"(texture(tint_symbol, vec3(1.0f, 2.0f, 3.0f), 4.0f);)";
case ValidTextureOverload::kSampleCompareLevelDepthCubeArrayF32: case ValidTextureOverload::kSampleCompareLevelDepthCubeArrayF32:
return R"(texture.SampleCmpLevelZero(sampler, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)"; return R"(texture(tint_symbol, vec4(1.0f, 2.0f, 3.0f, float(4)), 5.0f);)";
case ValidTextureOverload::kLoad1dLevelF32: case ValidTextureOverload::kLoad1dLevelF32:
case ValidTextureOverload::kLoad1dLevelU32: case ValidTextureOverload::kLoad1dLevelU32:
case ValidTextureOverload::kLoad1dLevelI32: case ValidTextureOverload::kLoad1dLevelI32:
return R"(texture.Load(ivec2(1, 3));)"; return R"(texelFetch(tint_symbol, ivec2(1, 3));)";
case ValidTextureOverload::kLoad2dLevelF32: case ValidTextureOverload::kLoad2dLevelF32:
case ValidTextureOverload::kLoad2dLevelU32: case ValidTextureOverload::kLoad2dLevelU32:
case ValidTextureOverload::kLoad2dLevelI32: case ValidTextureOverload::kLoad2dLevelI32:
return R"(texture.Load(ivec3(1, 2, 3));)"; return R"(texelFetch(tint_symbol, ivec3(1, 2, 3));)";
case ValidTextureOverload::kLoad2dArrayLevelF32: case ValidTextureOverload::kLoad2dArrayLevelF32:
case ValidTextureOverload::kLoad2dArrayLevelU32: case ValidTextureOverload::kLoad2dArrayLevelU32:
case ValidTextureOverload::kLoad2dArrayLevelI32: case ValidTextureOverload::kLoad2dArrayLevelI32:
case ValidTextureOverload::kLoad3dLevelF32: case ValidTextureOverload::kLoad3dLevelF32:
case ValidTextureOverload::kLoad3dLevelU32: case ValidTextureOverload::kLoad3dLevelU32:
case ValidTextureOverload::kLoad3dLevelI32: case ValidTextureOverload::kLoad3dLevelI32:
return R"(texture.Load(ivec4(1, 2, 3, 4));)"; return R"(texelFetch(tint_symbol, ivec4(1, 2, 3, 4));)";
case ValidTextureOverload::kLoadDepthMultisampled2dF32: case ValidTextureOverload::kLoadDepthMultisampled2dF32:
case ValidTextureOverload::kLoadMultisampled2dF32: case ValidTextureOverload::kLoadMultisampled2dF32:
case ValidTextureOverload::kLoadMultisampled2dU32: case ValidTextureOverload::kLoadMultisampled2dU32:
case ValidTextureOverload::kLoadMultisampled2dI32: case ValidTextureOverload::kLoadMultisampled2dI32:
return R"(texture.Load(ivec2(1, 2), 3);)"; return R"(texelFetch(tint_symbol, ivec2(1, 2), 3);)";
case ValidTextureOverload::kLoadDepth2dLevelF32: case ValidTextureOverload::kLoadDepth2dLevelF32:
return R"(texture.Load(ivec3(1, 2, 3)).x;)"; return R"(texelFetch(tint_symbol, ivec3(1, 2, 3)).x;)";
case ValidTextureOverload::kLoadDepth2dArrayLevelF32: case ValidTextureOverload::kLoadDepth2dArrayLevelF32:
return R"(texture.Load(ivec4(1, 2, 3, 4)).x;)"; return R"(texelFetch(tint_symbol, ivec4(1, 2, 3, 4)).x;)";
case ValidTextureOverload::kStoreWO1dRgba32float: case ValidTextureOverload::kStoreWO1dRgba32float:
return R"(texture[1] = vec4(2.0f, 3.0f, 4.0f, 5.0f);)"; return R"(imageStore(tint_symbol, 1, vec4(2.0f, 3.0f, 4.0f, 5.0f)).x;)";
case ValidTextureOverload::kStoreWO2dRgba32float: case ValidTextureOverload::kStoreWO2dRgba32float:
return R"(texture[ivec2(1, 2)] = vec4(3.0f, 4.0f, 5.0f, 6.0f);)"; return R"(imageStore(tint_symbol, ivec2(1, 2), vec4(3.0f, 4.0f, 5.0f, 6.0f)).x;)";
case ValidTextureOverload::kStoreWO2dArrayRgba32float: case ValidTextureOverload::kStoreWO2dArrayRgba32float:
return R"(texture[ivec3(1, 2, 3)] = vec4(4.0f, 5.0f, 6.0f, 7.0f);)"; return R"(imageStore(tint_symbol, ivec3(1, 2, 3), vec4(4.0f, 5.0f, 6.0f, 7.0f)).x;)";
case ValidTextureOverload::kStoreWO3dRgba32float: case ValidTextureOverload::kStoreWO3dRgba32float:
return R"(texture[ivec3(1, 2, 3)] = vec4(4.0f, 5.0f, 6.0f, 7.0f);)"; return R"(imageStore(tint_symbol, ivec3(1, 2, 3), vec4(4.0f, 5.0f, 6.0f, 7.0f)).x;)";
} }
return "<unmatched texture overload>"; return "<unmatched texture overload>";
} // NOLINT - Ignore the length of this function } // NOLINT - Ignore the length of this function

View File

@ -281,10 +281,9 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSampler) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, sampler, ast::StorageClass::kNone, ASSERT_FALSE(gen.EmitType(out, sampler, ast::StorageClass::kNone,
ast::Access::kReadWrite, "")) ast::Access::kReadWrite, ""))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "SamplerState");
} }
TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) { TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) {
@ -293,10 +292,9 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
std::stringstream out; std::stringstream out;
ASSERT_TRUE(gen.EmitType(out, sampler, ast::StorageClass::kNone, ASSERT_FALSE(gen.EmitType(out, sampler, ast::StorageClass::kNone,
ast::Access::kReadWrite, "")) ast::Access::kReadWrite, ""))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "SamplerComparisonState");
} }
struct GlslDepthTextureData { struct GlslDepthTextureData {
@ -331,12 +329,12 @@ INSTANTIATE_TEST_SUITE_P(
GlslGeneratorImplTest_Type, GlslGeneratorImplTest_Type,
GlslDepthTexturesTest, GlslDepthTexturesTest,
testing::Values( testing::Values(
GlslDepthTextureData{ast::TextureDimension::k2d, "Texture2D tex;"}, GlslDepthTextureData{ast::TextureDimension::k2d, "sampler2D tex;"},
GlslDepthTextureData{ast::TextureDimension::k2dArray, GlslDepthTextureData{ast::TextureDimension::k2dArray,
"Texture2DArray tex;"}, "sampler2DArray tex;"},
GlslDepthTextureData{ast::TextureDimension::kCube, "TextureCube tex;"}, GlslDepthTextureData{ast::TextureDimension::kCube, "samplerCube tex;"},
GlslDepthTextureData{ast::TextureDimension::kCubeArray, GlslDepthTextureData{ast::TextureDimension::kCubeArray,
"TextureCubeArray tex;"})); "samplerCubeArray tex;"}));
using GlslDepthMultisampledTexturesTest = TestHelper; using GlslDepthMultisampledTexturesTest = TestHelper;
TEST_F(GlslDepthMultisampledTexturesTest, Emit) { TEST_F(GlslDepthMultisampledTexturesTest, Emit) {
@ -354,7 +352,7 @@ TEST_F(GlslDepthMultisampledTexturesTest, Emit) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error(); ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr("Texture2DMS<float4> tex;")); EXPECT_THAT(gen.result(), HasSubstr("sampler2DMS tex;"));
} }
enum class TextureDataType { F32, U32, I32 }; enum class TextureDataType { F32, U32, I32 };
@ -406,92 +404,92 @@ INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Type,
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k1d, ast::TextureDimension::k1d,
TextureDataType::F32, TextureDataType::F32,
"Texture1D<float4> tex;", "sampler1D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k2d, ast::TextureDimension::k2d,
TextureDataType::F32, TextureDataType::F32,
"Texture2D<float4> tex;", "sampler2D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k2dArray, ast::TextureDimension::k2dArray,
TextureDataType::F32, TextureDataType::F32,
"Texture2DArray<float4> tex;", "sampler2DArray tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k3d, ast::TextureDimension::k3d,
TextureDataType::F32, TextureDataType::F32,
"Texture3D<float4> tex;", "sampler3D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::kCube, ast::TextureDimension::kCube,
TextureDataType::F32, TextureDataType::F32,
"TextureCube<float4> tex;", "samplerCube tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::kCubeArray, ast::TextureDimension::kCubeArray,
TextureDataType::F32, TextureDataType::F32,
"TextureCubeArray<float4> tex;", "samplerCubeArray tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k1d, ast::TextureDimension::k1d,
TextureDataType::U32, TextureDataType::U32,
"Texture1D<uint4> tex;", "usampler1D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k2d, ast::TextureDimension::k2d,
TextureDataType::U32, TextureDataType::U32,
"Texture2D<uint4> tex;", "usampler2D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k2dArray, ast::TextureDimension::k2dArray,
TextureDataType::U32, TextureDataType::U32,
"Texture2DArray<uint4> tex;", "usampler2DArray tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k3d, ast::TextureDimension::k3d,
TextureDataType::U32, TextureDataType::U32,
"Texture3D<uint4> tex;", "usampler3D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::kCube, ast::TextureDimension::kCube,
TextureDataType::U32, TextureDataType::U32,
"TextureCube<uint4> tex;", "usamplerCube tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::kCubeArray, ast::TextureDimension::kCubeArray,
TextureDataType::U32, TextureDataType::U32,
"TextureCubeArray<uint4> tex;", "usamplerCubeArray tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k1d, ast::TextureDimension::k1d,
TextureDataType::I32, TextureDataType::I32,
"Texture1D<int4> tex;", "isampler1D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k2d, ast::TextureDimension::k2d,
TextureDataType::I32, TextureDataType::I32,
"Texture2D<int4> tex;", "isampler2D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k2dArray, ast::TextureDimension::k2dArray,
TextureDataType::I32, TextureDataType::I32,
"Texture2DArray<int4> tex;", "isampler2DArray tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::k3d, ast::TextureDimension::k3d,
TextureDataType::I32, TextureDataType::I32,
"Texture3D<int4> tex;", "isampler3D tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::kCube, ast::TextureDimension::kCube,
TextureDataType::I32, TextureDataType::I32,
"TextureCube<int4> tex;", "isamplerCube tex;",
}, },
GlslSampledTextureData{ GlslSampledTextureData{
ast::TextureDimension::kCubeArray, ast::TextureDimension::kCubeArray,
TextureDataType::I32, TextureDataType::I32,
"TextureCubeArray<int4> tex;", "isamplerCubeArray tex;",
})); }));
TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) { TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) {
@ -504,7 +502,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) {
ASSERT_TRUE(gen.EmitType(out, s, ast::StorageClass::kNone, ASSERT_TRUE(gen.EmitType(out, s, ast::StorageClass::kNone,
ast::Access::kReadWrite, "")) ast::Access::kReadWrite, ""))
<< gen.error(); << gen.error();
EXPECT_EQ(out.str(), "Texture2DMS<float4>"); EXPECT_EQ(out.str(), "uniform highp sampler2DMS");
} }
struct GlslStorageTextureData { struct GlslStorageTextureData {
@ -539,45 +537,34 @@ TEST_P(GlslStorageTexturesTest, Emit) {
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
GlslGeneratorImplTest_Type, GlslGeneratorImplTest_Type,
GlslStorageTexturesTest, GlslStorageTexturesTest,
testing::Values(GlslStorageTextureData{ast::TextureDimension::k1d, testing::Values(
ast::ImageFormat::kRgba8Unorm, GlslStorageTextureData{ast::TextureDimension::k1d,
"RWTexture1D<float4> tex;"}, ast::ImageFormat::kRgba8Unorm, "image1D tex;"},
GlslStorageTextureData{ast::TextureDimension::k2d, GlslStorageTextureData{ast::TextureDimension::k2d,
ast::ImageFormat::kRgba16Float, ast::ImageFormat::kRgba16Float, "image2D tex;"},
"RWTexture2D<float4> tex;"}, GlslStorageTextureData{ast::TextureDimension::k2dArray,
GlslStorageTextureData{ast::TextureDimension::k2dArray, ast::ImageFormat::kR32Float,
ast::ImageFormat::kR32Float, "image2DArray tex;"},
"RWTexture2DArray<float4> tex;"}, GlslStorageTextureData{ast::TextureDimension::k3d,
GlslStorageTextureData{ast::TextureDimension::k3d, ast::ImageFormat::kRg32Float, "image3D tex;"},
ast::ImageFormat::kRg32Float, GlslStorageTextureData{ast::TextureDimension::k1d,
"RWTexture3D<float4> tex;"}, ast::ImageFormat::kRgba32Float, "image1D tex;"},
GlslStorageTextureData{ast::TextureDimension::k1d, GlslStorageTextureData{ast::TextureDimension::k2d,
ast::ImageFormat::kRgba32Float, ast::ImageFormat::kRgba16Uint, "image2D tex;"},
"RWTexture1D<float4> tex;"}, GlslStorageTextureData{ast::TextureDimension::k2dArray,
GlslStorageTextureData{ast::TextureDimension::k2d, ast::ImageFormat::kR32Uint, "image2DArray tex;"},
ast::ImageFormat::kRgba16Uint, GlslStorageTextureData{ast::TextureDimension::k3d,
"RWTexture2D<uint4> tex;"}, ast::ImageFormat::kRg32Uint, "image3D tex;"},
GlslStorageTextureData{ast::TextureDimension::k2dArray, GlslStorageTextureData{ast::TextureDimension::k1d,
ast::ImageFormat::kR32Uint, ast::ImageFormat::kRgba32Uint, "image1D tex;"},
"RWTexture2DArray<uint4> tex;"}, GlslStorageTextureData{ast::TextureDimension::k2d,
GlslStorageTextureData{ast::TextureDimension::k3d, ast::ImageFormat::kRgba16Sint, "image2D tex;"},
ast::ImageFormat::kRg32Uint, GlslStorageTextureData{ast::TextureDimension::k2dArray,
"RWTexture3D<uint4> tex;"}, ast::ImageFormat::kR32Sint, "image2DArray tex;"},
GlslStorageTextureData{ast::TextureDimension::k1d, GlslStorageTextureData{ast::TextureDimension::k3d,
ast::ImageFormat::kRgba32Uint, ast::ImageFormat::kRg32Sint, "image3D tex;"},
"RWTexture1D<uint4> tex;"}, GlslStorageTextureData{ast::TextureDimension::k1d,
GlslStorageTextureData{ast::TextureDimension::k2d, ast::ImageFormat::kRgba32Sint, "image1D tex;"}));
ast::ImageFormat::kRgba16Sint,
"RWTexture2D<int4> tex;"},
GlslStorageTextureData{ast::TextureDimension::k2dArray,
ast::ImageFormat::kR32Sint,
"RWTexture2DArray<int4> tex;"},
GlslStorageTextureData{ast::TextureDimension::k3d,
ast::ImageFormat::kRg32Sint,
"RWTexture3D<int4> tex;"},
GlslStorageTextureData{ast::TextureDimension::k1d,
ast::ImageFormat::kRgba32Sint,
"RWTexture1D<int4> tex;"}));
} // namespace } // namespace
} // namespace glsl } // namespace glsl