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