Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ETargetGLSL_140 and make it produce post 1.20 style texture lookups.

e.g. texture() and textureProj() instead of texture2D() and texture2DProj().
To do this I now (optionally) pass the ETargetVersion to Hlsl2Glsl_Initialize so it can choose what style of texture lookup functions initializeHLSLSupportLibrary() inserts into hlslSupportLib.
This means once initialized, every call to Hlsl2Glsl_Translate() has to use the matching ETargetVersion.
  • Loading branch information...
commit 0d9fd2fb87fa29a37246f33b2ff16300ab488dab 1 parent 13e0aeb
@anchsm anchsm authored
View
25 hlslang/GLSLCodeGen/glslOutput.cpp
@@ -12,6 +12,15 @@
#define snprintf _snprintf
#endif
+//ACS: some texture lookup types were deprecated after 1.20, and 1.40 won't accept them
+bool UsePost120TextureLookups(ETargetVersion targetVersion) {
+ if(targetVersion<ETargetVersionCount) {
+ return (targetVersion>ETargetGLSL_120);
+ }
+ else {
+ return false;
+ }
+}
void print_float (std::stringstream& out, float f)
{
@@ -296,6 +305,7 @@ void writeTex( const TString &name, TIntermAggregate *node, TGlslOutputTraverser
TBasicType sampler_type = (*nodes.begin())->getAsTyped()->getBasicType();
TString new_name;
+ //ACS: do we need to change these for 1.40? 1.20-style texture lookups should just not show up at all, right?
if (isShadowSampler(sampler_type)) {
if (name == "texture2D")
new_name = "shadow2D";
@@ -1346,6 +1356,7 @@ bool TGlslOutputTraverser::traverseAggregate( bool preVisit, TIntermAggregate *n
GlslFunction *current = goit->current;
std::stringstream& out = current->getActiveOutput();
int argCount = (int) node->getNodes().size();
+ bool usePost120TextureLookups = UsePost120TextureLookups(goit->m_TargetVersion);
if (node->getOp() == EOpNull)
{
@@ -1549,7 +1560,13 @@ bool TGlslOutputTraverser::traverseAggregate( bool preVisit, TIntermAggregate *n
case EOpTex2D:
if (argCount == 2)
- writeTex( "texture2D", node, goit);
+ {
+ if(usePost120TextureLookups) {
+ writeTex( "texture", node, goit);
+ } else {
+ writeTex( "texture2D", node, goit);
+ }
+ }
else
{
current->addLibFunction(EOpTex2DGrad);
@@ -1558,7 +1575,11 @@ bool TGlslOutputTraverser::traverseAggregate( bool preVisit, TIntermAggregate *n
return false;
case EOpTex2DProj:
- writeTex( "texture2DProj", node, goit);
+ if(usePost120TextureLookups) {
+ writeTex( "textureProj", node, goit);
+ } else {
+ writeTex( "texture2DProj", node, goit);
+ }
return false;
case EOpTex2DLod:
View
1  hlslang/GLSLCodeGen/hlslLinker.cpp
@@ -18,6 +18,7 @@ static const char* kTargetVersionStrings[ETargetVersionCount] = {
"", // ES 1.00
"", // 1.10
"#version 120\n", // 1.20
+ "#version 140\n", // 1.40
};
View
375 hlslang/GLSLCodeGen/hlslSupportLib.cpp
@@ -17,18 +17,256 @@ typedef std::map< TOperator, std::pair<std::string,std::string> > CodeExtensionM
static CodeExtensionMap *hlslSupportLibExtensions = 0;
static CodeExtensionMap *hlslSupportLibExtensionsESOverrides = 0;
+void insertPre130TextureLookups()
+{
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex1DBias,
+ "vec4 xll_tex1Dbias(sampler1D s, vec4 coord) {\n"
+ " return texture1D( s, coord.x, coord.w);\n"
+ "}\n\n" )
+ );
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex1DLod,
+ "vec4 xll_tex1Dlod(sampler1D s, vec4 coord) {\n"
+ " return texture1DLod( s, coord.x, coord.w);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex1DGrad,
+ "vec4 xll_tex1Dgrad(sampler1D s, float coord, float ddx, float ddy) {\n"
+ " return texture1DGradARB( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex2DBias,
+ "vec4 xll_tex2Dbias(sampler2D s, vec4 coord) {\n"
+ " return texture2D( s, coord.xy, coord.w);\n"
+ "}\n\n" )
+ );
-void initializeHLSLSupportLibrary()
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex2DLod,
+ "vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {\n"
+ " return texture2DLod( s, coord.xy, coord.w);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex2DLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTex2DLod,
+ "vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {\n"
+ " return texture2DLodEXT( s, coord.xy, coord.w);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DLod, std::make_pair("","#extension GL_EXT_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex2DGrad,
+ "vec4 xll_tex2Dgrad(sampler2D s, vec2 coord, vec2 ddx, vec2 ddy) {\n"
+ " return texture2DGradARB( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex2DGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTex2DGrad,
+ "vec4 xll_tex2Dgrad(sampler2D s, vec2 coord, vec2 ddx, vec2 ddy) {\n"
+ " return texture2DGradEXT( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DGrad, std::make_pair("#extension GL_EXT_shader_texture_lod : require\n","#extension GL_EXT_shader_texture_lod : require\n")));
+
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex3DBias,
+ "vec4 xll_tex3Dbias(sampler3D s, vec4 coord) {\n"
+ " return texture3D( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex3DLod,
+ "vec4 xll_tex3Dlod(sampler3D s, vec4 coord) {\n"
+ " return texture3DLod( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex3DGrad,
+ "vec4 xll_tex3Dgrad(sampler3D s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
+ " return texture3DGradARB( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeBias,
+ "vec4 xll_texCUBEbias(samplerCube s, vec4 coord) {\n"
+ " return textureCube( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeLod,
+ "vec4 xll_texCUBElod(samplerCube s, vec4 coord) {\n"
+ " return textureCubeLod( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTexCubeLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeGrad,
+ "vec4 xll_texCUBEgrad(samplerCUBE s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
+ " return textureCubeGradARB( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTexCubeGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ // shadow2D / shadow2Dproj
+ hlslSupportLib->insert(CodeMap::value_type(EOpShadow2D,
+ "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return shadow2D (s, coord).r; }\n"
+ ));
+ hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2D,
+ "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return shadow2DEXT (s, coord); }\n"
+ ));
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2D, std::make_pair("","#extension GL_EXT_shadow_samplers : require\n")));
+
+ hlslSupportLib->insert(CodeMap::value_type(EOpShadow2DProj,
+ "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return shadow2DProj (s, coord).r; }\n"
+ ));
+ hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2DProj,
+ "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return shadow2DProjEXT (s, coord); }\n"
+ ));
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2DProj, std::make_pair("","#extension GL_EXT_shadow_samplers : require\n")));
+
+}
+
+void insertPost120TextureLookups()
{
- assert (hlslSupportLib == 0);
- assert (hlslSupportLibExtensions == 0);
- assert (hlslSupportLibESOverrides == 0);
- assert (hlslSupportLibExtensionsESOverrides == 0);
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex1DBias,
+ "vec4 xll_tex1Dbias(sampler1D s, vec4 coord) {\n"
+ " return texture( s, coord.x, coord.w);\n"
+ "}\n\n" )
+ );
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex1DLod,
+ "vec4 xll_tex1Dlod(sampler1D s, vec4 coord) {\n"
+ " return textureLod( s, coord.x, coord.w);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
- hlslSupportLib = new CodeMap();
- hlslSupportLibExtensions = new CodeExtensionMap();
- hlslSupportLibESOverrides = new CodeMap();
- hlslSupportLibExtensionsESOverrides = new CodeExtensionMap();
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex1DGrad,
+ "vec4 xll_tex1Dgrad(sampler1D s, float coord, float ddx, float ddy) {\n"
+ " return textureGrad( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex2DBias,
+ "vec4 xll_tex2Dbias(sampler2D s, vec4 coord) {\n"
+ " return texture( s, coord.xy, coord.w);\n"
+ "}\n\n" )
+ );
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex2DLod,
+ "vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {\n"
+ " return textureLod( s, coord.xy, coord.w);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTex2DLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTex2DLod,
+ "vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {\n"
+ " return textureLod( s, coord.xy, coord.w);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DLod, std::make_pair("","#extension GL_EXT_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex2DGrad,
+ "vec4 xll_tex2Dgrad(sampler2D s, vec2 coord, vec2 ddx, vec2 ddy) {\n"
+ " return textureGrad( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTex2DGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTex2DGrad,
+ "vec4 xll_tex2Dgrad(sampler2D s, vec2 coord, vec2 ddx, vec2 ddy) {\n"
+ " return textureGrad( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DGrad, std::make_pair("#extension GL_EXT_shader_texture_lod : require\n","#extension GL_EXT_shader_texture_lod : require\n")));
+
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex3DBias,
+ "vec4 xll_tex3Dbias(sampler3D s, vec4 coord) {\n"
+ " return texture( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex3DLod,
+ "vec4 xll_tex3Dlod(sampler3D s, vec4 coord) {\n"
+ " return textureLod( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTex3DGrad,
+ "vec4 xll_tex3Dgrad(sampler3D s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
+ " return textureGrad( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeBias,
+ "vec4 xll_texCUBEbias(samplerCube s, vec4 coord) {\n"
+ " return texture( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeLod,
+ "vec4 xll_texCUBElod(samplerCube s, vec4 coord) {\n"
+ " return textureLod( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTexCubeLod, std::make_pair("","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeGrad,
+ "vec4 xll_texCUBEgrad(samplerCUBE s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
+ " return textureGrad( s, coord, ddx, ddy);\n"
+ "}\n\n" )
+ );
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTexCubeGrad, std::make_pair("#extension GL_ARB_shader_texture_lod : require\n","#extension GL_ARB_shader_texture_lod : require\n")));
+
+ // shadow2D / shadow2Dproj
+ hlslSupportLib->insert(CodeMap::value_type(EOpShadow2D,
+ "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return texture (s, coord).r; }\n"
+ ));
+ hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2D,
+ "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return texture (s, coord); }\n"
+ ));
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2D, std::make_pair("","#extension GL_EXT_shadow_samplers : require\n")));
+
+ hlslSupportLib->insert(CodeMap::value_type(EOpShadow2DProj,
+ "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return textureProj (s, coord).r; }\n"
+ ));
+ hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2DProj,
+ "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return textureProj (s, coord); }\n"
+ ));
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2DProj, std::make_pair("","#extension GL_EXT_shadow_samplers : require\n")));
+
+}
+
+void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
+{
+ assert (hlslSupportLib == 0);
+ assert (hlslSupportLibExtensions == 0);
+ assert (hlslSupportLibESOverrides == 0);
+ assert (hlslSupportLibExtensionsESOverrides == 0);
+
+ hlslSupportLib = new CodeMap();
+ hlslSupportLibExtensions = new CodeExtensionMap();
+ hlslSupportLibESOverrides = new CodeMap();
+ hlslSupportLibExtensionsESOverrides = new CodeExtensionMap();
+
+ //ACS: some texture lookup types were deprecated after 1.20, and 1.40 won't accept them
+ bool usePost120TextureLookups = false;
+ if(targetVersion!=ETargetVersionCount) //default
+ {
+ usePost120TextureLookups = (targetVersion>ETargetGLSL_120);
+ }
// Initialize GLSL code for the op codes that require support helper functions
@@ -725,118 +963,13 @@ void initializeHLSLSupportLibrary()
"}\n\n")
);
- hlslSupportLib->insert( CodeMap::value_type( EOpTex1DBias,
- "vec4 xll_tex1Dbias(sampler1D s, vec4 coord) {\n"
- " return texture1D( s, coord.x, coord.w);\n"
- "}\n\n" )
- );
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex1DLod,
- "vec4 xll_tex1Dlod(sampler1D s, vec4 coord) {\n"
- " return texture1DLod( s, coord.x, coord.w);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DLod, std::make_pair("","GL_ARB_shader_texture_lod")));
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex1DGrad,
- "vec4 xll_tex1Dgrad(sampler1D s, float coord, float ddx, float ddy) {\n"
- " return texture1DGradARB( s, coord, ddx, ddy);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex2DBias,
- "vec4 xll_tex2Dbias(sampler2D s, vec4 coord) {\n"
- " return texture2D( s, coord.xy, coord.w);\n"
- "}\n\n" )
- );
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex2DLod,
- "vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {\n"
- " return texture2DLod( s, coord.xy, coord.w);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTex2DLod, std::make_pair("","GL_ARB_shader_texture_lod")));
-
- hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTex2DLod,
- "vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {\n"
- " return texture2DLodEXT( s, coord.xy, coord.w);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DLod, std::make_pair("","GL_EXT_shader_texture_lod")));
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex2DGrad,
- "vec4 xll_tex2Dgrad(sampler2D s, vec2 coord, vec2 ddx, vec2 ddy) {\n"
- " return texture2DGradARB( s, coord, ddx, ddy);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTex2DGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
-
- hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTex2DGrad,
- "vec4 xll_tex2Dgrad(sampler2D s, vec2 coord, vec2 ddx, vec2 ddy) {\n"
- " return texture2DGradEXT( s, coord, ddx, ddy);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DGrad, std::make_pair("GL_EXT_shader_texture_lod","GL_EXT_shader_texture_lod")));
-
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex3DBias,
- "vec4 xll_tex3Dbias(sampler3D s, vec4 coord) {\n"
- " return texture3D( s, coord.xyz, coord.w);\n"
- "}\n\n" )
- );
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex3DLod,
- "vec4 xll_tex3Dlod(sampler3D s, vec4 coord) {\n"
- " return texture3DLod( s, coord.xyz, coord.w);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DLod, std::make_pair("","GL_ARB_shader_texture_lod")));
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTex3DGrad,
- "vec4 xll_tex3Dgrad(sampler3D s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
- " return texture3DGradARB( s, coord, ddx, ddy);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeBias,
- "vec4 xll_texCUBEbias(samplerCube s, vec4 coord) {\n"
- " return textureCube( s, coord.xyz, coord.w);\n"
- "}\n\n" )
- );
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeLod,
- "vec4 xll_texCUBElod(samplerCube s, vec4 coord) {\n"
- " return textureCubeLod( s, coord.xyz, coord.w);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTexCubeLod, std::make_pair("","GL_ARB_shader_texture_lod")));
-
- hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeGrad,
- "vec4 xll_texCUBEgrad(samplerCUBE s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
- " return textureCubeGradARB( s, coord, ddx, ddy);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensions->insert (std::make_pair(EOpTexCubeGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
-
- // shadow2D / shadow2Dproj
- hlslSupportLib->insert(CodeMap::value_type(EOpShadow2D,
- "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return shadow2D (s, coord).r; }\n"
- ));
- hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2D,
- "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return shadow2DEXT (s, coord); }\n"
- ));
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2D, std::make_pair("GL_EXT_shadow_samplers","GL_EXT_shadow_samplers")));
-
- hlslSupportLib->insert(CodeMap::value_type(EOpShadow2DProj,
- "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return shadow2DProj (s, coord).r; }\n"
- ));
- hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2DProj,
- "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return shadow2DProjEXT (s, coord); }\n"
- ));
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2DProj, std::make_pair("GL_EXT_shadow_samplers","GL_EXT_shadow_samplers")));
-
+ //ACS: if we're post-1.20 use the newer, non-deprecated, texture lookups
+ if(usePost120TextureLookups) {
+ insertPost120TextureLookups();
+ }
+ else {
+ insertPre130TextureLookups();
+ }
hlslSupportLib->insert( CodeMap::value_type( EOpD3DCOLORtoUBYTE4,
"ivec4 xll_D3DCOLORtoUBYTE4(vec4 x) {\n"
View
3  hlslang/GLSLCodeGen/hlslSupportLib.h
@@ -9,8 +9,9 @@
#include <set>
#include <string>
#include "../Include/intermediate.h"
+#include "../../include/hlsl2glsl.h" // for ETargetVersion
-void initializeHLSLSupportLibrary();
+void initializeHLSLSupportLibrary(ETargetVersion targetVersion);
void finalizeHLSLSupportLibrary();
typedef std::set<std::string> ExtensionSet;
View
23 hlslang/MachineIndependent/HLSL2GLSL.cpp
@@ -25,6 +25,12 @@ TSymbolTable SymbolTables[EShLangCount];
// Global pool allocator (per process)
TPoolAllocator* PerProcessGPA = 0;
+///ACS: added fixedTargetVersion
+/// * If left as default (ETargetVersionCount) Hlsl2Glsl operates as normal
+/// * If set, only Hlsl2Glsl_Translate calls of matching target will work, and
+/// when set to higher than ETargetGLSL_120, will emit non-deprecated-after-120
+/// texture lookup calls e.g. texture() & textureLod() instead of texture2D() & textureCubeLod()
+ETargetVersion FixedTargetVersion = ETargetVersionCount;
/// Initializize the symbol table
/// \param BuiltInStrings
@@ -133,7 +139,8 @@ static bool GenerateBuiltInSymbolTable(TInfoSink& infoSink, TSymbolTable* symbol
-int C_DECL Hlsl2Glsl_Initialize(GlobalAllocateFunction alloc, GlobalFreeFunction free, void* user)
+int C_DECL Hlsl2Glsl_Initialize(GlobalAllocateFunction alloc, GlobalFreeFunction free, void* user,
+ ETargetVersion fixedTargetVersion /*= ETargetVersionCount*/)
{
TInfoSink infoSink;
bool ret = true;
@@ -143,6 +150,8 @@ int C_DECL Hlsl2Glsl_Initialize(GlobalAllocateFunction alloc, GlobalFreeFunction
if (!InitProcess())
return 0;
+ FixedTargetVersion = fixedTargetVersion;
+
// This method should be called once per process. If its called by multiple threads, then
// we need to have thread synchronization code around the initialization of per process
// global pool allocator
@@ -168,7 +177,7 @@ int C_DECL Hlsl2Glsl_Initialize(GlobalAllocateFunction alloc, GlobalFreeFunction
symTables[EShLangVertex].pop();
symTables[EShLangFragment].pop();
- initializeHLSLSupportLibrary();
+ initializeHLSLSupportLibrary(FixedTargetVersion);
builtInPoolAllocator->popAll();
delete builtInPoolAllocator;
@@ -316,6 +325,15 @@ int C_DECL Hlsl2Glsl_Translate(
HlslCrossCompiler* compiler = handle;
compiler->infoSink.info.erase();
+
+ //ACS: added FixedTargetVersion
+ if (FixedTargetVersion!=ETargetVersionCount) {
+ if(targetVersion!=FixedTargetVersion) {
+ compiler->infoSink.info.message(EPrefixError, "Hlsl2Glsl was initialized with fixed target. Requested target does not match.");
+ return 0;
+ }
+ }
+
if (!compiler->IsASTTransformed() || !compiler->IsGlslProduced())
{
compiler->infoSink.info.message(EPrefixError, "Shader does not have valid object code.");
@@ -406,6 +424,7 @@ static bool kVersionUsesPrecision[ETargetVersionCount] = {
true, // ES 1.00
false, // 1.10
false, // 1.20
+ false, // 1.40
};
bool C_DECL Hlsl2Glsl_VersionUsesPrecision (ETargetVersion version)
View
11 include/hlsl2glsl.h
@@ -157,6 +157,7 @@ enum ETargetVersion
ETargetGLSL_ES_100,
ETargetGLSL_110,
ETargetGLSL_120,
+ ETargetGLSL_140,
// ETargetGLSL_ES_300,
// ETargetGLSL_330,
ETargetVersionCount
@@ -207,8 +208,14 @@ typedef void(*GlobalFreeFunction)(void*, void*);
/// HLSL2GLSL translator functions
/// \return
/// 1 on success, 0 on failure
-SH_IMPORT_EXPORT int C_DECL Hlsl2Glsl_Initialize(GlobalAllocateFunction alloc, GlobalFreeFunction free, void* user);
-
+///
+///ACS: added fixedTargetVersion
+/// * If left as default (ETargetVersionCount) Hlsl2Glsl operates as normal
+/// * If set, only Hlsl2Glsl_Translate calls of matching target will work, and
+/// when set to higher than ETargetGLSL_120, will emit non-deprecated-after-120
+/// texture lookup calls e.g. texture() & textureLod() instead of texture2D() & textureCubeLod()
+SH_IMPORT_EXPORT int C_DECL Hlsl2Glsl_Initialize(GlobalAllocateFunction alloc, GlobalFreeFunction free, void* user,
+ ETargetVersion fixedTargetVersion = ETargetVersionCount);
/// Finalize the HLSL2GLSL translator. This function should be called to de-initialize the HLSL2GLSL
/// translator and should only be called once on shutdown.
Please sign in to comment.
Something went wrong with that request. Please try again.