OSDN Git Service

Implement basic GLSL ES 3.0 texture sampling.
authorNicolas Capens <capn@google.com>
Wed, 18 Feb 2015 22:53:39 +0000 (17:53 -0500)
committerNicolas Capens <capn@google.com>
Tue, 24 Feb 2015 20:38:46 +0000 (20:38 +0000)
Bug 19331817

Change-Id: Ieb4581c62525112e0b76e94bcbbb8f9608c782ea
Reviewed-on: https://swiftshader-review.googlesource.com/2371
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
src/OpenGL/compiler/Initialize.cpp
src/OpenGL/compiler/OutputASM.cpp

index 9ddd374..7416fda 100644 (file)
@@ -379,6 +379,39 @@ void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TS
                symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3DLod", sampler3D, float3, float1);
        }
 
+    TType *gvec4 = new TType(EbtGVec4);
+
+    TType *gsampler2D = new TType(EbtGSampler2D);
+    TType *gsamplerCube = new TType(EbtGSamplerCube);
+    TType *gsampler3D = new TType(EbtGSampler3D);
+    TType *gsampler2DArray = new TType(EbtGSampler2DArray);
+
+    //
+    // Texture Functions for GLSL ES 3.0
+    //
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
+    symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
+
+    if(type == GL_FRAGMENT_SHADER)
+    {
+        symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
+        symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
+        symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
+        symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
+        symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
+        symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
+        symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
+    }
+
     //
     // Depth range in window coordinates
     //
index 726401f..d675e8d 100644 (file)
@@ -768,10 +768,10 @@ namespace glsl
                                {\r
                                        TString name = TFunction::unmangleName(node->getName());\r
 \r
-                                       if(name == "texture2D" || name == "textureCube" || name == "texture3D")\r
+                                       if(name == "texture" || name == "texture2D" || name == "textureCube" || name == "texture3D")\r
                                        {\r
                                                if(argumentCount == 2)\r
-                                               {       \r
+                                               {\r
                                                        emit(sw::Shader::OPCODE_TEX, result, arg[1], arg[0]);\r
                                                }\r
                                                else if(argumentCount == 3)   // bias\r