aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/gl/GrGLGpu.cpp28
-rw-r--r--src/gpu/glsl/GrGLSL.h25
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp13
-rw-r--r--src/sksl/README2
-rw-r--r--src/sksl/SkSLContext.h5
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.cpp63
-rw-r--r--src/sksl/SkSLSPIRVCodeGenerator.cpp59
-rw-r--r--src/sksl/SkSLSPIRVCodeGenerator.h2
-rw-r--r--src/sksl/ir/SkSLType.h2
-rw-r--r--src/sksl/sksl.include57
-rw-r--r--tests/SkSLGLSLTest.cpp42
11 files changed, 159 insertions, 139 deletions
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 9c25602187..94857789d9 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3807,9 +3807,8 @@ bool GrGLGpu::createCopyProgram(GrTexture* srcTex) {
fshaderTxt.appendf(
"// Copy Program FS\n"
"void main() {"
- " sk_FragColor = %s(u_texture, v_texCoord);"
- "}",
- GrGLSLTexture2DFunctionName(kVec2f_GrSLType, samplerType, this->glslGeneration())
+ " sk_FragColor = texture(u_texture, v_texCoord);"
+ "}"
);
const char* str;
@@ -3940,29 +3939,26 @@ bool GrGLGpu::createMipmapProgram(int progIdx) {
}
uTexture.appendDecl(glslCaps, &fshaderTxt);
fshaderTxt.append(";");
- const char* sampleFunction = GrGLSLTexture2DFunctionName(kVec2f_GrSLType,
- kTexture2DSampler_GrSLType,
- this->glslGeneration());
fshaderTxt.append(
"// Mipmap Program FS\n"
"void main() {"
);
if (oddWidth && oddHeight) {
- fshaderTxt.appendf(
- " sk_FragColor = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1) + "
- " %s(u_texture, v_texCoord2) + %s(u_texture, v_texCoord3)) * 0.25;",
- sampleFunction, sampleFunction, sampleFunction, sampleFunction
+ fshaderTxt.append(
+ " sk_FragColor = (texture(u_texture, v_texCoord0) + "
+ " texture(u_texture, v_texCoord1) + "
+ " texture(u_texture, v_texCoord2) + "
+ " texture(u_texture, v_texCoord3)) * 0.25;"
);
} else if (oddWidth || oddHeight) {
- fshaderTxt.appendf(
- " sk_FragColor = (%s(u_texture, v_texCoord0) + %s(u_texture, v_texCoord1)) * 0.5;",
- sampleFunction, sampleFunction
+ fshaderTxt.append(
+ " sk_FragColor = (texture(u_texture, v_texCoord0) + "
+ " texture(u_texture, v_texCoord1)) * 0.5;"
);
} else {
- fshaderTxt.appendf(
- " sk_FragColor = %s(u_texture, v_texCoord0);",
- sampleFunction
+ fshaderTxt.append(
+ " sk_FragColor = texture(u_texture, v_texCoord0);"
);
}
diff --git a/src/gpu/glsl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h
index 4461f4c60f..d27b25f293 100644
--- a/src/gpu/glsl/GrGLSL.h
+++ b/src/gpu/glsl/GrGLSL.h
@@ -57,31 +57,6 @@ enum GrGLSLGeneration {
bool GrGLSLSupportsNamedFragmentShaderOutputs(GrGLSLGeneration);
/**
- * Gets the name of the function that should be used to sample a 2D texture. Coord type is used
- * to indicate whether the texture is sampled using projective textured (kVec3f) or not (kVec2f).
- */
-inline const char* GrGLSLTexture2DFunctionName(GrSLType coordType, GrSLType samplerType,
- GrGLSLGeneration glslGen) {
- SkASSERT(GrSLTypeIs2DCombinedSamplerType(samplerType));
- SkASSERT(kVec2f_GrSLType == coordType || kVec3f_GrSLType == coordType);
- // GL_TEXTURE_RECTANGLE_ARB is written against OpenGL 2.0/GLSL 1.10. At that time there were
- // separate texture*() functions. In OpenGL 3.0/GLSL 1.30 the different texture*() functions
- // were deprecated in favor or the unified texture() function. RECTANGLE textures became
- // standard in OpenGL 3.2/GLSL 1.50 and use texture(). It isn't completely clear what function
- // should be used for RECTANGLE textures in GLSL versions >= 1.30 && < 1.50. We're going with
- // using texture().
- if (glslGen >= k130_GrGLSLGeneration) {
- return (kVec2f_GrSLType == coordType) ? "texture" : "textureProj";
- }
- if (kVec2f_GrSLType == coordType) {
- return (samplerType == kTexture2DRectSampler_GrSLType) ? "texture2DRect" : "texture2D";
- } else {
- return (samplerType == kTexture2DRectSampler_GrSLType) ? "texture2DRectProj"
- : "texture2DProj";
- }
-}
-
-/**
* Adds a line of GLSL code to declare the default precision for float types.
*/
void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision,
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 28578ddf63..b6e7ce9ebf 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -66,25 +66,18 @@ void GrGLSLShaderBuilder::appendTextureLookup(SkString* out,
SamplerHandle samplerHandle,
const char* coordName,
GrSLType varyingType) const {
- const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
const GrShaderVar& sampler = fProgramBuilder->samplerVariable(samplerHandle);
GrSLType samplerType = sampler.getType();
if (samplerType == kTexture2DRectSampler_GrSLType) {
if (varyingType == kVec2f_GrSLType) {
- out->appendf("%s(%s, textureSize(%s) * %s)",
- GrGLSLTexture2DFunctionName(varyingType, samplerType,
- glslCaps->generation()),
+ out->appendf("texture(%s, textureSize(%s) * %s)",
sampler.c_str(), sampler.c_str(), coordName);
} else {
- out->appendf("%s(%s, vec3(textureSize(%s) * %s.xy, %s.z))",
- GrGLSLTexture2DFunctionName(varyingType, samplerType,
- glslCaps->generation()),
+ out->appendf("texture(%s, vec3(textureSize(%s) * %s.xy, %s.z))",
sampler.c_str(), sampler.c_str(), coordName, coordName);
}
} else {
- out->appendf("%s(%s, %s)",
- GrGLSLTexture2DFunctionName(varyingType, samplerType, glslCaps->generation()),
- sampler.c_str(), coordName);
+ out->appendf("texture(%s, %s)", sampler.c_str(), coordName);
}
append_texture_swizzle(out, fProgramBuilder->samplerSwizzle(samplerHandle));
}
diff --git a/src/sksl/README b/src/sksl/README
index 0ab8a0500a..d18367f8d2 100644
--- a/src/sksl/README
+++ b/src/sksl/README
@@ -40,6 +40,8 @@ following differences between SkSL and GLSL:
have to be expressed "vec2(x, y) * 4.0". There is no performance penalty for
this, as the number is converted to a float at compile time)
* type suffixes on numbers (1.0f, 0xFFu) are both unnecessary and unsupported
+* Use texture() instead of textureProj(), e.g. texture(sampler2D, vec3) is
+ equivalent to GLSL's textureProj(sampler2D, vec3)
* some built-in functions and one or two rarely-used language features are not
yet supported (sorry!)
diff --git a/src/sksl/SkSLContext.h b/src/sksl/SkSLContext.h
index 6284c21a9a..18de3367bc 100644
--- a/src/sksl/SkSLContext.h
+++ b/src/sksl/SkSLContext.h
@@ -65,8 +65,9 @@ public:
, fSampler3D_Type(new Type(SkString("sampler3D"), SpvDim3D, false, false, false, true))
, fSamplerExternalOES_Type(new Type(SkString("samplerExternalOES"), SpvDim2D, false, false,
false, true))
- , fSamplerCube_Type(new Type(SkString("samplerCube")))
- , fSampler2DRect_Type(new Type(SkString("sampler2DRect")))
+ , fSamplerCube_Type(new Type(SkString("samplerCube"), SpvDimCube, false, false, false, true))
+ , fSampler2DRect_Type(new Type(SkString("sampler2DRect"), SpvDimRect, false, false, false,
+ true))
, fSampler1DArray_Type(new Type(SkString("sampler1DArray")))
, fSampler2DArray_Type(new Type(SkString("sampler2DArray")))
, fSamplerCubeArray_Type(new Type(SkString("samplerCubeArray")))
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index e4aec92caf..3a6f8c52a6 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -184,7 +184,68 @@ void GLSLCodeGenerator::writeFunctionCall(const FunctionCall& c) {
fHeader.writeText(" : require\n");
fFoundDerivatives = true;
}
- this->write(c.fFunction.fName + "(");
+ if (c.fFunction.fName == "texture" && c.fFunction.fBuiltin) {
+ const char* dim = "";
+ bool proj = false;
+ switch (c.fArguments[0]->fType.dimensions()) {
+ case SpvDim1D:
+ dim = "1D";
+ if (c.fArguments[1]->fType == *fContext.fFloat_Type) {
+ proj = false;
+ } else {
+ ASSERT(c.fArguments[1]->fType == *fContext.fVec2_Type);
+ proj = true;
+ }
+ break;
+ case SpvDim2D:
+ dim = "2D";
+ if (c.fArguments[1]->fType == *fContext.fVec2_Type) {
+ proj = false;
+ } else {
+ ASSERT(c.fArguments[1]->fType == *fContext.fVec3_Type);
+ proj = true;
+ }
+ break;
+ case SpvDim3D:
+ dim = "3D";
+ if (c.fArguments[1]->fType == *fContext.fVec3_Type) {
+ proj = false;
+ } else {
+ ASSERT(c.fArguments[1]->fType == *fContext.fVec4_Type);
+ proj = true;
+ }
+ break;
+ case SpvDimCube:
+ dim = "Cube";
+ proj = false;
+ break;
+ case SpvDimRect:
+ dim = "Rect";
+ proj = false;
+ break;
+ case SpvDimBuffer:
+ ASSERT(false); // doesn't exist
+ dim = "Buffer";
+ proj = false;
+ break;
+ case SpvDimSubpassData:
+ ASSERT(false); // doesn't exist
+ dim = "SubpassData";
+ proj = false;
+ break;
+ }
+ this->write("texture");
+ if (fCaps.generation() < k130_GrGLSLGeneration) {
+ this->write(dim);
+ }
+ if (proj) {
+ this->write("Proj");
+ }
+
+ } else {
+ this->write(c.fFunction.fName);
+ }
+ this->write("(");
const char* separator = "";
for (const auto& arg : c.fArguments) {
this->write(separator);
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index ecde11509d..089b899bfe 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -103,8 +103,6 @@ void SPIRVCodeGenerator::setupIntrinsics() {
fIntrinsicMap[SkString("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
SpvOpUndef, SpvOpUndef, SpvOpUndef);
fIntrinsicMap[SkString("texture")] = SPECIAL(Texture);
- fIntrinsicMap[SkString("texture2D")] = SPECIAL(Texture2D);
- fIntrinsicMap[SkString("textureProj")] = SPECIAL(TextureProj);
fIntrinsicMap[SkString("subpassLoad")] = SPECIAL(SubpassLoad);
@@ -1285,47 +1283,50 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn
return result;
}
case kTexture_SpecialIntrinsic: {
- SpvId type = this->getType(c.fType);
- SpvId sampler = this->writeExpression(*c.fArguments[0], out);
- SpvId uv = this->writeExpression(*c.fArguments[1], out);
- if (c.fArguments.size() == 3) {
- this->writeInstruction(SpvOpImageSampleImplicitLod, type, result, sampler, uv,
- SpvImageOperandsBiasMask,
- this->writeExpression(*c.fArguments[2], out),
- out);
- } else {
- ASSERT(c.fArguments.size() == 2);
- this->writeInstruction(SpvOpImageSampleImplicitLod, type, result, sampler, uv, out);
+ SpvOp_ op = SpvOpImageSampleImplicitLod;
+ switch (c.fArguments[0]->fType.dimensions()) {
+ case SpvDim1D:
+ if (c.fArguments[1]->fType == *fContext.fVec2_Type) {
+ op = SpvOpImageSampleProjImplicitLod;
+ } else {
+ ASSERT(c.fArguments[1]->fType == *fContext.fFloat_Type);
+ }
+ break;
+ case SpvDim2D:
+ if (c.fArguments[1]->fType == *fContext.fVec3_Type) {
+ op = SpvOpImageSampleProjImplicitLod;
+ } else {
+ ASSERT(c.fArguments[1]->fType == *fContext.fVec2_Type);
+ }
+ break;
+ case SpvDim3D:
+ if (c.fArguments[1]->fType == *fContext.fVec4_Type) {
+ op = SpvOpImageSampleProjImplicitLod;
+ } else {
+ ASSERT(c.fArguments[1]->fType == *fContext.fVec3_Type);
+ }
+ break;
+ case SpvDimCube: // fall through
+ case SpvDimRect: // fall through
+ case SpvDimBuffer: // fall through
+ case SpvDimSubpassData:
+ break;
}
- break;
- }
- case kTextureProj_SpecialIntrinsic: {
SpvId type = this->getType(c.fType);
SpvId sampler = this->writeExpression(*c.fArguments[0], out);
SpvId uv = this->writeExpression(*c.fArguments[1], out);
if (c.fArguments.size() == 3) {
- this->writeInstruction(SpvOpImageSampleProjImplicitLod, type, result, sampler, uv,
+ this->writeInstruction(op, type, result, sampler, uv,
SpvImageOperandsBiasMask,
this->writeExpression(*c.fArguments[2], out),
out);
} else {
ASSERT(c.fArguments.size() == 2);
- this->writeInstruction(SpvOpImageSampleProjImplicitLod, type, result, sampler, uv,
+ this->writeInstruction(op, type, result, sampler, uv,
out);
}
break;
}
- case kTexture2D_SpecialIntrinsic: {
- SpvId img = this->writeExpression(*c.fArguments[0], out);
- SpvId coords = this->writeExpression(*c.fArguments[1], out);
- this->writeInstruction(SpvOpImageSampleImplicitLod,
- this->getType(c.fType),
- result,
- img,
- coords,
- out);
- break;
- }
case kSubpassLoad_SpecialIntrinsic: {
SpvId img = this->writeExpression(*c.fArguments[0], out);
std::vector<std::unique_ptr<Expression>> args;
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h
index c885ffc3ff..fa7c022100 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.h
+++ b/src/sksl/SkSLSPIRVCodeGenerator.h
@@ -85,8 +85,6 @@ private:
enum SpecialIntrinsic {
kAtan_SpecialIntrinsic,
kTexture_SpecialIntrinsic,
- kTexture2D_SpecialIntrinsic,
- kTextureProj_SpecialIntrinsic,
kSubpassLoad_SpecialIntrinsic,
};
diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h
index a4632061ae..056022bed8 100644
--- a/src/sksl/ir/SkSLType.h
+++ b/src/sksl/ir/SkSLType.h
@@ -213,7 +213,7 @@ public:
return fCoercibleTypes;
}
- int dimensions() const {
+ SpvDim_ dimensions() const {
ASSERT(kSampler_Kind == fTypeKind);
return fDimensions;
}
diff --git a/src/sksl/sksl.include b/src/sksl/sksl.include
index d7b632657e..fc5e40f87d 100644
--- a/src/sksl/sksl.include
+++ b/src/sksl/sksl.include
@@ -301,14 +301,10 @@ $gvec4 subpassLoad(gsubpassInputMS subpass, int sample);
STRINGIFY(
-$gvec4 textureProj($gsampler1D sampler, vec2 P);
-$gvec4 textureProj($gsampler1D sampler, vec2 P, float bias);
-$gvec4 textureProj($gsampler1D sampler, vec4 P);
-$gvec4 textureProj($gsampler1D sampler, vec4 P, float bias);
-$gvec4 textureProj($gsampler2D sampler, vec3 P);
-$gvec4 textureProj($gsampler2D sampler, vec3 P, float bias);
-$gvec4 textureProj($gsampler2D sampler, vec4 P);
-$gvec4 textureProj($gsampler2D sampler, vec4 P, float bias);
+$gvec4 texture($gsampler1D sampler, vec2 P);
+$gvec4 texture($gsampler1D sampler, vec2 P, float bias);
+$gvec4 texture($gsampler2D sampler, vec3 P);
+$gvec4 texture($gsampler2D sampler, vec3 P, float bias);
/*
$gvec4 textureProj($gsampler3D sampler, vec4 P);
$gvec4 textureProj($gsampler3D sampler, vec4 P, float bias);
@@ -482,51 +478,6 @@ $gvec4 textureGatherOffsets($gsampler2DRect sampler, vec2 P, ivec2 offsets[4], i
vec4 textureGatherOffsets(sampler2DShadow sampler, vec2 P, float refZ, ivec2 offsets[4]);
vec4 textureGatherOffsets(sampler2DArrayShadow sampler, vec3 P, float refZ, ivec2 offsets[4]);
vec4 textureGatherOffsets(sampler2DRectShadow sampler, vec2 P, float refZ, ivec2 offsets[4]);
-*/
-vec4 texture1D(sampler1D sampler, float coord);
-vec4 texture1D(sampler1D sampler, float coord, float bias);
-/*
-vec4 texture1DProj(sampler1D sampler, vec2 coord);
-vec4 texture1DProj(sampler1D sampler, vec2 coord, float bias);
-vec4 texture1DProj(sampler1D sampler, vec4 coord);
-vec4 texture1DProj(sampler1D sampler, vec4 coord, float bias);
-vec4 texture1DLod(sampler1D sampler, float coord, float lod);
-vec4 texture1DProjLod(sampler1D sampler, vec2 coord, float lod);
-vec4 texture1DProjLod(sampler1D sampler, vec4 coord, float lod);
-*/
-vec4 texture2D(sampler2D sampler, vec2 coord);
-ivec4 texture2D(isampler2D sampler, vec2 coord);
-vec4 texture2D(samplerExternalOES sampler, vec2 coord);
-vec4 texture2D(sampler2D sampler, vec2 coord, float bias);
-vec4 texture2DProj(sampler2D sampler, vec3 coord);
-/*
-vec4 texture2DProj(sampler2D sampler, vec3 coord, float bias);
-vec4 texture2DProj(sampler2D sampler, vec4 coord);
-vec4 texture2DProj(sampler2D sampler, vec4 coord, float bias);
-vec4 texture2DLod(sampler2D sampler, vec2 coord, float lod);
-vec4 texture2DProjLod(sampler2D sampler, vec3 coord, float lod);
-vec4 texture2DProjLod(sampler2D sampler, vec4 coord, float lod);
-vec4 texture3D(sampler3D sampler, vec3 coord);
-vec4 texture3D(sampler3D sampler, vec3 coord, float bias);
-vec4 texture3DProj(sampler3D sampler, vec4 coord);
-vec4 texture3DProj(sampler3D sampler, vec4 coord, float bias);
-vec4 texture3DLod(sampler3D sampler, vec3 coord, float lod);
-vec4 texture3DProjLod(sampler3D sampler, vec4 coord, float lod);
-vec4 textureCube(samplerCube sampler, vec3 coord);
-vec4 textureCube(samplerCube sampler, vec3 coord, float bias);
-vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod);
-vec4 shadow1D(sampler1DShadow sampler, vec3 coord);
-vec4 shadow1D(sampler1DShadow sampler, vec3 coord, float bias);
-vec4 shadow2D(sampler2DShadow sampler, vec3 coord);
-vec4 shadow2D(sampler2DShadow sampler, vec3 coord, float bias);
-vec4 shadow1DProj(sampler1DShadow sampler, vec4 coord);
-vec4 shadow1DProj(sampler1DShadow sampler, vec4 coord, float bias);
-vec4 shadow2DProj(sampler2DShadow sampler, vec4 coord);
-vec4 shadow2DProj(sampler2DShadow sampler, vec4 coord, float bias);
-vec4 shadow1DLod(sampler1DShadow sampler, vec3 coord, float lod);
-vec4 shadow2DLod(sampler2DShadow sampler, vec3 coord, float lod);
-vec4 shadow1DProjLod(sampler1DShadow sampler, vec4 coord, float lod);
-vec4 shadow2DProjLod(sampler2DShadow sampler, vec4 coord, float lod);
uint atomicCounterIncrement(atomic_uint c);
uint atomicCounter(atomic_uint c);
uint atomicAdd(inout uint mem, uint data);
diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp
index 4a9338113f..52638a5795 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -547,4 +547,46 @@ DEF_TEST(SkSLCaps, r) {
"}\n");
}
+DEF_TEST(SkSLTexture, r) {
+ test(r,
+ "uniform sampler1D one;"
+ "uniform sampler2D two;"
+ "void main() {"
+ "vec4 a = texture(one, 0);"
+ "vec4 b = texture(two, vec2(0));"
+ "vec4 c = texture(one, vec2(0));"
+ "vec4 d = texture(two, vec3(0));"
+ "}",
+ *SkSL::GLSLCapsFactory::Default(),
+ "#version 400\n"
+ "out vec4 sk_FragColor;\n"
+ "uniform sampler1D one;\n"
+ "uniform sampler2D two;\n"
+ "void main() {\n"
+ " vec4 a = texture(one, 0.0);\n"
+ " vec4 b = texture(two, vec2(0.0));\n"
+ " vec4 c = textureProj(one, vec2(0.0));\n"
+ " vec4 d = textureProj(two, vec3(0.0));\n"
+ "}\n");
+ test(r,
+ "uniform sampler1D one;"
+ "uniform sampler2D two;"
+ "void main() {"
+ "vec4 a = texture(one, 0);"
+ "vec4 b = texture(two, vec2(0));"
+ "vec4 c = texture(one, vec2(0));"
+ "vec4 d = texture(two, vec3(0));"
+ "}",
+ *SkSL::GLSLCapsFactory::Version110(),
+ "#version 110\n"
+ "uniform sampler1D one;\n"
+ "uniform sampler2D two;\n"
+ "void main() {\n"
+ " vec4 a = texture1D(one, 0.0);\n"
+ " vec4 b = texture2D(two, vec2(0.0));\n"
+ " vec4 c = texture1DProj(one, vec2(0.0));\n"
+ " vec4 d = texture2DProj(two, vec3(0.0));\n"
+ "}\n");
+}
+
#endif