Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP: initial GLES3.0 stuff from Pyry Haulos

  • Loading branch information...
commit 4f74a729a98b061c7c1638221b23a2c54426f3e0 1 parent a819445
@aras-p authored
View
68 hlslang/GLSLCodeGen/hlslLinker.cpp
@@ -19,6 +19,7 @@ static const char* kTargetVersionStrings[ETargetVersionCount] = {
"", // 1.10
"#version 120\n", // 1.20
"#version 140\n", // 1.40
+ "", // ES 3.0 - #version 300 es is added later in shader build pipe
};
@@ -245,10 +246,39 @@ static const char* resultString[EAttrSemCount] = {
static const char* kUserVaryingPrefix = "xlv_";
-static inline void AddToVaryings (std::stringstream& s, TPrecision prec, const std::string& type, const std::string& name)
+static inline const char* GetVertexInputQualifier (ETargetVersion targetVersion)
+{
+ return targetVersion>=ETargetGLSL_ES_300 ? "in" : "attribute";
+}
+
+static inline const char* GetVertexOutputQualifier (ETargetVersion targetVersion)
+{
+ return targetVersion>=ETargetGLSL_ES_300 ? "out" : "varying";
+}
+
+static inline const char* GetFragmentInputQualifier (ETargetVersion targetVersion)
+{
+ return targetVersion>=ETargetGLSL_ES_300 ? "in" : "varying";
+}
+
+static inline void AddVertexOutput (std::stringstream& s, ETargetVersion targetVersion, TPrecision prec, const std::string& type, const std::string& name)
{
if (strstr (name.c_str(), kUserVaryingPrefix) == name.c_str())
- s << "varying " << getGLSLPrecisiontring(prec) << type << " " << name << ";\n";
+ s << GetVertexOutputQualifier(targetVersion) << " " << getGLSLPrecisiontring(prec) << type << " " << name << ";\n";
+}
+
+static inline void AddFragmentInput (std::stringstream& s, ETargetVersion targetVersion, TPrecision prec, const std::string& type, const std::string& name)
+{
+ if (strstr (name.c_str(), kUserVaryingPrefix) == name.c_str())
+ s << GetFragmentInputQualifier(targetVersion) << " " << getGLSLPrecisiontring(prec) << type << " " << name << ";\n";
+}
+
+static inline void AddToVaryings (std::stringstream& s, EShLanguage language, ETargetVersion targetVersion, TPrecision prec, const std::string& type, const std::string& name)
+{
+ if (language == EShLangVertex)
+ AddVertexOutput(s, targetVersion, prec, type, name);
+ else
+ AddFragmentInput(s, targetVersion, prec, type, name);
}
HlslLinker::HlslLinker(TInfoSink& infoSink_)
@@ -645,13 +675,22 @@ static const char* GetEntryName (const char* entryFunc)
static const char* kShaderTypeNames[2] = { "Vertex", "Fragment" };
-static void add_extension_from_semantic(EAttribSemantic sem, ExtensionSet& extensions)
+static void add_extension_from_semantic(EAttribSemantic sem, ETargetVersion targetVersion, ExtensionSet& extensions)
+{
+ if (targetVersion == ETargetGLSL_ES_300)
+ {
+ // \todo [2013-05-14 pyry] Not supported in any platform yet.
+ if (sem == EAttrSemPrimitiveID)
+ extensions.insert("GL_ARB_geometry_shader4");
+ }
+ else
{
if (sem == EAttrSemPrimitiveID || sem == EAttrSemVertexID)
extensions.insert("GL_EXT_gpu_shader4");
if (sem == EAttrSemInstanceID)
extensions.insert("GL_ARB_draw_instanced");
}
+}
bool HlslLinker::linkerSanityCheck(HlslCrossCompiler* compiler, const char* entryFunc)
@@ -835,7 +874,7 @@ static void emitSymbolWithPad (std::stringstream& str, const std::string& ctor,
}
-static void emitSingleInputVariable (EShLanguage lang, const std::string& name, const std::string& ctor, EGlslSymbolType type, TPrecision prec, std::stringstream& attrib, std::stringstream& varying)
+static void emitSingleInputVariable (EShLanguage lang, ETargetVersion targetVersion, const std::string& name, const std::string& ctor, EGlslSymbolType type, TPrecision prec, std::stringstream& attrib, std::stringstream& varying)
{
// vertex shader: emit custom attributes
if (lang == EShLangVertex && strncmp(name.c_str(), "gl_", 3) != 0)
@@ -851,13 +890,13 @@ static void emitSingleInputVariable (EShLanguage lang, const std::string& name,
if (type >= EgstBool && type <= EgstBool4)
typeOffset += 8;
- attrib << "attribute " << getTypeString((EGlslSymbolType)(type + typeOffset)) << " " << name << ";\n";
+ attrib << GetVertexInputQualifier(targetVersion) << " " << getTypeString((EGlslSymbolType)(type + typeOffset)) << " " << name << ";\n";
}
// fragment shader: emit varying
if (lang == EShLangFragment)
{
- AddToVaryings (varying, prec, ctor, name);
+ AddFragmentInput(varying, targetVersion, prec, ctor, name);
}
}
@@ -898,7 +937,7 @@ void HlslLinker::emitInputNonStructParam(GlslSymbol* sym, EShLanguage lang, bool
preamble << ";\n";
}
- emitSingleInputVariable (lang, name, ctor, sym->getType(), sym->getPrecision(), attrib, varying);
+ emitSingleInputVariable (lang, m_Target, name, ctor, sym->getType(), sym->getPrecision(), attrib, varying);
}
@@ -920,7 +959,7 @@ void HlslLinker::emitInputStructParam(GlslSymbol* sym, EShLanguage lang, std::st
const GlslStruct::StructMember &current = str->getMember(jj);
EAttribSemantic memberSem = parseAttributeSemantic (current.semantic);
- add_extension_from_semantic(memberSem, m_Extensions);
+ add_extension_from_semantic(memberSem, m_Target, m_Extensions);
// if member of the struct is an array, we have to loop over all array elements
int arraySize = 1;
@@ -965,7 +1004,7 @@ void HlslLinker::emitInputStructParam(GlslSymbol* sym, EShLanguage lang, std::st
}
- emitSingleInputVariable (lang, name, ctor, current.type, current.precision, attrib, varying);
+ emitSingleInputVariable (lang, m_Target, name, ctor, current.type, current.precision, attrib, varying);
}
}
}
@@ -1008,7 +1047,7 @@ void HlslLinker::emitOutputNonStructParam(GlslSymbol* sym, EShLanguage lang, boo
// In vertex shader, add to varyings
if (lang == EShLangVertex)
- AddToVaryings (varying, sym->getPrecision(), ctor, name);
+ AddVertexOutput (varying, m_Target, sym->getPrecision(), ctor, name);
call << "xlt_" << sym->getName();
@@ -1058,7 +1097,7 @@ void HlslLinker::emitOutputStructParam(GlslSymbol* sym, EShLanguage lang, bool u
// In vertex shader, add to varyings
if (lang == EShLangVertex)
- AddToVaryings (varying, current.precision, ctor, name);
+ AddVertexOutput (varying, m_Target, current.precision, ctor, name);
}
}
@@ -1163,7 +1202,7 @@ bool HlslLinker::emitReturnStruct(GlslStruct *retStruct, std::string parentName,
// In vertex shader, add to varyings
if (lang == EShLangVertex)
- AddToVaryings (varying, current.precision, ctor, name);
+ AddVertexOutput (varying, m_Target, current.precision, ctor, name);
}
}
}
@@ -1206,8 +1245,7 @@ bool HlslLinker::emitReturnValue(const EGlslSymbolType retType, GlslFunction* fu
// In vertex shader, add to varyings
if (lang == EShLangVertex)
- AddToVaryings (varying, funcMain->getPrecision(), ctor, name);
-
+ AddToVaryings (varying, lang, m_Target, funcMain->getPrecision(), ctor, name);
return true;
}
@@ -1287,7 +1325,7 @@ bool HlslLinker::link(HlslCrossCompiler* compiler, const char* entryFunc, ETarge
GlslSymbol *sym = funcMain->getParameter(ii);
EAttribSemantic attrSem = parseAttributeSemantic( sym->getSemantic());
- add_extension_from_semantic(attrSem, m_Extensions);
+ add_extension_from_semantic(attrSem, m_Target, m_Extensions);
switch (sym->getQualifier())
{
View
188 hlslang/GLSLCodeGen/hlslSupportLib.cpp
@@ -17,7 +17,7 @@ typedef std::map< TOperator, std::pair<std::string,std::string> > CodeExtensionM
static CodeExtensionMap *hlslSupportLibExtensions = 0;
static CodeExtensionMap *hlslSupportLibExtensionsESOverrides = 0;
-void insertPre130TextureLookups()
+void insertPre130TextureLookups()
{
hlslSupportLib->insert( CodeMap::value_type( EOpTex1DBias,
"vec4 xll_tex1Dbias(sampler1D s, vec4 coord) {\n"
@@ -94,40 +94,31 @@ void insertPre130TextureLookups()
);
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,
+ 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,
+ 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")));
- hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTexCubeLod,
- "vec4 xll_texCUBElod(samplerCube s, vec4 coord) {\n"
- " return textureCubeLodEXT( s, coord.xyz, coord.w);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTexCubeLod, std::make_pair("","GL_EXT_shader_texture_lod")));
-
-
hlslSupportLib->insert( CodeMap::value_type( EOpTexCubeGrad,
- "vec4 xll_texCUBEgrad(samplerCube s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
+ "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")));
-
- hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTexCubeGrad,
- "vec4 xll_texCUBEgrad(samplerCube s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
- " return textureCubeGradEXT( s, coord, ddx, ddy);\n"
- "}\n\n" )
- );
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTexCubeGrad, std::make_pair("GL_EXT_shader_texture_lod","GL_EXT_shader_texture_lod")));
+ hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTexCubeLod,
+ "vec4 xll_texCUBElod(samplerCube s, vec4 coord) {\n"
+ " return textureCubeLodEXT( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTexCubeLod, std::make_pair("","GL_EXT_shader_texture_lod")));
// shadow2D / shadow2Dproj
hlslSupportLib->insert(CodeMap::value_type(EOpShadow2D,
@@ -148,7 +139,7 @@ void insertPre130TextureLookups()
}
-void insertPost120TextureLookups()
+void insertPost120TextureLookups()
{
hlslSupportLib->insert( CodeMap::value_type( EOpTex1DBias,
"vec4 xll_tex1Dbias(sampler1D s, vec4 coord) {\n"
@@ -163,13 +154,7 @@ void insertPost120TextureLookups()
);
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 textureGrad( 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 texture( s, coord.xy, coord.w);\n"
@@ -189,20 +174,36 @@ void insertPost120TextureLookups()
"}\n\n" )
);
//hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DLod, std::make_pair("","GL_EXT_shader_texture_lod")));
+ hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DLod, std::make_pair("","GL_ARB_shader_texture_lod")));
- 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"
+ 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(EOpTex2DGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTex1DGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
- hlslSupportLibESOverrides->insert( CodeMap::value_type( EOpTex2DGrad,
+ 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( EOpTex2DGrad,
"vec4 xll_tex2Dgrad(sampler2D s, vec2 coord, vec2 ddx, vec2 ddy) {\n"
" return textureGrad( s, coord, ddx, ddy);\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(EOpTex2DGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
+ //hlslSupportLibExtensions->insert (std::make_pair(EOpTex2DLod, std::make_pair("","GL_ARB_shader_texture_lod")));
+
//hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DGrad, std::make_pair("GL_EXT_shader_texture_lod","GL_EXT_shader_texture_lod")));
+ //hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DLod, std::make_pair("","GL_EXT_shader_texture_lod")));
hlslSupportLib->insert( CodeMap::value_type( EOpTex3DBias,
@@ -210,13 +211,25 @@ void insertPost120TextureLookups()
" return texture( s, coord.xyz, coord.w);\n"
"}\n\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("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
hlslSupportLib->insert( CodeMap::value_type( EOpTex3DLod,
"vec4 xll_tex3Dlod(sampler3D s, vec4 coord) {\n"
" return textureLod( s, coord.xyz, coord.w);\n"
+ "}\n\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" )
);
//hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DLod, std::make_pair("","GL_ARB_shader_texture_lod")));
+ //hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpTex2DGrad, std::make_pair("GL_EXT_shader_texture_lod","GL_EXT_shader_texture_lod")));
hlslSupportLib->insert( CodeMap::value_type( EOpTex3DGrad,
"vec4 xll_tex3Dgrad(sampler3D s, vec3 coord, vec3 ddx, vec3 ddy) {\n"
@@ -225,9 +238,20 @@ void insertPost120TextureLookups()
);
//hlslSupportLibExtensions->insert (std::make_pair(EOpTex3DGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
+ 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( EOpTexCubeBias,
"vec4 xll_texCUBEbias(samplerCube 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" )
);
@@ -244,27 +268,42 @@ void insertPost120TextureLookups()
"}\n\n" )
);
//hlslSupportLibExtensions->insert (std::make_pair(EOpTexCubeGrad, std::make_pair("GL_ARB_shader_texture_lod","GL_ARB_shader_texture_lod")));
+ //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 textureGrad( 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 texture( s, coord.xyz, coord.w);\n"
+ "}\n\n" )
+ );
// shadow2D / shadow2Dproj
hlslSupportLib->insert(CodeMap::value_type(EOpShadow2D,
- "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return texture (s, coord).r; }\n"
+ "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return texture (s, coord); }\n"
));
hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2D,
- "float xll_shadow2D(sampler2DShadow s, vec3 coord) { return texture (s, coord); }\n"
+ "float xll_shadow2D(mediump sampler2DShadow s, vec3 coord) { return texture (s, coord); }\n"
));
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2D, std::make_pair("","GL_EXT_shadow_samplers")));
+ //hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2D, std::make_pair("","GL_EXT_shadow_samplers")));
hlslSupportLib->insert(CodeMap::value_type(EOpShadow2DProj,
- "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return textureProj (s, coord).r; }\n"
+ "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return textureProj (s, coord); }\n"
));
hlslSupportLibESOverrides->insert(CodeMap::value_type(EOpShadow2DProj,
- "float xll_shadow2Dproj(sampler2DShadow s, vec4 coord) { return textureProj (s, coord); }\n"
+ "float xll_shadow2Dproj(mediump sampler2DShadow s, vec4 coord) { return textureProj (s, coord); }\n"
));
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2DProj, std::make_pair("","GL_EXT_shadow_samplers")));
+ //hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpShadow2DProj, std::make_pair("","GL_EXT_shadow_samplers")));
}
-void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
+
+void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
{
assert (hlslSupportLib == 0);
assert (hlslSupportLibExtensions == 0);
@@ -280,7 +319,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
bool usePost120TextureLookups = false;
if(targetVersion!=ETargetVersionCount) //default
{
- usePost120TextureLookups = (targetVersion>ETargetGLSL_120);
+ usePost120TextureLookups = (targetVersion>ETargetGLSL_120);
}
// Initialize GLSL code for the op codes that require support helper functions
@@ -370,7 +409,9 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return mat4( dFdx(m[0]), dFdx(m[1]), dFdx(m[2]), dFdx(m[3]));\n"
"}\n\n")
);
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpDPdx, std::make_pair("","GL_OES_standard_derivatives")));
+
+ if (targetVersion < ETargetGLSL_ES_300)
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpDPdx, std::make_pair("","GL_OES_standard_derivatives")));
hlslSupportLib->insert( CodeMap::value_type( EOpDPdy,
"float xll_dFdy(float f) {\n"
@@ -395,7 +436,9 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return mat4( dFdy(m[0]), dFdy(m[1]), dFdy(m[2]), dFdy(m[3]));\n"
"}\n\n")
);
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpDPdy, std::make_pair("","GL_OES_standard_derivatives")));
+
+ if (targetVersion < ETargetGLSL_ES_300)
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpDPdy, std::make_pair("","GL_OES_standard_derivatives")));
hlslSupportLib->insert( CodeMap::value_type( EOpExp,
"mat2 xll_exp(mat2 m) {\n"
@@ -432,7 +475,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return mat4( log(m[0]), log(m[1]), log(m[2]), log(m[3]));\n"
"}\n\n")
);
-
+
hlslSupportLib->insert( CodeMap::value_type( EOpLog2,
"mat2 xll_log2(mat2 m) {\n"
" return mat2( log2(m[0]), log2(m[1]));\n"
@@ -456,7 +499,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return mat4( tan(m[0]), tan(m[1]), tan(m[2]), tan(m[3]));\n"
"}\n\n")
);
-
+
hlslSupportLib->insert( CodeMap::value_type( EOpAtan,
"mat2 xll_atan(mat2 m) {\n"
" return mat2( atan(m[0]), atan(m[1]));\n"
@@ -588,7 +631,8 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return mat4( fwidth(m[0]), fwidth(m[1]), fwidth(m[2]), fwidth(m[3]));\n"
"}\n\n")
);
- hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpFwidth, std::make_pair("","GL_OES_standard_derivatives")));
+ if (targetVersion < ETargetGLSL_ES_300)
+ hlslSupportLibExtensionsESOverrides->insert (std::make_pair(EOpFwidth, std::make_pair("","GL_OES_standard_derivatives")));
hlslSupportLib->insert( CodeMap::value_type( EOpFclip,
"void xll_clip(float x) {\n"
@@ -668,10 +712,10 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
"vec3 xll_matrixindex (mat3 m, int i) { vec3 v; v.x=m[0][i]; v.y=m[1][i]; v.z=m[2][i]; return v; }\n"
"vec4 xll_matrixindex (mat4 m, int i) { vec4 v; v.x=m[0][i]; v.y=m[1][i]; v.z=m[2][i]; v.w=m[3][i]; return v; }\n")
);
-
- // The GLSL ES implementation on NaCl does not support dynamic indexing
- // (except when the operand is a uniform in vertex shaders). The GLSL specification
- // leaves it open to vendors to support this or not. So, for NaCl we use if statements to
+
+ // The GLSL ES implementation on NaCl does not support dynamic indexing
+ // (except when the operand is a uniform in vertex shaders). The GLSL specification
+ // leaves it open to vendors to support this or not. So, for NaCl we use if statements to
// simulate the indexing.
hlslSupportLib->insert( CodeMap::value_type( EOpMatrixIndexDynamic,
"#if defined(SHADER_API_GLES) && defined(SHADER_API_DESKTOP)\n"
@@ -715,7 +759,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return m[0][0]*m[1][1] - m[0][1]*m[1][0];\n"
"}\n\n"
"float xll_determinant( mat3 m) {\n"
- " vec3 temp;\n"
+ " vec3 temp;\n"
" temp.x = m[1][1]*m[2][2] - m[1][2]*m[2][1];\n"
" temp.y = - (m[0][1]*m[2][2] - m[0][2]*m[2][1]);\n"
" temp.z = m[0][1]*m[1][2] - m[0][2]*m[1][1];\n"
@@ -755,6 +799,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
"}\n\n")
);
+ // \todo [pyry] There is mod() built-in in GLSL
hlslSupportLib->insert( CodeMap::value_type( EOpMod,
"float xll_mod( float x, float y ) {\n"
" float d = x / y;\n"
@@ -779,6 +824,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
)
);
+ // \todo [pyry] GLSL ES 3 includes built-in function for this
hlslSupportLib->insert( CodeMap::value_type( EOpModf,
"float xll_modf( float x, out int ip) {\n"
" ip = int (x);\n"
@@ -818,14 +864,16 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
"}\n\n"
)
);
-
+
+ // \todo [pyry] Built-in function exists in GLSL ES 3
hlslSupportLib->insert (CodeMap::value_type(EOpRound,
"float xll_round (float x) { return floor (x+0.5); }\n"
"vec2 xll_round (vec2 x) { return floor (x+vec2(0.5)); }\n"
"vec3 xll_round (vec3 x) { return floor (x+vec3(0.5)); }\n"
"vec4 xll_round (vec4 x) { return floor (x+vec4(0.5)); }\n"
));
-
+
+ // \todo [pyry] Built-in function exists in GLSL ES 3
hlslSupportLib->insert (CodeMap::value_type(EOpTrunc,
"float xll_trunc (float x) { return x < 0.0 ? -floor(-x) : floor(x); }\n"
"vec2 xll_trunc (vec2 v) { return vec2(\n"
@@ -844,7 +892,8 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" v.w < 0.0 ? -floor(-v.w) : floor(v.w)\n"
"); }\n"
));
-
+
+ // \todo [pyry] Built-in function exists in GLSL ES 3
hlslSupportLib->insert( CodeMap::value_type( EOpLdexp,
"float xll_ldexp( float x, float expon) {\n"
" return x * exp2 ( expon );\n"
@@ -868,7 +917,8 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return x * mat4( exp2 ( expon[0] ), exp2 ( expon[1] ), exp2 ( expon[2] ), exp2 ( expon[3] ) );\n"
"}\n\n" )
);
-
+
+ // \todo [pyry] Built-in function exists in GLSL ES 3
hlslSupportLib->insert( CodeMap::value_type( EOpSinCos,
"void xll_sincos( float x, out float s, out float c) {\n"
" s = sin(x); \n"
@@ -877,29 +927,29 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
"void xll_sincos( vec2 x, out vec2 s, out vec2 c) {\n"
" s = sin(x); \n"
" c = cos(x); \n"
- "}\n\n"
+ "}\n\n"
"void xll_sincos( vec3 x, out vec3 s, out vec3 c) {\n"
" s = sin(x); \n"
" c = cos(x); \n"
- "}\n\n"
+ "}\n\n"
"void xll_sincos( vec4 x, out vec4 s, out vec4 c) {\n"
" s = sin(x); \n"
" c = cos(x); \n"
- "}\n\n"
+ "}\n\n"
"void xll_sincos( mat2 x, out mat2 s, out mat2 c) {\n"
" s = mat2( sin ( x[0] ), sin ( x[1] ) ); \n"
" c = mat2( cos ( x[0] ), cos ( x[1] ) ); \n"
- "}\n\n"
+ "}\n\n"
"void xll_sincos( mat3 x, out mat3 s, out mat3 c) {\n"
" s = mat3( sin ( x[0] ), sin ( x[1] ), sin ( x[2] ) ); \n"
" c = mat3( cos ( x[0] ), cos ( x[1] ), cos ( x[2] ) ); \n"
- "}\n\n"
+ "}\n\n"
"void xll_sincos( mat4 x, out mat4 s, out mat4 c) {\n"
" s = mat4( sin ( x[0] ), sin ( x[1] ), sin ( x[2] ), sin ( x[3] ) ); \n"
" c = mat4( cos ( x[0] ), cos ( x[1] ), cos ( x[2] ), cos ( x[3] ) ); \n"
"}\n\n" )
);
-
+
hlslSupportLib->insert( CodeMap::value_type( EOpLog10,
"float xll_log10( float x ) {\n"
" return log2 ( x ) / 3.32192809; \n"
@@ -923,7 +973,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return mat4( xll_log10(m[0]), xll_log10(m[1]), xll_log10(m[2]), xll_log10(m[3]));\n"
"}\n\n")
);
-
+
hlslSupportLib->insert( CodeMap::value_type( EOpMix,
"mat2 xll_mix( mat2 x, mat2 y, mat2 s ) {\n"
" return mat2( mix(x[0],y[0],s[0]), mix(x[1],y[1],s[1]) ); \n"
@@ -933,7 +983,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
"}\n\n"
"mat4 xll_mix( mat4 x, mat4 y, mat4 s ) {\n"
" return mat4( mix(x[0],y[0],s[0]), mix(x[1],y[1],s[1]), mix(x[2],y[2],s[2]), mix(x[3],y[3],s[3]) ); \n"
- "}\n\n")
+ "}\n\n")
);
hlslSupportLib->insert( CodeMap::value_type( EOpLit,
@@ -977,7 +1027,7 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return mat4( step(m[0],y[0]), step(m[1],y[1]), step(m[2],y[2]), step(m[3],y[3]));\n"
"}\n\n")
);
-
+
//ACS: if we're post-1.20 use the newer, non-deprecated, texture lookups
if(usePost120TextureLookups) {
insertPost120TextureLookups();
@@ -986,13 +1036,13 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
insertPre130TextureLookups();
}
- hlslSupportLib->insert( CodeMap::value_type( EOpD3DCOLORtoUBYTE4,
+ hlslSupportLib->insert( CodeMap::value_type( EOpD3DCOLORtoUBYTE4,
"ivec4 xll_D3DCOLORtoUBYTE4(vec4 x) {\n"
" return ivec4 ( x.zyxw * 255.001953 );\n"
"}\n\n" )
);
-
- hlslSupportLib->insert( CodeMap::value_type( EOpVecTernarySel,
+
+ hlslSupportLib->insert( CodeMap::value_type( EOpVecTernarySel,
"vec2 xll_vecTSel (bvec2 a, vec2 b, vec2 c) {\n"
" return vec2 (a.x ? b.x : c.x, a.y ? b.y : c.y);\n"
"}\n"
@@ -1003,11 +1053,11 @@ void initializeHLSLSupportLibrary(ETargetVersion targetVersion)
" return vec4 (a.x ? b.x : c.x, a.y ? b.y : c.y, a.z ? b.z : c.z, a.w ? b.w : c.w);\n"
"}\n\n"
)
- );
+ );
}
-void finalizeHLSLSupportLibrary()
+void finalizeHLSLSupportLibrary()
{
delete hlslSupportLib;
hlslSupportLib = 0;
@@ -1048,7 +1098,7 @@ std::string getHLSLSupportCode (TOperator op, ExtensionSet& extensions, bool ver
extensions.insert(ext);
}
}
-
+
assert (hlslSupportLib);
assert (hlslSupportLibESOverrides);
View
11 hlslang/MachineIndependent/HLSL2GLSL.cpp
@@ -230,7 +230,7 @@ static bool GenerateBuiltInSymbolTable(TInfoSink& infoSink, TSymbolTable* symbol
}
-
+// \todo [2013-05-14 pyry] Remove fixed target version.
int C_DECL Hlsl2Glsl_Initialize(ETargetVersion fixedTargetVersion /*= ETargetVersionCount*/)
{
TInfoSink infoSink;
@@ -262,8 +262,6 @@ int C_DECL Hlsl2Glsl_Initialize(ETargetVersion fixedTargetVersion /*= ETargetVer
symTables[EShLangVertex].pop();
symTables[EShLangFragment].pop();
- initializeHLSLSupportLibrary(FixedTargetVersion);
-
builtInPoolAllocator->popAll();
delete builtInPoolAllocator;
@@ -285,7 +283,6 @@ void C_DECL Hlsl2Glsl_Shutdown()
PerProcessGPA->popAll();
delete PerProcessGPA;
PerProcessGPA = NULL;
- finalizeHLSLSupportLibrary();
}
DetachThread();
@@ -424,6 +421,9 @@ int C_DECL Hlsl2Glsl_Translate(
}
}
+ // \todo [2013-05-14 pyry] Maintain different support library per target version.
+ initializeHLSLSupportLibrary(targetVersion);
+
if (!compiler->IsASTTransformed() || !compiler->IsGlslProduced())
{
compiler->infoSink.info.message(EPrefixError, "Shader does not have valid object code.");
@@ -432,6 +432,8 @@ int C_DECL Hlsl2Glsl_Translate(
bool ret = compiler->GetLinker()->link(compiler, entry, targetVersion, options);
+ finalizeHLSLSupportLibrary();
+
return ret ? 1 : 0;
}
@@ -515,6 +517,7 @@ static bool kVersionUsesPrecision[ETargetVersionCount] = {
false, // 1.10
false, // 1.20
false, // 1.40
+ true, // ES 3.0
};
bool C_DECL Hlsl2Glsl_VersionUsesPrecision (ETargetVersion version)
View
3  hlslang/MachineIndependent/hlslang.y
@@ -30,6 +30,7 @@ Jutta Degener, 1995
#define YYPARSE_PARAM_DECL TParseContext&
#define YY_DECL int yylex(YYSTYPE* pyylval, TParseContext& parseContext)
#define YYLEX_PARAM parseContext
+ void yyerror(const char*);
#else
#define YYPARSE_PARAM parseContextLocal
#define parseContext (*((TParseContext*)(parseContextLocal)))
@@ -1841,7 +1842,7 @@ type_specifier_nonarray
SET_BASIC_TYPE($$,$1,EbtSampler1DShadow,EbpUndefined);
}
| SAMPLER2DSHADOW {
- SET_BASIC_TYPE($$,$1,EbtSampler2DShadow,EbpUndefined);
+ SET_BASIC_TYPE($$,$1,EbtSampler2DShadow,EbpMedium);
}
| struct_specifier {
$$ = $1;
View
5 include/hlsl2glsl.h 100755 → 100644
@@ -10,6 +10,7 @@
#define SH_IMPORT_EXPORT
#else
#define SH_IMPORT_EXPORT
+ #define __fastcall
#define C_DECL
#endif
@@ -156,8 +157,8 @@ enum ETargetVersion
ETargetGLSL_ES_100,
ETargetGLSL_110,
ETargetGLSL_120,
- ETargetGLSL_140,
- // ETargetGLSL_ES_300,
+ ETargetGLSL_140,
+ ETargetGLSL_ES_300,
// ETargetGLSL_330,
ETargetVersionCount
};
View
2  tools/bison.simple
@@ -36,7 +36,7 @@ char *alloca ();
#endif /* not HAVE_ALLOCA_H */
#endif /* not __GNUC__ */
-extern void yyerror(const char* s);
+extern void yyerror(char* s);
#ifndef alloca
#ifdef __GNUC__
Please sign in to comment.
Something went wrong with that request. Please try again.