Commit af2b33be by Jiawei Shao Committed by Commit Bot

Use ShaderMap in ProgramD3D - Part I

This patch is the first part of using ShaderMap to contain shader information in ProgramD3D, including the refactoring on struct D3DUniform, D3DUniformBlock and ProgramD3DMetadata. In the next patch all shader information in class ProgramD3D will be organized in the form of ShaderMap. BUG=angleproject:2169 Change-Id: I27008169dbf6cd8017a67f36f474667feddbd1f6 Reviewed-on: https://chromium-review.googlesource.com/1018728 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 37b3e596
...@@ -55,9 +55,7 @@ struct D3DUniform : private angle::NonCopyable ...@@ -55,9 +55,7 @@ struct D3DUniform : private angle::NonCopyable
bool isImage() const; bool isImage() const;
bool isArray() const { return !arraySizes.empty(); } bool isArray() const { return !arraySizes.empty(); }
unsigned int getArraySizeProduct() const; unsigned int getArraySizeProduct() const;
bool isReferencedByVertexShader() const; bool isReferencedByShader(gl::ShaderType shaderType) const;
bool isReferencedByFragmentShader() const;
bool isReferencedByComputeShader() const;
const uint8_t *firstNonNullData() const; const uint8_t *firstNonNullData() const;
const uint8_t *getDataPtrToElement(size_t elementIndex) const; const uint8_t *getDataPtrToElement(size_t elementIndex) const;
...@@ -68,15 +66,11 @@ struct D3DUniform : private angle::NonCopyable ...@@ -68,15 +66,11 @@ struct D3DUniform : private angle::NonCopyable
std::vector<unsigned int> arraySizes; std::vector<unsigned int> arraySizes;
// Pointer to a system copies of the data. Separate pointers for each uniform storage type. // Pointer to a system copies of the data. Separate pointers for each uniform storage type.
uint8_t *vsData; gl::ShaderMap<uint8_t *> mShaderData;
uint8_t *psData;
uint8_t *csData;
// Register information. // Register information.
HLSLRegisterType regType; HLSLRegisterType regType;
unsigned int vsRegisterIndex; gl::ShaderMap<unsigned int> mShaderRegisterIndexes;
unsigned int psRegisterIndex;
unsigned int csRegisterIndex;
unsigned int registerCount; unsigned int registerCount;
// Register "elements" are used for uniform structs in ES3, to appropriately identify single // Register "elements" are used for uniform structs in ES3, to appropriately identify single
...@@ -90,22 +84,14 @@ struct D3DUniform : private angle::NonCopyable ...@@ -90,22 +84,14 @@ struct D3DUniform : private angle::NonCopyable
struct D3DUniformBlock struct D3DUniformBlock
{ {
D3DUniformBlock() D3DUniformBlock() { mShaderRegisterIndexes.fill(GL_INVALID_INDEX); }
: vsRegisterIndex(GL_INVALID_INDEX),
psRegisterIndex(GL_INVALID_INDEX), bool activeInShader(gl::ShaderType shaderType) const
csRegisterIndex(GL_INVALID_INDEX)
{ {
return mShaderRegisterIndexes[shaderType] != GL_INVALID_INDEX;
} }
bool vertexActive() const { return vsRegisterIndex != GL_INVALID_INDEX; } gl::ShaderMap<unsigned int> mShaderRegisterIndexes;
bool fragmentActive() const { return psRegisterIndex != GL_INVALID_INDEX; }
bool computeActive() const { return csRegisterIndex != GL_INVALID_INDEX; }
unsigned int vsRegisterIndex;
unsigned int psRegisterIndex;
unsigned int csRegisterIndex;
}; };
struct D3DVarying final struct D3DVarying final
...@@ -129,8 +115,7 @@ class ProgramD3DMetadata final : angle::NonCopyable ...@@ -129,8 +115,7 @@ class ProgramD3DMetadata final : angle::NonCopyable
{ {
public: public:
ProgramD3DMetadata(RendererD3D *renderer, ProgramD3DMetadata(RendererD3D *renderer,
const ShaderD3D *vertexShader, const gl::ShaderMap<const ShaderD3D *> &attachedShaders);
const ShaderD3D *fragmentShader);
int getRendererMajorShaderModel() const; int getRendererMajorShaderModel() const;
bool usesBroadcast(const gl::ContextState &data) const; bool usesBroadcast(const gl::ContextState &data) const;
...@@ -155,11 +140,8 @@ class ProgramD3DMetadata final : angle::NonCopyable ...@@ -155,11 +140,8 @@ class ProgramD3DMetadata final : angle::NonCopyable
const std::string mShaderModelSuffix; const std::string mShaderModelSuffix;
const bool mUsesInstancedPointSpriteEmulation; const bool mUsesInstancedPointSpriteEmulation;
const bool mUsesViewScale; const bool mUsesViewScale;
const bool mHasANGLEMultiviewEnabled;
const bool mUsesViewID;
const bool mCanSelectViewInVertexShader; const bool mCanSelectViewInVertexShader;
const ShaderD3D *mVertexShader; const gl::ShaderMap<const ShaderD3D *> mAttachedShaders;
const ShaderD3D *mFragmentShader;
}; };
class ProgramD3D : public ProgramImpl class ProgramD3D : public ProgramImpl
...@@ -223,12 +205,9 @@ class ProgramD3D : public ProgramImpl ...@@ -223,12 +205,9 @@ class ProgramD3D : public ProgramImpl
GLint components, GLint components,
const GLfloat *coeffs) override; const GLfloat *coeffs) override;
void initializeUniformStorage();
void updateUniformBufferCache(const gl::Caps &caps, void updateUniformBufferCache(const gl::Caps &caps,
unsigned int reservedVertex, const gl::ShaderMap<unsigned int> &reservedShaderRegisterIndexes);
unsigned int reservedFragment); const std::vector<GLint> &getShaderUniformBufferCache(gl::ShaderType shaderType) const;
const std::vector<GLint> &getVertexUniformBufferCache() const;
const std::vector<GLint> &getFragmentUniformBufferCache() const;
void dirtyAllUniforms(); void dirtyAllUniforms();
...@@ -287,9 +266,10 @@ class ProgramD3D : public ProgramImpl ...@@ -287,9 +266,10 @@ class ProgramD3D : public ProgramImpl
void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override; void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override;
UniformStorageD3D &getVertexUniformStorage() const { return *mVertexUniformStorage.get(); } UniformStorageD3D *getShaderUniformStorage(gl::ShaderType shaderType) const
UniformStorageD3D &getFragmentUniformStorage() const { return *mFragmentUniformStorage.get(); } {
UniformStorageD3D &getComputeUniformStorage() const { return *mComputeUniformStorage.get(); } return mShaderUniformStorages[shaderType].get();
}
unsigned int getSerial() const; unsigned int getSerial() const;
...@@ -395,6 +375,8 @@ class ProgramD3D : public ProgramImpl ...@@ -395,6 +375,8 @@ class ProgramD3D : public ProgramImpl
typedef std::map<std::string, D3DUniform *> D3DUniformMap; typedef std::map<std::string, D3DUniform *> D3DUniformMap;
void initializeUniformStorage(const gl::ShaderBitSet &availableShaderStages);
void defineUniformsAndAssignRegisters(const gl::Context *context); void defineUniformsAndAssignRegisters(const gl::Context *context);
void defineUniformBase(const gl::Shader *shader, void defineUniformBase(const gl::Shader *shader,
const sh::Uniform &uniform, const sh::Uniform &uniform,
...@@ -516,9 +498,7 @@ class ProgramD3D : public ProgramImpl ...@@ -516,9 +498,7 @@ class ProgramD3D : public ProgramImpl
bool mUsesPointSize; bool mUsesPointSize;
bool mUsesFlatInterpolation; bool mUsesFlatInterpolation;
std::unique_ptr<UniformStorageD3D> mVertexUniformStorage; gl::ShaderMap<std::unique_ptr<UniformStorageD3D>> mShaderUniformStorages;
std::unique_ptr<UniformStorageD3D> mFragmentUniformStorage;
std::unique_ptr<UniformStorageD3D> mComputeUniformStorage;
std::vector<Sampler> mSamplersPS; std::vector<Sampler> mSamplersPS;
std::vector<Sampler> mSamplersVS; std::vector<Sampler> mSamplersVS;
...@@ -541,8 +521,7 @@ class ProgramD3D : public ProgramImpl ...@@ -541,8 +521,7 @@ class ProgramD3D : public ProgramImpl
unsigned int mSerial; unsigned int mSerial;
std::vector<GLint> mVertexUBOCache; gl::ShaderMap<std::vector<int>> mShaderUBOCaches;
std::vector<GLint> mFragmentUBOCache;
VertexExecutable::Signature mCachedVertexSignature; VertexExecutable::Signature mCachedVertexSignature;
gl::InputLayout mCachedInputLayout; gl::InputLayout mCachedInputLayout;
Optional<size_t> mCachedVertexExecutableIndex; Optional<size_t> mCachedVertexExecutableIndex;
......
...@@ -1996,16 +1996,15 @@ unsigned int Renderer11::getReservedFragmentUniformVectors() const ...@@ -1996,16 +1996,15 @@ unsigned int Renderer11::getReservedFragmentUniformVectors() const
return d3d11_gl::GetReservedFragmentUniformVectors(mRenderer11DeviceCaps.featureLevel); return d3d11_gl::GetReservedFragmentUniformVectors(mRenderer11DeviceCaps.featureLevel);
} }
unsigned int Renderer11::getReservedVertexUniformBuffers() const gl::ShaderMap<unsigned int> Renderer11::getReservedShaderUniformBuffers() const
{ {
// we reserve one buffer for the application uniforms, and one for driver uniforms gl::ShaderMap<unsigned int> shaderReservedUniformBuffers = {};
return 2;
}
unsigned int Renderer11::getReservedFragmentUniformBuffers() const
{
// we reserve one buffer for the application uniforms, and one for driver uniforms // we reserve one buffer for the application uniforms, and one for driver uniforms
return 2; shaderReservedUniformBuffers[gl::ShaderType::Vertex] = 2;
shaderReservedUniformBuffers[gl::ShaderType::Fragment] = 2;
return shaderReservedUniformBuffers;
} }
d3d11::ANGLED3D11DeviceType Renderer11::getDeviceType() const d3d11::ANGLED3D11DeviceType Renderer11::getDeviceType() const
......
...@@ -157,8 +157,7 @@ class Renderer11 : public RendererD3D ...@@ -157,8 +157,7 @@ class Renderer11 : public RendererD3D
unsigned int getReservedVertexUniformVectors() const; unsigned int getReservedVertexUniformVectors() const;
unsigned int getReservedFragmentUniformVectors() const; unsigned int getReservedFragmentUniformVectors() const;
unsigned int getReservedVertexUniformBuffers() const; gl::ShaderMap<unsigned int> getReservedShaderUniformBuffers() const;
unsigned int getReservedFragmentUniformBuffers() const;
bool getShareHandleSupport() const; bool getShareHandleSupport() const;
......
...@@ -3077,9 +3077,9 @@ gl::Error StateManager11::generateSwizzles(const gl::Context *context) ...@@ -3077,9 +3077,9 @@ gl::Error StateManager11::generateSwizzles(const gl::Context *context)
gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D) gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D)
{ {
UniformStorage11 *vertexUniformStorage = UniformStorage11 *vertexUniformStorage =
GetAs<UniformStorage11>(&programD3D->getVertexUniformStorage()); GetAs<UniformStorage11>(programD3D->getShaderUniformStorage(gl::ShaderType::Vertex));
UniformStorage11 *fragmentUniformStorage = UniformStorage11 *fragmentUniformStorage =
GetAs<UniformStorage11>(&programD3D->getFragmentUniformStorage()); GetAs<UniformStorage11>(programD3D->getShaderUniformStorage(gl::ShaderType::Fragment));
ASSERT(vertexUniformStorage); ASSERT(vertexUniformStorage);
ASSERT(fragmentUniformStorage); ASSERT(fragmentUniformStorage);
...@@ -3180,7 +3180,7 @@ gl::Error StateManager11::applyDriverUniforms(const ProgramD3D &programD3D) ...@@ -3180,7 +3180,7 @@ gl::Error StateManager11::applyDriverUniforms(const ProgramD3D &programD3D)
gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D)
{ {
UniformStorage11 *computeUniformStorage = UniformStorage11 *computeUniformStorage =
GetAs<UniformStorage11>(&programD3D->getComputeUniformStorage()); GetAs<UniformStorage11>(programD3D->getShaderUniformStorage(gl::ShaderType::Compute));
ASSERT(computeUniformStorage); ASSERT(computeUniformStorage);
const d3d11::Buffer *constantBuffer = nullptr; const d3d11::Buffer *constantBuffer = nullptr;
...@@ -3223,19 +3223,22 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) ...@@ -3223,19 +3223,22 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D)
gl::Error StateManager11::syncUniformBuffers(const gl::Context *context, ProgramD3D *programD3D) gl::Error StateManager11::syncUniformBuffers(const gl::Context *context, ProgramD3D *programD3D)
{ {
unsigned int reservedVertex = mRenderer->getReservedVertexUniformBuffers(); gl::ShaderMap<unsigned int> shaderReservedUBOs = mRenderer->getReservedShaderUniformBuffers();
unsigned int reservedFragment = mRenderer->getReservedFragmentUniformBuffers(); programD3D->updateUniformBufferCache(context->getCaps(), shaderReservedUBOs);
programD3D->updateUniformBufferCache(context->getCaps(), reservedVertex, reservedFragment); const auto &vertexUniformBuffers =
programD3D->getShaderUniformBufferCache(gl::ShaderType::Vertex);
const auto &vertexUniformBuffers = programD3D->getVertexUniformBufferCache(); const auto &fragmentUniformBuffers =
const auto &fragmentUniformBuffers = programD3D->getFragmentUniformBufferCache(); programD3D->getShaderUniformBufferCache(gl::ShaderType::Fragment);
const auto &glState = context->getGLState(); const auto &glState = context->getGLState();
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported(); ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported();
mConstantBufferObserver.reset(); mConstantBufferObserver.reset();
unsigned int reservedVertex = shaderReservedUBOs[gl::ShaderType::Vertex];
unsigned int reservedFragment = shaderReservedUBOs[gl::ShaderType::Fragment];
for (size_t bufferIndex = 0; bufferIndex < vertexUniformBuffers.size(); bufferIndex++) for (size_t bufferIndex = 0; bufferIndex < vertexUniformBuffers.size(); bufferIndex++)
{ {
GLint binding = vertexUniformBuffers[bufferIndex]; GLint binding = vertexUniformBuffers[bufferIndex];
......
...@@ -1817,8 +1817,8 @@ gl::Error Renderer9::applyUniforms(ProgramD3D *programD3D) ...@@ -1817,8 +1817,8 @@ gl::Error Renderer9::applyUniforms(ProgramD3D *programD3D)
for (const D3DUniform *targetUniform : uniformArray) for (const D3DUniform *targetUniform : uniformArray)
{ {
// Built-in uniforms must be skipped. // Built-in uniforms must be skipped.
if (!targetUniform->isReferencedByFragmentShader() && if (!targetUniform->isReferencedByShader(gl::ShaderType::Vertex) &&
!targetUniform->isReferencedByVertexShader()) !targetUniform->isReferencedByShader(gl::ShaderType::Fragment))
continue; continue;
const GLfloat *f = reinterpret_cast<const GLfloat *>(targetUniform->firstNonNullData()); const GLfloat *f = reinterpret_cast<const GLfloat *>(targetUniform->firstNonNullData());
...@@ -1862,15 +1862,17 @@ gl::Error Renderer9::applyUniforms(ProgramD3D *programD3D) ...@@ -1862,15 +1862,17 @@ gl::Error Renderer9::applyUniforms(ProgramD3D *programD3D)
void Renderer9::applyUniformnfv(const D3DUniform *targetUniform, const GLfloat *v) void Renderer9::applyUniformnfv(const D3DUniform *targetUniform, const GLfloat *v)
{ {
if (targetUniform->isReferencedByFragmentShader()) if (targetUniform->isReferencedByShader(gl::ShaderType::Fragment))
{ {
mDevice->SetPixelShaderConstantF(targetUniform->psRegisterIndex, v, mDevice->SetPixelShaderConstantF(
targetUniform->mShaderRegisterIndexes[gl::ShaderType::Fragment], v,
targetUniform->registerCount); targetUniform->registerCount);
} }
if (targetUniform->isReferencedByVertexShader()) if (targetUniform->isReferencedByShader(gl::ShaderType::Vertex))
{ {
mDevice->SetVertexShaderConstantF(targetUniform->vsRegisterIndex, v, mDevice->SetVertexShaderConstantF(
targetUniform->mShaderRegisterIndexes[gl::ShaderType::Vertex], v,
targetUniform->registerCount); targetUniform->registerCount);
} }
} }
......
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