Commit 334d615f by Jamie Madill

Fix up the style in DynamicHLSL a bit.

Use std::stringstream when possible, and use Context's caps instead of the Renderer's. BUG=angleproject:754 Change-Id: I2dc773709bbd612ab7ea372a358337c0a81869a3 Reviewed-on: https://chromium-review.googlesource.com/307872Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b2e2425a
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
#include "libANGLE/renderer/d3d/ShaderD3D.h" #include "libANGLE/renderer/d3d/ShaderD3D.h"
// For use with ArrayString, see angleutils.h // For use with ArrayString, see angleutils.h
static_assert(GL_INVALID_INDEX == UINT_MAX, "GL_INVALID_INDEX must be equal to the max unsigned int."); static_assert(GL_INVALID_INDEX == UINT_MAX,
"GL_INVALID_INDEX must be equal to the max unsigned int.");
using namespace gl; using namespace gl;
...@@ -31,12 +32,17 @@ std::string HLSLComponentTypeString(GLenum componentType) ...@@ -31,12 +32,17 @@ std::string HLSLComponentTypeString(GLenum componentType)
{ {
switch (componentType) switch (componentType)
{ {
case GL_UNSIGNED_INT: return "uint"; case GL_UNSIGNED_INT:
case GL_INT: return "int"; return "uint";
case GL_INT:
return "int";
case GL_UNSIGNED_NORMALIZED: case GL_UNSIGNED_NORMALIZED:
case GL_SIGNED_NORMALIZED: case GL_SIGNED_NORMALIZED:
case GL_FLOAT: return "float"; case GL_FLOAT:
default: UNREACHABLE(); return "not-component-type"; return "float";
default:
UNREACHABLE();
return "not-component-type";
} }
} }
...@@ -49,16 +55,27 @@ std::string HLSLMatrixTypeString(GLenum type) ...@@ -49,16 +55,27 @@ std::string HLSLMatrixTypeString(GLenum type)
{ {
switch (type) switch (type)
{ {
case GL_FLOAT_MAT2: return "float2x2"; case GL_FLOAT_MAT2:
case GL_FLOAT_MAT3: return "float3x3"; return "float2x2";
case GL_FLOAT_MAT4: return "float4x4"; case GL_FLOAT_MAT3:
case GL_FLOAT_MAT2x3: return "float2x3"; return "float3x3";
case GL_FLOAT_MAT3x2: return "float3x2"; case GL_FLOAT_MAT4:
case GL_FLOAT_MAT2x4: return "float2x4"; return "float4x4";
case GL_FLOAT_MAT4x2: return "float4x2"; case GL_FLOAT_MAT2x3:
case GL_FLOAT_MAT3x4: return "float3x4"; return "float2x3";
case GL_FLOAT_MAT4x3: return "float4x3"; case GL_FLOAT_MAT3x2:
default: UNREACHABLE(); return "not-matrix-type"; return "float3x2";
case GL_FLOAT_MAT2x4:
return "float2x4";
case GL_FLOAT_MAT4x2:
return "float4x2";
case GL_FLOAT_MAT3x4:
return "float3x4";
case GL_FLOAT_MAT4x3:
return "float4x3";
default:
UNREACHABLE();
return "not-matrix-type";
} }
} }
...@@ -69,10 +86,12 @@ std::string HLSLTypeString(GLenum type) ...@@ -69,10 +86,12 @@ std::string HLSLTypeString(GLenum type)
return HLSLMatrixTypeString(type); return HLSLMatrixTypeString(type);
} }
return HLSLComponentTypeString(gl::VariableComponentType(type), gl::VariableComponentCount(type)); return HLSLComponentTypeString(gl::VariableComponentType(type),
gl::VariableComponentCount(type));
} }
const PixelShaderOutputVariable *FindOutputAtLocation(const std::vector<PixelShaderOutputVariable> &outputVariables, const PixelShaderOutputVariable *FindOutputAtLocation(
const std::vector<PixelShaderOutputVariable> &outputVariables,
unsigned int location) unsigned int location)
{ {
for (size_t variableIndex = 0; variableIndex < outputVariables.size(); ++variableIndex) for (size_t variableIndex = 0; variableIndex < outputVariables.size(); ++variableIndex)
...@@ -83,7 +102,7 @@ const PixelShaderOutputVariable *FindOutputAtLocation(const std::vector<PixelSha ...@@ -83,7 +102,7 @@ const PixelShaderOutputVariable *FindOutputAtLocation(const std::vector<PixelSha
} }
} }
return NULL; return nullptr;
} }
typedef const PackedVarying *VaryingPacking[gl::IMPLEMENTATION_MAX_VARYING_VECTORS][4]; typedef const PackedVarying *VaryingPacking[gl::IMPLEMENTATION_MAX_VARYING_VECTORS][4];
...@@ -179,7 +198,7 @@ bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, Vary ...@@ -179,7 +198,7 @@ bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, Vary
} }
else if (elements == 1) else if (elements == 1)
{ {
int space[4] = { 0 }; int space[4] = {0};
for (int y = 0; y < maxVaryingVectors; y++) for (int y = 0; y < maxVaryingVectors; y++)
{ {
...@@ -220,7 +239,8 @@ bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, Vary ...@@ -220,7 +239,8 @@ bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, Vary
return true; return true;
} }
} }
else UNREACHABLE(); else
UNREACHABLE();
return false; return false;
} }
...@@ -233,15 +253,14 @@ DynamicHLSL::DynamicHLSL(RendererD3D *const renderer) : mRenderer(renderer) ...@@ -233,15 +253,14 @@ DynamicHLSL::DynamicHLSL(RendererD3D *const renderer) : mRenderer(renderer)
{ {
} }
// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111 // Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading
// Language 1.00 rev. 17] appendix A section 7 page 111
// Returns the number of used varying registers, or -1 if unsuccesful // Returns the number of used varying registers, or -1 if unsuccesful
int DynamicHLSL::packVaryings(InfoLog &infoLog, int DynamicHLSL::packVaryings(const gl::Caps &caps,
InfoLog &infoLog,
std::vector<PackedVarying> *packedVaryings, std::vector<PackedVarying> *packedVaryings,
const std::vector<std::string> &transformFeedbackVaryings) const std::vector<std::string> &transformFeedbackVaryings)
{ {
// TODO (geofflang): Use context's caps
const int maxVaryingVectors = mRenderer->getRendererCaps().maxVaryingVectors;
VaryingPacking packing = {}; VaryingPacking packing = {};
std::set<std::string> uniqueVaryingNames; std::set<std::string> uniqueVaryingNames;
...@@ -258,7 +277,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog, ...@@ -258,7 +277,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
ASSERT(uniqueVaryingNames.count(varying.name) == 0); ASSERT(uniqueVaryingNames.count(varying.name) == 0);
if (PackVarying(&packedVarying, maxVaryingVectors, packing)) if (PackVarying(&packedVarying, caps.maxVaryingVectors, packing))
{ {
uniqueVaryingNames.insert(varying.name); uniqueVaryingNames.insert(varying.name);
} }
...@@ -286,7 +305,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog, ...@@ -286,7 +305,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
const sh::Varying &varying = *packedVarying.varying; const sh::Varying &varying = *packedVarying.varying;
if (transformFeedbackVaryingName == varying.name) if (transformFeedbackVaryingName == varying.name)
{ {
if (!PackVarying(&packedVarying, maxVaryingVectors, packing)) if (!PackVarying(&packedVarying, caps.maxVaryingVectors, packing))
{ {
infoLog << "Could not pack varying " << varying.name; infoLog << "Could not pack varying " << varying.name;
return -1; return -1;
...@@ -309,7 +328,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog, ...@@ -309,7 +328,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
// Return the number of used registers // Return the number of used registers
int registers = 0; int registers = 0;
for (int r = 0; r < maxVaryingVectors; r++) for (GLuint r = 0; r < caps.maxVaryingVectors; r++)
{ {
if (packing[r][0] || packing[r][1] || packing[r][2] || packing[r][3]) if (packing[r][0] || packing[r][1] || packing[r][2] || packing[r][3])
{ {
...@@ -320,7 +339,8 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog, ...@@ -320,7 +339,8 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
return registers; return registers;
} }
std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &varyings, std::string DynamicHLSL::generateVaryingHLSL(const gl::Caps &caps,
const std::vector<PackedVarying> &varyings,
bool shaderUsesPointSize) const bool shaderUsesPointSize) const
{ {
std::string varyingSemantic = getVaryingSemantic(shaderUsesPointSize); std::string varyingSemantic = getVaryingSemantic(shaderUsesPointSize);
...@@ -365,9 +385,8 @@ std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &v ...@@ -365,9 +385,8 @@ std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &v
UNREACHABLE(); UNREACHABLE();
} }
unsigned int semanticIndex = unsigned int semanticIndex = elementIndex * variableRows +
elementIndex * variableRows + packedVarying.columnIndex * caps.maxVaryingVectors +
packedVarying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors +
packedVarying.registerIndex + row; packedVarying.registerIndex + row;
std::string n = Str(semanticIndex); std::string n = Str(semanticIndex);
...@@ -392,11 +411,16 @@ std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &v ...@@ -392,11 +411,16 @@ std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &v
return varyingHLSL; return varyingHLSL;
} }
std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &sourceShader, std::string DynamicHLSL::generateVertexShaderForInputLayout(
const std::string &sourceShader,
const InputLayout &inputLayout, const InputLayout &inputLayout,
const std::vector<sh::Attribute> &shaderAttributes) const const std::vector<sh::Attribute> &shaderAttributes) const
{ {
std::string structHLSL, initHLSL; std::stringstream structStream;
std::stringstream initStream;
structStream << "struct VS_INPUT\n"
<< "{\n";
int semanticIndex = 0; int semanticIndex = 0;
unsigned int inputIndex = 0; unsigned int inputIndex = 0;
...@@ -405,7 +429,8 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s ...@@ -405,7 +429,8 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
// If the renderer does not support Geometry shaders then Instanced PointSprite emulation // If the renderer does not support Geometry shaders then Instanced PointSprite emulation
// must be used. // must be used.
bool usesPointSize = sourceShader.find("GL_USES_POINT_SIZE") != std::string::npos; bool usesPointSize = sourceShader.find("GL_USES_POINT_SIZE") != std::string::npos;
bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation; bool useInstancedPointSpriteEmulation =
usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
// Instanced PointSprite emulation requires additional entries in the // Instanced PointSprite emulation requires additional entries in the
// VS_INPUT structure to support the vertices that make up the quad vertices. // VS_INPUT structure to support the vertices that make up the quad vertices.
...@@ -417,8 +442,8 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s ...@@ -417,8 +442,8 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
// before per instance data in the shader. // before per instance data in the shader.
if (useInstancedPointSpriteEmulation) if (useInstancedPointSpriteEmulation)
{ {
structHLSL += " float3 spriteVertexPos : SPRITEPOSITION0;\n"; structStream << " float3 spriteVertexPos : SPRITEPOSITION0;\n"
structHLSL += " float2 spriteTexCoord : SPRITETEXCOORD0;\n"; << " float2 spriteTexCoord : SPRITETEXCOORD0;\n";
} }
for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); ++attributeIndex) for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); ++attributeIndex)
...@@ -434,7 +459,8 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s ...@@ -434,7 +459,8 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
if (IsMatrixType(shaderAttribute.type)) if (IsMatrixType(shaderAttribute.type))
{ {
// Matrix types are always transposed // Matrix types are always transposed
structHLSL += " " + HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type)); structStream << " "
<< HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type));
} }
else else
{ {
...@@ -442,31 +468,34 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s ...@@ -442,31 +468,34 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
if (shaderAttribute.name == "gl_InstanceID") if (shaderAttribute.name == "gl_InstanceID")
{ {
// The input type of the instance ID in HLSL (uint) differs from the one in ESSL (int). // The input type of the instance ID in HLSL (uint) differs from the one in ESSL
structHLSL += " uint"; // (int).
structStream << " uint";
} }
else else
{ {
structHLSL += " " + HLSLComponentTypeString(componentType, VariableComponentCount(shaderAttribute.type)); structStream << " " << HLSLComponentTypeString(
componentType,
VariableComponentCount(shaderAttribute.type));
} }
} }
structHLSL += " " + decorateVariable(shaderAttribute.name) + " : "; structStream << " " << decorateVariable(shaderAttribute.name) << " : ";
if (shaderAttribute.name == "gl_InstanceID") if (shaderAttribute.name == "gl_InstanceID")
{ {
structHLSL += "SV_InstanceID"; structStream << "SV_InstanceID";
} }
else else
{ {
structHLSL += "TEXCOORD" + Str(semanticIndex); structStream << "TEXCOORD" << semanticIndex;
semanticIndex += VariableRegisterCount(shaderAttribute.type); semanticIndex += VariableRegisterCount(shaderAttribute.type);
} }
structHLSL += ";\n"; structStream << ";\n";
// HLSL code for initialization // HLSL code for initialization
initHLSL += " " + decorateVariable(shaderAttribute.name) + " = "; initStream << " " << decorateVariable(shaderAttribute.name) << " = ";
// Mismatched vertex attribute to vertex input may result in an undefined // Mismatched vertex attribute to vertex input may result in an undefined
// data reinterpretation (eg for pure integer->float, float->pure integer) // data reinterpretation (eg for pure integer->float, float->pure integer)
...@@ -474,46 +503,48 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s ...@@ -474,46 +503,48 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
if (IsMatrixType(shaderAttribute.type) || if (IsMatrixType(shaderAttribute.type) ||
(mRenderer->getVertexConversionType(vertexFormatType) & VERTEX_CONVERT_GPU) != 0) (mRenderer->getVertexConversionType(vertexFormatType) & VERTEX_CONVERT_GPU) != 0)
{ {
initHLSL += generateAttributeConversionHLSL(vertexFormatType, shaderAttribute); initStream << generateAttributeConversionHLSL(vertexFormatType, shaderAttribute);
} }
else else
{ {
initHLSL += "input." + decorateVariable(shaderAttribute.name); initStream << "input." << decorateVariable(shaderAttribute.name);
} }
initHLSL += ";\n"; initStream << ";\n";
inputIndex += VariableRowCount(TransposeMatrixType(shaderAttribute.type)); inputIndex += VariableRowCount(TransposeMatrixType(shaderAttribute.type));
} }
} }
std::string replacementHLSL = "struct VS_INPUT\n" structStream << "};\n"
"{\n" +
structHLSL +
"};\n"
"\n" "\n"
"void initAttributes(VS_INPUT input)\n" "void initAttributes(VS_INPUT input)\n"
"{\n" + "{\n"
initHLSL + << initStream.str() << "}\n";
"}\n";
std::string vertexHLSL(sourceShader); std::string vertexHLSL(sourceShader);
size_t copyInsertionPos = vertexHLSL.find(VERTEX_ATTRIBUTE_STUB_STRING); size_t copyInsertionPos = vertexHLSL.find(VERTEX_ATTRIBUTE_STUB_STRING);
vertexHLSL.replace(copyInsertionPos, VERTEX_ATTRIBUTE_STUB_STRING.length(), replacementHLSL); vertexHLSL.replace(copyInsertionPos, VERTEX_ATTRIBUTE_STUB_STRING.length(), structStream.str());
return vertexHLSL; return vertexHLSL;
} }
std::string DynamicHLSL::generatePixelShaderForOutputSignature(const std::string &sourceShader, const std::vector<PixelShaderOutputVariable> &outputVariables, std::string DynamicHLSL::generatePixelShaderForOutputSignature(
bool usesFragDepth, const std::vector<GLenum> &outputLayout) const const std::string &sourceShader,
const std::vector<PixelShaderOutputVariable> &outputVariables,
bool usesFragDepth,
const std::vector<GLenum> &outputLayout) const
{ {
const int shaderModel = mRenderer->getMajorShaderModel(); const int shaderModel = mRenderer->getMajorShaderModel();
std::string targetSemantic = (shaderModel >= 4) ? "SV_TARGET" : "COLOR"; std::string targetSemantic = (shaderModel >= 4) ? "SV_TARGET" : "COLOR";
std::string depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH"; std::string depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH";
std::string declarationHLSL; std::stringstream declarationStream;
std::string copyHLSL; std::stringstream copyStream;
declarationStream << "struct PS_OUTPUT\n"
"{\n";
for (size_t layoutIndex = 0; layoutIndex < outputLayout.size(); ++layoutIndex) for (size_t layoutIndex = 0; layoutIndex < outputLayout.size(); ++layoutIndex)
{ {
...@@ -523,44 +554,44 @@ std::string DynamicHLSL::generatePixelShaderForOutputSignature(const std::string ...@@ -523,44 +554,44 @@ std::string DynamicHLSL::generatePixelShaderForOutputSignature(const std::string
{ {
unsigned int location = (binding - GL_COLOR_ATTACHMENT0); unsigned int location = (binding - GL_COLOR_ATTACHMENT0);
const PixelShaderOutputVariable *outputVariable = FindOutputAtLocation(outputVariables, location); const PixelShaderOutputVariable *outputVariable =
FindOutputAtLocation(outputVariables, location);
// OpenGL ES 3.0 spec $4.2.1 // OpenGL ES 3.0 spec $4.2.1
// If [...] not all user-defined output variables are written, the values of fragment colors // If [...] not all user-defined output variables are written, the values of fragment
// colors
// corresponding to unwritten variables are similarly undefined. // corresponding to unwritten variables are similarly undefined.
if (outputVariable) if (outputVariable)
{ {
declarationHLSL += " " + HLSLTypeString(outputVariable->type) + " " + declarationStream << " " + HLSLTypeString(outputVariable->type) << " "
outputVariable->name + " : " + targetSemantic + << outputVariable->name << " : " << targetSemantic
Str(static_cast<int>(layoutIndex)) + ";\n"; << static_cast<int>(layoutIndex) << ";\n";
copyHLSL += " output." + outputVariable->name + " = " + outputVariable->source + ";\n"; copyStream << " output." << outputVariable->name << " = "
<< outputVariable->source << ";\n";
} }
} }
} }
if (usesFragDepth) if (usesFragDepth)
{ {
declarationHLSL += " float gl_Depth : " + depthSemantic + ";\n"; declarationStream << " float gl_Depth : " << depthSemantic << ";\n";
copyHLSL += " output.gl_Depth = gl_Depth; \n"; copyStream << " output.gl_Depth = gl_Depth; \n";
} }
std::string replacementHLSL = "struct PS_OUTPUT\n" declarationStream << "};\n"
"{\n" +
declarationHLSL +
"};\n"
"\n" "\n"
"PS_OUTPUT generateOutput()\n" "PS_OUTPUT generateOutput()\n"
"{\n" "{\n"
" PS_OUTPUT output;\n" + " PS_OUTPUT output;\n"
copyHLSL + << copyStream.str() << " return output;\n"
" return output;\n"
"}\n"; "}\n";
std::string pixelHLSL(sourceShader); std::string pixelHLSL(sourceShader);
size_t outputInsertionPos = pixelHLSL.find(PIXEL_OUTPUT_STUB_STRING); size_t outputInsertionPos = pixelHLSL.find(PIXEL_OUTPUT_STUB_STRING);
pixelHLSL.replace(outputInsertionPos, PIXEL_OUTPUT_STUB_STRING.length(), replacementHLSL); pixelHLSL.replace(outputInsertionPos, PIXEL_OUTPUT_STUB_STRING.length(),
declarationStream.str());
return pixelHLSL; return pixelHLSL;
} }
...@@ -577,21 +608,14 @@ struct DynamicHLSL::SemanticInfo ...@@ -577,21 +608,14 @@ struct DynamicHLSL::SemanticInfo
{ {
struct BuiltinInfo struct BuiltinInfo
{ {
BuiltinInfo() BuiltinInfo() : enabled(false), index(0), systemValue(false) {}
: enabled(false),
index(0),
systemValue(false)
{}
bool enabled; bool enabled;
std::string semantic; std::string semantic;
unsigned int index; unsigned int index;
bool systemValue; bool systemValue;
std::string str() const std::string str() const { return (systemValue ? semantic : (semantic + Str(index))); }
{
return (systemValue ? semantic : (semantic + Str(index)));
}
void enableSystem(const std::string &systemValueSemantic) void enableSystem(const std::string &systemValueSemantic)
{ {
...@@ -615,8 +639,12 @@ struct DynamicHLSL::SemanticInfo ...@@ -615,8 +639,12 @@ struct DynamicHLSL::SemanticInfo
BuiltinInfo glPointSize; BuiltinInfo glPointSize;
}; };
DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters, bool position, bool fragCoord, DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters,
bool pointCoord, bool pointSize, bool pixelShader) const bool position,
bool fragCoord,
bool pointCoord,
bool pointSize,
bool pixelShader) const
{ {
SemanticInfo info; SemanticInfo info;
bool hlsl4 = (mRenderer->getMajorShaderModel() >= 4); bool hlsl4 = (mRenderer->getMajorShaderModel() >= 4);
...@@ -670,7 +698,8 @@ DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters, bool ...@@ -670,7 +698,8 @@ DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters, bool
return info; return info;
} }
std::string DynamicHLSL::generateVaryingLinkHLSL(const SemanticInfo &info, const std::string &varyingHLSL) const std::string DynamicHLSL::generateVaryingLinkHLSL(const SemanticInfo &info,
const std::string &varyingHLSL) const
{ {
std::string linkHLSL = "{\n"; std::string linkHLSL = "{\n";
...@@ -697,7 +726,8 @@ std::string DynamicHLSL::generateVaryingLinkHLSL(const SemanticInfo &info, const ...@@ -697,7 +726,8 @@ std::string DynamicHLSL::generateVaryingLinkHLSL(const SemanticInfo &info, const
linkHLSL += " float gl_PointSize : " + info.glPointSize.str() + ";\n"; linkHLSL += " float gl_PointSize : " + info.glPointSize.str() + ";\n";
} }
// Do this after glPointSize, to potentially combine gl_PointCoord and gl_PointSize into the same register. // Do this after glPointSize, to potentially combine gl_PointCoord and gl_PointSize into the
// same register.
linkHLSL += varyingHLSL; linkHLSL += varyingHLSL;
linkHLSL += "};\n"; linkHLSL += "};\n";
...@@ -710,14 +740,15 @@ void DynamicHLSL::storeBuiltinLinkedVaryings(const SemanticInfo &info, ...@@ -710,14 +740,15 @@ void DynamicHLSL::storeBuiltinLinkedVaryings(const SemanticInfo &info,
{ {
if (info.glPosition.enabled) if (info.glPosition.enabled)
{ {
linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, info.glPosition.semantic, linkedVaryings->push_back(LinkedVarying(
info.glPosition.index, 1)); "gl_Position", GL_FLOAT_VEC4, 1, info.glPosition.semantic, info.glPosition.index, 1));
} }
if (info.glFragCoord.enabled) if (info.glFragCoord.enabled)
{ {
linkedVaryings->push_back(LinkedVarying("gl_FragCoord", GL_FLOAT_VEC4, 1, info.glFragCoord.semantic, linkedVaryings->push_back(LinkedVarying("gl_FragCoord", GL_FLOAT_VEC4, 1,
info.glFragCoord.index, 1)); info.glFragCoord.semantic, info.glFragCoord.index,
1));
} }
if (info.glPointSize.enabled) if (info.glPointSize.enabled)
...@@ -753,31 +784,29 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -753,31 +784,29 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
const gl::Program::Data &programData, const gl::Program::Data &programData,
InfoLog &infoLog, InfoLog &infoLog,
int registers, int registers,
std::string &pixelHLSL, std::string *pixelHLSL,
std::string &vertexHLSL, std::string *vertexHLSL,
const std::vector<PackedVarying> &packedVaryings, const std::vector<PackedVarying> &packedVaryings,
std::vector<LinkedVarying> *linkedVaryings, std::vector<LinkedVarying> *linkedVaryings,
std::vector<PixelShaderOutputVariable> *outPixelShaderKey, std::vector<PixelShaderOutputVariable> *outPixelShaderKey,
bool *outUsesFragDepth) const bool *outUsesFragDepth) const
{ {
if (pixelHLSL.empty() || vertexHLSL.empty()) ASSERT(pixelHLSL->empty() && vertexHLSL->empty());
{
return false;
}
const gl::Shader *vertexShaderGL = programData.getAttachedVertexShader(); const gl::Shader *vertexShaderGL = programData.getAttachedVertexShader();
const ShaderD3D *vertexShader = GetImplAs<ShaderD3D>(vertexShaderGL); const ShaderD3D *vertexShader = GetImplAs<ShaderD3D>(vertexShaderGL);
const gl::Shader *fragmentShaderGL = programData.getAttachedFragmentShader(); const gl::Shader *fragmentShaderGL = programData.getAttachedFragmentShader();
const ShaderD3D *fragmentShader = GetImplAs<ShaderD3D>(fragmentShaderGL); const ShaderD3D *fragmentShader = GetImplAs<ShaderD3D>(fragmentShaderGL);
bool usesMRT = fragmentShader->mUsesMultipleRenderTargets; bool usesMRT = fragmentShader->usesMultipleRenderTargets();
bool usesFragCoord = fragmentShader->mUsesFragCoord; bool usesFragCoord = fragmentShader->usesFragCoord();
bool usesPointCoord = fragmentShader->mUsesPointCoord; bool usesPointCoord = fragmentShader->usesPointCoord();
bool usesPointSize = vertexShader->mUsesPointSize; bool usesPointSize = vertexShader->usesPointSize();
bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation; bool useInstancedPointSpriteEmulation =
usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
// Validation done in the compiler // Validation done in the compiler
ASSERT(!fragmentShader->mUsesFragColor || !fragmentShader->mUsesFragData); ASSERT(!fragmentShader->usesFragColor() || !fragmentShader->usesFragData());
// Write the HLSL input/output declarations // Write the HLSL input/output declarations
const int shaderModel = mRenderer->getMajorShaderModel(); const int shaderModel = mRenderer->getMajorShaderModel();
...@@ -786,12 +815,12 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -786,12 +815,12 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
// Two cases when writing to gl_FragColor and using ESSL 1.0: // Two cases when writing to gl_FragColor and using ESSL 1.0:
// - with a 3.0 context, the output color is copied to channel 0 // - with a 3.0 context, the output color is copied to channel 0
// - with a 2.0 context, the output color is broadcast to all channels // - with a 2.0 context, the output color is broadcast to all channels
const bool broadcast = (fragmentShader->mUsesFragColor && data.clientVersion < 3); const bool broadcast = (fragmentShader->usesFragColor() && data.clientVersion < 3);
const unsigned int numRenderTargets = (broadcast || usesMRT ? data.caps->maxDrawBuffers : 1); const unsigned int numRenderTargets = (broadcast || usesMRT ? data.caps->maxDrawBuffers : 1);
// gl_Position only needs to be outputted from the vertex shader if transform feedback is active. // gl_Position only needs to be outputted from the vertex shader if transform feedback is
// This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from the vertex shader in this case. // active. This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from
// This saves us 1 output vector. // the vertex shader in this case. This saves us 1 output vector.
bool outputPositionFromVS = !(shaderModel >= 4 && mRenderer->getShaderModelSuffix() != ""); bool outputPositionFromVS = !(shaderModel >= 4 && mRenderer->getShaderModelSuffix() != "");
int shaderVersion = vertexShaderGL->getShaderVersion(); int shaderVersion = vertexShaderGL->getShaderVersion();
...@@ -802,78 +831,87 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -802,78 +831,87 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
return false; return false;
} }
const std::string &varyingHLSL = generateVaryingHLSL(packedVaryings, usesPointSize); const std::string &varyingHLSL = generateVaryingHLSL(*data.caps, packedVaryings, usesPointSize);
// Instanced PointSprite emulation requires that gl_PointCoord is present in the vertex shader VS_OUTPUT // Instanced PointSprite emulation requires that gl_PointCoord is present in the vertex shader
// structure to ensure compatibility with the generated PS_INPUT of the pixel shader. // VS_OUTPUT structure to ensure compatibility with the generated PS_INPUT of the pixel shader.
// GeometryShader PointSprite emulation does not require this additional entry because the // GeometryShader PointSprite emulation does not require this additional entry because the
// GS_OUTPUT of the Geometry shader contains the pointCoord value and already matches the PS_INPUT of the // GS_OUTPUT of the Geometry shader contains the pointCoord value and already matches the
// generated pixel shader. // PS_INPUT of the generated pixel shader. The Geometry Shader point sprite implementation needs
// The Geometry Shader point sprite implementation needs gl_PointSize to be in VS_OUTPUT and GS_INPUT. // gl_PointSize to be in VS_OUTPUT and GS_INPUT. Instanced point sprites doesn't need
// Instanced point sprites doesn't need gl_PointSize in VS_OUTPUT. // gl_PointSize in VS_OUTPUT.
const SemanticInfo &vertexSemantics = getSemanticInfo(registers, outputPositionFromVS, const SemanticInfo &vertexSemantics =
usesFragCoord, (useInstancedPointSpriteEmulation && usesPointCoord), getSemanticInfo(registers, outputPositionFromVS, usesFragCoord,
(useInstancedPointSpriteEmulation && usesPointCoord),
(!useInstancedPointSpriteEmulation && usesPointSize), false); (!useInstancedPointSpriteEmulation && usesPointSize), false);
storeUserLinkedVaryings(packedVaryings, usesPointSize, linkedVaryings); storeUserLinkedVaryings(packedVaryings, usesPointSize, linkedVaryings);
storeBuiltinLinkedVaryings(vertexSemantics, linkedVaryings); storeBuiltinLinkedVaryings(vertexSemantics, linkedVaryings);
std::stringstream vertexStream;
vertexStream << vertexShaderGL->getTranslatedSource();
// Instanced PointSprite emulation requires additional entries originally generated in the // Instanced PointSprite emulation requires additional entries originally generated in the
// GeometryShader HLSL. These include pointsize clamp values. // GeometryShader HLSL. These include pointsize clamp values.
if (useInstancedPointSpriteEmulation) if (useInstancedPointSpriteEmulation)
{ {
vertexHLSL += "static float minPointSize = " + Str((int)mRenderer->getRendererCaps().minAliasedPointSize) + ".0f;\n" vertexStream << "static float minPointSize = "
"static float maxPointSize = " + Str((int)mRenderer->getRendererCaps().maxAliasedPointSize) + ".0f;\n"; << static_cast<int>(data.caps->minAliasedPointSize) << ".0f;\n"
<< "static float maxPointSize = "
<< static_cast<int>(data.caps->maxAliasedPointSize) << ".0f;\n";
} }
// Add stub string to be replaced when shader is dynamically defined by its layout // Add stub string to be replaced when shader is dynamically defined by its layout
vertexHLSL += "\n" + VERTEX_ATTRIBUTE_STUB_STRING + "\n" vertexStream << "\n" << VERTEX_ATTRIBUTE_STUB_STRING + "\n"
"struct VS_OUTPUT\n" + generateVaryingLinkHLSL(vertexSemantics, varyingHLSL) + "\n" << "struct VS_OUTPUT\n" + generateVaryingLinkHLSL(vertexSemantics, varyingHLSL) +
"VS_OUTPUT main(VS_INPUT input)\n" "\n"
"{\n" << "VS_OUTPUT main(VS_INPUT input)\n"
" initAttributes(input);\n"; << "{\n"
<< " initAttributes(input);\n";
if (vertexShader->usesDeferredInit()) if (vertexShader->usesDeferredInit())
{ {
vertexHLSL += "\n" vertexStream << "\n"
" initializeDeferredGlobals();\n"; << " initializeDeferredGlobals();\n";
} }
vertexHLSL += "\n" vertexStream << "\n"
" gl_main();\n" << " gl_main();\n"
"\n" << "\n"
" VS_OUTPUT output;\n"; << " VS_OUTPUT output;\n";
if (outputPositionFromVS) if (outputPositionFromVS)
{ {
vertexHLSL += " output.gl_Position = gl_Position;\n"; vertexStream << " output.gl_Position = gl_Position;\n";
} }
// On D3D9 or D3D11 Feature Level 9, we need to emulate large viewports using dx_ViewAdjust. // On D3D9 or D3D11 Feature Level 9, we need to emulate large viewports using dx_ViewAdjust.
if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "") if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
{ {
vertexHLSL += " output.dx_Position.x = gl_Position.x;\n" vertexStream << " output.dx_Position.x = gl_Position.x;\n"
" output.dx_Position.y = -gl_Position.y;\n" << " output.dx_Position.y = -gl_Position.y;\n"
" output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n" << " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
" output.dx_Position.w = gl_Position.w;\n"; << " output.dx_Position.w = gl_Position.w;\n";
} }
else else
{ {
vertexHLSL += " output.dx_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n" vertexStream << " output.dx_Position.x = gl_Position.x * dx_ViewAdjust.z + "
" output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + dx_ViewAdjust.y * gl_Position.w);\n" "dx_ViewAdjust.x * gl_Position.w;\n"
" output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n" << " output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + "
" output.dx_Position.w = gl_Position.w;\n"; "dx_ViewAdjust.y * gl_Position.w);\n"
<< " output.dx_Position.z = (gl_Position.z + gl_Position.w) * 0.5;\n"
<< " output.dx_Position.w = gl_Position.w;\n";
} }
// We don't need to output gl_PointSize if we use are emulating point sprites via instancing. // We don't need to output gl_PointSize if we use are emulating point sprites via instancing.
if (usesPointSize && shaderModel >= 3 && !useInstancedPointSpriteEmulation) if (usesPointSize && shaderModel >= 3 && !useInstancedPointSpriteEmulation)
{ {
vertexHLSL += " output.gl_PointSize = gl_PointSize;\n"; vertexStream << " output.gl_PointSize = gl_PointSize;\n";
} }
if (usesFragCoord) if (usesFragCoord)
{ {
vertexHLSL += " output.gl_FragCoord = gl_Position;\n"; vertexStream << " output.gl_FragCoord = gl_Position;\n";
} }
for (const PackedVarying &packedVarying : packedVaryings) for (const PackedVarying &packedVarying : packedVaryings)
...@@ -895,21 +933,19 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -895,21 +933,19 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
int r = packedVarying.registerIndex + int r = packedVarying.registerIndex +
packedVarying.columnIndex * data.caps->maxVaryingVectors + packedVarying.columnIndex * data.caps->maxVaryingVectors +
elementIndex * variableRows + row; elementIndex * variableRows + row;
vertexHLSL += " output.v" + Str(r); vertexStream << " output.v" << r << " = _" + varying.name;
vertexHLSL += " = _" + varying.name;
if (varying.isArray()) if (varying.isArray())
{ {
vertexHLSL += ArrayString(elementIndex); vertexStream << ArrayString(elementIndex);
} }
if (variableRows > 1) if (variableRows > 1)
{ {
vertexHLSL += ArrayString(row); vertexStream << ArrayString(row);
} }
vertexHLSL += ";\n"; vertexStream << ";\n";
} }
} }
} }
...@@ -918,40 +954,50 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -918,40 +954,50 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
// the final output vertex positions of the quad that represents each sprite. // the final output vertex positions of the quad that represents each sprite.
if (useInstancedPointSpriteEmulation) if (useInstancedPointSpriteEmulation)
{ {
vertexHLSL += "\n" vertexStream << "\n"
" gl_PointSize = clamp(gl_PointSize, minPointSize, maxPointSize);\n" << " gl_PointSize = clamp(gl_PointSize, minPointSize, maxPointSize);\n"
" output.dx_Position.xyz += float3(input.spriteVertexPos.x * gl_PointSize / (dx_ViewCoords.x*2), input.spriteVertexPos.y * gl_PointSize / (dx_ViewCoords.y*2), input.spriteVertexPos.z) * output.dx_Position.w;\n"; << " output.dx_Position.xyz += float3(input.spriteVertexPos.x * "
"gl_PointSize / (dx_ViewCoords.x*2), input.spriteVertexPos.y * "
"gl_PointSize / (dx_ViewCoords.y*2), input.spriteVertexPos.z) * "
"output.dx_Position.w;\n";
if (usesPointCoord) if (usesPointCoord)
{ {
vertexHLSL += "\n" vertexStream << "\n"
" output.gl_PointCoord = input.spriteTexCoord;\n"; << " output.gl_PointCoord = input.spriteTexCoord;\n";
} }
} }
vertexHLSL += "\n" vertexStream << "\n"
" return output;\n" << " return output;\n"
"}\n"; << "}\n";
std::stringstream pixelStream;
pixelStream << fragmentShaderGL->getTranslatedSource();
const SemanticInfo &pixelSemantics = getSemanticInfo(registers, outputPositionFromVS, usesFragCoord, usesPointCoord, const SemanticInfo &pixelSemantics =
getSemanticInfo(registers, outputPositionFromVS, usesFragCoord, usesPointCoord,
(!useInstancedPointSpriteEmulation && usesPointSize), true); (!useInstancedPointSpriteEmulation && usesPointSize), true);
pixelHLSL += "struct PS_INPUT\n" + generateVaryingLinkHLSL(pixelSemantics, varyingHLSL) + "\n"; pixelStream << "struct PS_INPUT\n" << generateVaryingLinkHLSL(pixelSemantics, varyingHLSL)
<< "\n";
if (shaderVersion < 300) if (shaderVersion < 300)
{ {
for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++) for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets;
renderTargetIndex++)
{ {
PixelShaderOutputVariable outputKeyVariable; PixelShaderOutputVariable outputKeyVariable;
outputKeyVariable.type = GL_FLOAT_VEC4; outputKeyVariable.type = GL_FLOAT_VEC4;
outputKeyVariable.name = "gl_Color" + Str(renderTargetIndex); outputKeyVariable.name = "gl_Color" + Str(renderTargetIndex);
outputKeyVariable.source = broadcast ? "gl_Color[0]" : "gl_Color[" + Str(renderTargetIndex) + "]"; outputKeyVariable.source =
broadcast ? "gl_Color[0]" : "gl_Color[" + Str(renderTargetIndex) + "]";
outputKeyVariable.outputIndex = renderTargetIndex; outputKeyVariable.outputIndex = renderTargetIndex;
outPixelShaderKey->push_back(outputKeyVariable); outPixelShaderKey->push_back(outputKeyVariable);
} }
*outUsesFragDepth = fragmentShader->mUsesFragDepth; *outUsesFragDepth = fragmentShader->usesFragDepth();
} }
else else
{ {
...@@ -962,7 +1008,8 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -962,7 +1008,8 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
const VariableLocation &outputLocation = outputPair.second; const VariableLocation &outputLocation = outputPair.second;
const sh::ShaderVariable &outputVariable = shaderOutputVars[outputLocation.index]; const sh::ShaderVariable &outputVariable = shaderOutputVars[outputLocation.index];
const std::string &variableName = "out_" + outputLocation.name; const std::string &variableName = "out_" + outputLocation.name;
const std::string &elementString = (outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element)); const std::string &elementString =
(outputLocation.element == GL_INVALID_INDEX ? "" : Str(outputLocation.element));
ASSERT(outputVariable.staticUse); ASSERT(outputVariable.staticUse);
...@@ -978,69 +1025,74 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -978,69 +1025,74 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
*outUsesFragDepth = false; *outUsesFragDepth = false;
} }
pixelHLSL += PIXEL_OUTPUT_STUB_STRING + "\n"; pixelStream << PIXEL_OUTPUT_STUB_STRING + "\n";
if (fragmentShader->mUsesFrontFacing) if (fragmentShader->usesFrontFacing())
{ {
if (shaderModel >= 4) if (shaderModel >= 4)
{ {
pixelHLSL += "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n" pixelStream << "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n"
"{\n"; << "{\n";
} }
else else
{ {
pixelHLSL += "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n" pixelStream << "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n"
"{\n"; << "{\n";
} }
} }
else else
{ {
pixelHLSL += "PS_OUTPUT main(PS_INPUT input)\n" pixelStream << "PS_OUTPUT main(PS_INPUT input)\n"
"{\n"; << "{\n";
} }
if (usesFragCoord) if (usesFragCoord)
{ {
pixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n"; pixelStream << " float rhw = 1.0 / input.gl_FragCoord.w;\n";
// Certain Shader Models (4_0+ and 3_0) allow reading from dx_Position in the pixel shader. // Certain Shader Models (4_0+ and 3_0) allow reading from dx_Position in the pixel shader.
// Other Shader Models (4_0_level_9_3 and 2_x) don't support this, so we emulate it using dx_ViewCoords. // Other Shader Models (4_0_level_9_3 and 2_x) don't support this, so we emulate it using
// dx_ViewCoords.
if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "") if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
{ {
pixelHLSL += " gl_FragCoord.x = input.dx_Position.x;\n" pixelStream << " gl_FragCoord.x = input.dx_Position.x;\n"
" gl_FragCoord.y = input.dx_Position.y;\n"; << " gl_FragCoord.y = input.dx_Position.y;\n";
} }
else if (shaderModel == 3) else if (shaderModel == 3)
{ {
pixelHLSL += " gl_FragCoord.x = input.dx_Position.x + 0.5;\n" pixelStream << " gl_FragCoord.x = input.dx_Position.x + 0.5;\n"
" gl_FragCoord.y = input.dx_Position.y + 0.5;\n"; << " gl_FragCoord.y = input.dx_Position.y + 0.5;\n";
} }
else else
{ {
// dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See Renderer::setViewport() // dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See
pixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_ViewCoords.x + dx_ViewCoords.z;\n" // Renderer::setViewport()
" gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_ViewCoords.y + dx_ViewCoords.w;\n"; pixelStream << " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_ViewCoords.x + "
"dx_ViewCoords.z;\n"
<< " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_ViewCoords.y + "
"dx_ViewCoords.w;\n";
} }
pixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + dx_DepthFront.y;\n" pixelStream << " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + "
" gl_FragCoord.w = rhw;\n"; "dx_DepthFront.y;\n"
<< " gl_FragCoord.w = rhw;\n";
} }
if (usesPointCoord && shaderModel >= 3) if (usesPointCoord && shaderModel >= 3)
{ {
pixelHLSL += " gl_PointCoord.x = input.gl_PointCoord.x;\n"; pixelStream << " gl_PointCoord.x = input.gl_PointCoord.x;\n"
pixelHLSL += " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n"; << " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n";
} }
if (fragmentShader->mUsesFrontFacing) if (fragmentShader->usesFrontFacing())
{ {
if (shaderModel <= 3) if (shaderModel <= 3)
{ {
pixelHLSL += " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n"; pixelStream << " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n";
} }
else else
{ {
pixelHLSL += " gl_FrontFacing = isFrontFace;\n"; pixelStream << " gl_FrontFacing = isFrontFace;\n";
} }
} }
...@@ -1068,21 +1120,21 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -1068,21 +1120,21 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
std::string n = Str(packedVarying.registerIndex + std::string n = Str(packedVarying.registerIndex +
packedVarying.columnIndex * data.caps->maxVaryingVectors + packedVarying.columnIndex * data.caps->maxVaryingVectors +
elementIndex * variableRows + row); elementIndex * variableRows + row);
pixelHLSL += " _" + varying.name; pixelStream << " _" + varying.name;
if (varying.isArray()) if (varying.isArray())
{ {
pixelHLSL += ArrayString(elementIndex); pixelStream << ArrayString(elementIndex);
} }
if (variableRows > 1) if (variableRows > 1)
{ {
pixelHLSL += ArrayString(row); pixelStream << ArrayString(row);
} }
if (varying.isStruct()) if (varying.isStruct())
{ {
pixelHLSL += " = input.v" + n + ";\n"; pixelStream << " = input.v" << n << ";\n";
break; break;
} }
else else
...@@ -1090,16 +1142,16 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -1090,16 +1142,16 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
switch (VariableColumnCount(transposedType)) switch (VariableColumnCount(transposedType))
{ {
case 1: case 1:
pixelHLSL += " = input.v" + n + ".x;\n"; pixelStream << " = input.v" << n << ".x;\n";
break; break;
case 2: case 2:
pixelHLSL += " = input.v" + n + ".xy;\n"; pixelStream << " = input.v" << n << ".xy;\n";
break; break;
case 3: case 3:
pixelHLSL += " = input.v" + n + ".xyz;\n"; pixelStream << " = input.v" << n << ".xyz;\n";
break; break;
case 4: case 4:
pixelHLSL += " = input.v" + n + ";\n"; pixelStream << " = input.v" << n << ";\n";
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1111,30 +1163,35 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -1111,30 +1163,35 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
if (fragmentShader->usesDeferredInit()) if (fragmentShader->usesDeferredInit())
{ {
pixelHLSL += "\n" pixelStream << "\n"
" initializeDeferredGlobals();\n"; << " initializeDeferredGlobals();\n";
} }
pixelHLSL += "\n" pixelStream << "\n"
" gl_main();\n" << " gl_main();\n"
"\n" << "\n"
" return generateOutput();\n" << " return generateOutput();\n"
"}\n"; << "}\n";
*vertexHLSL = vertexStream.str();
*pixelHLSL = pixelStream.str();
return true; return true;
} }
std::string DynamicHLSL::generateGeometryShaderHLSL( std::string DynamicHLSL::generateGeometryShaderHLSL(
const gl::Data &data,
int registers, int registers,
const ShaderD3D *fragmentShader, const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const const std::vector<PackedVarying> &packedVaryings) const
{ {
// for now we only handle point sprite emulation // for now we only handle point sprite emulation
ASSERT(mRenderer->getMajorShaderModel() >= 4); ASSERT(mRenderer->getMajorShaderModel() >= 4);
return generatePointSpriteHLSL(registers, fragmentShader, packedVaryings); return generatePointSpriteHLSL(data, registers, fragmentShader, packedVaryings);
} }
std::string DynamicHLSL::generatePointSpriteHLSL( std::string DynamicHLSL::generatePointSpriteHLSL(
const gl::Data &data,
int registers, int registers,
const ShaderD3D *fragmentShader, const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const const std::vector<PackedVarying> &packedVaryings) const
...@@ -1142,83 +1199,91 @@ std::string DynamicHLSL::generatePointSpriteHLSL( ...@@ -1142,83 +1199,91 @@ std::string DynamicHLSL::generatePointSpriteHLSL(
ASSERT(registers >= 0); ASSERT(registers >= 0);
ASSERT(mRenderer->getMajorShaderModel() >= 4); ASSERT(mRenderer->getMajorShaderModel() >= 4);
std::string geomHLSL; bool usesFragCoord = fragmentShader->usesFragCoord();
bool usesPointCoord = fragmentShader->usesPointCoord();
const SemanticInfo &inSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord, std::stringstream shaderStream;
false, true, false);
const SemanticInfo &outSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord, const SemanticInfo &inSemantics =
fragmentShader->mUsesPointCoord, true, false); getSemanticInfo(registers, true, usesFragCoord, false, true, false);
const SemanticInfo &outSemantics =
getSemanticInfo(registers, true, usesFragCoord, usesPointCoord, true, false);
// If we're generating the geometry shader, we assume the vertex shader uses point size. // If we're generating the geometry shader, we assume the vertex shader uses point size.
std::string varyingHLSL = generateVaryingHLSL(packedVaryings, true); std::string varyingHLSL = generateVaryingHLSL(*data.caps, packedVaryings, true);
std::string inLinkHLSL = generateVaryingLinkHLSL(inSemantics, varyingHLSL); std::string inLinkHLSL = generateVaryingLinkHLSL(inSemantics, varyingHLSL);
std::string outLinkHLSL = generateVaryingLinkHLSL(outSemantics, varyingHLSL); std::string outLinkHLSL = generateVaryingLinkHLSL(outSemantics, varyingHLSL);
// TODO(geofflang): use context's caps shaderStream
geomHLSL += "uniform float4 dx_ViewCoords : register(c1);\n" << "uniform float4 dx_ViewCoords : register(c1);\n"
"\n" << "\n"
"struct GS_INPUT\n" + inLinkHLSL + "\n" + << "struct GS_INPUT\n" << inLinkHLSL << "\n"
"struct GS_OUTPUT\n" + outLinkHLSL + "\n" + << "struct GS_OUTPUT\n" << outLinkHLSL << "\n"
"\n" << "\n"
"static float2 pointSpriteCorners[] = \n" << "static float2 pointSpriteCorners[] = \n"
"{\n" << "{\n"
" float2( 0.5f, -0.5f),\n" << " float2( 0.5f, -0.5f),\n"
" float2( 0.5f, 0.5f),\n" << " float2( 0.5f, 0.5f),\n"
" float2(-0.5f, -0.5f),\n" << " float2(-0.5f, -0.5f),\n"
" float2(-0.5f, 0.5f)\n" << " float2(-0.5f, 0.5f)\n"
"};\n" << "};\n"
"\n" << "\n"
"static float2 pointSpriteTexcoords[] = \n" << "static float2 pointSpriteTexcoords[] = \n"
"{\n" << "{\n"
" float2(1.0f, 1.0f),\n" << " float2(1.0f, 1.0f),\n"
" float2(1.0f, 0.0f),\n" << " float2(1.0f, 0.0f),\n"
" float2(0.0f, 1.0f),\n" << " float2(0.0f, 1.0f),\n"
" float2(0.0f, 0.0f)\n" << " float2(0.0f, 0.0f)\n"
"};\n" << "};\n"
"\n" << "\n"
"static float minPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().minAliasedPointSize)) + ".0f;\n" << "static float minPointSize = " << static_cast<int>(data.caps->minAliasedPointSize)
"static float maxPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().maxAliasedPointSize)) + ".0f;\n" << ".0f;\n"
"\n" << "static float maxPointSize = " << static_cast<int>(data.caps->maxAliasedPointSize)
"[maxvertexcount(4)]\n" << ".0f;\n"
"void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n" << "\n"
"{\n" << "[maxvertexcount(4)]\n"
" GS_OUTPUT output = (GS_OUTPUT)0;\n" << "void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n"
" output.gl_Position = input[0].gl_Position;\n" << "{\n"
" output.gl_PointSize = input[0].gl_PointSize;\n"; << " GS_OUTPUT output = (GS_OUTPUT)0;\n"
<< " output.gl_Position = input[0].gl_Position;\n"
<< " output.gl_PointSize = input[0].gl_PointSize;\n";
for (int r = 0; r < registers; r++) for (int r = 0; r < registers; r++)
{ {
geomHLSL += " output.v" + Str(r) + " = input[0].v" + Str(r) + ";\n"; shaderStream << " output.v" << r << " = input[0].v" << r << ";\n";
} }
if (fragmentShader->mUsesFragCoord) if (usesFragCoord)
{ {
geomHLSL += " output.gl_FragCoord = input[0].gl_FragCoord;\n"; shaderStream << " output.gl_FragCoord = input[0].gl_FragCoord;\n";
} }
geomHLSL += " \n" shaderStream
" float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\n" << " \n"
" float4 dx_Position = input[0].dx_Position;\n" << " float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\n"
" float2 viewportScale = float2(1.0f / dx_ViewCoords.x, 1.0f / dx_ViewCoords.y) * dx_Position.w;\n"; << " float4 dx_Position = input[0].dx_Position;\n"
<< " float2 viewportScale = float2(1.0f / dx_ViewCoords.x, 1.0f / dx_ViewCoords.y) * "
"dx_Position.w;\n";
for (int corner = 0; corner < 4; corner++) for (int corner = 0; corner < 4; corner++)
{ {
geomHLSL += " \n" shaderStream << " \n"
" output.dx_Position = dx_Position + float4(pointSpriteCorners[" + Str(corner) + "] * viewportScale * gl_PointSize, 0.0f, 0.0f);\n"; << " output.dx_Position = dx_Position + float4(pointSpriteCorners["
<< corner << "] * viewportScale * gl_PointSize, 0.0f, 0.0f);\n";
if (fragmentShader->mUsesPointCoord) if (usesPointCoord)
{ {
geomHLSL += " output.gl_PointCoord = pointSpriteTexcoords[" + Str(corner) + "];\n"; shaderStream << " output.gl_PointCoord = pointSpriteTexcoords[" << corner << "];\n";
} }
geomHLSL += " outStream.Append(output);\n"; shaderStream << " outStream.Append(output);\n";
} }
geomHLSL += " \n" shaderStream << " \n"
" outStream.RestartStrip();\n" << " outStream.RestartStrip();\n"
"}\n"; << "}\n";
return geomHLSL; return shaderStream.str();
} }
// This method needs to match OutputHLSL::decorate // This method needs to match OutputHLSL::decorate
...@@ -1232,7 +1297,8 @@ std::string DynamicHLSL::decorateVariable(const std::string &name) ...@@ -1232,7 +1297,8 @@ std::string DynamicHLSL::decorateVariable(const std::string &name)
return name; return name;
} }
std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType, std::string DynamicHLSL::generateAttributeConversionHLSL(
gl::VertexFormatType vertexFormatType,
const sh::ShaderVariable &shaderAttrib) const const sh::ShaderVariable &shaderAttrib) const
{ {
const gl::VertexFormat &vertexFormat = gl::GetVertexFormatFromType(vertexFormatType); const gl::VertexFormat &vertexFormat = gl::GetVertexFormatFromType(vertexFormatType);
...@@ -1248,7 +1314,8 @@ std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType ve ...@@ -1248,7 +1314,8 @@ std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType ve
int shaderComponentCount = VariableComponentCount(shaderAttrib.type); int shaderComponentCount = VariableComponentCount(shaderAttrib.type);
// Perform integer to float conversion (if necessary) // Perform integer to float conversion (if necessary)
bool requiresTypeConversion = (shaderComponentType == GL_FLOAT && vertexFormat.type != GL_FLOAT); bool requiresTypeConversion =
(shaderComponentType == GL_FLOAT && vertexFormat.type != GL_FLOAT);
if (requiresTypeConversion) if (requiresTypeConversion)
{ {
...@@ -1260,5 +1327,4 @@ std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType ve ...@@ -1260,5 +1327,4 @@ std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType ve
// No conversion necessary // No conversion necessary
return attribString; return attribString;
} }
} // namespace rx
}
...@@ -74,26 +74,32 @@ class DynamicHLSL : angle::NonCopyable ...@@ -74,26 +74,32 @@ class DynamicHLSL : angle::NonCopyable
public: public:
explicit DynamicHLSL(RendererD3D *const renderer); explicit DynamicHLSL(RendererD3D *const renderer);
int packVaryings(gl::InfoLog &infoLog, int packVaryings(const gl::Caps &caps,
gl::InfoLog &infoLog,
std::vector<PackedVarying> *packedVaryings, std::vector<PackedVarying> *packedVaryings,
const std::vector<std::string> &transformFeedbackVaryings); const std::vector<std::string> &transformFeedbackVaryings);
std::string generateVertexShaderForInputLayout(const std::string &sourceShader, std::string generateVertexShaderForInputLayout(
const std::string &sourceShader,
const gl::InputLayout &inputLayout, const gl::InputLayout &inputLayout,
const std::vector<sh::Attribute> &shaderAttributes) const; const std::vector<sh::Attribute> &shaderAttributes) const;
std::string generatePixelShaderForOutputSignature(const std::string &sourceShader, const std::vector<PixelShaderOutputVariable> &outputVariables, std::string generatePixelShaderForOutputSignature(
bool usesFragDepth, const std::vector<GLenum> &outputLayout) const; const std::string &sourceShader,
const std::vector<PixelShaderOutputVariable> &outputVariables,
bool usesFragDepth,
const std::vector<GLenum> &outputLayout) const;
bool generateShaderLinkHLSL(const gl::Data &data, bool generateShaderLinkHLSL(const gl::Data &data,
const gl::Program::Data &programData, const gl::Program::Data &programData,
gl::InfoLog &infoLog, gl::InfoLog &infoLog,
int registers, int registers,
std::string &pixelHLSL, std::string *pixelHLSL,
std::string &vertexHLSL, std::string *vertexHLSL,
const std::vector<PackedVarying> &packedVaryings, const std::vector<PackedVarying> &packedVaryings,
std::vector<gl::LinkedVarying> *linkedVaryings, std::vector<gl::LinkedVarying> *linkedVaryings,
std::vector<PixelShaderOutputVariable> *outPixelShaderKey, std::vector<PixelShaderOutputVariable> *outPixelShaderKey,
bool *outUsesFragDepth) const; bool *outUsesFragDepth) const;
std::string generateGeometryShaderHLSL(int registers, std::string generateGeometryShaderHLSL(const gl::Data &data,
int registers,
const ShaderD3D *fragmentShader, const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const; const std::vector<PackedVarying> &packedVaryings) const;
...@@ -103,16 +109,24 @@ class DynamicHLSL : angle::NonCopyable ...@@ -103,16 +109,24 @@ class DynamicHLSL : angle::NonCopyable
struct SemanticInfo; struct SemanticInfo;
std::string getVaryingSemantic(bool pointSize) const; std::string getVaryingSemantic(bool pointSize) const;
SemanticInfo getSemanticInfo(int startRegisters, bool position, bool fragCoord, bool pointCoord, SemanticInfo getSemanticInfo(int startRegisters,
bool pointSize, bool pixelShader) const; bool position,
std::string generateVaryingLinkHLSL(const SemanticInfo &info, const std::string &varyingHLSL) const; bool fragCoord,
std::string generateVaryingHLSL(const std::vector<PackedVarying> &varyings, bool pointCoord,
bool pointSize,
bool pixelShader) const;
std::string generateVaryingLinkHLSL(const SemanticInfo &info,
const std::string &varyingHLSL) const;
std::string generateVaryingHLSL(const gl::Caps &caps,
const std::vector<PackedVarying> &varyings,
bool shaderUsesPointSize) const; bool shaderUsesPointSize) const;
void storeUserLinkedVaryings(const std::vector<PackedVarying> &packedVaryings, void storeUserLinkedVaryings(const std::vector<PackedVarying> &packedVaryings,
bool shaderUsesPointSize, bool shaderUsesPointSize,
std::vector<gl::LinkedVarying> *linkedVaryings) const; std::vector<gl::LinkedVarying> *linkedVaryings) const;
void storeBuiltinLinkedVaryings(const SemanticInfo &info, std::vector<gl::LinkedVarying> *linkedVaryings) const; void storeBuiltinLinkedVaryings(const SemanticInfo &info,
std::string generatePointSpriteHLSL(int registers, std::vector<gl::LinkedVarying> *linkedVaryings) const;
std::string generatePointSpriteHLSL(const gl::Data &data,
int registers,
const ShaderD3D *fragmentShader, const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const; const std::vector<PackedVarying> &packedVaryings) const;
...@@ -122,7 +136,6 @@ class DynamicHLSL : angle::NonCopyable ...@@ -122,7 +136,6 @@ class DynamicHLSL : angle::NonCopyable
std::string generateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType, std::string generateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType,
const sh::ShaderVariable &shaderAttrib) const; const sh::ShaderVariable &shaderAttrib) const;
}; };
} }
#endif // LIBANGLE_RENDERER_D3D_DYNAMICHLSL_H_ #endif // LIBANGLE_RENDERER_D3D_DYNAMICHLSL_H_
...@@ -289,7 +289,8 @@ gl::Error HLSLCompiler::compileToBinary(gl::InfoLog &infoLog, const std::string ...@@ -289,7 +289,8 @@ gl::Error HLSLCompiler::compileToBinary(gl::InfoLog &infoLog, const std::string
return gl::Error(GL_OUT_OF_MEMORY, "HLSL compiler had an unexpected failure, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "HLSL compiler had an unexpected failure, result: 0x%X.", result);
} }
infoLog << "Warning: D3D shader compilation failed with " << configs[i].name << " flags."; infoLog << "Warning: D3D shader compilation failed with " << configs[i].name << " flags. ("
<< profile << ")";
if (i + 1 < configs.size()) if (i + 1 < configs.size())
{ {
......
...@@ -38,14 +38,13 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader) ...@@ -38,14 +38,13 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader)
GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type); GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type);
for (size_t rowIndex = 0; for (size_t rowIndex = 0;
static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); ++rowIndex)
++rowIndex)
{ {
GLenum componentType = gl::VariableComponentType(transposedType); GLenum componentType = gl::VariableComponentType(transposedType);
GLuint components = static_cast<GLuint>(gl::VariableColumnCount(transposedType)); GLuint components = static_cast<GLuint>(gl::VariableColumnCount(transposedType));
bool pureInt = (componentType != GL_FLOAT); bool pureInt = (componentType != GL_FLOAT);
gl::VertexFormatType defaultType = gl::GetVertexFormatType( gl::VertexFormatType defaultType =
componentType, GL_FALSE, components, pureInt); gl::GetVertexFormatType(componentType, GL_FALSE, components, pureInt);
defaultLayout.push_back(defaultType); defaultLayout.push_back(defaultType);
} }
...@@ -55,7 +54,8 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader) ...@@ -55,7 +54,8 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader)
return defaultLayout; return defaultLayout;
} }
std::vector<GLenum> GetDefaultOutputLayoutFromShader(const std::vector<PixelShaderOutputVariable> &shaderOutputVars) std::vector<GLenum> GetDefaultOutputLayoutFromShader(
const std::vector<PixelShaderOutputVariable> &shaderOutputVars)
{ {
std::vector<GLenum> defaultPixelOutput; std::vector<GLenum> defaultPixelOutput;
...@@ -90,8 +90,10 @@ struct AttributeSorter ...@@ -90,8 +90,10 @@ struct AttributeSorter
int indexA = (*originalIndices)[a]; int indexA = (*originalIndices)[a];
int indexB = (*originalIndices)[b]; int indexB = (*originalIndices)[b];
if (indexA == -1) return false; if (indexA == -1)
if (indexB == -1) return true; return false;
if (indexB == -1)
return true;
return (indexA < indexB); return (indexA < indexB);
} }
...@@ -178,6 +180,86 @@ void GetUniformBlockInfo(const std::vector<VarT> &fields, ...@@ -178,6 +180,86 @@ void GetUniformBlockInfo(const std::vector<VarT> &fields,
} }
} }
template <typename T>
bool TransposeMatrix(T *target,
const GLfloat *value,
int targetWidth,
int targetHeight,
int srcWidth,
int srcHeight)
{
bool dirty = false;
int copyWidth = std::min(targetHeight, srcWidth);
int copyHeight = std::min(targetWidth, srcHeight);
for (int x = 0; x < copyWidth; x++)
{
for (int y = 0; y < copyHeight; y++)
{
SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]),
&dirty);
}
}
// clear unfilled right side
for (int y = 0; y < copyWidth; y++)
{
for (int x = copyHeight; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
// clear unfilled bottom.
for (int y = copyWidth; y < targetHeight; y++)
{
for (int x = 0; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
return dirty;
}
template <typename T>
bool ExpandMatrix(T *target,
const GLfloat *value,
int targetWidth,
int targetHeight,
int srcWidth,
int srcHeight)
{
bool dirty = false;
int copyWidth = std::min(targetWidth, srcWidth);
int copyHeight = std::min(targetHeight, srcHeight);
for (int y = 0; y < copyHeight; y++)
{
for (int x = 0; x < copyWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]),
&dirty);
}
}
// clear unfilled right side
for (int y = 0; y < copyHeight; y++)
{
for (int x = copyWidth; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
// clear unfilled bottom.
for (int y = copyHeight; y < targetHeight; y++)
{
for (int x = 0; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
return dirty;
}
} // anonymous namespace } // anonymous namespace
D3DUniform::D3DUniform(GLenum typeIn, D3DUniform::D3DUniform(GLenum typeIn,
...@@ -231,9 +313,7 @@ bool D3DUniform::isReferencedByFragmentShader() const ...@@ -231,9 +313,7 @@ bool D3DUniform::isReferencedByFragmentShader() const
ProgramD3D::VertexExecutable::VertexExecutable(const gl::InputLayout &inputLayout, ProgramD3D::VertexExecutable::VertexExecutable(const gl::InputLayout &inputLayout,
const Signature &signature, const Signature &signature,
ShaderExecutableD3D *shaderExecutable) ShaderExecutableD3D *shaderExecutable)
: mInputs(inputLayout), : mInputs(inputLayout), mSignature(signature), mShaderExecutable(shaderExecutable)
mSignature(signature),
mShaderExecutable(shaderExecutable)
{ {
} }
...@@ -281,8 +361,7 @@ bool ProgramD3D::VertexExecutable::matchesSignature(const Signature &signature) ...@@ -281,8 +361,7 @@ bool ProgramD3D::VertexExecutable::matchesSignature(const Signature &signature)
ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature, ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature,
ShaderExecutableD3D *shaderExecutable) ShaderExecutableD3D *shaderExecutable)
: mOutputSignature(outputSignature), : mOutputSignature(outputSignature), mShaderExecutable(shaderExecutable)
mShaderExecutable(shaderExecutable)
{ {
} }
...@@ -334,7 +413,9 @@ bool ProgramD3D::usesInstancedPointSpriteEmulation() const ...@@ -334,7 +413,9 @@ bool ProgramD3D::usesInstancedPointSpriteEmulation() const
return mRenderer->getWorkarounds().useInstancedPointSpriteEmulation; return mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
} }
GLint ProgramD3D::getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const GLint ProgramD3D::getSamplerMapping(gl::SamplerType type,
unsigned int samplerIndex,
const gl::Caps &caps) const
{ {
GLint logicalTextureUnit = -1; GLint logicalTextureUnit = -1;
...@@ -354,10 +435,12 @@ GLint ProgramD3D::getSamplerMapping(gl::SamplerType type, unsigned int samplerIn ...@@ -354,10 +435,12 @@ GLint ProgramD3D::getSamplerMapping(gl::SamplerType type, unsigned int samplerIn
logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit; logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
} }
break; break;
default: UNREACHABLE(); default:
UNREACHABLE();
} }
if (logicalTextureUnit >= 0 && logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits)) if (logicalTextureUnit >= 0 &&
logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
{ {
return logicalTextureUnit; return logicalTextureUnit;
} }
...@@ -379,7 +462,8 @@ GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samp ...@@ -379,7 +462,8 @@ GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samp
ASSERT(samplerIndex < mSamplersVS.size()); ASSERT(samplerIndex < mSamplersVS.size());
ASSERT(mSamplersVS[samplerIndex].active); ASSERT(mSamplersVS[samplerIndex].active);
return mSamplersVS[samplerIndex].textureType; return mSamplersVS[samplerIndex].textureType;
default: UNREACHABLE(); default:
UNREACHABLE();
} }
return GL_TEXTURE_2D; return GL_TEXTURE_2D;
...@@ -458,8 +542,9 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -458,8 +542,9 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
{ {
reset(); reset();
DeviceIdentifier binaryDeviceIdentifier = { 0 }; DeviceIdentifier binaryDeviceIdentifier = {0};
stream->readBytes(reinterpret_cast<unsigned char*>(&binaryDeviceIdentifier), sizeof(DeviceIdentifier)); stream->readBytes(reinterpret_cast<unsigned char *>(&binaryDeviceIdentifier),
sizeof(DeviceIdentifier));
DeviceIdentifier identifier = mRenderer->getAdapterIdentifier(); DeviceIdentifier identifier = mRenderer->getAdapterIdentifier();
if (memcmp(&identifier, &binaryDeviceIdentifier, sizeof(DeviceIdentifier)) != 0) if (memcmp(&identifier, &binaryDeviceIdentifier, sizeof(DeviceIdentifier)) != 0)
...@@ -545,7 +630,8 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -545,7 +630,8 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
const unsigned int transformFeedbackVaryingCount = stream->readInt<unsigned int>(); const unsigned int transformFeedbackVaryingCount = stream->readInt<unsigned int>();
mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount); mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount);
for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++) for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount;
varyingIndex++)
{ {
gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex]; gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex];
...@@ -558,15 +644,18 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -558,15 +644,18 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
} }
stream->readString(&mVertexHLSL); stream->readString(&mVertexHLSL);
stream->readBytes(reinterpret_cast<unsigned char*>(&mVertexWorkarounds), sizeof(D3DCompilerWorkarounds)); stream->readBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds),
sizeof(D3DCompilerWorkarounds));
stream->readString(&mPixelHLSL); stream->readString(&mPixelHLSL);
stream->readBytes(reinterpret_cast<unsigned char*>(&mPixelWorkarounds), sizeof(D3DCompilerWorkarounds)); stream->readBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
sizeof(D3DCompilerWorkarounds));
stream->readBool(&mUsesFragDepth); stream->readBool(&mUsesFragDepth);
stream->readBool(&mUsesPointSize); stream->readBool(&mUsesPointSize);
const size_t pixelShaderKeySize = stream->readInt<unsigned int>(); const size_t pixelShaderKeySize = stream->readInt<unsigned int>();
mPixelShaderKey.resize(pixelShaderKeySize); mPixelShaderKey.resize(pixelShaderKeySize);
for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKeySize; pixelShaderKeyIndex++) for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKeySize;
pixelShaderKeyIndex++)
{ {
stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].type); stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].type);
stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].name); stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].name);
...@@ -574,10 +663,11 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -574,10 +663,11 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].outputIndex); stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].outputIndex);
} }
const unsigned char* binary = reinterpret_cast<const unsigned char*>(stream->data()); const unsigned char *binary = reinterpret_cast<const unsigned char *>(stream->data());
const unsigned int vertexShaderCount = stream->readInt<unsigned int>(); const unsigned int vertexShaderCount = stream->readInt<unsigned int>();
for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++) for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount;
vertexShaderIndex++)
{ {
size_t inputLayoutSize = stream->readInt<size_t>(); size_t inputLayoutSize = stream->readInt<size_t>();
gl::InputLayout inputLayout(inputLayoutSize, gl::VERTEX_FORMAT_INVALID); gl::InputLayout inputLayout(inputLayoutSize, gl::VERTEX_FORMAT_INVALID);
...@@ -611,7 +701,8 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -611,7 +701,8 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
VertexExecutable::getSignature(mRenderer, inputLayout, &signature); VertexExecutable::getSignature(mRenderer, inputLayout, &signature);
// add new binary // add new binary
mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, shaderExecutable)); mVertexExecutables.push_back(
new VertexExecutable(inputLayout, signature, shaderExecutable));
stream->skip(vertexShaderSize); stream->skip(vertexShaderSize);
} }
...@@ -681,9 +772,11 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -681,9 +772,11 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
{ {
// Output the DeviceIdentifier before we output any shader code // Output the DeviceIdentifier before we output any shader code
// When we load the binary again later, we can validate the device identifier before trying to compile any HLSL // When we load the binary again later, we can validate the device identifier before trying to
// compile any HLSL
DeviceIdentifier binaryIdentifier = mRenderer->getAdapterIdentifier(); DeviceIdentifier binaryIdentifier = mRenderer->getAdapterIdentifier();
stream->writeBytes(reinterpret_cast<unsigned char*>(&binaryIdentifier), sizeof(DeviceIdentifier)); stream->writeBytes(reinterpret_cast<unsigned char *>(&binaryIdentifier),
sizeof(DeviceIdentifier));
stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL); stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
...@@ -743,15 +836,18 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) ...@@ -743,15 +836,18 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
} }
stream->writeString(mVertexHLSL); stream->writeString(mVertexHLSL);
stream->writeBytes(reinterpret_cast<unsigned char*>(&mVertexWorkarounds), sizeof(D3DCompilerWorkarounds)); stream->writeBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds),
sizeof(D3DCompilerWorkarounds));
stream->writeString(mPixelHLSL); stream->writeString(mPixelHLSL);
stream->writeBytes(reinterpret_cast<unsigned char*>(&mPixelWorkarounds), sizeof(D3DCompilerWorkarounds)); stream->writeBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
sizeof(D3DCompilerWorkarounds));
stream->writeInt(mUsesFragDepth); stream->writeInt(mUsesFragDepth);
stream->writeInt(mUsesPointSize); stream->writeInt(mUsesPointSize);
const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey; const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey;
stream->writeInt(pixelShaderKey.size()); stream->writeInt(pixelShaderKey.size());
for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKey.size(); pixelShaderKeyIndex++) for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKey.size();
pixelShaderKeyIndex++)
{ {
const PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex]; const PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex];
stream->writeInt(variable.type); stream->writeInt(variable.type);
...@@ -761,7 +857,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) ...@@ -761,7 +857,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
} }
stream->writeInt(mVertexExecutables.size()); stream->writeInt(mVertexExecutables.size());
for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size(); vertexExecutableIndex++) for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size();
vertexExecutableIndex++)
{ {
VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex]; VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex];
...@@ -781,7 +878,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) ...@@ -781,7 +878,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
} }
stream->writeInt(mPixelExecutables.size()); stream->writeInt(mPixelExecutables.size());
for (size_t pixelExecutableIndex = 0; pixelExecutableIndex < mPixelExecutables.size(); pixelExecutableIndex++) for (size_t pixelExecutableIndex = 0; pixelExecutableIndex < mPixelExecutables.size();
pixelExecutableIndex++)
{ {
PixelExecutable *pixelExecutable = mPixelExecutables[pixelExecutableIndex]; PixelExecutable *pixelExecutable = mPixelExecutables[pixelExecutableIndex];
...@@ -799,7 +897,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) ...@@ -799,7 +897,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
stream->writeBytes(pixelBlob, pixelShaderSize); stream->writeBytes(pixelBlob, pixelShaderSize);
} }
size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0; size_t geometryShaderSize =
(mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
stream->writeInt(geometryShaderSize); stream->writeInt(geometryShaderSize);
if (mGeometryExecutable != NULL && geometryShaderSize > 0) if (mGeometryExecutable != NULL && geometryShaderSize > 0)
...@@ -811,12 +910,14 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) ...@@ -811,12 +910,14 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutableD3D **outExecutable) gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo,
ShaderExecutableD3D **outExecutable)
{ {
mPixelShaderOutputFormatCache.clear(); mPixelShaderOutputFormatCache.clear();
const FramebufferD3D *fboD3D = GetImplAs<FramebufferD3D>(fbo); const FramebufferD3D *fboD3D = GetImplAs<FramebufferD3D>(fbo);
const gl::AttachmentList &colorbuffers = fboD3D->getColorAttachmentsForRender(mRenderer->getWorkarounds()); const gl::AttachmentList &colorbuffers =
fboD3D->getColorAttachmentsForRender(mRenderer->getWorkarounds());
for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment) for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment)
{ {
...@@ -824,7 +925,9 @@ gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fb ...@@ -824,7 +925,9 @@ gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fb
if (colorbuffer) if (colorbuffer)
{ {
mPixelShaderOutputFormatCache.push_back(colorbuffer->getBinding() == GL_BACK ? GL_COLOR_ATTACHMENT0 : colorbuffer->getBinding()); mPixelShaderOutputFormatCache.push_back(colorbuffer->getBinding() == GL_BACK
? GL_COLOR_ATTACHMENT0
: colorbuffer->getBinding());
} }
else else
{ {
...@@ -848,8 +951,8 @@ gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum ...@@ -848,8 +951,8 @@ gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum
} }
} }
std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(mPixelHLSL, mPixelShaderKey, mUsesFragDepth, std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(
outputSignature); mPixelHLSL, mPixelShaderKey, mUsesFragDepth, outputSignature);
// Generate new pixel executable // Generate new pixel executable
ShaderExecutableD3D *pixelExecutable = NULL; ShaderExecutableD3D *pixelExecutable = NULL;
...@@ -917,7 +1020,8 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i ...@@ -917,7 +1020,8 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i
if (vertexExecutable) if (vertexExecutable)
{ {
mVertexExecutables.push_back(new VertexExecutable(inputLayout, mCachedVertexSignature, vertexExecutable)); mVertexExecutables.push_back(
new VertexExecutable(inputLayout, mCachedVertexSignature, vertexExecutable));
} }
else if (!infoLog) else if (!infoLog)
{ {
...@@ -930,7 +1034,8 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i ...@@ -930,7 +1034,8 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, LinkResult ProgramD3D::compileProgramExecutables(const gl::Data &data,
gl::InfoLog &infoLog,
int registers, int registers,
const std::vector<PackedVarying> &packedVaryings) const std::vector<PackedVarying> &packedVaryings)
{ {
...@@ -939,7 +1044,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, ...@@ -939,7 +1044,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
const gl::InputLayout &defaultInputLayout = const gl::InputLayout &defaultInputLayout =
GetDefaultInputLayoutFromShader(mData.getAttachedVertexShader()); GetDefaultInputLayoutFromShader(mData.getAttachedVertexShader());
ShaderExecutableD3D *defaultVertexExecutable = NULL; ShaderExecutableD3D *defaultVertexExecutable = NULL;
gl::Error error = getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog); gl::Error error =
getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog);
if (error.isError()) if (error.isError())
{ {
return LinkResult(false, error); return LinkResult(false, error);
...@@ -947,7 +1053,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, ...@@ -947,7 +1053,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey()); std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey());
ShaderExecutableD3D *defaultPixelExecutable = NULL; ShaderExecutableD3D *defaultPixelExecutable = NULL;
error = getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog); error =
getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog);
if (error.isError()) if (error.isError())
{ {
return LinkResult(false, error); return LinkResult(false, error);
...@@ -955,8 +1062,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, ...@@ -955,8 +1062,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
if (usesGeometryShader()) if (usesGeometryShader())
{ {
std::string geometryHLSL = std::string geometryHLSL = mDynamicHLSL->generateGeometryShaderHLSL(
mDynamicHLSL->generateGeometryShaderHLSL(registers, fragmentShaderD3D, packedVaryings); data, registers, fragmentShaderD3D, packedVaryings);
error = mRenderer->compileToExecutable( error = mRenderer->compileToExecutable(
infoLog, geometryHLSL, SHADER_GEOMETRY, mTransformFeedbackLinkedVaryings, infoLog, geometryHLSL, SHADER_GEOMETRY, mTransformFeedbackLinkedVaryings,
...@@ -973,8 +1080,9 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, ...@@ -973,8 +1080,9 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
if (usesGeometryShader() && mGeometryExecutable) if (usesGeometryShader() && mGeometryExecutable)
{ {
// Geometry shaders are currently only used internally, so there is no corresponding shader object at the interface level // Geometry shaders are currently only used internally, so there is no corresponding shader
// For now the geometry shader debug info is pre-pended to the vertex shader, this is a bit of a clutch // object at the interface level. For now the geometry shader debug info is prepended to
// the vertex shader.
vertexShaderD3D->appendDebugInfo("// GEOMETRY SHADER BEGIN\n\n"); vertexShaderD3D->appendDebugInfo("// GEOMETRY SHADER BEGIN\n\n");
vertexShaderD3D->appendDebugInfo(mGeometryExecutable->getDebugInfo()); vertexShaderD3D->appendDebugInfo(mGeometryExecutable->getDebugInfo());
vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n"); vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n");
...@@ -991,7 +1099,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, ...@@ -991,7 +1099,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
} }
#endif #endif
bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable && (!usesGeometryShader() || mGeometryExecutable)); bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable &&
(!usesGeometryShader() || mGeometryExecutable));
return LinkResult(linkSuccess, gl::Error(GL_NO_ERROR)); return LinkResult(linkSuccess, gl::Error(GL_NO_ERROR));
} }
...@@ -1018,10 +1127,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog) ...@@ -1018,10 +1127,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
mSamplersVS.resize(data.caps->maxVertexTextureImageUnits); mSamplersVS.resize(data.caps->maxVertexTextureImageUnits);
mSamplersPS.resize(data.caps->maxTextureImageUnits); mSamplersPS.resize(data.caps->maxTextureImageUnits);
mVertexHLSL = vertexShader->getTranslatedSource();
vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds); vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds);
mPixelHLSL = fragmentShader->getTranslatedSource();
fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds); fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds);
if (mRenderer->getRendererLimitations().noFrontFacingSupport) if (mRenderer->getRendererLimitations().noFrontFacingSupport)
...@@ -1037,7 +1143,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog) ...@@ -1037,7 +1143,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
MergeVaryings(*vertexShader, *fragmentShader, mData.getTransformFeedbackVaryingNames()); MergeVaryings(*vertexShader, *fragmentShader, mData.getTransformFeedbackVaryingNames());
// Map the varyings to the register file // Map the varyings to the register file
int registers = mDynamicHLSL->packVaryings(infoLog, &packedVaryings, int registers = mDynamicHLSL->packVaryings(*data.caps, infoLog, &packedVaryings,
mData.getTransformFeedbackVaryingNames()); mData.getTransformFeedbackVaryingNames());
if (registers < 0) if (registers < 0)
...@@ -1046,8 +1152,8 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog) ...@@ -1046,8 +1152,8 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
} }
std::vector<gl::LinkedVarying> linkedVaryings; std::vector<gl::LinkedVarying> linkedVaryings;
if (!mDynamicHLSL->generateShaderLinkHLSL(data, mData, infoLog, registers, mPixelHLSL, if (!mDynamicHLSL->generateShaderLinkHLSL(data, mData, infoLog, registers, &mPixelHLSL,
mVertexHLSL, packedVaryings, &linkedVaryings, &mVertexHLSL, packedVaryings, &linkedVaryings,
&mPixelShaderKey, &mUsesFragDepth)) &mPixelShaderKey, &mUsesFragDepth))
{ {
return LinkResult(false, gl::Error(GL_NO_ERROR)); return LinkResult(false, gl::Error(GL_NO_ERROR));
...@@ -1061,7 +1167,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog) ...@@ -1061,7 +1167,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
gatherTransformFeedbackVaryings(linkedVaryings); gatherTransformFeedbackVaryings(linkedVaryings);
LinkResult result = compileProgramExecutables(infoLog, registers, packedVaryings); LinkResult result = compileProgramExecutables(data, infoLog, registers, packedVaryings);
if (result.error.isError() || !result.linkSuccess) if (result.error.isError() || !result.linkSuccess)
{ {
infoLog << "Failed to create D3D shaders."; infoLog << "Failed to create D3D shaders.";
...@@ -1257,7 +1363,7 @@ void ProgramD3D::dirtyAllUniforms() ...@@ -1257,7 +1363,7 @@ void ProgramD3D::dirtyAllUniforms()
} }
} }
void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat* v) void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
{ {
setUniform(location, count, v, GL_FLOAT); setUniform(location, count, v, GL_FLOAT);
} }
...@@ -1277,47 +1383,74 @@ void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) ...@@ -1277,47 +1383,74 @@ void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
setUniform(location, count, v, GL_FLOAT_VEC4); setUniform(location, count, v, GL_FLOAT_VEC4);
} }
void ProgramD3D::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2); setUniformMatrixfv<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2);
} }
void ProgramD3D::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3); setUniformMatrixfv<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3);
} }
void ProgramD3D::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4); setUniformMatrixfv<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4);
} }
void ProgramD3D::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix2x3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3); setUniformMatrixfv<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3);
} }
void ProgramD3D::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix3x2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2); setUniformMatrixfv<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2);
} }
void ProgramD3D::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix2x4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4); setUniformMatrixfv<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4);
} }
void ProgramD3D::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix4x2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2); setUniformMatrixfv<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2);
} }
void ProgramD3D::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix3x4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4); setUniformMatrixfv<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4);
} }
void ProgramD3D::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) void ProgramD3D::setUniformMatrix4x3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value)
{ {
setUniformMatrixfv<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3); setUniformMatrixfv<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3);
} }
...@@ -1515,7 +1648,7 @@ void ProgramD3D::defineUniform(GLenum shaderType, ...@@ -1515,7 +1648,7 @@ void ProgramD3D::defineUniform(GLenum shaderType,
} }
template <typename T> template <typename T>
static inline void SetIfDirty(T *dest, const T& source, bool *dirtyFlag) static inline void SetIfDirty(T *dest, const T &source, bool *dirtyFlag)
{ {
ASSERT(dest != NULL); ASSERT(dest != NULL);
ASSERT(dirtyFlag != NULL); ASSERT(dirtyFlag != NULL);
...@@ -1566,7 +1699,8 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum ...@@ -1566,7 +1699,8 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum
for (int c = 0; c < components; c++) for (int c = 0; c < components; c++)
{ {
SetIfDirty(dest + c, (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE, &targetUniform->dirty); SetIfDirty(dest + c, (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE,
&targetUniform->dirty);
} }
for (int c = components; c < 4; c++) for (int c = components; c < 4; c++)
{ {
...@@ -1585,7 +1719,7 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum ...@@ -1585,7 +1719,7 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
GLint *dest = target + (i * 4); GLint *dest = target + (i * 4);
const GLint *source = reinterpret_cast<const GLint*>(v) + (i * components); const GLint *source = reinterpret_cast<const GLint *>(v) + (i * components);
SetIfDirty(dest + 0, source[0], &targetUniform->dirty); SetIfDirty(dest + 0, source[0], &targetUniform->dirty);
SetIfDirty(dest + 1, 0, &targetUniform->dirty); SetIfDirty(dest + 1, 0, &targetUniform->dirty);
...@@ -1598,75 +1732,8 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum ...@@ -1598,75 +1732,8 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum
mDirtySamplerMapping = true; mDirtySamplerMapping = true;
} }
} }
else UNREACHABLE(); else
} UNREACHABLE();
template<typename T>
bool transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
{
bool dirty = false;
int copyWidth = std::min(targetHeight, srcWidth);
int copyHeight = std::min(targetWidth, srcHeight);
for (int x = 0; x < copyWidth; x++)
{
for (int y = 0; y < copyHeight; y++)
{
SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]), &dirty);
}
}
// clear unfilled right side
for (int y = 0; y < copyWidth; y++)
{
for (int x = copyHeight; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
// clear unfilled bottom.
for (int y = copyWidth; y < targetHeight; y++)
{
for (int x = 0; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
return dirty;
}
template<typename T>
bool expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
{
bool dirty = false;
int copyWidth = std::min(targetWidth, srcWidth);
int copyHeight = std::min(targetHeight, srcHeight);
for (int y = 0; y < copyHeight; y++)
{
for (int x = 0; x < copyWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]), &dirty);
}
}
// clear unfilled right side
for (int y = 0; y < copyHeight; y++)
{
for (int x = copyWidth; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
// clear unfilled bottom.
for (int y = copyHeight; y < targetHeight; y++)
{
for (int x = 0; x < targetWidth; x++)
{
SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
}
}
return dirty;
} }
template <int cols, int rows> template <int cols, int rows>
...@@ -1691,11 +1758,13 @@ void ProgramD3D::setUniformMatrixfv(GLint location, ...@@ -1691,11 +1758,13 @@ void ProgramD3D::setUniformMatrixfv(GLint location,
// Internally store matrices as transposed versions to accomodate HLSL matrix indexing // Internally store matrices as transposed versions to accomodate HLSL matrix indexing
if (transpose == GL_FALSE) if (transpose == GL_FALSE)
{ {
targetUniform->dirty = transposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) || targetUniform->dirty; targetUniform->dirty = TransposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) ||
targetUniform->dirty;
} }
else else
{ {
targetUniform->dirty = expandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty; targetUniform->dirty =
ExpandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty;
} }
target += targetMatrixStride; target += targetMatrixStride;
value += cols * rows; value += cols * rows;
...@@ -1853,7 +1922,8 @@ void ProgramD3D::initAttributesByLayout() ...@@ -1853,7 +1922,8 @@ void ProgramD3D::initAttributesByLayout()
AttributeSorter(mSemanticIndexes)); AttributeSorter(mSemanticIndexes));
} }
void ProgramD3D::sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes, void ProgramD3D::sortAttributesByLayout(
const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const
{ {
......
...@@ -90,7 +90,9 @@ class ProgramD3D : public ProgramImpl ...@@ -90,7 +90,9 @@ class ProgramD3D : public ProgramImpl
const std::vector<PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; } const std::vector<PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
GLint getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const; GLint getSamplerMapping(gl::SamplerType type,
unsigned int samplerIndex,
const gl::Caps &caps) const;
GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const; GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const;
GLint getUsedSamplerRange(gl::SamplerType type) const; GLint getUsedSamplerRange(gl::SamplerType type) const;
void updateSamplerMapping(); void updateSamplerMapping();
...@@ -103,9 +105,14 @@ class ProgramD3D : public ProgramImpl ...@@ -103,9 +105,14 @@ class ProgramD3D : public ProgramImpl
LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream); LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream);
gl::Error save(gl::BinaryOutputStream *stream); gl::Error save(gl::BinaryOutputStream *stream);
gl::Error getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutableD3D **outExectuable); gl::Error getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo,
gl::Error getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputLayout, ShaderExecutableD3D **outExectuable, gl::InfoLog *infoLog); ShaderExecutableD3D **outExectuable);
gl::Error getVertexExecutableForInputLayout(const gl::InputLayout &inputLayout, ShaderExecutableD3D **outExectuable, gl::InfoLog *infoLog); gl::Error getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputLayout,
ShaderExecutableD3D **outExectuable,
gl::InfoLog *infoLog);
gl::Error getVertexExecutableForInputLayout(const gl::InputLayout &inputLayout,
ShaderExecutableD3D **outExectuable,
gl::InfoLog *infoLog);
ShaderExecutableD3D *getGeometryExecutable() const { return mGeometryExecutable; } ShaderExecutableD3D *getGeometryExecutable() const { return mGeometryExecutable; }
LinkResult link(const gl::Data &data, gl::InfoLog &infoLog) override; LinkResult link(const gl::Data &data, gl::InfoLog &infoLog) override;
...@@ -132,15 +139,42 @@ class ProgramD3D : public ProgramImpl ...@@ -132,15 +139,42 @@ class ProgramD3D : public ProgramImpl
void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); void setUniform2uiv(GLint location, GLsizei count, const GLuint *v);
void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); void setUniform3uiv(GLint location, GLsizei count, const GLuint *v);
void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); void setUniform4uiv(GLint location, GLsizei count, const GLuint *v);
void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); void setUniformMatrix2fv(GLint location,
void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLsizei count,
void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLboolean transpose,
void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); const GLfloat *value);
void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); void setUniformMatrix3fv(GLint location,
void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLsizei count,
void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); GLboolean transpose,
void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); const GLfloat *value);
void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); void setUniformMatrix4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformMatrix2x3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformMatrix3x2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformMatrix2x4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformMatrix4x2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformMatrix3x4fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformMatrix4x3fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override; void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override;
...@@ -149,7 +183,8 @@ class ProgramD3D : public ProgramImpl ...@@ -149,7 +183,8 @@ class ProgramD3D : public ProgramImpl
unsigned int getSerial() const; unsigned int getSerial() const;
void sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes, void sortAttributesByLayout(
const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const; const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const;
const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndexes; } const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndexes; }
...@@ -187,10 +222,14 @@ class ProgramD3D : public ProgramImpl ...@@ -187,10 +222,14 @@ class ProgramD3D : public ProgramImpl
class PixelExecutable class PixelExecutable
{ {
public: public:
PixelExecutable(const std::vector<GLenum> &outputSignature, ShaderExecutableD3D *shaderExecutable); PixelExecutable(const std::vector<GLenum> &outputSignature,
ShaderExecutableD3D *shaderExecutable);
~PixelExecutable(); ~PixelExecutable();
bool matchesSignature(const std::vector<GLenum> &signature) const { return mOutputSignature == signature; } bool matchesSignature(const std::vector<GLenum> &signature) const
{
return mOutputSignature == signature;
}
const std::vector<GLenum> &outputSignature() const { return mOutputSignature; } const std::vector<GLenum> &outputSignature() const { return mOutputSignature; }
ShaderExecutableD3D *shaderExecutable() const { return mShaderExecutable; } ShaderExecutableD3D *shaderExecutable() const { return mShaderExecutable; }
...@@ -230,12 +269,17 @@ class ProgramD3D : public ProgramImpl ...@@ -230,12 +269,17 @@ class ProgramD3D : public ProgramImpl
GLuint *outUsedRange); GLuint *outUsedRange);
template <typename T> template <typename T>
void setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType); void setUniform(GLint location, GLsizei count, const T *v, GLenum targetUniformType);
template <int cols, int rows> template <int cols, int rows>
void setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType); void setUniformMatrixfv(GLint location,
GLsizei count,
LinkResult compileProgramExecutables(gl::InfoLog &infoLog, GLboolean transpose,
const GLfloat *value,
GLenum targetUniformType);
LinkResult compileProgramExecutables(const gl::Data &data,
gl::InfoLog &infoLog,
int registers, int registers,
const std::vector<PackedVarying> &packedVaryings); const std::vector<PackedVarying> &packedVaryings);
...@@ -301,7 +345,6 @@ class ProgramD3D : public ProgramImpl ...@@ -301,7 +345,6 @@ class ProgramD3D : public ProgramImpl
static unsigned int issueSerial(); static unsigned int issueSerial();
static unsigned int mCurrentSerial; static unsigned int mCurrentSerial;
}; };
} }
#endif // LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_ #endif // LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
...@@ -21,8 +21,6 @@ struct D3DCompilerWorkarounds; ...@@ -21,8 +21,6 @@ struct D3DCompilerWorkarounds;
class ShaderD3D : public ShaderImpl class ShaderD3D : public ShaderImpl
{ {
friend class DynamicHLSL;
public: public:
ShaderD3D(const gl::Shader::Data &data); ShaderD3D(const gl::Shader::Data &data);
virtual ~ShaderD3D(); virtual ~ShaderD3D();
...@@ -40,10 +38,17 @@ class ShaderD3D : public ShaderImpl ...@@ -40,10 +38,17 @@ class ShaderD3D : public ShaderImpl
void appendDebugInfo(const std::string &info) { mDebugInfo += info; } void appendDebugInfo(const std::string &info) { mDebugInfo += info; }
void generateWorkarounds(D3DCompilerWorkarounds *workarounds) const; void generateWorkarounds(D3DCompilerWorkarounds *workarounds) const;
bool usesDepthRange() const { return mUsesDepthRange; }
bool usesMultipleRenderTargets() const { return mUsesMultipleRenderTargets; }
bool usesFragColor() const { return mUsesFragColor; }
bool usesFragData() const { return mUsesFragData; }
bool usesFragCoord() const { return mUsesFragCoord; }
bool usesFrontFacing() const { return mUsesFrontFacing; }
bool usesPointSize() const { return mUsesPointSize; } bool usesPointSize() const { return mUsesPointSize; }
bool usesPointCoord() const { return mUsesPointCoord; }
bool usesDepthRange() const { return mUsesDepthRange; }
bool usesFragDepth() const { return mUsesFragDepth; }
bool usesDeferredInit() const { return mUsesDeferredInit; } bool usesDeferredInit() const { return mUsesDeferredInit; }
bool usesFrontFacing() const { return mUsesFrontFacing; }
ShShaderOutput getCompilerOutputType() const; ShShaderOutput getCompilerOutputType() const;
...@@ -67,7 +72,6 @@ class ShaderD3D : public ShaderImpl ...@@ -67,7 +72,6 @@ class ShaderD3D : public ShaderImpl
std::map<std::string, unsigned int> mUniformRegisterMap; std::map<std::string, unsigned int> mUniformRegisterMap;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap; std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
}; };
} }
#endif // LIBANGLE_RENDERER_D3D_SHADERD3D_H_ #endif // LIBANGLE_RENDERER_D3D_SHADERD3D_H_
...@@ -381,6 +381,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5650Support) ...@@ -381,6 +381,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5650Support)
ASSERT_EGL_SUCCESS(); ASSERT_EGL_SUCCESS();
GLuint program = createProgram(); GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program); drawWithProgram(program);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
glDeleteProgram(program); glDeleteProgram(program);
...@@ -422,6 +423,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig4444Support) ...@@ -422,6 +423,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig4444Support)
ASSERT_EGL_SUCCESS(); ASSERT_EGL_SUCCESS();
GLuint program = createProgram(); GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program); drawWithProgram(program);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
glDeleteProgram(program); glDeleteProgram(program);
...@@ -463,6 +465,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5551Support) ...@@ -463,6 +465,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5551Support)
ASSERT_EGL_SUCCESS(); ASSERT_EGL_SUCCESS();
GLuint program = createProgram(); GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program); drawWithProgram(program);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
glDeleteProgram(program); glDeleteProgram(program);
...@@ -504,6 +507,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig8880Support) ...@@ -504,6 +507,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig8880Support)
ASSERT_EGL_SUCCESS(); ASSERT_EGL_SUCCESS();
GLuint program = createProgram(); GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program); drawWithProgram(program);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
glDeleteProgram(program); glDeleteProgram(program);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment