Commit a914f7ff by Jiawei Shao Committed by Commit Bot

Use ShaderMap in Statemanager11 - Part II

This patch is the last patch of storing shader resources into ShaderMap in Statemanager11. This patch also splits several large functions into smaller one to make the code structure clearer. BUG=angleproject:2169 Change-Id: Id6d89976de0376b2479bd11d7551fc6f5b521c13 Reviewed-on: https://chromium-review.googlesource.com/1092511Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
parent 4004ae0e
...@@ -299,6 +299,11 @@ class ProgramD3D : public ProgramImpl ...@@ -299,6 +299,11 @@ class ProgramD3D : public ProgramImpl
const gl::ProgramState &getState() const { return mState; } const gl::ProgramState &getState() const { return mState; }
bool hasShaderStage(gl::ShaderType shaderType) const
{
return mState.getLinkedShaderStages()[shaderType];
}
private: private:
// These forward-declared tasks are used for multi-thread shader compiles. // These forward-declared tasks are used for multi-thread shader compiles.
class GetExecutableTask; class GetExecutableTask;
......
...@@ -1735,9 +1735,10 @@ void StateManager11::deinitialize() ...@@ -1735,9 +1735,10 @@ void StateManager11::deinitialize()
mVertexDataManager.deinitialize(); mVertexDataManager.deinitialize();
mIndexDataManager.deinitialize(); mIndexDataManager.deinitialize();
mDriverConstantBufferVS.reset(); for (d3d11::Buffer &ShaderDriverConstantBuffer : mShaderDriverConstantBuffers)
mDriverConstantBufferPS.reset(); {
mDriverConstantBufferCS.reset(); ShaderDriverConstantBuffer.reset();
}
mPointSpriteVertexBuffer.reset(); mPointSpriteVertexBuffer.reset();
mPointSpriteIndexBuffer.reset(); mPointSpriteIndexBuffer.reset();
...@@ -2400,6 +2401,11 @@ gl::Error StateManager11::syncTextures(const gl::Context *context) ...@@ -2400,6 +2401,11 @@ gl::Error StateManager11::syncTextures(const gl::Context *context)
{ {
ANGLE_TRY(applyTextures(context, gl::ShaderType::Vertex)); ANGLE_TRY(applyTextures(context, gl::ShaderType::Vertex));
ANGLE_TRY(applyTextures(context, gl::ShaderType::Fragment)); ANGLE_TRY(applyTextures(context, gl::ShaderType::Fragment));
if (mProgramD3D->hasShaderStage(gl::ShaderType::Geometry))
{
ANGLE_TRY(applyTextures(context, gl::ShaderType::Geometry));
}
return gl::NoError(); return gl::NoError();
} }
...@@ -2985,50 +2991,66 @@ gl::Error StateManager11::generateSwizzles(const gl::Context *context) ...@@ -2985,50 +2991,66 @@ gl::Error StateManager11::generateSwizzles(const gl::Context *context)
return gl::NoError(); return gl::NoError();
} }
gl::Error StateManager11::applyUniforms() gl::Error StateManager11::applyUniformsForShader(gl::ShaderType shaderType)
{ {
UniformStorage11 *vertexUniformStorage = UniformStorage11 *shaderUniformStorage =
GetAs<UniformStorage11>(mProgramD3D->getShaderUniformStorage(gl::ShaderType::Vertex)); GetAs<UniformStorage11>(mProgramD3D->getShaderUniformStorage(shaderType));
UniformStorage11 *fragmentUniformStorage = ASSERT(shaderUniformStorage);
GetAs<UniformStorage11>(mProgramD3D->getShaderUniformStorage(gl::ShaderType::Fragment));
ASSERT(vertexUniformStorage);
ASSERT(fragmentUniformStorage);
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
const d3d11::Buffer *vertexConstantBuffer = nullptr; const d3d11::Buffer *shaderConstantBuffer = nullptr;
ANGLE_TRY(vertexUniformStorage->getConstantBuffer(mRenderer, &vertexConstantBuffer)); ANGLE_TRY(shaderUniformStorage->getConstantBuffer(mRenderer, &shaderConstantBuffer));
const d3d11::Buffer *pixelConstantBuffer = nullptr;
ANGLE_TRY(fragmentUniformStorage->getConstantBuffer(mRenderer, &pixelConstantBuffer));
if (vertexUniformStorage->size() > 0 && if (shaderUniformStorage->size() > 0 && mProgramD3D->areShaderUniformsDirty(shaderType))
mProgramD3D->areShaderUniformsDirty(gl::ShaderType::Vertex))
{ {
UpdateUniformBuffer(deviceContext, vertexUniformStorage, vertexConstantBuffer); UpdateUniformBuffer(deviceContext, shaderUniformStorage, shaderConstantBuffer);
}
if (fragmentUniformStorage->size() > 0 &&
mProgramD3D->areShaderUniformsDirty(gl::ShaderType::Fragment))
{
UpdateUniformBuffer(deviceContext, fragmentUniformStorage, pixelConstantBuffer);
} }
unsigned int slot = d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK; unsigned int slot = d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK;
if (mCurrentConstantBufferVS[slot] != vertexConstantBuffer->getSerial()) switch (shaderType)
{ {
deviceContext->VSSetConstantBuffers(slot, 1, vertexConstantBuffer->getPointer()); case gl::ShaderType::Vertex:
mCurrentConstantBufferVS[slot] = vertexConstantBuffer->getSerial(); if (mCurrentConstantBufferVS[slot] != shaderConstantBuffer->getSerial())
mCurrentConstantBufferVSOffset[slot] = 0; {
mCurrentConstantBufferVSSize[slot] = 0; deviceContext->VSSetConstantBuffers(slot, 1, shaderConstantBuffer->getPointer());
mCurrentConstantBufferVS[slot] = shaderConstantBuffer->getSerial();
mCurrentConstantBufferVSOffset[slot] = 0;
mCurrentConstantBufferVSSize[slot] = 0;
}
break;
case gl::ShaderType::Fragment:
if (mCurrentConstantBufferPS[slot] != shaderConstantBuffer->getSerial())
{
deviceContext->PSSetConstantBuffers(slot, 1, shaderConstantBuffer->getPointer());
mCurrentConstantBufferPS[slot] = shaderConstantBuffer->getSerial();
mCurrentConstantBufferPSOffset[slot] = 0;
mCurrentConstantBufferPSSize[slot] = 0;
}
break;
// TODO(jiawei.shao@intel.com): apply geometry shader uniforms
case gl::ShaderType::Geometry:
UNIMPLEMENTED();
break;
default:
UNREACHABLE();
break;
} }
if (mCurrentConstantBufferPS[slot] != pixelConstantBuffer->getSerial()) return gl::NoError();
}
gl::Error StateManager11::applyUniforms()
{
ANGLE_TRY(applyUniformsForShader(gl::ShaderType::Vertex));
ANGLE_TRY(applyUniformsForShader(gl::ShaderType::Fragment));
if (mProgramD3D->hasShaderStage(gl::ShaderType::Geometry))
{ {
deviceContext->PSSetConstantBuffers(slot, 1, pixelConstantBuffer->getPointer()); ANGLE_TRY(applyUniformsForShader(gl::ShaderType::Geometry));
mCurrentConstantBufferPS[slot] = pixelConstantBuffer->getSerial();
mCurrentConstantBufferPSOffset[slot] = 0;
mCurrentConstantBufferPSSize[slot] = 0;
} }
mProgramD3D->markUniformsClean(); mProgramD3D->markUniformsClean();
...@@ -3036,52 +3058,74 @@ gl::Error StateManager11::applyUniforms() ...@@ -3036,52 +3058,74 @@ gl::Error StateManager11::applyUniforms()
return gl::NoError(); return gl::NoError();
} }
gl::Error StateManager11::applyDriverUniforms() gl::Error StateManager11::applyDriverUniformsForShader(gl::ShaderType shaderType)
{ {
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
if (!mDriverConstantBufferVS.valid()) d3d11::Buffer &shaderDriverConstantBuffer = mShaderDriverConstantBuffers[shaderType];
if (!shaderDriverConstantBuffer.valid())
{ {
size_t requiredSize = mShaderConstants.getRequiredBufferSize(gl::ShaderType::Vertex); size_t requiredSize = mShaderConstants.getRequiredBufferSize(shaderType);
D3D11_BUFFER_DESC constantBufferDescription = {0}; D3D11_BUFFER_DESC constantBufferDescription = {0};
d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize); d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize);
ANGLE_TRY(mRenderer->allocateResource(constantBufferDescription, &mDriverConstantBufferVS)); ANGLE_TRY(
mRenderer->allocateResource(constantBufferDescription, &shaderDriverConstantBuffer));
ID3D11Buffer *driverVSConstants = mDriverConstantBufferVS.get(); ID3D11Buffer *driverConstants = shaderDriverConstantBuffer.get();
deviceContext->VSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, switch (shaderType)
&driverVSConstants); {
} case gl::ShaderType::Vertex:
deviceContext->VSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1,
&driverConstants);
break;
if (!mDriverConstantBufferPS.valid()) case gl::ShaderType::Fragment:
{ deviceContext->PSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1,
size_t requiredSize = mShaderConstants.getRequiredBufferSize(gl::ShaderType::Fragment); &driverConstants);
break;
D3D11_BUFFER_DESC constantBufferDescription = {0}; case gl::ShaderType::Geometry:
d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize); deviceContext->GSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1,
ANGLE_TRY(mRenderer->allocateResource(constantBufferDescription, &mDriverConstantBufferPS)); &driverConstants);
break;
ID3D11Buffer *driverVSConstants = mDriverConstantBufferPS.get(); default:
deviceContext->PSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, UNREACHABLE();
&driverVSConstants); return gl::NoError();
}
} }
// Sampler metadata and driver constants need to coexist in the same constant buffer to conserve // Sampler metadata and driver constants need to coexist in the same constant buffer to
// constant buffer slots. We update both in the constant buffer if needed. // conserve constant buffer slots. We update both in the constant buffer if needed.
ANGLE_TRY(mShaderConstants.updateBuffer(mRenderer, gl::ShaderType::Vertex, *mProgramD3D, ANGLE_TRY(mShaderConstants.updateBuffer(mRenderer, shaderType, *mProgramD3D,
mDriverConstantBufferVS)); shaderDriverConstantBuffer));
ANGLE_TRY(mShaderConstants.updateBuffer(mRenderer, gl::ShaderType::Fragment, *mProgramD3D,
mDriverConstantBufferPS)); return gl::NoError();
}
gl::Error StateManager11::applyDriverUniforms()
{
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ANGLE_TRY(applyDriverUniformsForShader(gl::ShaderType::Vertex));
ANGLE_TRY(applyDriverUniformsForShader(gl::ShaderType::Fragment));
if (mProgramD3D->hasShaderStage(gl::ShaderType::Geometry))
{
ANGLE_TRY(applyDriverUniformsForShader(gl::ShaderType::Geometry));
}
// needed for the point sprite geometry shader // needed for the point sprite geometry shader
// GSSetConstantBuffers triggers device removal on 9_3, so we should only call it for ES3. // GSSetConstantBuffers triggers device removal on 9_3, so we should only call it for ES3.
if (mRenderer->isES3Capable()) if (mRenderer->isES3Capable())
{ {
if (mCurrentGeometryConstantBuffer != mDriverConstantBufferPS.getSerial()) d3d11::Buffer &driverConstantBufferPS =
mShaderDriverConstantBuffers[gl::ShaderType::Fragment];
if (mCurrentGeometryConstantBuffer != driverConstantBufferPS.getSerial())
{ {
ASSERT(mDriverConstantBufferPS.valid()); ASSERT(driverConstantBufferPS.valid());
deviceContext->GSSetConstantBuffers(0, 1, mDriverConstantBufferPS.getPointer()); deviceContext->GSSetConstantBuffers(0, 1, driverConstantBufferPS.getPointer());
mCurrentGeometryConstantBuffer = mDriverConstantBufferPS.getSerial(); mCurrentGeometryConstantBuffer = driverConstantBufferPS.getSerial();
} }
} }
...@@ -3114,54 +3158,48 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) ...@@ -3114,54 +3158,48 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D)
mCurrentComputeConstantBuffer = constantBuffer->getSerial(); mCurrentComputeConstantBuffer = constantBuffer->getSerial();
} }
if (!mDriverConstantBufferCS.valid()) if (!mShaderDriverConstantBuffers[gl::ShaderType::Compute].valid())
{ {
size_t requiredSize = mShaderConstants.getRequiredBufferSize(gl::ShaderType::Compute); size_t requiredSize = mShaderConstants.getRequiredBufferSize(gl::ShaderType::Compute);
D3D11_BUFFER_DESC constantBufferDescription = {0}; D3D11_BUFFER_DESC constantBufferDescription = {0};
d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize); d3d11::InitConstantBufferDesc(&constantBufferDescription, requiredSize);
ANGLE_TRY(mRenderer->allocateResource(constantBufferDescription, &mDriverConstantBufferCS)); ANGLE_TRY(mRenderer->allocateResource(
ID3D11Buffer *buffer = mDriverConstantBufferCS.get(); constantBufferDescription, &mShaderDriverConstantBuffers[gl::ShaderType::Compute]));
ID3D11Buffer *buffer = mShaderDriverConstantBuffers[gl::ShaderType::Compute].get();
deviceContext->CSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, deviceContext->CSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1,
&buffer); &buffer);
} }
ANGLE_TRY(mShaderConstants.updateBuffer(mRenderer, gl::ShaderType::Compute, *programD3D, ANGLE_TRY(mShaderConstants.updateBuffer(mRenderer, gl::ShaderType::Compute, *programD3D,
mDriverConstantBufferCS)); mShaderDriverConstantBuffers[gl::ShaderType::Compute]));
return gl::NoError(); return gl::NoError();
} }
gl::Error StateManager11::syncUniformBuffers(const gl::Context *context) gl::Error StateManager11::syncUniformBuffersForShader(const gl::Context *context,
gl::ShaderType shaderType)
{ {
gl::ShaderMap<unsigned int> shaderReservedUBOs = mRenderer->getReservedShaderUniformBuffers(); gl::ShaderMap<unsigned int> shaderReservedUBOs = mRenderer->getReservedShaderUniformBuffers();
mProgramD3D->updateUniformBufferCache(context->getCaps(), shaderReservedUBOs);
const auto &vertexUniformBuffers =
mProgramD3D->getShaderUniformBufferCache(gl::ShaderType::Vertex);
const auto &fragmentUniformBuffers =
mProgramD3D->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(); const auto &shaderUniformBuffers = mProgramD3D->getShaderUniformBufferCache(shaderType);
const unsigned int reservedUBOs = shaderReservedUBOs[shaderType];
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 < shaderUniformBuffers.size(); ++bufferIndex)
{ {
GLint binding = vertexUniformBuffers[bufferIndex]; const GLint binding = shaderUniformBuffers[bufferIndex];
if (binding == -1) if (binding == -1)
{ {
continue; continue;
} }
const auto &uniformBuffer = glState.getIndexedUniformBuffer(binding); const auto &uniformBuffer = glState.getIndexedUniformBuffer(binding);
GLintptr uniformBufferOffset = uniformBuffer.getOffset(); const GLintptr uniformBufferOffset = uniformBuffer.getOffset();
GLsizeiptr uniformBufferSize = uniformBuffer.getSize(); const GLsizeiptr uniformBufferSize = uniformBuffer.getSize();
if (uniformBuffer.get() == nullptr) if (uniformBuffer.get() == nullptr)
{ {
...@@ -3176,89 +3214,93 @@ gl::Error StateManager11::syncUniformBuffers(const gl::Context *context) ...@@ -3176,89 +3214,93 @@ gl::Error StateManager11::syncUniformBuffers(const gl::Context *context)
ANGLE_TRY(bufferStorage->getConstantBufferRange(context, uniformBufferOffset, ANGLE_TRY(bufferStorage->getConstantBufferRange(context, uniformBufferOffset,
uniformBufferSize, &constantBuffer, uniformBufferSize, &constantBuffer,
&firstConstant, &numConstants)); &firstConstant, &numConstants));
ASSERT(constantBuffer); ASSERT(constantBuffer);
if (mCurrentConstantBufferVS[bufferIndex] == constantBuffer->getSerial() && const unsigned int appliedIndex = reservedUBOs + static_cast<unsigned int>(bufferIndex);
mCurrentConstantBufferVSOffset[bufferIndex] == uniformBufferOffset && switch (shaderType)
mCurrentConstantBufferVSSize[bufferIndex] == uniformBufferSize)
{ {
continue; case gl::ShaderType::Vertex:
} {
if (mCurrentConstantBufferVS[bufferIndex] == constantBuffer->getSerial() &&
unsigned int appliedIndex = reservedVertex + static_cast<unsigned int>(bufferIndex); mCurrentConstantBufferVSOffset[bufferIndex] == uniformBufferOffset &&
mCurrentConstantBufferVSSize[bufferIndex] == uniformBufferSize)
{
continue;
}
if (firstConstant != 0 && uniformBufferSize != 0) if (firstConstant != 0 && uniformBufferSize != 0)
{ {
ASSERT(numConstants != 0); ASSERT(numConstants != 0);
deviceContext1->VSSetConstantBuffers1(appliedIndex, 1, constantBuffer->getPointer(), deviceContext1->VSSetConstantBuffers1(appliedIndex, 1,
&firstConstant, &numConstants); constantBuffer->getPointer(),
} &firstConstant, &numConstants);
else }
{ else
deviceContext->VSSetConstantBuffers(appliedIndex, 1, constantBuffer->getPointer()); {
} deviceContext->VSSetConstantBuffers(appliedIndex, 1,
constantBuffer->getPointer());
}
mCurrentConstantBufferVS[appliedIndex] = constantBuffer->getSerial(); mCurrentConstantBufferVS[appliedIndex] = constantBuffer->getSerial();
mCurrentConstantBufferVSOffset[appliedIndex] = uniformBufferOffset; mCurrentConstantBufferVSOffset[appliedIndex] = uniformBufferOffset;
mCurrentConstantBufferVSSize[appliedIndex] = uniformBufferSize; mCurrentConstantBufferVSSize[appliedIndex] = uniformBufferSize;
break;
}
mConstantBufferObserver.bindVS(bufferIndex, bufferStorage); case gl::ShaderType::Fragment:
} {
if (mCurrentConstantBufferPS[bufferIndex] == constantBuffer->getSerial() &&
mCurrentConstantBufferPSOffset[bufferIndex] == uniformBufferOffset &&
mCurrentConstantBufferPSSize[bufferIndex] == uniformBufferSize)
{
continue;
}
for (size_t bufferIndex = 0; bufferIndex < fragmentUniformBuffers.size(); bufferIndex++) if (firstConstant != 0 && uniformBufferSize != 0)
{ {
GLint binding = fragmentUniformBuffers[bufferIndex]; deviceContext1->PSSetConstantBuffers1(appliedIndex, 1,
constantBuffer->getPointer(),
&firstConstant, &numConstants);
}
else
{
deviceContext->PSSetConstantBuffers(appliedIndex, 1,
constantBuffer->getPointer());
}
if (binding == -1) mCurrentConstantBufferPS[appliedIndex] = constantBuffer->getSerial();
{ mCurrentConstantBufferPSOffset[appliedIndex] = uniformBufferOffset;
continue; mCurrentConstantBufferPSSize[appliedIndex] = uniformBufferSize;
} break;
}
const auto &uniformBuffer = glState.getIndexedUniformBuffer(binding); // TODO(jiawei.shao@intel.com): update geometry shader uniform buffers.
GLintptr uniformBufferOffset = uniformBuffer.getOffset(); case gl::ShaderType::Geometry:
GLsizeiptr uniformBufferSize = uniformBuffer.getSize(); UNIMPLEMENTED();
break;
if (uniformBuffer.get() == nullptr) default:
{ UNREACHABLE();
continue;
} }
Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get()); mConstantBufferObserver.bindToShader(shaderType, bufferIndex, bufferStorage);
const d3d11::Buffer *constantBuffer = nullptr; }
UINT firstConstant = 0;
UINT numConstants = 0;
ANGLE_TRY(bufferStorage->getConstantBufferRange(context, uniformBufferOffset,
uniformBufferSize, &constantBuffer,
&firstConstant, &numConstants));
ASSERT(constantBuffer);
if (mCurrentConstantBufferPS[bufferIndex] == constantBuffer->getSerial() &&
mCurrentConstantBufferPSOffset[bufferIndex] == uniformBufferOffset &&
mCurrentConstantBufferPSSize[bufferIndex] == uniformBufferSize)
{
continue;
}
unsigned int appliedIndex = reservedFragment + static_cast<unsigned int>(bufferIndex); return gl::NoError();
}
if (firstConstant != 0 && uniformBufferSize != 0) gl::Error StateManager11::syncUniformBuffers(const gl::Context *context)
{ {
deviceContext1->PSSetConstantBuffers1(appliedIndex, 1, constantBuffer->getPointer(), gl::ShaderMap<unsigned int> shaderReservedUBOs = mRenderer->getReservedShaderUniformBuffers();
&firstConstant, &numConstants); mProgramD3D->updateUniformBufferCache(context->getCaps(), shaderReservedUBOs);
}
else
{
deviceContext->PSSetConstantBuffers(appliedIndex, 1, constantBuffer->getPointer());
}
mCurrentConstantBufferPS[appliedIndex] = constantBuffer->getSerial(); mConstantBufferObserver.reset();
mCurrentConstantBufferPSOffset[appliedIndex] = uniformBufferOffset;
mCurrentConstantBufferPSSize[appliedIndex] = uniformBufferSize;
mConstantBufferObserver.bindPS(bufferIndex, bufferStorage); ANGLE_TRY(syncUniformBuffersForShader(context, gl::ShaderType::Vertex));
ANGLE_TRY(syncUniformBuffersForShader(context, gl::ShaderType::Fragment));
if (mProgramD3D->hasShaderStage(gl::ShaderType::Geometry))
{
ANGLE_TRY(syncUniformBuffersForShader(context, gl::ShaderType::Geometry));
} }
return gl::NoError(); return gl::NoError();
...@@ -3301,18 +3343,19 @@ gl::Error StateManager11::syncTransformFeedbackBuffers(const gl::Context *contex ...@@ -3301,18 +3343,19 @@ gl::Error StateManager11::syncTransformFeedbackBuffers(const gl::Context *contex
} }
// ConstantBufferObserver implementation. // ConstantBufferObserver implementation.
// TODO(jiawei.shao@intel.com): add constant buffer observers for geometry shader.
StateManager11::ConstantBufferObserver::ConstantBufferObserver() StateManager11::ConstantBufferObserver::ConstantBufferObserver()
{ {
for (size_t vsIndex = 0; vsIndex < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; for (size_t vsIndex = 0; vsIndex < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS;
++vsIndex) ++vsIndex)
{ {
mBindingsVS.emplace_back(this, vsIndex); mShaderBindings[gl::ShaderType::Vertex].emplace_back(this, vsIndex);
} }
for (size_t fsIndex = 0; fsIndex < gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS; for (size_t fsIndex = 0; fsIndex < gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS;
++fsIndex) ++fsIndex)
{ {
mBindingsPS.emplace_back(this, fsIndex); mShaderBindings[gl::ShaderType::Fragment].emplace_back(this, fsIndex);
} }
} }
...@@ -3332,30 +3375,24 @@ void StateManager11::ConstantBufferObserver::onSubjectStateChange(const gl::Cont ...@@ -3332,30 +3375,24 @@ void StateManager11::ConstantBufferObserver::onSubjectStateChange(const gl::Cont
} }
} }
void StateManager11::ConstantBufferObserver::bindVS(size_t index, Buffer11 *buffer) void StateManager11::ConstantBufferObserver::bindToShader(gl::ShaderType shaderType,
{ size_t index,
ASSERT(buffer); Buffer11 *buffer)
ASSERT(index < mBindingsVS.size());
mBindingsVS[index].bind(buffer);
}
void StateManager11::ConstantBufferObserver::bindPS(size_t index, Buffer11 *buffer)
{ {
ASSERT(buffer); ASSERT(buffer);
ASSERT(index < mBindingsPS.size()); ASSERT(shaderType != gl::ShaderType::InvalidEnum);
mBindingsPS[index].bind(buffer); ASSERT(index < mShaderBindings[shaderType].size());
mShaderBindings[shaderType][index].bind(buffer);
} }
void StateManager11::ConstantBufferObserver::reset() void StateManager11::ConstantBufferObserver::reset()
{ {
for (angle::ObserverBinding &vsBinding : mBindingsVS) for (std::vector<angle::ObserverBinding> &shaderBindings : mShaderBindings)
{ {
vsBinding.bind(nullptr); for (angle::ObserverBinding &shaderBinding : shaderBindings)
} {
shaderBinding.bind(nullptr);
for (angle::ObserverBinding &psBinding : mBindingsPS) }
{
psBinding.bind(nullptr);
} }
} }
......
...@@ -316,9 +316,12 @@ class StateManager11 final : angle::NonCopyable ...@@ -316,9 +316,12 @@ class StateManager11 final : angle::NonCopyable
gl::Error generateSwizzles(const gl::Context *context); gl::Error generateSwizzles(const gl::Context *context);
gl::Error applyDriverUniforms(); gl::Error applyDriverUniforms();
gl::Error applyDriverUniformsForShader(gl::ShaderType shaderType);
gl::Error applyUniforms(); gl::Error applyUniforms();
gl::Error applyUniformsForShader(gl::ShaderType shaderType);
gl::Error syncUniformBuffers(const gl::Context *context); gl::Error syncUniformBuffers(const gl::Context *context);
gl::Error syncUniformBuffersForShader(const gl::Context *context, gl::ShaderType shaderType);
gl::Error syncTransformFeedbackBuffers(const gl::Context *context); gl::Error syncTransformFeedbackBuffers(const gl::Context *context);
// These are currently only called internally. // These are currently only called internally.
...@@ -513,9 +516,7 @@ class StateManager11 final : angle::NonCopyable ...@@ -513,9 +516,7 @@ class StateManager11 final : angle::NonCopyable
bool mIsMultiviewEnabled; bool mIsMultiviewEnabled;
// Driver Constants. // Driver Constants.
d3d11::Buffer mDriverConstantBufferVS; gl::ShaderMap<d3d11::Buffer> mShaderDriverConstantBuffers;
d3d11::Buffer mDriverConstantBufferPS;
d3d11::Buffer mDriverConstantBufferCS;
ResourceSerial mCurrentComputeConstantBuffer; ResourceSerial mCurrentComputeConstantBuffer;
ResourceSerial mCurrentGeometryConstantBuffer; ResourceSerial mCurrentGeometryConstantBuffer;
...@@ -550,12 +551,10 @@ class StateManager11 final : angle::NonCopyable ...@@ -550,12 +551,10 @@ class StateManager11 final : angle::NonCopyable
angle::SubjectMessage message) override; angle::SubjectMessage message) override;
void reset(); void reset();
void bindVS(size_t index, Buffer11 *buffer); void bindToShader(gl::ShaderType shaderType, size_t index, Buffer11 *buffer);
void bindPS(size_t index, Buffer11 *buffer);
private: private:
std::vector<angle::ObserverBinding> mBindingsVS; gl::ShaderMap<std::vector<angle::ObserverBinding>> mShaderBindings;
std::vector<angle::ObserverBinding> mBindingsPS;
}; };
ConstantBufferObserver mConstantBufferObserver; ConstantBufferObserver mConstantBufferObserver;
......
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