Commit 467c15f9 by Jiawei Shao Committed by Commit Bot

Use ShaderMap in ProgramD3D - Part II

This patch refactors ProgramD3D by storing all shader information into ShaderMap to simplify the code structure. This patch also fixes a bug on getting the number of maximum uniform blocks. BUG=angleproject:2169 Change-Id: I5b9fbfd70a18f8731ce19efed0df88037d495389 Reviewed-on: https://chromium-review.googlesource.com/1024749 Commit-Queue: Jiawei Shao <jiawei.shao@intel.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 7267aa65
...@@ -286,6 +286,7 @@ class ProgramState final : angle::NonCopyable ...@@ -286,6 +286,7 @@ class ProgramState final : angle::NonCopyable
const std::string &getLabel(); const std::string &getLabel();
Shader *getAttachedShader(ShaderType shaderType) const; Shader *getAttachedShader(ShaderType shaderType) const;
const gl::ShaderMap<Shader *> &getAttachedShaders() const { return mAttachedShaders; }
const std::vector<std::string> &getTransformFeedbackVaryingNames() const const std::vector<std::string> &getTransformFeedbackVaryingNames() const
{ {
return mTransformFeedbackVaryingNames; return mTransformFeedbackVaryingNames;
......
...@@ -454,10 +454,11 @@ void DynamicHLSL::generateShaderLinkHLSL(const gl::Context *context, ...@@ -454,10 +454,11 @@ void DynamicHLSL::generateShaderLinkHLSL(const gl::Context *context,
const ProgramD3DMetadata &programMetadata, const ProgramD3DMetadata &programMetadata,
const VaryingPacking &varyingPacking, const VaryingPacking &varyingPacking,
const BuiltinVaryingsD3D &builtinsD3D, const BuiltinVaryingsD3D &builtinsD3D,
std::string *pixelHLSL, gl::ShaderMap<std::string> *shaderHLSL) const
std::string *vertexHLSL) const
{ {
ASSERT(pixelHLSL->empty() && vertexHLSL->empty()); ASSERT(shaderHLSL);
ASSERT((*shaderHLSL)[gl::ShaderType::Vertex].empty() &&
(*shaderHLSL)[gl::ShaderType::Fragment].empty());
const auto &data = context->getContextState(); const auto &data = context->getContextState();
gl::Shader *vertexShaderGL = programData.getAttachedShader(ShaderType::Vertex); gl::Shader *vertexShaderGL = programData.getAttachedShader(ShaderType::Vertex);
...@@ -844,8 +845,8 @@ void DynamicHLSL::generateShaderLinkHLSL(const gl::Context *context, ...@@ -844,8 +845,8 @@ void DynamicHLSL::generateShaderLinkHLSL(const gl::Context *context,
<< " return generateOutput();\n" << " return generateOutput();\n"
<< "}\n"; << "}\n";
*vertexHLSL = vertexStream.str(); (*shaderHLSL)[gl::ShaderType::Vertex] = vertexStream.str();
*pixelHLSL = pixelStream.str(); (*shaderHLSL)[gl::ShaderType::Fragment] = pixelStream.str();
} }
std::string DynamicHLSL::generateComputeShaderLinkHLSL(const gl::Context *context, std::string DynamicHLSL::generateComputeShaderLinkHLSL(const gl::Context *context,
......
...@@ -139,8 +139,7 @@ class DynamicHLSL : angle::NonCopyable ...@@ -139,8 +139,7 @@ class DynamicHLSL : angle::NonCopyable
const ProgramD3DMetadata &programMetadata, const ProgramD3DMetadata &programMetadata,
const gl::VaryingPacking &varyingPacking, const gl::VaryingPacking &varyingPacking,
const BuiltinVaryingsD3D &builtinsD3D, const BuiltinVaryingsD3D &builtinsD3D,
std::string *pixelHLSL, gl::ShaderMap<std::string> *shaderHLSL) const;
std::string *vertexHLSL) const;
std::string generateComputeShaderLinkHLSL(const gl::Context *context, std::string generateComputeShaderLinkHLSL(const gl::Context *context,
const gl::ProgramState &programData) const; const gl::ProgramState &programData) const;
......
...@@ -164,7 +164,7 @@ gl::PrimitiveType GetGeometryShaderTypeFromDrawMode(GLenum drawMode) ...@@ -164,7 +164,7 @@ gl::PrimitiveType GetGeometryShaderTypeFromDrawMode(GLenum drawMode)
} }
} }
bool FindFlatInterpolationVarying(const std::vector<sh::Varying> &varyings) bool HasFlatInterpolationVarying(const std::vector<sh::Varying> &varyings)
{ {
// Note: this assumes nested structs can only be packed with one interpolation. // Note: this assumes nested structs can only be packed with one interpolation.
for (const auto &varying : varyings) for (const auto &varying : varyings)
...@@ -178,6 +178,46 @@ bool FindFlatInterpolationVarying(const std::vector<sh::Varying> &varyings) ...@@ -178,6 +178,46 @@ bool FindFlatInterpolationVarying(const std::vector<sh::Varying> &varyings)
return false; return false;
} }
bool FindFlatInterpolationVaryingPerShader(const gl::Context *context, gl::Shader *shader)
{
ASSERT(context && shader);
switch (shader->getType())
{
case gl::ShaderType::Vertex:
return HasFlatInterpolationVarying(shader->getOutputVaryings(context));
case gl::ShaderType::Fragment:
return HasFlatInterpolationVarying(shader->getInputVaryings(context));
case gl::ShaderType::Geometry:
return HasFlatInterpolationVarying(shader->getInputVaryings(context)) ||
HasFlatInterpolationVarying(shader->getOutputVaryings(context));
default:
UNREACHABLE();
return false;
}
}
bool FindFlatInterpolationVarying(const gl::Context *context,
const gl::ShaderMap<gl::Shader *> &shaders)
{
ASSERT(context);
for (gl::ShaderType shaderType : gl::kAllGraphicsShaderTypes)
{
gl::Shader *shader = shaders[shaderType];
if (!shader)
{
continue;
}
if (FindFlatInterpolationVaryingPerShader(context, shader))
{
return true;
}
}
return false;
}
// Helper method to de-tranpose a matrix uniform for an API query. // Helper method to de-tranpose a matrix uniform for an API query.
void GetMatrixUniform(GLint columns, GLint rows, GLfloat *dataOut, const GLfloat *source) void GetMatrixUniform(GLint columns, GLint rows, GLfloat *dataOut, const GLfloat *source)
{ {
...@@ -289,6 +329,44 @@ bool UniformBlockInfo::getBlockMemberInfo(const std::string &name, ...@@ -289,6 +329,44 @@ bool UniformBlockInfo::getBlockMemberInfo(const std::string &name,
return true; return true;
}; };
// TODO(jiawei.shao@intel.com): remove this function once we use ShaderMap in gl::Caps.
GLuint GetMaximumSamplersPerShader(gl::ShaderType shaderType, const gl::Caps &caps)
{
switch (shaderType)
{
case gl::ShaderType::Fragment:
return caps.maxTextureImageUnits;
case gl::ShaderType::Vertex:
return caps.maxVertexTextureImageUnits;
case gl::ShaderType::Compute:
return caps.maxComputeTextureImageUnits;
case gl::ShaderType::Geometry:
return caps.maxGeometryTextureImageUnits;
default:
UNREACHABLE();
return 0u;
}
}
// TODO(jiawei.shao@intel.com): remove this function once we use ShaderMap in gl::Caps.
GLuint GetMaximumShaderUniformBlocksPerShader(gl::ShaderType shaderType, const gl::Caps &caps)
{
switch (shaderType)
{
case gl::ShaderType::Vertex:
return caps.maxVertexUniformBlocks;
case gl::ShaderType::Fragment:
return caps.maxFragmentUniformBlocks;
case gl::ShaderType::Compute:
return caps.maxComputeUniformBlocks;
case gl::ShaderType::Geometry:
return caps.maxGeometryUniformBlocks;
default:
UNREACHABLE();
return 0u;
}
}
} // anonymous namespace } // anonymous namespace
// D3DUniform Implementation // D3DUniform Implementation
...@@ -604,9 +682,7 @@ ProgramD3D::ProgramD3D(const gl::ProgramState &state, RendererD3D *renderer) ...@@ -604,9 +682,7 @@ ProgramD3D::ProgramD3D(const gl::ProgramState &state, RendererD3D *renderer)
mComputeExecutable(nullptr), mComputeExecutable(nullptr),
mUsesPointSize(false), mUsesPointSize(false),
mUsesFlatInterpolation(false), mUsesFlatInterpolation(false),
mUsedVertexSamplerRange(0), mUsedShaderSamplerRanges({}),
mUsedPixelSamplerRange(0),
mUsedComputeSamplerRange(0),
mDirtySamplerMapping(true), mDirtySamplerMapping(true),
mUsedComputeImageRange(0), mUsedComputeImageRange(0),
mUsedComputeReadonlyImageRange(0), mUsedComputeReadonlyImageRange(0),
...@@ -655,31 +731,14 @@ GLint ProgramD3D::getSamplerMapping(gl::ShaderType type, ...@@ -655,31 +731,14 @@ GLint ProgramD3D::getSamplerMapping(gl::ShaderType type,
{ {
GLint logicalTextureUnit = -1; GLint logicalTextureUnit = -1;
switch (type) ASSERT(type != gl::ShaderType::InvalidEnum);
ASSERT(samplerIndex < GetMaximumSamplersPerShader(type, caps));
const auto &samplers = mShaderSamplers[type];
if (samplerIndex < samplers.size() && samplers[samplerIndex].active)
{ {
case gl::ShaderType::Fragment: logicalTextureUnit = samplers[samplerIndex].logicalTextureUnit;
ASSERT(samplerIndex < caps.maxTextureImageUnits);
if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
{
logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
}
break;
case gl::ShaderType::Vertex:
ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
{
logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
}
break;
case gl::ShaderType::Compute:
ASSERT(samplerIndex < caps.maxComputeTextureImageUnits);
if (samplerIndex < mSamplersCS.size() && mSamplersCS[samplerIndex].active)
{
logicalTextureUnit = mSamplersCS[samplerIndex].logicalTextureUnit;
}
break;
default:
UNREACHABLE();
} }
if (logicalTextureUnit >= 0 && if (logicalTextureUnit >= 0 &&
...@@ -696,41 +755,19 @@ GLint ProgramD3D::getSamplerMapping(gl::ShaderType type, ...@@ -696,41 +755,19 @@ GLint ProgramD3D::getSamplerMapping(gl::ShaderType type,
gl::TextureType ProgramD3D::getSamplerTextureType(gl::ShaderType type, gl::TextureType ProgramD3D::getSamplerTextureType(gl::ShaderType type,
unsigned int samplerIndex) const unsigned int samplerIndex) const
{ {
switch (type) ASSERT(type != gl::ShaderType::InvalidEnum);
{
case gl::ShaderType::Fragment:
ASSERT(samplerIndex < mSamplersPS.size());
ASSERT(mSamplersPS[samplerIndex].active);
return mSamplersPS[samplerIndex].textureType;
case gl::ShaderType::Vertex:
ASSERT(samplerIndex < mSamplersVS.size());
ASSERT(mSamplersVS[samplerIndex].active);
return mSamplersVS[samplerIndex].textureType;
case gl::ShaderType::Compute:
ASSERT(samplerIndex < mSamplersCS.size());
ASSERT(mSamplersCS[samplerIndex].active);
return mSamplersCS[samplerIndex].textureType;
default:
UNREACHABLE();
return gl::TextureType::InvalidEnum;
}
const auto &samplers = mShaderSamplers[type];
ASSERT(samplerIndex < samplers.size());
ASSERT(samplers[samplerIndex].active);
return samplers[samplerIndex].textureType;
} }
GLuint ProgramD3D::getUsedSamplerRange(gl::ShaderType type) const GLuint ProgramD3D::getUsedSamplerRange(gl::ShaderType type) const
{ {
switch (type) ASSERT(type != gl::ShaderType::InvalidEnum);
{ return mUsedShaderSamplerRanges[type];
case gl::ShaderType::Fragment:
return mUsedPixelSamplerRange;
case gl::ShaderType::Vertex:
return mUsedVertexSamplerRange;
case gl::ShaderType::Compute:
return mUsedComputeSamplerRange;
default:
UNREACHABLE();
return 0u;
}
} }
ProgramD3D::SamplerMapping ProgramD3D::updateSamplerMapping() ProgramD3D::SamplerMapping ProgramD3D::updateSamplerMapping()
...@@ -750,50 +787,24 @@ ProgramD3D::SamplerMapping ProgramD3D::updateSamplerMapping() ...@@ -750,50 +787,24 @@ ProgramD3D::SamplerMapping ProgramD3D::updateSamplerMapping()
int count = d3dUniform->getArraySizeProduct(); int count = d3dUniform->getArraySizeProduct();
if (d3dUniform->isReferencedByShader(gl::ShaderType::Fragment)) for (gl::ShaderType shaderType : gl::AllShaderTypes())
{
unsigned int firstIndex = d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Fragment];
for (int i = 0; i < count; i++)
{
unsigned int samplerIndex = firstIndex + i;
if (samplerIndex < mSamplersPS.size())
{
ASSERT(mSamplersPS[samplerIndex].active);
mSamplersPS[samplerIndex].logicalTextureUnit = d3dUniform->mSamplerData[i];
}
}
}
if (d3dUniform->isReferencedByShader(gl::ShaderType::Vertex))
{ {
unsigned int firstIndex = d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Vertex]; if (!d3dUniform->isReferencedByShader(shaderType))
for (int i = 0; i < count; i++)
{ {
unsigned int samplerIndex = firstIndex + i; continue;
if (samplerIndex < mSamplersVS.size())
{
ASSERT(mSamplersVS[samplerIndex].active);
mSamplersVS[samplerIndex].logicalTextureUnit = d3dUniform->mSamplerData[i];
}
} }
}
if (d3dUniform->isReferencedByShader(gl::ShaderType::Compute)) unsigned int firstIndex = d3dUniform->mShaderRegisterIndexes[shaderType];
{
unsigned int firstIndex = d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Compute];
std::vector<Sampler> &samplers = mShaderSamplers[shaderType];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
unsigned int samplerIndex = firstIndex + i; unsigned int samplerIndex = firstIndex + i;
if (samplerIndex < mSamplersCS.size()) if (samplerIndex < samplers.size())
{ {
ASSERT(mSamplersCS[samplerIndex].active); ASSERT(samplers[samplerIndex].active);
mSamplersCS[samplerIndex].logicalTextureUnit = d3dUniform->mSamplerData[i]; samplers[samplerIndex].logicalTextureUnit = d3dUniform->mSamplerData[i];
} }
} }
} }
...@@ -879,33 +890,19 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context, ...@@ -879,33 +890,19 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context,
stream->readInt(&index); stream->readInt(&index);
} }
const unsigned int psSamplerCount = stream->readInt<unsigned int>(); for (gl::ShaderType shaderType : gl::AllShaderTypes())
for (unsigned int i = 0; i < psSamplerCount; ++i)
{
Sampler sampler;
stream->readBool(&sampler.active);
stream->readInt(&sampler.logicalTextureUnit);
stream->readEnum(&sampler.textureType);
mSamplersPS.push_back(sampler);
}
const unsigned int vsSamplerCount = stream->readInt<unsigned int>();
for (unsigned int i = 0; i < vsSamplerCount; ++i)
{ {
Sampler sampler; const unsigned int samplerCount = stream->readInt<unsigned int>();
stream->readBool(&sampler.active); for (unsigned int i = 0; i < samplerCount; ++i)
stream->readInt(&sampler.logicalTextureUnit); {
stream->readEnum(&sampler.textureType); Sampler sampler;
mSamplersVS.push_back(sampler); stream->readBool(&sampler.active);
} stream->readInt(&sampler.logicalTextureUnit);
stream->readEnum(&sampler.textureType);
mShaderSamplers[shaderType].push_back(sampler);
}
const unsigned int csSamplerCount = stream->readInt<unsigned int>(); stream->readInt(&mUsedShaderSamplerRanges[shaderType]);
for (unsigned int i = 0; i < csSamplerCount; ++i)
{
Sampler sampler;
stream->readBool(&sampler.active);
stream->readInt(&sampler.logicalTextureUnit);
stream->readEnum(&sampler.textureType);
mSamplersCS.push_back(sampler);
} }
const unsigned int csImageCount = stream->readInt<unsigned int>(); const unsigned int csImageCount = stream->readInt<unsigned int>();
...@@ -926,9 +923,6 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context, ...@@ -926,9 +923,6 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context,
mReadonlyImagesCS.push_back(image); mReadonlyImagesCS.push_back(image);
} }
stream->readInt(&mUsedVertexSamplerRange);
stream->readInt(&mUsedPixelSamplerRange);
stream->readInt(&mUsedComputeSamplerRange);
stream->readInt(&mUsedComputeImageRange); stream->readInt(&mUsedComputeImageRange);
stream->readInt(&mUsedComputeReadonlyImageRange); stream->readInt(&mUsedComputeReadonlyImageRange);
...@@ -989,12 +983,13 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context, ...@@ -989,12 +983,13 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context,
stream->readInt(&varying->outputSlot); stream->readInt(&varying->outputSlot);
} }
stream->readString(&mVertexHLSL); for (gl::ShaderType shaderType : gl::AllShaderTypes())
stream->readBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds), {
sizeof(angle::CompilerWorkaroundsD3D)); stream->readString(&mShaderHLSL[shaderType]);
stream->readString(&mPixelHLSL); stream->readBytes(reinterpret_cast<unsigned char *>(&mShaderWorkarounds[shaderType]),
stream->readBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds), sizeof(angle::CompilerWorkaroundsD3D));
sizeof(angle::CompilerWorkaroundsD3D)); }
stream->readBool(&mUsesFragDepth); stream->readBool(&mUsesFragDepth);
stream->readBool(&mHasANGLEMultiviewEnabled); stream->readBool(&mHasANGLEMultiviewEnabled);
stream->readBool(&mUsesViewID); stream->readBool(&mUsesViewID);
...@@ -1156,28 +1151,17 @@ void ProgramD3D::save(const gl::Context *context, gl::BinaryOutputStream *stream ...@@ -1156,28 +1151,17 @@ void ProgramD3D::save(const gl::Context *context, gl::BinaryOutputStream *stream
stream->writeInt(d3dSemantic); stream->writeInt(d3dSemantic);
} }
stream->writeInt(mSamplersPS.size()); for (gl::ShaderType shaderType : gl::AllShaderTypes())
for (unsigned int i = 0; i < mSamplersPS.size(); ++i)
{
stream->writeInt(mSamplersPS[i].active);
stream->writeInt(mSamplersPS[i].logicalTextureUnit);
stream->writeEnum(mSamplersPS[i].textureType);
}
stream->writeInt(mSamplersVS.size());
for (unsigned int i = 0; i < mSamplersVS.size(); ++i)
{ {
stream->writeInt(mSamplersVS[i].active); stream->writeInt(mShaderSamplers[shaderType].size());
stream->writeInt(mSamplersVS[i].logicalTextureUnit); for (unsigned int i = 0; i < mShaderSamplers[shaderType].size(); ++i)
stream->writeEnum(mSamplersVS[i].textureType); {
} stream->writeInt(mShaderSamplers[shaderType][i].active);
stream->writeInt(mShaderSamplers[shaderType][i].logicalTextureUnit);
stream->writeEnum(mShaderSamplers[shaderType][i].textureType);
}
stream->writeInt(mSamplersCS.size()); stream->writeInt(mUsedShaderSamplerRanges[shaderType]);
for (unsigned int i = 0; i < mSamplersCS.size(); ++i)
{
stream->writeInt(mSamplersCS[i].active);
stream->writeInt(mSamplersCS[i].logicalTextureUnit);
stream->writeEnum(mSamplersCS[i].textureType);
} }
stream->writeInt(mImagesCS.size()); stream->writeInt(mImagesCS.size());
...@@ -1194,9 +1178,6 @@ void ProgramD3D::save(const gl::Context *context, gl::BinaryOutputStream *stream ...@@ -1194,9 +1178,6 @@ void ProgramD3D::save(const gl::Context *context, gl::BinaryOutputStream *stream
stream->writeInt(mReadonlyImagesCS[i].logicalImageUnit); stream->writeInt(mReadonlyImagesCS[i].logicalImageUnit);
} }
stream->writeInt(mUsedVertexSamplerRange);
stream->writeInt(mUsedPixelSamplerRange);
stream->writeInt(mUsedComputeSamplerRange);
stream->writeInt(mUsedComputeImageRange); stream->writeInt(mUsedComputeImageRange);
stream->writeInt(mUsedComputeReadonlyImageRange); stream->writeInt(mUsedComputeReadonlyImageRange);
...@@ -1231,12 +1212,13 @@ void ProgramD3D::save(const gl::Context *context, gl::BinaryOutputStream *stream ...@@ -1231,12 +1212,13 @@ void ProgramD3D::save(const gl::Context *context, gl::BinaryOutputStream *stream
stream->writeInt(varying.outputSlot); stream->writeInt(varying.outputSlot);
} }
stream->writeString(mVertexHLSL); for (gl::ShaderType shaderType : gl::AllShaderTypes())
stream->writeBytes(reinterpret_cast<unsigned char *>(&mVertexWorkarounds), {
sizeof(angle::CompilerWorkaroundsD3D)); stream->writeString(mShaderHLSL[shaderType]);
stream->writeString(mPixelHLSL); stream->writeBytes(reinterpret_cast<unsigned char *>(&mShaderWorkarounds[shaderType]),
stream->writeBytes(reinterpret_cast<unsigned char *>(&mPixelWorkarounds), sizeof(angle::CompilerWorkaroundsD3D));
sizeof(angle::CompilerWorkaroundsD3D)); }
stream->writeInt(mUsesFragDepth); stream->writeInt(mUsesFragDepth);
stream->writeInt(mHasANGLEMultiviewEnabled); stream->writeInt(mHasANGLEMultiviewEnabled);
stream->writeInt(mUsesViewID); stream->writeInt(mUsesViewID);
...@@ -1341,7 +1323,8 @@ gl::Error ProgramD3D::getPixelExecutableForCachedOutputLayout(ShaderExecutableD3 ...@@ -1341,7 +1323,8 @@ gl::Error ProgramD3D::getPixelExecutableForCachedOutputLayout(ShaderExecutableD3
} }
std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature( std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(
mPixelHLSL, mPixelShaderKey, mUsesFragDepth, mPixelShaderOutputLayoutCache); mShaderHLSL[gl::ShaderType::Fragment], mPixelShaderKey, mUsesFragDepth,
mPixelShaderOutputLayoutCache);
// Generate new pixel executable // Generate new pixel executable
ShaderExecutableD3D *pixelExecutable = nullptr; ShaderExecutableD3D *pixelExecutable = nullptr;
...@@ -1351,8 +1334,8 @@ gl::Error ProgramD3D::getPixelExecutableForCachedOutputLayout(ShaderExecutableD3 ...@@ -1351,8 +1334,8 @@ gl::Error ProgramD3D::getPixelExecutableForCachedOutputLayout(ShaderExecutableD3
ANGLE_TRY(mRenderer->compileToExecutable( ANGLE_TRY(mRenderer->compileToExecutable(
*currentInfoLog, finalPixelHLSL, gl::ShaderType::Fragment, mStreamOutVaryings, *currentInfoLog, finalPixelHLSL, gl::ShaderType::Fragment, mStreamOutVaryings,
(mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), mPixelWorkarounds, (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS),
&pixelExecutable)); mShaderWorkarounds[gl::ShaderType::Fragment], &pixelExecutable));
if (pixelExecutable) if (pixelExecutable)
{ {
...@@ -1382,7 +1365,7 @@ gl::Error ProgramD3D::getVertexExecutableForCachedInputLayout(ShaderExecutableD3 ...@@ -1382,7 +1365,7 @@ gl::Error ProgramD3D::getVertexExecutableForCachedInputLayout(ShaderExecutableD3
// Generate new dynamic layout with attribute conversions // Generate new dynamic layout with attribute conversions
std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout( std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(
mVertexHLSL, mCachedInputLayout, mState.getAttributes()); mShaderHLSL[gl::ShaderType::Vertex], mCachedInputLayout, mState.getAttributes());
// Generate new vertex executable // Generate new vertex executable
ShaderExecutableD3D *vertexExecutable = nullptr; ShaderExecutableD3D *vertexExecutable = nullptr;
...@@ -1392,8 +1375,8 @@ gl::Error ProgramD3D::getVertexExecutableForCachedInputLayout(ShaderExecutableD3 ...@@ -1392,8 +1375,8 @@ gl::Error ProgramD3D::getVertexExecutableForCachedInputLayout(ShaderExecutableD3
ANGLE_TRY(mRenderer->compileToExecutable( ANGLE_TRY(mRenderer->compileToExecutable(
*currentInfoLog, finalVertexHLSL, gl::ShaderType::Vertex, mStreamOutVaryings, *currentInfoLog, finalVertexHLSL, gl::ShaderType::Vertex, mStreamOutVaryings,
(mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), mVertexWorkarounds, (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS),
&vertexExecutable)); mShaderWorkarounds[gl::ShaderType::Vertex], &vertexExecutable));
if (vertexExecutable) if (vertexExecutable)
{ {
...@@ -1684,7 +1667,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context, ...@@ -1684,7 +1667,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context,
gl::Shader *computeShader = mState.getAttachedShader(gl::ShaderType::Compute); gl::Shader *computeShader = mState.getAttachedShader(gl::ShaderType::Compute);
if (computeShader) if (computeShader)
{ {
mSamplersCS.resize(data.getCaps().maxComputeTextureImageUnits); mShaderSamplers[gl::ShaderType::Compute].resize(data.getCaps().maxComputeTextureImageUnits);
mImagesCS.resize(data.getCaps().maxImageUnits); mImagesCS.resize(data.getCaps().maxImageUnits);
mReadonlyImagesCS.resize(data.getCaps().maxImageUnits); mReadonlyImagesCS.resize(data.getCaps().maxImageUnits);
...@@ -1705,18 +1688,21 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context, ...@@ -1705,18 +1688,21 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context,
} }
else else
{ {
gl::Shader *vertexShader = mState.getAttachedShader(gl::ShaderType::Vertex);
gl::Shader *fragmentShader = mState.getAttachedShader(gl::ShaderType::Fragment);
gl::ShaderMap<const ShaderD3D *> shadersD3D = {}; gl::ShaderMap<const ShaderD3D *> shadersD3D = {};
shadersD3D[gl::ShaderType::Vertex] = GetImplAs<ShaderD3D>(vertexShader); for (gl::ShaderType shaderType : gl::kAllGraphicsShaderTypes)
shadersD3D[gl::ShaderType::Fragment] = GetImplAs<ShaderD3D>(fragmentShader); {
if (mState.getAttachedShader(shaderType))
{
shadersD3D[shaderType] = GetImplAs<ShaderD3D>(mState.getAttachedShader(shaderType));
mShaderSamplers[shaderType].resize(
GetMaximumSamplersPerShader(shaderType, data.getCaps()));
mSamplersVS.resize(data.getCaps().maxVertexTextureImageUnits); shadersD3D[shaderType]->generateWorkarounds(&mShaderWorkarounds[shaderType]);
mSamplersPS.resize(data.getCaps().maxTextureImageUnits);
shadersD3D[gl::ShaderType::Vertex]->generateWorkarounds(&mVertexWorkarounds); mShaderUniformsDirty.set(shaderType);
shadersD3D[gl::ShaderType::Fragment]->generateWorkarounds(&mPixelWorkarounds); }
}
if (mRenderer->getNativeLimitations().noFrontFacingSupport) if (mRenderer->getNativeLimitations().noFrontFacingSupport)
{ {
...@@ -1731,7 +1717,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context, ...@@ -1731,7 +1717,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context,
BuiltinVaryingsD3D builtins(metadata, resources.varyingPacking); BuiltinVaryingsD3D builtins(metadata, resources.varyingPacking);
mDynamicHLSL->generateShaderLinkHLSL(context, mState, metadata, resources.varyingPacking, mDynamicHLSL->generateShaderLinkHLSL(context, mState, metadata, resources.varyingPacking,
builtins, &mPixelHLSL, &mVertexHLSL); builtins, &mShaderHLSL);
mUsesPointSize = shadersD3D[gl::ShaderType::Vertex]->usesPointSize(); mUsesPointSize = shadersD3D[gl::ShaderType::Vertex]->usesPointSize();
mDynamicHLSL->getPixelShaderOutputKey(data, mState, metadata, &mPixelShaderKey); mDynamicHLSL->getPixelShaderOutputKey(data, mState, metadata, &mPixelShaderKey);
...@@ -1740,9 +1726,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context, ...@@ -1740,9 +1726,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context,
mHasANGLEMultiviewEnabled = metadata.hasANGLEMultiviewEnabled(); mHasANGLEMultiviewEnabled = metadata.hasANGLEMultiviewEnabled();
// Cache if we use flat shading // Cache if we use flat shading
mUsesFlatInterpolation = mUsesFlatInterpolation = FindFlatInterpolationVarying(context, mState.getAttachedShaders());
(FindFlatInterpolationVarying(fragmentShader->getInputVaryings(context)) ||
FindFlatInterpolationVarying(vertexShader->getOutputVaryings(context)));
if (mRenderer->getMajorShaderModel() >= 4) if (mRenderer->getMajorShaderModel() >= 4)
{ {
...@@ -1753,10 +1737,6 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context, ...@@ -1753,10 +1737,6 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context,
initAttribLocationsToD3DSemantic(context); initAttribLocationsToD3DSemantic(context);
// TODO(jiawei.shao@intel.com): set geometry uniforms dirty if user-defined geometry shader
// exists. Tracking bug: http://anglebug.com/1941
mShaderUniformsDirty.set(gl::ShaderType::Vertex);
mShaderUniformsDirty.set(gl::ShaderType::Fragment);
defineUniformsAndAssignRegisters(context); defineUniformsAndAssignRegisters(context);
gatherTransformFeedbackVaryings(resources.varyingPacking, builtins[gl::ShaderType::Vertex]); gatherTransformFeedbackVaryings(resources.varyingPacking, builtins[gl::ShaderType::Vertex]);
...@@ -1909,7 +1889,7 @@ void ProgramD3D::updateUniformBufferCache( ...@@ -1909,7 +1889,7 @@ void ProgramD3D::updateUniformBufferCache(
unsigned int registerIndex = uniformBlock.mShaderRegisterIndexes[shaderType] - unsigned int registerIndex = uniformBlock.mShaderRegisterIndexes[shaderType] -
reservedShaderRegisterIndexes[shaderType]; reservedShaderRegisterIndexes[shaderType];
ASSERT(registerIndex < caps.maxVertexUniformBlocks); ASSERT(registerIndex < GetMaximumShaderUniformBlocksPerShader(shaderType, caps));
std::vector<int> &shaderUBOcache = mShaderUBOCaches[shaderType]; std::vector<int> &shaderUBOcache = mShaderUBOCaches[shaderType];
if (shaderUBOcache.size() <= registerIndex) if (shaderUBOcache.size() <= registerIndex)
...@@ -2485,48 +2465,29 @@ void ProgramD3D::assignSamplerRegisters(size_t uniformIndex) ...@@ -2485,48 +2465,29 @@ void ProgramD3D::assignSamplerRegisters(size_t uniformIndex)
unsigned int registerOffset = mState.getUniforms()[uniformIndex].flattenedOffsetInParentArrays * unsigned int registerOffset = mState.getUniforms()[uniformIndex].flattenedOffsetInParentArrays *
d3dUniform->getArraySizeProduct(); d3dUniform->getArraySizeProduct();
// TODO(jiawei.shao@intel.com): refactor this code when using ShaderMap on mSamplers(VS|PS|CS) bool hasUniform = false;
// and mUsed(Vertex|Pixel|Compute)SamplerRange. for (gl::ShaderType shaderType : gl::AllShaderTypes())
const gl::Shader *computeShader = mState.getAttachedShader(gl::ShaderType::Compute);
if (computeShader)
{
const ShaderD3D *computeShaderD3D =
GetImplAs<ShaderD3D>(mState.getAttachedShader(gl::ShaderType::Compute));
ASSERT(computeShaderD3D->hasUniform(baseName));
d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Compute] =
computeShaderD3D->getUniformRegister(baseName) + registerOffset;
ASSERT(d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Compute] != GL_INVALID_INDEX);
AssignSamplers(d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Compute],
d3dUniform->typeInfo, d3dUniform->getArraySizeProduct(), mSamplersCS,
&mUsedComputeSamplerRange);
}
else
{ {
const ShaderD3D *vertexShaderD3D = if (!mState.getAttachedShader(shaderType))
GetImplAs<ShaderD3D>(mState.getAttachedShader(gl::ShaderType::Vertex));
const ShaderD3D *fragmentShaderD3D =
GetImplAs<ShaderD3D>(mState.getAttachedShader(gl::ShaderType::Fragment));
ASSERT(vertexShaderD3D->hasUniform(baseName) || fragmentShaderD3D->hasUniform(baseName));
if (vertexShaderD3D->hasUniform(baseName))
{ {
d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Vertex] = continue;
vertexShaderD3D->getUniformRegister(baseName) + registerOffset;
ASSERT(d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Vertex] != GL_INVALID_INDEX);
AssignSamplers(d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Vertex],
d3dUniform->typeInfo, d3dUniform->getArraySizeProduct(), mSamplersVS,
&mUsedVertexSamplerRange);
} }
if (fragmentShaderD3D->hasUniform(baseName))
const ShaderD3D *shaderD3D = GetImplAs<ShaderD3D>(mState.getAttachedShader(shaderType));
if (shaderD3D->hasUniform(baseName))
{ {
d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Fragment] = d3dUniform->mShaderRegisterIndexes[shaderType] =
fragmentShaderD3D->getUniformRegister(baseName) + registerOffset; shaderD3D->getUniformRegister(baseName) + registerOffset;
ASSERT(d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Fragment] != ASSERT(d3dUniform->mShaderRegisterIndexes[shaderType] != GL_INVALID_VALUE);
GL_INVALID_INDEX);
AssignSamplers(d3dUniform->mShaderRegisterIndexes[gl::ShaderType::Fragment], AssignSamplers(d3dUniform->mShaderRegisterIndexes[shaderType], d3dUniform->typeInfo,
d3dUniform->typeInfo, d3dUniform->getArraySizeProduct(), mSamplersPS, d3dUniform->getArraySizeProduct(), mShaderSamplers[shaderType],
&mUsedPixelSamplerRange); &mUsedShaderSamplerRanges[shaderType]);
hasUniform = true;
} }
} }
ASSERT(hasUniform);
} }
// static // static
...@@ -2653,11 +2614,12 @@ void ProgramD3D::reset() ...@@ -2653,11 +2614,12 @@ void ProgramD3D::reset()
mComputeExecutable.reset(nullptr); mComputeExecutable.reset(nullptr);
mVertexHLSL.clear(); for (gl::ShaderType shaderType : gl::AllShaderTypes())
mVertexWorkarounds = angle::CompilerWorkaroundsD3D(); {
mShaderHLSL[shaderType].clear();
mShaderWorkarounds[shaderType] = CompilerWorkaroundsD3D();
}
mPixelHLSL.clear();
mPixelWorkarounds = angle::CompilerWorkaroundsD3D();
mUsesFragDepth = false; mUsesFragDepth = false;
mHasANGLEMultiviewEnabled = false; mHasANGLEMultiviewEnabled = false;
mUsesViewID = false; mUsesViewID = false;
...@@ -2671,17 +2633,13 @@ void ProgramD3D::reset() ...@@ -2671,17 +2633,13 @@ void ProgramD3D::reset()
for (gl::ShaderType shaderType : gl::AllShaderTypes()) for (gl::ShaderType shaderType : gl::AllShaderTypes())
{ {
mShaderUniformStorages[shaderType].reset(); mShaderUniformStorages[shaderType].reset();
mShaderSamplers[shaderType].clear();
} }
mSamplersPS.clear();
mSamplersVS.clear();
mSamplersCS.clear();
mImagesCS.clear(); mImagesCS.clear();
mReadonlyImagesCS.clear(); mReadonlyImagesCS.clear();
mUsedVertexSamplerRange = 0; mUsedShaderSamplerRanges.fill(0);
mUsedPixelSamplerRange = 0;
mUsedComputeSamplerRange = 0;
mDirtySamplerMapping = true; mDirtySamplerMapping = true;
mUsedComputeImageRange = 0; mUsedComputeImageRange = 0;
mUsedComputeReadonlyImageRange = 0; mUsedComputeReadonlyImageRange = 0;
......
...@@ -480,11 +480,9 @@ class ProgramD3D : public ProgramImpl ...@@ -480,11 +480,9 @@ class ProgramD3D : public ProgramImpl
std::vector<std::unique_ptr<ShaderExecutableD3D>> mGeometryExecutables; std::vector<std::unique_ptr<ShaderExecutableD3D>> mGeometryExecutables;
std::unique_ptr<ShaderExecutableD3D> mComputeExecutable; std::unique_ptr<ShaderExecutableD3D> mComputeExecutable;
std::string mVertexHLSL; gl::ShaderMap<std::string> mShaderHLSL;
angle::CompilerWorkaroundsD3D mVertexWorkarounds; gl::ShaderMap<angle::CompilerWorkaroundsD3D> mShaderWorkarounds;
std::string mPixelHLSL;
angle::CompilerWorkaroundsD3D mPixelWorkarounds;
bool mUsesFragDepth; bool mUsesFragDepth;
bool mHasANGLEMultiviewEnabled; bool mHasANGLEMultiviewEnabled;
bool mUsesViewID; bool mUsesViewID;
...@@ -500,12 +498,8 @@ class ProgramD3D : public ProgramImpl ...@@ -500,12 +498,8 @@ class ProgramD3D : public ProgramImpl
gl::ShaderMap<std::unique_ptr<UniformStorageD3D>> mShaderUniformStorages; gl::ShaderMap<std::unique_ptr<UniformStorageD3D>> mShaderUniformStorages;
std::vector<Sampler> mSamplersPS; gl::ShaderMap<std::vector<Sampler>> mShaderSamplers;
std::vector<Sampler> mSamplersVS; gl::ShaderMap<GLuint> mUsedShaderSamplerRanges;
std::vector<Sampler> mSamplersCS;
GLuint mUsedVertexSamplerRange;
GLuint mUsedPixelSamplerRange;
GLuint mUsedComputeSamplerRange;
bool mDirtySamplerMapping; bool mDirtySamplerMapping;
std::vector<Image> mImagesCS; std::vector<Image> mImagesCS;
......
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