diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2016-11-28 12:03:26 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-28 17:53:44 +0000 |
commit | 2b3dab62bccdbf6244aef9103e9e739147af8616 (patch) | |
tree | 989120c1cd65a242045a07ff2e1b4f3b6c9ef521 /src | |
parent | 343b6772b6cf4715ec1e1f7f604289c0c852a2a7 (diff) |
removed textureProj() and legacy texture functions from sksl
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5120
Change-Id: I21b111d54becaca845134376e54a5a7c0a6cd6c8
Reviewed-on: https://skia-review.googlesource.com/5120
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 28 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSL.h | 25 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLShaderBuilder.cpp | 13 | ||||
-rw-r--r-- | src/sksl/README | 2 | ||||
-rw-r--r-- | src/sksl/SkSLContext.h | 5 | ||||
-rw-r--r-- | src/sksl/SkSLGLSLCodeGenerator.cpp | 63 | ||||
-rw-r--r-- | src/sksl/SkSLSPIRVCodeGenerator.cpp | 59 | ||||
-rw-r--r-- | src/sksl/SkSLSPIRVCodeGenerator.h | 2 | ||||
-rw-r--r-- | src/sksl/ir/SkSLType.h | 2 | ||||
-rw-r--r-- | src/sksl/sksl.include | 57 |
10 files changed, 117 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); |