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<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>();
// Simplify cleans up messy `*(&(expr))` expressions from InlinePointerLets.
manager.Add<Simplify>();
@@ -72,10 +81,6 @@ Output Glsl::Run(const Program* in, const DataMap& inputs) {
// variables directly.
data.Add<CanonicalizeEntryPointIO::Config>(
CanonicalizeEntryPointIO::ShaderStyle::kHlsl);
if (cfg) {
manager.Add<SingleEntryPoint>();
data.Add<SingleEntryPoint::Config>(cfg->entry_point);
}
auto out = manager.Run(in, data);
if (!out.program.IsValid()) {
return out;

View File

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