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 @@
#include "libANGLE/renderer/d3d/ShaderD3D.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;
......@@ -31,12 +32,17 @@ std::string HLSLComponentTypeString(GLenum componentType)
{
switch (componentType)
{
case GL_UNSIGNED_INT: return "uint";
case GL_INT: return "int";
case GL_UNSIGNED_NORMALIZED:
case GL_SIGNED_NORMALIZED:
case GL_FLOAT: return "float";
default: UNREACHABLE(); return "not-component-type";
case GL_UNSIGNED_INT:
return "uint";
case GL_INT:
return "int";
case GL_UNSIGNED_NORMALIZED:
case GL_SIGNED_NORMALIZED:
case GL_FLOAT:
return "float";
default:
UNREACHABLE();
return "not-component-type";
}
}
......@@ -49,16 +55,27 @@ std::string HLSLMatrixTypeString(GLenum type)
{
switch (type)
{
case GL_FLOAT_MAT2: return "float2x2";
case GL_FLOAT_MAT3: return "float3x3";
case GL_FLOAT_MAT4: return "float4x4";
case GL_FLOAT_MAT2x3: return "float2x3";
case GL_FLOAT_MAT3x2: 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";
case GL_FLOAT_MAT2:
return "float2x2";
case GL_FLOAT_MAT3:
return "float3x3";
case GL_FLOAT_MAT4:
return "float4x4";
case GL_FLOAT_MAT2x3:
return "float2x3";
case GL_FLOAT_MAT3x2:
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,11 +86,13 @@ std::string HLSLTypeString(GLenum 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,
unsigned int location)
const PixelShaderOutputVariable *FindOutputAtLocation(
const std::vector<PixelShaderOutputVariable> &outputVariables,
unsigned int location)
{
for (size_t variableIndex = 0; variableIndex < outputVariables.size(); ++variableIndex)
{
......@@ -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];
......@@ -92,20 +111,20 @@ bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, Vary
{
// Make sure we use transposed matrix types to count registers correctly.
int registers = 0;
int elements = 0;
int elements = 0;
const sh::Varying &varying = *packedVarying->varying;
if (varying.isStruct())
{
registers = HLSLVariableRegisterCount(varying, true) * varying.elementCount();
elements = 4;
elements = 4;
}
else
{
GLenum transposedType = TransposeMatrixType(varying.type);
registers = VariableRowCount(transposedType) * varying.elementCount();
elements = VariableColumnCount(transposedType);
elements = VariableColumnCount(transposedType);
}
if (elements >= 2 && elements <= 4)
......@@ -179,7 +198,7 @@ bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, Vary
}
else if (elements == 1)
{
int space[4] = { 0 };
int space[4] = {0};
for (int y = 0; y < maxVaryingVectors; y++)
{
......@@ -220,7 +239,8 @@ bool PackVarying(PackedVarying *packedVarying, const int maxVaryingVectors, Vary
return true;
}
}
else UNREACHABLE();
else
UNREACHABLE();
return false;
}
......@@ -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
int DynamicHLSL::packVaryings(InfoLog &infoLog,
int DynamicHLSL::packVaryings(const gl::Caps &caps,
InfoLog &infoLog,
std::vector<PackedVarying> *packedVaryings,
const std::vector<std::string> &transformFeedbackVaryings)
{
// TODO (geofflang): Use context's caps
const int maxVaryingVectors = mRenderer->getRendererCaps().maxVaryingVectors;
VaryingPacking packing = {};
std::set<std::string> uniqueVaryingNames;
......@@ -258,7 +277,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
ASSERT(uniqueVaryingNames.count(varying.name) == 0);
if (PackVarying(&packedVarying, maxVaryingVectors, packing))
if (PackVarying(&packedVarying, caps.maxVaryingVectors, packing))
{
uniqueVaryingNames.insert(varying.name);
}
......@@ -286,7 +305,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
const sh::Varying &varying = *packedVarying.varying;
if (transformFeedbackVaryingName == varying.name)
{
if (!PackVarying(&packedVarying, maxVaryingVectors, packing))
if (!PackVarying(&packedVarying, caps.maxVaryingVectors, packing))
{
infoLog << "Could not pack varying " << varying.name;
return -1;
......@@ -309,7 +328,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
// Return the number of used registers
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])
{
......@@ -320,7 +339,8 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog,
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
{
std::string varyingSemantic = getVaryingSemantic(shaderUsesPointSize);
......@@ -365,10 +385,9 @@ std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &v
UNREACHABLE();
}
unsigned int semanticIndex =
elementIndex * variableRows +
packedVarying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors +
packedVarying.registerIndex + row;
unsigned int semanticIndex = elementIndex * variableRows +
packedVarying.columnIndex * caps.maxVaryingVectors +
packedVarying.registerIndex + row;
std::string n = Str(semanticIndex);
std::string typeString;
......@@ -392,20 +411,26 @@ std::string DynamicHLSL::generateVaryingHLSL(const std::vector<PackedVarying> &v
return varyingHLSL;
}
std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &sourceShader,
const InputLayout &inputLayout,
const std::vector<sh::Attribute> &shaderAttributes) const
std::string DynamicHLSL::generateVertexShaderForInputLayout(
const std::string &sourceShader,
const InputLayout &inputLayout,
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;
// If gl_PointSize is used in the shader then pointsprites rendering is expected.
// If the renderer does not support Geometry shaders then Instanced PointSprite emulation
// must be used.
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
// 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
// before per instance data in the shader.
if (useInstancedPointSpriteEmulation)
{
structHLSL += " float3 spriteVertexPos : SPRITEPOSITION0;\n";
structHLSL += " float2 spriteTexCoord : SPRITETEXCOORD0;\n";
structStream << " float3 spriteVertexPos : SPRITEPOSITION0;\n"
<< " float2 spriteTexCoord : SPRITETEXCOORD0;\n";
}
for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); ++attributeIndex)
......@@ -434,7 +459,8 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
if (IsMatrixType(shaderAttribute.type))
{
// Matrix types are always transposed
structHLSL += " " + HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type));
structStream << " "
<< HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type));
}
else
{
......@@ -442,31 +468,34 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
if (shaderAttribute.name == "gl_InstanceID")
{
// The input type of the instance ID in HLSL (uint) differs from the one in ESSL (int).
structHLSL += " uint";
// The input type of the instance ID in HLSL (uint) differs from the one in ESSL
// (int).
structStream << " uint";
}
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")
{
structHLSL += "SV_InstanceID";
structStream << "SV_InstanceID";
}
else
{
structHLSL += "TEXCOORD" + Str(semanticIndex);
structStream << "TEXCOORD" << semanticIndex;
semanticIndex += VariableRegisterCount(shaderAttribute.type);
}
structHLSL += ";\n";
structStream << ";\n";
// HLSL code for initialization
initHLSL += " " + decorateVariable(shaderAttribute.name) + " = ";
initStream << " " << decorateVariable(shaderAttribute.name) << " = ";
// Mismatched vertex attribute to vertex input may result in an undefined
// data reinterpretation (eg for pure integer->float, float->pure integer)
......@@ -474,46 +503,48 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
if (IsMatrixType(shaderAttribute.type) ||
(mRenderer->getVertexConversionType(vertexFormatType) & VERTEX_CONVERT_GPU) != 0)
{
initHLSL += generateAttributeConversionHLSL(vertexFormatType, shaderAttribute);
initStream << generateAttributeConversionHLSL(vertexFormatType, shaderAttribute);
}
else
{
initHLSL += "input." + decorateVariable(shaderAttribute.name);
initStream << "input." << decorateVariable(shaderAttribute.name);
}
initHLSL += ";\n";
initStream << ";\n";
inputIndex += VariableRowCount(TransposeMatrixType(shaderAttribute.type));
}
}
std::string replacementHLSL = "struct VS_INPUT\n"
"{\n" +
structHLSL +
"};\n"
"\n"
"void initAttributes(VS_INPUT input)\n"
"{\n" +
initHLSL +
"}\n";
structStream << "};\n"
"\n"
"void initAttributes(VS_INPUT input)\n"
"{\n"
<< initStream.str() << "}\n";
std::string vertexHLSL(sourceShader);
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;
}
std::string DynamicHLSL::generatePixelShaderForOutputSignature(const std::string &sourceShader, const std::vector<PixelShaderOutputVariable> &outputVariables,
bool usesFragDepth, const std::vector<GLenum> &outputLayout) const
std::string DynamicHLSL::generatePixelShaderForOutputSignature(
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 depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH";
std::string depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH";
std::string declarationHLSL;
std::string copyHLSL;
std::stringstream declarationStream;
std::stringstream copyStream;
declarationStream << "struct PS_OUTPUT\n"
"{\n";
for (size_t layoutIndex = 0; layoutIndex < outputLayout.size(); ++layoutIndex)
{
......@@ -523,44 +554,44 @@ std::string DynamicHLSL::generatePixelShaderForOutputSignature(const std::string
{
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
// 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.
if (outputVariable)
{
declarationHLSL += " " + HLSLTypeString(outputVariable->type) + " " +
outputVariable->name + " : " + targetSemantic +
Str(static_cast<int>(layoutIndex)) + ";\n";
declarationStream << " " + HLSLTypeString(outputVariable->type) << " "
<< outputVariable->name << " : " << targetSemantic
<< static_cast<int>(layoutIndex) << ";\n";
copyHLSL += " output." + outputVariable->name + " = " + outputVariable->source + ";\n";
copyStream << " output." << outputVariable->name << " = "
<< outputVariable->source << ";\n";
}
}
}
if (usesFragDepth)
{
declarationHLSL += " float gl_Depth : " + depthSemantic + ";\n";
copyHLSL += " output.gl_Depth = gl_Depth; \n";
declarationStream << " float gl_Depth : " << depthSemantic << ";\n";
copyStream << " output.gl_Depth = gl_Depth; \n";
}
std::string replacementHLSL = "struct PS_OUTPUT\n"
"{\n" +
declarationHLSL +
"};\n"
"\n"
"PS_OUTPUT generateOutput()\n"
"{\n"
" PS_OUTPUT output;\n" +
copyHLSL +
" return output;\n"
"}\n";
declarationStream << "};\n"
"\n"
"PS_OUTPUT generateOutput()\n"
"{\n"
" PS_OUTPUT output;\n"
<< copyStream.str() << " return output;\n"
"}\n";
std::string pixelHLSL(sourceShader);
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;
}
......@@ -577,34 +608,27 @@ struct DynamicHLSL::SemanticInfo
{
struct BuiltinInfo
{
BuiltinInfo()
: enabled(false),
index(0),
systemValue(false)
{}
BuiltinInfo() : enabled(false), index(0), systemValue(false) {}
bool enabled;
std::string semantic;
unsigned int index;
bool systemValue;
std::string str() const
{
return (systemValue ? semantic : (semantic + Str(index)));
}
std::string str() const { return (systemValue ? semantic : (semantic + Str(index))); }
void enableSystem(const std::string &systemValueSemantic)
{
enabled = true;
semantic = systemValueSemantic;
enabled = true;
semantic = systemValueSemantic;
systemValue = true;
}
void enable(const std::string &semanticVal, unsigned int indexVal)
{
enabled = true;
enabled = true;
semantic = semanticVal;
index = indexVal;
index = indexVal;
}
};
......@@ -615,11 +639,15 @@ struct DynamicHLSL::SemanticInfo
BuiltinInfo glPointSize;
};
DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters, bool position, bool fragCoord,
bool pointCoord, bool pointSize, bool pixelShader) const
DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters,
bool position,
bool fragCoord,
bool pointCoord,
bool pointSize,
bool pixelShader) const
{
SemanticInfo info;
bool hlsl4 = (mRenderer->getMajorShaderModel() >= 4);
bool hlsl4 = (mRenderer->getMajorShaderModel() >= 4);
const std::string &varyingSemantic = getVaryingSemantic(pointSize);
int reservedRegisterIndex = startRegisters;
......@@ -670,7 +698,8 @@ DynamicHLSL::SemanticInfo DynamicHLSL::getSemanticInfo(int startRegisters, bool
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";
......@@ -697,7 +726,8 @@ std::string DynamicHLSL::generateVaryingLinkHLSL(const SemanticInfo &info, const
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 += "};\n";
......@@ -710,14 +740,15 @@ void DynamicHLSL::storeBuiltinLinkedVaryings(const SemanticInfo &info,
{
if (info.glPosition.enabled)
{
linkedVaryings->push_back(LinkedVarying("gl_Position", GL_FLOAT_VEC4, 1, info.glPosition.semantic,
info.glPosition.index, 1));
linkedVaryings->push_back(LinkedVarying(
"gl_Position", GL_FLOAT_VEC4, 1, info.glPosition.semantic, info.glPosition.index, 1));
}
if (info.glFragCoord.enabled)
{
linkedVaryings->push_back(LinkedVarying("gl_FragCoord", GL_FLOAT_VEC4, 1, info.glFragCoord.semantic,
info.glFragCoord.index, 1));
linkedVaryings->push_back(LinkedVarying("gl_FragCoord", GL_FLOAT_VEC4, 1,
info.glFragCoord.semantic, info.glFragCoord.index,
1));
}
if (info.glPointSize.enabled)
......@@ -740,7 +771,7 @@ void DynamicHLSL::storeUserLinkedVaryings(const std::vector<PackedVarying> &pack
ASSERT(!varying.isBuiltIn());
GLenum transposedType = TransposeMatrixType(varying.type);
int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
linkedVaryings->push_back(
LinkedVarying(varying.name, varying.type, varying.elementCount(), varyingSemantic,
......@@ -753,45 +784,43 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
const gl::Program::Data &programData,
InfoLog &infoLog,
int registers,
std::string &pixelHLSL,
std::string &vertexHLSL,
std::string *pixelHLSL,
std::string *vertexHLSL,
const std::vector<PackedVarying> &packedVaryings,
std::vector<LinkedVarying> *linkedVaryings,
std::vector<PixelShaderOutputVariable> *outPixelShaderKey,
bool *outUsesFragDepth) const
{
if (pixelHLSL.empty() || vertexHLSL.empty())
{
return false;
}
ASSERT(pixelHLSL->empty() && vertexHLSL->empty());
const gl::Shader *vertexShaderGL = programData.getAttachedVertexShader();
const ShaderD3D *vertexShader = GetImplAs<ShaderD3D>(vertexShaderGL);
const gl::Shader *fragmentShaderGL = programData.getAttachedFragmentShader();
const ShaderD3D *fragmentShader = GetImplAs<ShaderD3D>(fragmentShaderGL);
bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
bool usesFragCoord = fragmentShader->mUsesFragCoord;
bool usesPointCoord = fragmentShader->mUsesPointCoord;
bool usesPointSize = vertexShader->mUsesPointSize;
bool useInstancedPointSpriteEmulation = usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
bool usesMRT = fragmentShader->usesMultipleRenderTargets();
bool usesFragCoord = fragmentShader->usesFragCoord();
bool usesPointCoord = fragmentShader->usesPointCoord();
bool usesPointSize = vertexShader->usesPointSize();
bool useInstancedPointSpriteEmulation =
usesPointSize && mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
// Validation done in the compiler
ASSERT(!fragmentShader->mUsesFragColor || !fragmentShader->mUsesFragData);
ASSERT(!fragmentShader->usesFragColor() || !fragmentShader->usesFragData());
// Write the HLSL input/output declarations
const int shaderModel = mRenderer->getMajorShaderModel();
const int shaderModel = mRenderer->getMajorShaderModel();
const int registersNeeded = registers + (usesFragCoord ? 1 : 0) + (usesPointCoord ? 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 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);
// gl_Position only needs to be outputted from the vertex shader if transform feedback is active.
// This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from the vertex shader in this case.
// This saves us 1 output vector.
// gl_Position only needs to be outputted from the vertex shader if transform feedback is
// active. This isn't supported on D3D11 Feature Level 9_3, so we don't output gl_Position from
// the vertex shader in this case. This saves us 1 output vector.
bool outputPositionFromVS = !(shaderModel >= 4 && mRenderer->getShaderModelSuffix() != "");
int shaderVersion = vertexShaderGL->getShaderVersion();
......@@ -802,78 +831,87 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
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
// structure to ensure compatibility with the generated PS_INPUT of the pixel shader.
// Instanced PointSprite emulation requires that gl_PointCoord is present in the vertex 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
// GS_OUTPUT of the Geometry shader contains the pointCoord value and already matches the PS_INPUT of the
// generated pixel shader.
// The Geometry Shader point sprite implementation needs gl_PointSize to be in VS_OUTPUT and GS_INPUT.
// Instanced point sprites doesn't need gl_PointSize in VS_OUTPUT.
const SemanticInfo &vertexSemantics = getSemanticInfo(registers, outputPositionFromVS,
usesFragCoord, (useInstancedPointSpriteEmulation && usesPointCoord),
(!useInstancedPointSpriteEmulation && usesPointSize), false);
// GS_OUTPUT of the Geometry shader contains the pointCoord value and already matches the
// PS_INPUT of the generated pixel shader. The Geometry Shader point sprite implementation needs
// gl_PointSize to be in VS_OUTPUT and GS_INPUT. Instanced point sprites doesn't need
// gl_PointSize in VS_OUTPUT.
const SemanticInfo &vertexSemantics =
getSemanticInfo(registers, outputPositionFromVS, usesFragCoord,
(useInstancedPointSpriteEmulation && usesPointCoord),
(!useInstancedPointSpriteEmulation && usesPointSize), false);
storeUserLinkedVaryings(packedVaryings, usesPointSize, linkedVaryings);
storeBuiltinLinkedVaryings(vertexSemantics, linkedVaryings);
std::stringstream vertexStream;
vertexStream << vertexShaderGL->getTranslatedSource();
// 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)
{
vertexHLSL += "static float minPointSize = " + Str((int)mRenderer->getRendererCaps().minAliasedPointSize) + ".0f;\n"
"static float maxPointSize = " + Str((int)mRenderer->getRendererCaps().maxAliasedPointSize) + ".0f;\n";
vertexStream << "static float minPointSize = "
<< 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
vertexHLSL += "\n" + VERTEX_ATTRIBUTE_STUB_STRING + "\n"
"struct VS_OUTPUT\n" + generateVaryingLinkHLSL(vertexSemantics, varyingHLSL) + "\n"
"VS_OUTPUT main(VS_INPUT input)\n"
"{\n"
" initAttributes(input);\n";
vertexStream << "\n" << VERTEX_ATTRIBUTE_STUB_STRING + "\n"
<< "struct VS_OUTPUT\n" + generateVaryingLinkHLSL(vertexSemantics, varyingHLSL) +
"\n"
<< "VS_OUTPUT main(VS_INPUT input)\n"
<< "{\n"
<< " initAttributes(input);\n";
if (vertexShader->usesDeferredInit())
{
vertexHLSL += "\n"
" initializeDeferredGlobals();\n";
vertexStream << "\n"
<< " initializeDeferredGlobals();\n";
}
vertexHLSL += "\n"
" gl_main();\n"
"\n"
" VS_OUTPUT output;\n";
vertexStream << "\n"
<< " gl_main();\n"
<< "\n"
<< " VS_OUTPUT output;\n";
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.
if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
if (shaderModel >= 4 && mRenderer->getShaderModelSuffix() == "")
{
vertexHLSL += " output.dx_Position.x = gl_Position.x;\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.w = gl_Position.w;\n";
vertexStream << " output.dx_Position.x = gl_Position.x;\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.w = gl_Position.w;\n";
}
else
{
vertexHLSL += " output.dx_Position.x = gl_Position.x * dx_ViewAdjust.z + dx_ViewAdjust.x * gl_Position.w;\n"
" output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + 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";
vertexStream << " output.dx_Position.x = gl_Position.x * dx_ViewAdjust.z + "
"dx_ViewAdjust.x * gl_Position.w;\n"
<< " output.dx_Position.y = -(gl_Position.y * dx_ViewAdjust.w + "
"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.
if (usesPointSize && shaderModel >= 3 && !useInstancedPointSpriteEmulation)
{
vertexHLSL += " output.gl_PointSize = gl_PointSize;\n";
vertexStream << " output.gl_PointSize = gl_PointSize;\n";
}
if (usesFragCoord)
{
vertexHLSL += " output.gl_FragCoord = gl_Position;\n";
vertexStream << " output.gl_FragCoord = gl_Position;\n";
}
for (const PackedVarying &packedVarying : packedVaryings)
......@@ -895,21 +933,19 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
int r = packedVarying.registerIndex +
packedVarying.columnIndex * data.caps->maxVaryingVectors +
elementIndex * variableRows + row;
vertexHLSL += " output.v" + Str(r);
vertexHLSL += " = _" + varying.name;
vertexStream << " output.v" << r << " = _" + varying.name;
if (varying.isArray())
{
vertexHLSL += ArrayString(elementIndex);
vertexStream << ArrayString(elementIndex);
}
if (variableRows > 1)
{
vertexHLSL += ArrayString(row);
vertexStream << ArrayString(row);
}
vertexHLSL += ";\n";
vertexStream << ";\n";
}
}
}
......@@ -918,40 +954,50 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
// the final output vertex positions of the quad that represents each sprite.
if (useInstancedPointSpriteEmulation)
{
vertexHLSL += "\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";
vertexStream << "\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";
if (usesPointCoord)
{
vertexHLSL += "\n"
" output.gl_PointCoord = input.spriteTexCoord;\n";
vertexStream << "\n"
<< " output.gl_PointCoord = input.spriteTexCoord;\n";
}
}
vertexHLSL += "\n"
" return output;\n"
"}\n";
vertexStream << "\n"
<< " return output;\n"
<< "}\n";
std::stringstream pixelStream;
pixelStream << fragmentShaderGL->getTranslatedSource();
const SemanticInfo &pixelSemantics = getSemanticInfo(registers, outputPositionFromVS, usesFragCoord, usesPointCoord,
(!useInstancedPointSpriteEmulation && usesPointSize), true);
const SemanticInfo &pixelSemantics =
getSemanticInfo(registers, outputPositionFromVS, usesFragCoord, usesPointCoord,
(!useInstancedPointSpriteEmulation && usesPointSize), true);
pixelHLSL += "struct PS_INPUT\n" + generateVaryingLinkHLSL(pixelSemantics, varyingHLSL) + "\n";
pixelStream << "struct PS_INPUT\n" << generateVaryingLinkHLSL(pixelSemantics, varyingHLSL)
<< "\n";
if (shaderVersion < 300)
{
for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets; renderTargetIndex++)
for (unsigned int renderTargetIndex = 0; renderTargetIndex < numRenderTargets;
renderTargetIndex++)
{
PixelShaderOutputVariable outputKeyVariable;
outputKeyVariable.type = GL_FLOAT_VEC4;
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;
outPixelShaderKey->push_back(outputKeyVariable);
}
*outUsesFragDepth = fragmentShader->mUsesFragDepth;
*outUsesFragDepth = fragmentShader->usesFragDepth();
}
else
{
......@@ -962,14 +1008,15 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
const VariableLocation &outputLocation = outputPair.second;
const sh::ShaderVariable &outputVariable = shaderOutputVars[outputLocation.index];
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);
PixelShaderOutputVariable outputKeyVariable;
outputKeyVariable.type = outputVariable.type;
outputKeyVariable.name = variableName + elementString;
outputKeyVariable.source = variableName + ArrayString(outputLocation.element);
outputKeyVariable.type = outputVariable.type;
outputKeyVariable.name = variableName + elementString;
outputKeyVariable.source = variableName + ArrayString(outputLocation.element);
outputKeyVariable.outputIndex = outputPair.first;
outPixelShaderKey->push_back(outputKeyVariable);
......@@ -978,69 +1025,74 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
*outUsesFragDepth = false;
}
pixelHLSL += PIXEL_OUTPUT_STUB_STRING + "\n";
pixelStream << PIXEL_OUTPUT_STUB_STRING + "\n";
if (fragmentShader->mUsesFrontFacing)
if (fragmentShader->usesFrontFacing())
{
if (shaderModel >= 4)
{
pixelHLSL += "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n"
"{\n";
pixelStream << "PS_OUTPUT main(PS_INPUT input, bool isFrontFace : SV_IsFrontFace)\n"
<< "{\n";
}
else
{
pixelHLSL += "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n"
"{\n";
pixelStream << "PS_OUTPUT main(PS_INPUT input, float vFace : VFACE)\n"
<< "{\n";
}
}
else
{
pixelHLSL += "PS_OUTPUT main(PS_INPUT input)\n"
"{\n";
pixelStream << "PS_OUTPUT main(PS_INPUT input)\n"
<< "{\n";
}
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.
// 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() == "")
{
pixelHLSL += " gl_FragCoord.x = input.dx_Position.x;\n"
" gl_FragCoord.y = input.dx_Position.y;\n";
pixelStream << " gl_FragCoord.x = input.dx_Position.x;\n"
<< " gl_FragCoord.y = input.dx_Position.y;\n";
}
else if (shaderModel == 3)
{
pixelHLSL += " gl_FragCoord.x = input.dx_Position.x + 0.5;\n"
" gl_FragCoord.y = input.dx_Position.y + 0.5;\n";
pixelStream << " gl_FragCoord.x = input.dx_Position.x + 0.5;\n"
<< " gl_FragCoord.y = input.dx_Position.y + 0.5;\n";
}
else
{
// dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See Renderer::setViewport()
pixelHLSL += " 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";
// dx_ViewCoords contains the viewport width/2, height/2, center.x and center.y. See
// Renderer::setViewport()
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"
" gl_FragCoord.w = rhw;\n";
pixelStream << " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_DepthFront.x + "
"dx_DepthFront.y;\n"
<< " gl_FragCoord.w = rhw;\n";
}
if (usesPointCoord && shaderModel >= 3)
{
pixelHLSL += " gl_PointCoord.x = input.gl_PointCoord.x;\n";
pixelHLSL += " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n";
pixelStream << " gl_PointCoord.x = input.gl_PointCoord.x;\n"
<< " gl_PointCoord.y = 1.0 - input.gl_PointCoord.y;\n";
}
if (fragmentShader->mUsesFrontFacing)
if (fragmentShader->usesFrontFacing())
{
if (shaderModel <= 3)
{
pixelHLSL += " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n";
pixelStream << " gl_FrontFacing = (vFace * dx_DepthFront.z >= 0.0);\n";
}
else
{
pixelHLSL += " gl_FrontFacing = isFrontFace;\n";
pixelStream << " gl_FrontFacing = isFrontFace;\n";
}
}
......@@ -1068,21 +1120,21 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
std::string n = Str(packedVarying.registerIndex +
packedVarying.columnIndex * data.caps->maxVaryingVectors +
elementIndex * variableRows + row);
pixelHLSL += " _" + varying.name;
pixelStream << " _" + varying.name;
if (varying.isArray())
{
pixelHLSL += ArrayString(elementIndex);
pixelStream << ArrayString(elementIndex);
}
if (variableRows > 1)
{
pixelHLSL += ArrayString(row);
pixelStream << ArrayString(row);
}
if (varying.isStruct())
{
pixelHLSL += " = input.v" + n + ";\n";
pixelStream << " = input.v" << n << ";\n";
break;
}
else
......@@ -1090,16 +1142,16 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
switch (VariableColumnCount(transposedType))
{
case 1:
pixelHLSL += " = input.v" + n + ".x;\n";
pixelStream << " = input.v" << n << ".x;\n";
break;
case 2:
pixelHLSL += " = input.v" + n + ".xy;\n";
pixelStream << " = input.v" << n << ".xy;\n";
break;
case 3:
pixelHLSL += " = input.v" + n + ".xyz;\n";
pixelStream << " = input.v" << n << ".xyz;\n";
break;
case 4:
pixelHLSL += " = input.v" + n + ";\n";
pixelStream << " = input.v" << n << ";\n";
break;
default:
UNREACHABLE();
......@@ -1111,30 +1163,35 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
if (fragmentShader->usesDeferredInit())
{
pixelHLSL += "\n"
" initializeDeferredGlobals();\n";
pixelStream << "\n"
<< " initializeDeferredGlobals();\n";
}
pixelHLSL += "\n"
" gl_main();\n"
"\n"
" return generateOutput();\n"
"}\n";
pixelStream << "\n"
<< " gl_main();\n"
<< "\n"
<< " return generateOutput();\n"
<< "}\n";
*vertexHLSL = vertexStream.str();
*pixelHLSL = pixelStream.str();
return true;
}
std::string DynamicHLSL::generateGeometryShaderHLSL(
const gl::Data &data,
int registers,
const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const
{
// for now we only handle point sprite emulation
ASSERT(mRenderer->getMajorShaderModel() >= 4);
return generatePointSpriteHLSL(registers, fragmentShader, packedVaryings);
return generatePointSpriteHLSL(data, registers, fragmentShader, packedVaryings);
}
std::string DynamicHLSL::generatePointSpriteHLSL(
const gl::Data &data,
int registers,
const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const
......@@ -1142,83 +1199,91 @@ std::string DynamicHLSL::generatePointSpriteHLSL(
ASSERT(registers >= 0);
ASSERT(mRenderer->getMajorShaderModel() >= 4);
std::string geomHLSL;
bool usesFragCoord = fragmentShader->usesFragCoord();
bool usesPointCoord = fragmentShader->usesPointCoord();
const SemanticInfo &inSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord,
false, true, false);
const SemanticInfo &outSemantics = getSemanticInfo(registers, true, fragmentShader->mUsesFragCoord,
fragmentShader->mUsesPointCoord, true, false);
std::stringstream shaderStream;
const SemanticInfo &inSemantics =
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.
std::string varyingHLSL = generateVaryingHLSL(packedVaryings, true);
std::string inLinkHLSL = generateVaryingLinkHLSL(inSemantics, varyingHLSL);
std::string varyingHLSL = generateVaryingHLSL(*data.caps, packedVaryings, true);
std::string inLinkHLSL = generateVaryingLinkHLSL(inSemantics, varyingHLSL);
std::string outLinkHLSL = generateVaryingLinkHLSL(outSemantics, varyingHLSL);
// TODO(geofflang): use context's caps
geomHLSL += "uniform float4 dx_ViewCoords : register(c1);\n"
"\n"
"struct GS_INPUT\n" + inLinkHLSL + "\n" +
"struct GS_OUTPUT\n" + outLinkHLSL + "\n" +
"\n"
"static float2 pointSpriteCorners[] = \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"
"};\n"
"\n"
"static float2 pointSpriteTexcoords[] = \n"
"{\n"
" float2(1.0f, 1.0f),\n"
" float2(1.0f, 0.0f),\n"
" float2(0.0f, 1.0f),\n"
" float2(0.0f, 0.0f)\n"
"};\n"
"\n"
"static float minPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().minAliasedPointSize)) + ".0f;\n"
"static float maxPointSize = " + Str(static_cast<int>(mRenderer->getRendererCaps().maxAliasedPointSize)) + ".0f;\n"
"\n"
"[maxvertexcount(4)]\n"
"void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n"
"{\n"
" GS_OUTPUT output = (GS_OUTPUT)0;\n"
" output.gl_Position = input[0].gl_Position;\n"
" output.gl_PointSize = input[0].gl_PointSize;\n";
shaderStream
<< "uniform float4 dx_ViewCoords : register(c1);\n"
<< "\n"
<< "struct GS_INPUT\n" << inLinkHLSL << "\n"
<< "struct GS_OUTPUT\n" << outLinkHLSL << "\n"
<< "\n"
<< "static float2 pointSpriteCorners[] = \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"
<< "};\n"
<< "\n"
<< "static float2 pointSpriteTexcoords[] = \n"
<< "{\n"
<< " float2(1.0f, 1.0f),\n"
<< " float2(1.0f, 0.0f),\n"
<< " float2(0.0f, 1.0f),\n"
<< " float2(0.0f, 0.0f)\n"
<< "};\n"
<< "\n"
<< "static float minPointSize = " << static_cast<int>(data.caps->minAliasedPointSize)
<< ".0f;\n"
<< "static float maxPointSize = " << static_cast<int>(data.caps->maxAliasedPointSize)
<< ".0f;\n"
<< "\n"
<< "[maxvertexcount(4)]\n"
<< "void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n"
<< "{\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++)
{
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"
" float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\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";
shaderStream
<< " \n"
<< " float gl_PointSize = clamp(input[0].gl_PointSize, minPointSize, maxPointSize);\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++)
{
geomHLSL += " \n"
" output.dx_Position = dx_Position + float4(pointSpriteCorners[" + Str(corner) + "] * viewportScale * gl_PointSize, 0.0f, 0.0f);\n";
shaderStream << " \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"
" outStream.RestartStrip();\n"
"}\n";
shaderStream << " \n"
<< " outStream.RestartStrip();\n"
<< "}\n";
return geomHLSL;
return shaderStream.str();
}
// This method needs to match OutputHLSL::decorate
......@@ -1232,11 +1297,12 @@ std::string DynamicHLSL::decorateVariable(const std::string &name)
return name;
}
std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType,
const sh::ShaderVariable &shaderAttrib) const
std::string DynamicHLSL::generateAttributeConversionHLSL(
gl::VertexFormatType vertexFormatType,
const sh::ShaderVariable &shaderAttrib) const
{
const gl::VertexFormat &vertexFormat = gl::GetVertexFormatFromType(vertexFormatType);
std::string attribString = "input." + decorateVariable(shaderAttrib.name);
std::string attribString = "input." + decorateVariable(shaderAttrib.name);
// Matrix
if (IsMatrixType(shaderAttrib.type))
......@@ -1245,10 +1311,11 @@ std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType ve
}
GLenum shaderComponentType = VariableComponentType(shaderAttrib.type);
int shaderComponentCount = VariableComponentCount(shaderAttrib.type);
int shaderComponentCount = VariableComponentCount(shaderAttrib.type);
// 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)
{
......@@ -1260,5 +1327,4 @@ std::string DynamicHLSL::generateAttributeConversionHLSL(gl::VertexFormatType ve
// No conversion necessary
return attribString;
}
}
} // namespace rx
......@@ -74,26 +74,32 @@ class DynamicHLSL : angle::NonCopyable
public:
explicit DynamicHLSL(RendererD3D *const renderer);
int packVaryings(gl::InfoLog &infoLog,
int packVaryings(const gl::Caps &caps,
gl::InfoLog &infoLog,
std::vector<PackedVarying> *packedVaryings,
const std::vector<std::string> &transformFeedbackVaryings);
std::string generateVertexShaderForInputLayout(const std::string &sourceShader,
const gl::InputLayout &inputLayout,
const std::vector<sh::Attribute> &shaderAttributes) const;
std::string generatePixelShaderForOutputSignature(const std::string &sourceShader, const std::vector<PixelShaderOutputVariable> &outputVariables,
bool usesFragDepth, const std::vector<GLenum> &outputLayout) const;
std::string generateVertexShaderForInputLayout(
const std::string &sourceShader,
const gl::InputLayout &inputLayout,
const std::vector<sh::Attribute> &shaderAttributes) const;
std::string generatePixelShaderForOutputSignature(
const std::string &sourceShader,
const std::vector<PixelShaderOutputVariable> &outputVariables,
bool usesFragDepth,
const std::vector<GLenum> &outputLayout) const;
bool generateShaderLinkHLSL(const gl::Data &data,
const gl::Program::Data &programData,
gl::InfoLog &infoLog,
int registers,
std::string &pixelHLSL,
std::string &vertexHLSL,
std::string *pixelHLSL,
std::string *vertexHLSL,
const std::vector<PackedVarying> &packedVaryings,
std::vector<gl::LinkedVarying> *linkedVaryings,
std::vector<PixelShaderOutputVariable> *outPixelShaderKey,
bool *outUsesFragDepth) const;
std::string generateGeometryShaderHLSL(int registers,
std::string generateGeometryShaderHLSL(const gl::Data &data,
int registers,
const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const;
......@@ -103,16 +109,24 @@ class DynamicHLSL : angle::NonCopyable
struct SemanticInfo;
std::string getVaryingSemantic(bool pointSize) const;
SemanticInfo getSemanticInfo(int startRegisters, bool position, bool fragCoord, bool pointCoord,
bool pointSize, bool pixelShader) const;
std::string generateVaryingLinkHLSL(const SemanticInfo &info, const std::string &varyingHLSL) const;
std::string generateVaryingHLSL(const std::vector<PackedVarying> &varyings,
SemanticInfo getSemanticInfo(int startRegisters,
bool position,
bool fragCoord,
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;
void storeUserLinkedVaryings(const std::vector<PackedVarying> &packedVaryings,
bool shaderUsesPointSize,
std::vector<gl::LinkedVarying> *linkedVaryings) const;
void storeBuiltinLinkedVaryings(const SemanticInfo &info, std::vector<gl::LinkedVarying> *linkedVaryings) const;
std::string generatePointSpriteHLSL(int registers,
void storeBuiltinLinkedVaryings(const SemanticInfo &info,
std::vector<gl::LinkedVarying> *linkedVaryings) const;
std::string generatePointSpriteHLSL(const gl::Data &data,
int registers,
const ShaderD3D *fragmentShader,
const std::vector<PackedVarying> &packedVaryings) const;
......@@ -122,7 +136,6 @@ class DynamicHLSL : angle::NonCopyable
std::string generateAttributeConversionHLSL(gl::VertexFormatType vertexFormatType,
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
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())
{
......
......@@ -38,14 +38,13 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader)
GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type);
for (size_t rowIndex = 0;
static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType);
++rowIndex)
static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); ++rowIndex)
{
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);
gl::VertexFormatType defaultType = gl::GetVertexFormatType(
componentType, GL_FALSE, components, pureInt);
gl::VertexFormatType defaultType =
gl::GetVertexFormatType(componentType, GL_FALSE, components, pureInt);
defaultLayout.push_back(defaultType);
}
......@@ -55,7 +54,8 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader)
return defaultLayout;
}
std::vector<GLenum> GetDefaultOutputLayoutFromShader(const std::vector<PixelShaderOutputVariable> &shaderOutputVars)
std::vector<GLenum> GetDefaultOutputLayoutFromShader(
const std::vector<PixelShaderOutputVariable> &shaderOutputVars)
{
std::vector<GLenum> defaultPixelOutput;
......@@ -90,8 +90,10 @@ struct AttributeSorter
int indexA = (*originalIndices)[a];
int indexB = (*originalIndices)[b];
if (indexA == -1) return false;
if (indexB == -1) return true;
if (indexA == -1)
return false;
if (indexB == -1)
return true;
return (indexA < indexB);
}
......@@ -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
D3DUniform::D3DUniform(GLenum typeIn,
......@@ -231,9 +313,7 @@ bool D3DUniform::isReferencedByFragmentShader() const
ProgramD3D::VertexExecutable::VertexExecutable(const gl::InputLayout &inputLayout,
const Signature &signature,
ShaderExecutableD3D *shaderExecutable)
: mInputs(inputLayout),
mSignature(signature),
mShaderExecutable(shaderExecutable)
: mInputs(inputLayout), mSignature(signature), mShaderExecutable(shaderExecutable)
{
}
......@@ -281,8 +361,7 @@ bool ProgramD3D::VertexExecutable::matchesSignature(const Signature &signature)
ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature,
ShaderExecutableD3D *shaderExecutable)
: mOutputSignature(outputSignature),
mShaderExecutable(shaderExecutable)
: mOutputSignature(outputSignature), mShaderExecutable(shaderExecutable)
{
}
......@@ -334,30 +413,34 @@ bool ProgramD3D::usesInstancedPointSpriteEmulation() const
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;
switch (type)
{
case gl::SAMPLER_PIXEL:
ASSERT(samplerIndex < caps.maxTextureImageUnits);
if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
{
logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
}
break;
case gl::SAMPLER_VERTEX:
ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
{
logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
}
break;
default: UNREACHABLE();
case gl::SAMPLER_PIXEL:
ASSERT(samplerIndex < caps.maxTextureImageUnits);
if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
{
logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
}
break;
case gl::SAMPLER_VERTEX:
ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
{
logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
}
break;
default:
UNREACHABLE();
}
if (logicalTextureUnit >= 0 && logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
if (logicalTextureUnit >= 0 &&
logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
{
return logicalTextureUnit;
}
......@@ -371,15 +454,16 @@ GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samp
{
switch (type)
{
case gl::SAMPLER_PIXEL:
ASSERT(samplerIndex < mSamplersPS.size());
ASSERT(mSamplersPS[samplerIndex].active);
return mSamplersPS[samplerIndex].textureType;
case gl::SAMPLER_VERTEX:
ASSERT(samplerIndex < mSamplersVS.size());
ASSERT(mSamplersVS[samplerIndex].active);
return mSamplersVS[samplerIndex].textureType;
default: UNREACHABLE();
case gl::SAMPLER_PIXEL:
ASSERT(samplerIndex < mSamplersPS.size());
ASSERT(mSamplersPS[samplerIndex].active);
return mSamplersPS[samplerIndex].textureType;
case gl::SAMPLER_VERTEX:
ASSERT(samplerIndex < mSamplersVS.size());
ASSERT(mSamplersVS[samplerIndex].active);
return mSamplersVS[samplerIndex].textureType;
default:
UNREACHABLE();
}
return GL_TEXTURE_2D;
......@@ -389,13 +473,13 @@ GLint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const
{
switch (type)
{
case gl::SAMPLER_PIXEL:
return mUsedPixelSamplerRange;
case gl::SAMPLER_VERTEX:
return mUsedVertexSamplerRange;
default:
UNREACHABLE();
return 0;
case gl::SAMPLER_PIXEL:
return mUsedPixelSamplerRange;
case gl::SAMPLER_VERTEX:
return mUsedVertexSamplerRange;
default:
UNREACHABLE();
return 0;
}
}
......@@ -458,8 +542,9 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
{
reset();
DeviceIdentifier binaryDeviceIdentifier = { 0 };
stream->readBytes(reinterpret_cast<unsigned char*>(&binaryDeviceIdentifier), sizeof(DeviceIdentifier));
DeviceIdentifier binaryDeviceIdentifier = {0};
stream->readBytes(reinterpret_cast<unsigned char *>(&binaryDeviceIdentifier),
sizeof(DeviceIdentifier));
DeviceIdentifier identifier = mRenderer->getAdapterIdentifier();
if (memcmp(&identifier, &binaryDeviceIdentifier, sizeof(DeviceIdentifier)) != 0)
......@@ -545,7 +630,8 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
const unsigned int transformFeedbackVaryingCount = stream->readInt<unsigned int>();
mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount);
for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++)
for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount;
varyingIndex++)
{
gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex];
......@@ -558,15 +644,18 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
}
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->readBytes(reinterpret_cast<unsigned char*>(&mPixelWorkarounds), sizeof(D3DCompilerWorkarounds));
stream->readBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
sizeof(D3DCompilerWorkarounds));
stream->readBool(&mUsesFragDepth);
stream->readBool(&mUsesPointSize);
const size_t pixelShaderKeySize = stream->readInt<unsigned int>();
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->readString(&mPixelShaderKey[pixelShaderKeyIndex].name);
......@@ -574,10 +663,11 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
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>();
for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++)
for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount;
vertexShaderIndex++)
{
size_t inputLayoutSize = stream->readInt<size_t>();
gl::InputLayout inputLayout(inputLayoutSize, gl::VERTEX_FORMAT_INVALID);
......@@ -587,7 +677,7 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
inputLayout[inputIndex] = stream->readInt<gl::VertexFormatType>();
}
unsigned int vertexShaderSize = stream->readInt<unsigned int>();
unsigned int vertexShaderSize = stream->readInt<unsigned int>();
const unsigned char *vertexShaderFunction = binary + stream->offset();
ShaderExecutableD3D *shaderExecutable = nullptr;
......@@ -611,7 +701,8 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
VertexExecutable::getSignature(mRenderer, inputLayout, &signature);
// add new binary
mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, shaderExecutable));
mVertexExecutables.push_back(
new VertexExecutable(inputLayout, signature, shaderExecutable));
stream->skip(vertexShaderSize);
}
......@@ -626,7 +717,7 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
stream->readInt(&outputs[outputIndex]);
}
const size_t pixelShaderSize = stream->readInt<unsigned int>();
const size_t pixelShaderSize = stream->readInt<unsigned int>();
const unsigned char *pixelShaderFunction = binary + stream->offset();
ShaderExecutableD3D *shaderExecutable = nullptr;
......@@ -681,9 +772,11 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
{
// 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();
stream->writeBytes(reinterpret_cast<unsigned char*>(&binaryIdentifier), sizeof(DeviceIdentifier));
stream->writeBytes(reinterpret_cast<unsigned char *>(&binaryIdentifier),
sizeof(DeviceIdentifier));
stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
......@@ -743,15 +836,18 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
}
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->writeBytes(reinterpret_cast<unsigned char*>(&mPixelWorkarounds), sizeof(D3DCompilerWorkarounds));
stream->writeBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds),
sizeof(D3DCompilerWorkarounds));
stream->writeInt(mUsesFragDepth);
stream->writeInt(mUsesPointSize);
const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey;
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];
stream->writeInt(variable.type);
......@@ -761,7 +857,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
}
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];
......@@ -781,7 +878,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
}
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];
......@@ -799,7 +897,8 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
stream->writeBytes(pixelBlob, pixelShaderSize);
}
size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
size_t geometryShaderSize =
(mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
stream->writeInt(geometryShaderSize);
if (mGeometryExecutable != NULL && geometryShaderSize > 0)
......@@ -811,12 +910,14 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
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();
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)
{
......@@ -824,7 +925,9 @@ gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fb
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
{
......@@ -848,8 +951,8 @@ gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum
}
}
std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(mPixelHLSL, mPixelShaderKey, mUsesFragDepth,
outputSignature);
std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(
mPixelHLSL, mPixelShaderKey, mUsesFragDepth, outputSignature);
// Generate new pixel executable
ShaderExecutableD3D *pixelExecutable = NULL;
......@@ -917,7 +1020,8 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i
if (vertexExecutable)
{
mVertexExecutables.push_back(new VertexExecutable(inputLayout, mCachedVertexSignature, vertexExecutable));
mVertexExecutables.push_back(
new VertexExecutable(inputLayout, mCachedVertexSignature, vertexExecutable));
}
else if (!infoLog)
{
......@@ -930,7 +1034,8 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i
return gl::Error(GL_NO_ERROR);
}
LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
LinkResult ProgramD3D::compileProgramExecutables(const gl::Data &data,
gl::InfoLog &infoLog,
int registers,
const std::vector<PackedVarying> &packedVaryings)
{
......@@ -939,15 +1044,17 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
const gl::InputLayout &defaultInputLayout =
GetDefaultInputLayoutFromShader(mData.getAttachedVertexShader());
ShaderExecutableD3D *defaultVertexExecutable = NULL;
gl::Error error = getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog);
gl::Error error =
getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog);
if (error.isError())
{
return LinkResult(false, error);
}
std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey());
std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey());
ShaderExecutableD3D *defaultPixelExecutable = NULL;
error = getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog);
error =
getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog);
if (error.isError())
{
return LinkResult(false, error);
......@@ -955,8 +1062,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
if (usesGeometryShader())
{
std::string geometryHLSL =
mDynamicHLSL->generateGeometryShaderHLSL(registers, fragmentShaderD3D, packedVaryings);
std::string geometryHLSL = mDynamicHLSL->generateGeometryShaderHLSL(
data, registers, fragmentShaderD3D, packedVaryings);
error = mRenderer->compileToExecutable(
infoLog, geometryHLSL, SHADER_GEOMETRY, mTransformFeedbackLinkedVaryings,
......@@ -973,8 +1080,9 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
if (usesGeometryShader() && mGeometryExecutable)
{
// Geometry shaders are currently only used internally, so there is no corresponding shader object at the interface level
// For now the geometry shader debug info is pre-pended to the vertex shader, this is a bit of a clutch
// Geometry shaders are currently only used internally, so there is no corresponding shader
// 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(mGeometryExecutable->getDebugInfo());
vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n");
......@@ -991,7 +1099,8 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog,
}
#endif
bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable && (!usesGeometryShader() || mGeometryExecutable));
bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable &&
(!usesGeometryShader() || mGeometryExecutable));
return LinkResult(linkSuccess, gl::Error(GL_NO_ERROR));
}
......@@ -1018,10 +1127,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
mSamplersVS.resize(data.caps->maxVertexTextureImageUnits);
mSamplersPS.resize(data.caps->maxTextureImageUnits);
mVertexHLSL = vertexShader->getTranslatedSource();
vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds);
mPixelHLSL = fragmentShader->getTranslatedSource();
fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds);
if (mRenderer->getRendererLimitations().noFrontFacingSupport)
......@@ -1037,7 +1143,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
MergeVaryings(*vertexShader, *fragmentShader, mData.getTransformFeedbackVaryingNames());
// Map the varyings to the register file
int registers = mDynamicHLSL->packVaryings(infoLog, &packedVaryings,
int registers = mDynamicHLSL->packVaryings(*data.caps, infoLog, &packedVaryings,
mData.getTransformFeedbackVaryingNames());
if (registers < 0)
......@@ -1046,8 +1152,8 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
}
std::vector<gl::LinkedVarying> linkedVaryings;
if (!mDynamicHLSL->generateShaderLinkHLSL(data, mData, infoLog, registers, mPixelHLSL,
mVertexHLSL, packedVaryings, &linkedVaryings,
if (!mDynamicHLSL->generateShaderLinkHLSL(data, mData, infoLog, registers, &mPixelHLSL,
&mVertexHLSL, packedVaryings, &linkedVaryings,
&mPixelShaderKey, &mUsesFragDepth))
{
return LinkResult(false, gl::Error(GL_NO_ERROR));
......@@ -1061,7 +1167,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
gatherTransformFeedbackVaryings(linkedVaryings);
LinkResult result = compileProgramExecutables(infoLog, registers, packedVaryings);
LinkResult result = compileProgramExecutables(data, infoLog, registers, packedVaryings);
if (result.error.isError() || !result.linkSuccess)
{
infoLog << "Failed to create D3D shaders.";
......@@ -1145,7 +1251,7 @@ void ProgramD3D::assignUniformBlockRegisters()
void ProgramD3D::initializeUniformStorage()
{
// Compute total default block size
unsigned int vertexRegisters = 0;
unsigned int vertexRegisters = 0;
unsigned int fragmentRegisters = 0;
for (const D3DUniform *d3dUniform : mD3DUniforms)
{
......@@ -1164,7 +1270,7 @@ void ProgramD3D::initializeUniformStorage()
}
}
mVertexUniformStorage = mRenderer->createUniformStorage(vertexRegisters * 16u);
mVertexUniformStorage = mRenderer->createUniformStorage(vertexRegisters * 16u);
mFragmentUniformStorage = mRenderer->createUniformStorage(fragmentRegisters * 16u);
}
......@@ -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);
}
......@@ -1277,47 +1383,74 @@ void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
......@@ -1370,7 +1503,7 @@ void ProgramD3D::setUniformBlockBinding(GLuint /*uniformBlockIndex*/,
void ProgramD3D::defineUniformsAndAssignRegisters()
{
D3DUniformMap uniformMap;
const gl::Shader *vertexShader = mData.getAttachedVertexShader();
const gl::Shader *vertexShader = mData.getAttachedVertexShader();
for (const sh::Uniform &vertexUniform : vertexShader->getUniforms())
{
......@@ -1380,7 +1513,7 @@ void ProgramD3D::defineUniformsAndAssignRegisters()
}
}
const gl::Shader *fragmentShader = mData.getAttachedFragmentShader();
const gl::Shader *fragmentShader = mData.getAttachedFragmentShader();
for (const sh::Uniform &fragmentUniform : fragmentShader->getUniforms())
{
if (fragmentUniform.staticUse)
......@@ -1454,7 +1587,7 @@ void ProgramD3D::defineUniform(GLenum shaderType,
for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
{
const sh::ShaderVariable &field = uniform.fields[fieldIndex];
const sh::ShaderVariable &field = uniform.fields[fieldIndex];
const std::string &fieldFullName = (fullName + elementString + "." + field.name);
defineUniform(shaderType, field, fieldFullName, encoder, uniformMap);
......@@ -1515,19 +1648,19 @@ void ProgramD3D::defineUniform(GLenum shaderType,
}
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(dirtyFlag != NULL);
*dirtyFlag = *dirtyFlag || (memcmp(dest, &source, sizeof(T)) != 0);
*dest = source;
*dest = source;
}
template <typename T>
void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum targetUniformType)
{
const int components = gl::VariableComponentCount(targetUniformType);
const int components = gl::VariableComponentCount(targetUniformType);
const GLenum targetBoolType = gl::VariableBoolVectorType(targetUniformType);
D3DUniform *targetUniform = getD3DUniformFromLocation(location);
......@@ -1542,7 +1675,7 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum
for (unsigned int i = 0; i < count; i++)
{
T *dest = target + (i * 4);
T *dest = target + (i * 4);
const T *source = v + (i * components);
for (int c = 0; c < components; c++)
......@@ -1561,12 +1694,13 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum
for (unsigned int i = 0; i < count; i++)
{
GLint *dest = boolParams + (i * 4);
GLint *dest = boolParams + (i * 4);
const T *source = v + (i * components);
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++)
{
......@@ -1584,8 +1718,8 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum
for (unsigned int i = 0; i < count; i++)
{
GLint *dest = target + (i * 4);
const GLint *source = reinterpret_cast<const GLint*>(v) + (i * components);
GLint *dest = target + (i * 4);
const GLint *source = reinterpret_cast<const GLint *>(v) + (i * components);
SetIfDirty(dest + 0, source[0], &targetUniform->dirty);
SetIfDirty(dest + 1, 0, &targetUniform->dirty);
......@@ -1598,75 +1732,8 @@ void ProgramD3D::setUniform(GLint location, GLsizei countIn, const T *v, GLenum
mDirtySamplerMapping = true;
}
}
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;
else
UNREACHABLE();
}
template <int cols, int rows>
......@@ -1691,11 +1758,13 @@ void ProgramD3D::setUniformMatrixfv(GLint location,
// Internally store matrices as transposed versions to accomodate HLSL matrix indexing
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
{
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;
value += cols * rows;
......@@ -1802,8 +1871,8 @@ void ProgramD3D::reset()
mSamplersVS.clear();
mUsedVertexSamplerRange = 0;
mUsedPixelSamplerRange = 0;
mDirtySamplerMapping = true;
mUsedPixelSamplerRange = 0;
mDirtySamplerMapping = true;
std::fill(mSemanticIndexes, mSemanticIndexes + ArraySize(mSemanticIndexes), -1);
std::fill(mAttributesByLayout, mAttributesByLayout + ArraySize(mAttributesByLayout), -1);
......@@ -1853,15 +1922,16 @@ void ProgramD3D::initAttributesByLayout()
AttributeSorter(mSemanticIndexes));
}
void ProgramD3D::sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const
void ProgramD3D::sortAttributesByLayout(
const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const
{
for (size_t attribIndex = 0; attribIndex < unsortedAttributes.size(); ++attribIndex)
{
int oldIndex = mAttributesByLayout[attribIndex];
int oldIndex = mAttributesByLayout[attribIndex];
sortedSemanticIndicesOut[attribIndex] = mSemanticIndexes[oldIndex];
sortedAttributesOut[attribIndex] = &unsortedAttributes[oldIndex];
sortedAttributesOut[attribIndex] = &unsortedAttributes[oldIndex];
}
}
......
......@@ -90,7 +90,9 @@ class ProgramD3D : public ProgramImpl
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;
GLint getUsedSamplerRange(gl::SamplerType type) const;
void updateSamplerMapping();
......@@ -103,9 +105,14 @@ class ProgramD3D : public ProgramImpl
LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream);
gl::Error save(gl::BinaryOutputStream *stream);
gl::Error getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutableD3D **outExectuable);
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);
gl::Error getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo,
ShaderExecutableD3D **outExectuable);
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; }
LinkResult link(const gl::Data &data, gl::InfoLog &infoLog) override;
......@@ -132,15 +139,42 @@ class ProgramD3D : public ProgramImpl
void setUniform2uiv(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 setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
void setUniformMatrix3fv(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 setUniformMatrix2fv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value);
void setUniformMatrix3fv(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;
......@@ -149,9 +183,10 @@ class ProgramD3D : public ProgramImpl
unsigned int getSerial() const;
void sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const;
void sortAttributesByLayout(
const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const;
const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndexes; }
const SemanticIndexArray &getAttributesByLayout() const { return mAttributesByLayout; }
......@@ -187,10 +222,14 @@ class ProgramD3D : public ProgramImpl
class PixelExecutable
{
public:
PixelExecutable(const std::vector<GLenum> &outputSignature, ShaderExecutableD3D *shaderExecutable);
PixelExecutable(const std::vector<GLenum> &outputSignature,
ShaderExecutableD3D *shaderExecutable);
~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; }
ShaderExecutableD3D *shaderExecutable() const { return mShaderExecutable; }
......@@ -230,12 +269,17 @@ class ProgramD3D : public ProgramImpl
GLuint *outUsedRange);
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>
void setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType);
LinkResult compileProgramExecutables(gl::InfoLog &infoLog,
void setUniformMatrixfv(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value,
GLenum targetUniformType);
LinkResult compileProgramExecutables(const gl::Data &data,
gl::InfoLog &infoLog,
int registers,
const std::vector<PackedVarying> &packedVaryings);
......@@ -301,7 +345,6 @@ class ProgramD3D : public ProgramImpl
static unsigned int issueSerial();
static unsigned int mCurrentSerial;
};
}
#endif // LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
#endif // LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
......@@ -21,8 +21,6 @@ struct D3DCompilerWorkarounds;
class ShaderD3D : public ShaderImpl
{
friend class DynamicHLSL;
public:
ShaderD3D(const gl::Shader::Data &data);
virtual ~ShaderD3D();
......@@ -40,10 +38,17 @@ class ShaderD3D : public ShaderImpl
void appendDebugInfo(const std::string &info) { mDebugInfo += info; }
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 usesPointCoord() const { return mUsesPointCoord; }
bool usesDepthRange() const { return mUsesDepthRange; }
bool usesFragDepth() const { return mUsesFragDepth; }
bool usesDeferredInit() const { return mUsesDeferredInit; }
bool usesFrontFacing() const { return mUsesFrontFacing; }
ShShaderOutput getCompilerOutputType() const;
......@@ -67,7 +72,6 @@ class ShaderD3D : public ShaderImpl
std::map<std::string, unsigned int> mUniformRegisterMap;
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)
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program);
EXPECT_GL_NO_ERROR();
glDeleteProgram(program);
......@@ -422,6 +423,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig4444Support)
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program);
EXPECT_GL_NO_ERROR();
glDeleteProgram(program);
......@@ -463,6 +465,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig5551Support)
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program);
EXPECT_GL_NO_ERROR();
glDeleteProgram(program);
......@@ -504,6 +507,7 @@ TEST_F(EGLSurfaceTest, CreateWithEGLConfig8880Support)
ASSERT_EGL_SUCCESS();
GLuint program = createProgram();
ASSERT_NE(0u, program);
drawWithProgram(program);
EXPECT_GL_NO_ERROR();
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