Commit d63961d0 by Jamie Madill Committed by Commit Bot

D3D11: Move Constant Buffer state to StateManager11.

Also moves the logic of the constant buffer sync to StateManager11. Removes a few of the remaining virtual methods in RendererD3D. BUG=angleproject:1390 BUG=angleproject:2052 Change-Id: Ia6c1c3949fff84323331510d80bbfb6e1665d294 Reviewed-on: https://chromium-review.googlesource.com/659226 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 9df395c8
...@@ -1765,11 +1765,13 @@ void ProgramD3D::initializeUniformStorage() ...@@ -1765,11 +1765,13 @@ void ProgramD3D::initializeUniformStorage()
} }
} }
gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data) void ProgramD3D::updateUniformBufferCache(const gl::Caps &caps,
unsigned int reservedVertex,
unsigned int reservedFragment)
{ {
if (mState.getUniformBlocks().empty()) if (mState.getUniformBlocks().empty())
{ {
return gl::NoError(); return;
} }
ensureUniformBlocksInitialized(); ensureUniformBlocksInitialized();
...@@ -1777,9 +1779,6 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data) ...@@ -1777,9 +1779,6 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data)
mVertexUBOCache.clear(); mVertexUBOCache.clear();
mFragmentUBOCache.clear(); mFragmentUBOCache.clear();
const unsigned int reservedBuffersInVS = mRenderer->getReservedVertexUniformBuffers();
const unsigned int reservedBuffersInFS = mRenderer->getReservedFragmentUniformBuffers();
for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < mD3DUniformBlocks.size(); for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < mD3DUniformBlocks.size();
uniformBlockIndex++) uniformBlockIndex++)
{ {
...@@ -1794,8 +1793,8 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data) ...@@ -1794,8 +1793,8 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data)
if (uniformBlock.vertexStaticUse()) if (uniformBlock.vertexStaticUse())
{ {
unsigned int registerIndex = uniformBlock.vsRegisterIndex - reservedBuffersInVS; unsigned int registerIndex = uniformBlock.vsRegisterIndex - reservedVertex;
ASSERT(registerIndex < data.getCaps().maxVertexUniformBlocks); ASSERT(registerIndex < caps.maxVertexUniformBlocks);
if (mVertexUBOCache.size() <= registerIndex) if (mVertexUBOCache.size() <= registerIndex)
{ {
...@@ -1808,8 +1807,8 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data) ...@@ -1808,8 +1807,8 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data)
if (uniformBlock.fragmentStaticUse()) if (uniformBlock.fragmentStaticUse())
{ {
unsigned int registerIndex = uniformBlock.psRegisterIndex - reservedBuffersInFS; unsigned int registerIndex = uniformBlock.psRegisterIndex - reservedFragment;
ASSERT(registerIndex < data.getCaps().maxFragmentUniformBlocks); ASSERT(registerIndex < caps.maxFragmentUniformBlocks);
if (mFragmentUBOCache.size() <= registerIndex) if (mFragmentUBOCache.size() <= registerIndex)
{ {
...@@ -1820,8 +1819,16 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data) ...@@ -1820,8 +1819,16 @@ gl::Error ProgramD3D::applyUniformBuffers(const gl::ContextState &data)
mFragmentUBOCache[registerIndex] = blockBinding; mFragmentUBOCache[registerIndex] = blockBinding;
} }
} }
}
return mRenderer->setUniformBuffers(data, mVertexUBOCache, mFragmentUBOCache); const std::vector<GLint> &ProgramD3D::getVertexUniformBufferCache() const
{
return mVertexUBOCache;
}
const std::vector<GLint> &ProgramD3D::getFragmentUniformBufferCache() const
{
return mFragmentUBOCache;
} }
void ProgramD3D::dirtyAllUniforms() void ProgramD3D::dirtyAllUniforms()
......
...@@ -208,7 +208,12 @@ class ProgramD3D : public ProgramImpl ...@@ -208,7 +208,12 @@ class ProgramD3D : public ProgramImpl
const GLfloat *coeffs) override; const GLfloat *coeffs) override;
void initializeUniformStorage(); void initializeUniformStorage();
gl::Error applyUniformBuffers(const gl::ContextState &data); void updateUniformBufferCache(const gl::Caps &caps,
unsigned int reservedVertex,
unsigned int reservedFragment);
const std::vector<GLint> &getVertexUniformBufferCache() const;
const std::vector<GLint> &getFragmentUniformBufferCache() const;
void dirtyAllUniforms(); void dirtyAllUniforms();
void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); void setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
......
...@@ -150,13 +150,6 @@ class RendererD3D : public BufferFactoryD3D ...@@ -150,13 +150,6 @@ class RendererD3D : public BufferFactoryD3D
HANDLE shareHandle, HANDLE shareHandle,
const egl::AttributeMap &attribs) const = 0; const egl::AttributeMap &attribs) const = 0;
virtual gl::Error setUniformBuffers(const gl::ContextState &data,
const std::vector<GLint> &vertexUniformBuffers,
const std::vector<GLint> &fragmentUniformBuffers) = 0;
virtual unsigned int getReservedVertexUniformBuffers() const = 0;
virtual unsigned int getReservedFragmentUniformBuffers() const = 0;
virtual int getMajorShaderModel() const = 0; virtual int getMajorShaderModel() const = 0;
const angle::WorkaroundsD3D &getWorkarounds() const; const angle::WorkaroundsD3D &getWorkarounds() const;
......
...@@ -646,7 +646,7 @@ gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getEmulatedIndexedBuffer( ...@@ -646,7 +646,7 @@ gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getEmulatedIndexedBuffer(
gl::Error Buffer11::getConstantBufferRange(GLintptr offset, gl::Error Buffer11::getConstantBufferRange(GLintptr offset,
GLsizeiptr size, GLsizeiptr size,
ID3D11Buffer **bufferOut, const d3d11::Buffer **bufferOut,
UINT *firstConstantOut, UINT *firstConstantOut,
UINT *numConstantsOut) UINT *numConstantsOut)
{ {
...@@ -664,7 +664,7 @@ gl::Error Buffer11::getConstantBufferRange(GLintptr offset, ...@@ -664,7 +664,7 @@ gl::Error Buffer11::getConstantBufferRange(GLintptr offset,
*numConstantsOut = 0; *numConstantsOut = 0;
} }
*bufferOut = GetAs<NativeStorage>(bufferStorage)->getBuffer().get(); *bufferOut = &GetAs<NativeStorage>(bufferStorage)->getBuffer();
return gl::NoError(); return gl::NoError();
} }
......
...@@ -59,7 +59,7 @@ class Buffer11 : public BufferD3D ...@@ -59,7 +59,7 @@ class Buffer11 : public BufferD3D
GLint startVertex); GLint startVertex);
gl::Error getConstantBufferRange(GLintptr offset, gl::Error getConstantBufferRange(GLintptr offset,
GLsizeiptr size, GLsizeiptr size,
ID3D11Buffer **bufferOut, const d3d11::Buffer **bufferOut,
UINT *firstConstantOut, UINT *firstConstantOut,
UINT *numConstantsOut); UINT *numConstantsOut);
gl::ErrorOrResult<ID3D11ShaderResourceView *> getSRV(DXGI_FORMAT srvFormat); gl::ErrorOrResult<ID3D11ShaderResourceView *> getSRV(DXGI_FORMAT srvFormat);
......
...@@ -1399,132 +1399,6 @@ void *Renderer11::getD3DDevice() ...@@ -1399,132 +1399,6 @@ void *Renderer11::getD3DDevice()
return reinterpret_cast<void *>(mDevice); return reinterpret_cast<void *>(mDevice);
} }
gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
const std::vector<GLint> &vertexUniformBuffers,
const std::vector<GLint> &fragmentUniformBuffers)
{
for (size_t uniformBufferIndex = 0; uniformBufferIndex < vertexUniformBuffers.size();
uniformBufferIndex++)
{
GLint binding = vertexUniformBuffers[uniformBufferIndex];
if (binding == -1)
{
continue;
}
const gl::OffsetBindingPointer<gl::Buffer> &uniformBuffer =
data.getState().getIndexedUniformBuffer(binding);
GLintptr uniformBufferOffset = uniformBuffer.getOffset();
GLsizeiptr uniformBufferSize = uniformBuffer.getSize();
if (uniformBuffer.get() == nullptr)
{
continue;
}
Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get());
ID3D11Buffer *constantBuffer = nullptr;
UINT firstConstant = 0;
UINT numConstants = 0;
ANGLE_TRY(bufferStorage->getConstantBufferRange(uniformBufferOffset, uniformBufferSize,
&constantBuffer, &firstConstant,
&numConstants));
if (!constantBuffer)
{
return gl::OutOfMemory() << "Error retrieving constant buffer";
}
if (mCurrentConstantBufferVS[uniformBufferIndex] != bufferStorage->getSerial() ||
mCurrentConstantBufferVSOffset[uniformBufferIndex] != uniformBufferOffset ||
mCurrentConstantBufferVSSize[uniformBufferIndex] != uniformBufferSize)
{
if (firstConstant != 0 && uniformBufferSize != 0)
{
ASSERT(numConstants != 0);
mDeviceContext1->VSSetConstantBuffers1(
getReservedVertexUniformBuffers() +
static_cast<unsigned int>(uniformBufferIndex),
1, &constantBuffer, &firstConstant, &numConstants);
}
else
{
mDeviceContext->VSSetConstantBuffers(
getReservedVertexUniformBuffers() +
static_cast<unsigned int>(uniformBufferIndex),
1, &constantBuffer);
}
mCurrentConstantBufferVS[uniformBufferIndex] = bufferStorage->getSerial();
mCurrentConstantBufferVSOffset[uniformBufferIndex] = uniformBufferOffset;
mCurrentConstantBufferVSSize[uniformBufferIndex] = uniformBufferSize;
}
}
for (size_t uniformBufferIndex = 0; uniformBufferIndex < fragmentUniformBuffers.size();
uniformBufferIndex++)
{
GLint binding = fragmentUniformBuffers[uniformBufferIndex];
if (binding == -1)
{
continue;
}
const gl::OffsetBindingPointer<gl::Buffer> &uniformBuffer =
data.getState().getIndexedUniformBuffer(binding);
GLintptr uniformBufferOffset = uniformBuffer.getOffset();
GLsizeiptr uniformBufferSize = uniformBuffer.getSize();
if (uniformBuffer.get() == nullptr)
{
continue;
}
Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get());
ID3D11Buffer *constantBuffer = nullptr;
UINT firstConstant = 0;
UINT numConstants = 0;
ANGLE_TRY(bufferStorage->getConstantBufferRange(uniformBufferOffset, uniformBufferSize,
&constantBuffer, &firstConstant,
&numConstants));
if (!constantBuffer)
{
return gl::OutOfMemory() << "Error retrieving constant buffer";
}
if (mCurrentConstantBufferPS[uniformBufferIndex] != bufferStorage->getSerial() ||
mCurrentConstantBufferPSOffset[uniformBufferIndex] != uniformBufferOffset ||
mCurrentConstantBufferPSSize[uniformBufferIndex] != uniformBufferSize)
{
if (firstConstant != 0 && uniformBufferSize != 0)
{
mDeviceContext1->PSSetConstantBuffers1(
getReservedFragmentUniformBuffers() +
static_cast<unsigned int>(uniformBufferIndex),
1, &constantBuffer, &firstConstant, &numConstants);
}
else
{
mDeviceContext->PSSetConstantBuffers(
getReservedFragmentUniformBuffers() +
static_cast<unsigned int>(uniformBufferIndex),
1, &constantBuffer);
}
mCurrentConstantBufferPS[uniformBufferIndex] = bufferStorage->getSerial();
mCurrentConstantBufferPSOffset[uniformBufferIndex] = uniformBufferOffset;
mCurrentConstantBufferPSSize[uniformBufferIndex] = uniformBufferSize;
}
}
return gl::NoError();
}
bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSize) bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSize)
{ {
D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
...@@ -2126,17 +2000,6 @@ void Renderer11::markAllStateDirty(const gl::Context *context) ...@@ -2126,17 +2000,6 @@ void Renderer11::markAllStateDirty(const gl::Context *context)
mStateManager.invalidateEverything(context); mStateManager.invalidateEverything(context);
mAppliedTFObject = angle::DirtyPointer; mAppliedTFObject = angle::DirtyPointer;
for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; i++)
{
mCurrentConstantBufferVS[i] = static_cast<unsigned int>(-1);
mCurrentConstantBufferVSOffset[i] = 0;
mCurrentConstantBufferVSSize[i] = 0;
mCurrentConstantBufferPS[i] = static_cast<unsigned int>(-1);
mCurrentConstantBufferPSOffset[i] = 0;
mCurrentConstantBufferPSSize[i] = 0;
}
} }
void Renderer11::releaseDeviceResources() void Renderer11::releaseDeviceResources()
...@@ -3962,8 +3825,6 @@ gl::Error Renderer11::genericDrawElements(const gl::Context *context, ...@@ -3962,8 +3825,6 @@ gl::Error Renderer11::genericDrawElements(const gl::Context *context,
// API validation layer. // API validation layer.
ASSERT(!glState.isTransformFeedbackActiveUnpaused()); ASSERT(!glState.isTransformFeedbackActiveUnpaused());
ANGLE_TRY(programD3D->applyUniformBuffers(data));
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
ANGLE_TRY(drawElementsImpl(context, mode, count, type, indices, instances)); ANGLE_TRY(drawElementsImpl(context, mode, count, type, indices, instances));
...@@ -3993,7 +3854,6 @@ gl::Error Renderer11::genericDrawArrays(const gl::Context *context, ...@@ -3993,7 +3854,6 @@ gl::Error Renderer11::genericDrawArrays(const gl::Context *context,
ANGLE_TRY(mStateManager.updateState(context, mode)); ANGLE_TRY(mStateManager.updateState(context, mode));
ANGLE_TRY(applyTransformFeedbackBuffers(data)); ANGLE_TRY(applyTransformFeedbackBuffers(data));
ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, first, count, instances, nullptr)); ANGLE_TRY(mStateManager.applyVertexBuffer(context, mode, first, count, instances, nullptr));
ANGLE_TRY(programD3D->applyUniformBuffers(data));
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
...@@ -4024,7 +3884,6 @@ gl::Error Renderer11::genericDrawIndirect(const gl::Context *context, ...@@ -4024,7 +3884,6 @@ gl::Error Renderer11::genericDrawIndirect(const gl::Context *context,
ANGLE_TRY(mStateManager.updateState(context, mode)); ANGLE_TRY(mStateManager.updateState(context, mode));
ANGLE_TRY(applyTransformFeedbackBuffers(contextState)); ANGLE_TRY(applyTransformFeedbackBuffers(contextState));
ASSERT(!glState.isTransformFeedbackActiveUnpaused()); ASSERT(!glState.isTransformFeedbackActiveUnpaused());
ANGLE_TRY(programD3D->applyUniformBuffers(contextState));
if (type == GL_NONE) if (type == GL_NONE)
{ {
...@@ -4087,7 +3946,6 @@ gl::Error Renderer11::dispatchCompute(const gl::Context *context, ...@@ -4087,7 +3946,6 @@ gl::Error Renderer11::dispatchCompute(const gl::Context *context,
ANGLE_TRY(mStateManager.updateStateForCompute(context, numGroupsX, numGroupsY, numGroupsZ)); ANGLE_TRY(mStateManager.updateStateForCompute(context, numGroupsX, numGroupsY, numGroupsZ));
ANGLE_TRY(applyComputeShader(context)); ANGLE_TRY(applyComputeShader(context));
// TODO(Xinghua): applyUniformBuffers for compute shader.
mDeviceContext->Dispatch(numGroupsX, numGroupsY, numGroupsZ); mDeviceContext->Dispatch(numGroupsX, numGroupsY, numGroupsZ);
return gl::NoError(); return gl::NoError();
......
...@@ -146,10 +146,6 @@ class Renderer11 : public RendererD3D ...@@ -146,10 +146,6 @@ class Renderer11 : public RendererD3D
HANDLE shareHandle, HANDLE shareHandle,
const egl::AttributeMap &attribs) const override; const egl::AttributeMap &attribs) const override;
gl::Error setUniformBuffers(const gl::ContextState &data,
const std::vector<GLint> &vertexUniformBuffers,
const std::vector<GLint> &fragmentUniformBuffers) override;
bool applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSize); bool applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSize);
gl::Error applyTransformFeedbackBuffers(const gl::ContextState &data); gl::Error applyTransformFeedbackBuffers(const gl::ContextState &data);
...@@ -162,8 +158,8 @@ class Renderer11 : public RendererD3D ...@@ -162,8 +158,8 @@ class Renderer11 : public RendererD3D
unsigned int getReservedVertexUniformVectors() const; unsigned int getReservedVertexUniformVectors() const;
unsigned int getReservedFragmentUniformVectors() const; unsigned int getReservedFragmentUniformVectors() const;
unsigned int getReservedVertexUniformBuffers() const override; unsigned int getReservedVertexUniformBuffers() const;
unsigned int getReservedFragmentUniformBuffers() const override; unsigned int getReservedFragmentUniformBuffers() const;
bool getShareHandleSupport() const; bool getShareHandleSupport() const;
...@@ -547,13 +543,6 @@ class Renderer11 : public RendererD3D ...@@ -547,13 +543,6 @@ class Renderer11 : public RendererD3D
// Currently applied transform feedback buffers // Currently applied transform feedback buffers
uintptr_t mAppliedTFObject; uintptr_t mAppliedTFObject;
unsigned int mCurrentConstantBufferVS[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS];
GLintptr mCurrentConstantBufferVSOffset[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS];
GLsizeiptr mCurrentConstantBufferVSSize[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS];
unsigned int mCurrentConstantBufferPS[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS];
GLintptr mCurrentConstantBufferPSOffset[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS];
GLsizeiptr mCurrentConstantBufferPSSize[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS];
StreamingIndexBufferInterface *mLineLoopIB; StreamingIndexBufferInterface *mLineLoopIB;
StreamingIndexBufferInterface *mTriangleFanIB; StreamingIndexBufferInterface *mTriangleFanIB;
......
...@@ -651,6 +651,8 @@ gl::Error StateManager11::updateStateForCompute(const gl::Context *context, ...@@ -651,6 +651,8 @@ gl::Error StateManager11::updateStateForCompute(const gl::Context *context,
// TODO(jmadill): More complete implementation. // TODO(jmadill): More complete implementation.
ANGLE_TRY(syncTextures(context)); ANGLE_TRY(syncTextures(context));
// TODO(Xinghua): applyUniformBuffers for compute shader.
return gl::NoError(); return gl::NoError();
} }
...@@ -1337,10 +1339,21 @@ void StateManager11::invalidateEverything(const gl::Context *context) ...@@ -1337,10 +1339,21 @@ void StateManager11::invalidateEverything(const gl::Context *context)
invalidateDriverUniforms(); invalidateDriverUniforms();
mCurrentVertexConstantBuffer.dirty();
mCurrentPixelConstantBuffer.dirty();
mCurrentGeometryConstantBuffer.dirty(); mCurrentGeometryConstantBuffer.dirty();
mCurrentComputeConstantBuffer.dirty(); mCurrentComputeConstantBuffer.dirty();
static_assert(gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS ==
gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS,
"Same size required");
for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS; i++)
{
mCurrentConstantBufferVS[i].dirty();
mCurrentConstantBufferVSOffset[i] = 0;
mCurrentConstantBufferVSSize[i] = 0;
mCurrentConstantBufferPS[i].dirty();
mCurrentConstantBufferPSOffset[i] = 0;
mCurrentConstantBufferPSSize[i] = 0;
}
} }
void StateManager11::invalidateVertexBuffer() void StateManager11::invalidateVertexBuffer()
...@@ -1852,6 +1865,9 @@ gl::Error StateManager11::updateState(const gl::Context *context, GLenum drawMod ...@@ -1852,6 +1865,9 @@ gl::Error StateManager11::updateState(const gl::Context *context, GLenum drawMod
ANGLE_TRY(applyUniforms(programD3D)); ANGLE_TRY(applyUniforms(programD3D));
ANGLE_TRY(applyDriverUniforms(*programD3D, drawMode)); ANGLE_TRY(applyDriverUniforms(*programD3D, drawMode));
// TOOD(jmadill): Use dirty bits.
ANGLE_TRY(syncUniformBuffers(context, programD3D));
// Check that we haven't set any dirty bits in the flushing of the dirty bits loop. // Check that we haven't set any dirty bits in the flushing of the dirty bits loop.
ASSERT(mInternalDirtyBits.none()); ASSERT(mInternalDirtyBits.none());
...@@ -2422,20 +2438,22 @@ gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D) ...@@ -2422,20 +2438,22 @@ gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D)
deviceContext->Unmap(pixelConstantBuffer->get(), 0); deviceContext->Unmap(pixelConstantBuffer->get(), 0);
} }
if (mCurrentVertexConstantBuffer != vertexConstantBuffer->getSerial()) unsigned int slot = d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK;
if (mCurrentConstantBufferVS[slot] != vertexConstantBuffer->getSerial())
{ {
deviceContext->VSSetConstantBuffers( deviceContext->VSSetConstantBuffers(slot, 1, vertexConstantBuffer->getPointer());
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1, mCurrentConstantBufferVS[slot] = vertexConstantBuffer->getSerial();
vertexConstantBuffer->getPointer()); mCurrentConstantBufferVSOffset[slot] = 0;
mCurrentVertexConstantBuffer = vertexConstantBuffer->getSerial(); mCurrentConstantBufferVSSize[slot] = 0;
} }
if (mCurrentPixelConstantBuffer != pixelConstantBuffer->getSerial()) if (mCurrentConstantBufferPS[slot] != pixelConstantBuffer->getSerial())
{ {
deviceContext->PSSetConstantBuffers( deviceContext->PSSetConstantBuffers(slot, 1, pixelConstantBuffer->getPointer());
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1, mCurrentConstantBufferPS[slot] = pixelConstantBuffer->getSerial();
pixelConstantBuffer->getPointer()); mCurrentConstantBufferPSOffset[slot] = 0;
mCurrentPixelConstantBuffer = pixelConstantBuffer->getSerial(); mCurrentConstantBufferPSSize[slot] = 0;
} }
programD3D->markUniformsClean(); programD3D->markUniformsClean();
...@@ -2545,4 +2563,127 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) ...@@ -2545,4 +2563,127 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D)
return gl::NoError(); return gl::NoError();
} }
gl::Error StateManager11::syncUniformBuffers(const gl::Context *context, ProgramD3D *programD3D)
{
unsigned int reservedVertex = mRenderer->getReservedVertexUniformBuffers();
unsigned int reservedFragment = mRenderer->getReservedFragmentUniformBuffers();
programD3D->updateUniformBufferCache(context->getCaps(), reservedVertex, reservedFragment);
const auto &vertexUniformBuffers = programD3D->getVertexUniformBufferCache();
const auto &fragmentUniformBuffers = programD3D->getFragmentUniformBufferCache();
const auto &glState = context->getGLState();
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported();
for (size_t bufferIndex = 0; bufferIndex < vertexUniformBuffers.size(); bufferIndex++)
{
GLint binding = vertexUniformBuffers[bufferIndex];
if (binding == -1)
{
continue;
}
const auto &uniformBuffer = glState.getIndexedUniformBuffer(binding);
GLintptr uniformBufferOffset = uniformBuffer.getOffset();
GLsizeiptr uniformBufferSize = uniformBuffer.getSize();
if (uniformBuffer.get() == nullptr)
{
continue;
}
Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get());
const d3d11::Buffer *constantBuffer = nullptr;
UINT firstConstant = 0;
UINT numConstants = 0;
ANGLE_TRY(bufferStorage->getConstantBufferRange(uniformBufferOffset, uniformBufferSize,
&constantBuffer, &firstConstant,
&numConstants));
ASSERT(constantBuffer);
if (mCurrentConstantBufferVS[bufferIndex] == constantBuffer->getSerial() &&
mCurrentConstantBufferVSOffset[bufferIndex] == uniformBufferOffset &&
mCurrentConstantBufferVSSize[bufferIndex] == uniformBufferSize)
{
continue;
}
unsigned int appliedIndex = reservedVertex + static_cast<unsigned int>(bufferIndex);
if (firstConstant != 0 && uniformBufferSize != 0)
{
ASSERT(numConstants != 0);
deviceContext1->VSSetConstantBuffers1(appliedIndex, 1, constantBuffer->getPointer(),
&firstConstant, &numConstants);
}
else
{
deviceContext->VSSetConstantBuffers(appliedIndex, 1, constantBuffer->getPointer());
}
mCurrentConstantBufferVS[appliedIndex] = constantBuffer->getSerial();
mCurrentConstantBufferVSOffset[appliedIndex] = uniformBufferOffset;
mCurrentConstantBufferVSSize[appliedIndex] = uniformBufferSize;
}
for (size_t bufferIndex = 0; bufferIndex < fragmentUniformBuffers.size(); bufferIndex++)
{
GLint binding = fragmentUniformBuffers[bufferIndex];
if (binding == -1)
{
continue;
}
const auto &uniformBuffer = glState.getIndexedUniformBuffer(binding);
GLintptr uniformBufferOffset = uniformBuffer.getOffset();
GLsizeiptr uniformBufferSize = uniformBuffer.getSize();
if (uniformBuffer.get() == nullptr)
{
continue;
}
Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get());
const d3d11::Buffer *constantBuffer = nullptr;
UINT firstConstant = 0;
UINT numConstants = 0;
ANGLE_TRY(bufferStorage->getConstantBufferRange(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);
if (firstConstant != 0 && uniformBufferSize != 0)
{
deviceContext1->PSSetConstantBuffers1(appliedIndex, 1, constantBuffer->getPointer(),
&firstConstant, &numConstants);
}
else
{
deviceContext->PSSetConstantBuffers(appliedIndex, 1, constantBuffer->getPointer());
}
mCurrentConstantBufferPS[appliedIndex] = constantBuffer->getSerial();
mCurrentConstantBufferPSOffset[appliedIndex] = uniformBufferOffset;
mCurrentConstantBufferPSSize[appliedIndex] = uniformBufferSize;
}
return gl::NoError();
}
} // namespace rx } // namespace rx
...@@ -295,6 +295,8 @@ class StateManager11 final : angle::NonCopyable ...@@ -295,6 +295,8 @@ class StateManager11 final : angle::NonCopyable
gl::Error applyDriverUniforms(const ProgramD3D &programD3D, GLenum drawMode); gl::Error applyDriverUniforms(const ProgramD3D &programD3D, GLenum drawMode);
gl::Error applyUniforms(ProgramD3D *programD3D); gl::Error applyUniforms(ProgramD3D *programD3D);
gl::Error syncUniformBuffers(const gl::Context *context, ProgramD3D *programD3D);
enum DirtyBitType enum DirtyBitType
{ {
DIRTY_BIT_RENDER_TARGET, DIRTY_BIT_RENDER_TARGET,
...@@ -453,10 +455,24 @@ class StateManager11 final : angle::NonCopyable ...@@ -453,10 +455,24 @@ class StateManager11 final : angle::NonCopyable
d3d11::Buffer mDriverConstantBufferPS; d3d11::Buffer mDriverConstantBufferPS;
d3d11::Buffer mDriverConstantBufferCS; d3d11::Buffer mDriverConstantBufferCS;
ResourceSerial mCurrentVertexConstantBuffer;
ResourceSerial mCurrentPixelConstantBuffer;
ResourceSerial mCurrentComputeConstantBuffer; ResourceSerial mCurrentComputeConstantBuffer;
ResourceSerial mCurrentGeometryConstantBuffer; ResourceSerial mCurrentGeometryConstantBuffer;
template <typename T>
using VertexConstantBufferArray =
std::array<T, gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS>;
VertexConstantBufferArray<ResourceSerial> mCurrentConstantBufferVS;
VertexConstantBufferArray<GLintptr> mCurrentConstantBufferVSOffset;
VertexConstantBufferArray<GLsizeiptr> mCurrentConstantBufferVSSize;
template <typename T>
using FragmentConstantBufferArray =
std::array<T, gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS>;
FragmentConstantBufferArray<ResourceSerial> mCurrentConstantBufferPS;
FragmentConstantBufferArray<GLintptr> mCurrentConstantBufferPSOffset;
FragmentConstantBufferArray<GLsizeiptr> mCurrentConstantBufferPSSize;
}; };
} // namespace rx } // namespace rx
......
...@@ -1034,14 +1034,6 @@ gl::Error Renderer9::setTexture(const gl::Context *context, ...@@ -1034,14 +1034,6 @@ gl::Error Renderer9::setTexture(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer9::setUniformBuffers(const gl::ContextState & /*data*/,
const std::vector<GLint> & /*vertexUniformBuffers*/,
const std::vector<GLint> & /*fragmentUniformBuffers*/)
{
// No effect in ES2/D3D9
return gl::NoError();
}
gl::Error Renderer9::updateState(const gl::Context *context, GLenum drawMode) gl::Error Renderer9::updateState(const gl::Context *context, GLenum drawMode)
{ {
const auto &glState = context->getGLState(); const auto &glState = context->getGLState();
...@@ -2473,16 +2465,6 @@ unsigned int Renderer9::getReservedFragmentUniformVectors() const ...@@ -2473,16 +2465,6 @@ unsigned int Renderer9::getReservedFragmentUniformVectors() const
return d3d9_gl::GetReservedFragmentUniformVectors(); return d3d9_gl::GetReservedFragmentUniformVectors();
} }
unsigned int Renderer9::getReservedVertexUniformBuffers() const
{
return 0;
}
unsigned int Renderer9::getReservedFragmentUniformBuffers() const
{
return 0;
}
bool Renderer9::getShareHandleSupport() const bool Renderer9::getShareHandleSupport() const
{ {
// PIX doesn't seem to support using share handles, so disable them. // PIX doesn't seem to support using share handles, so disable them.
...@@ -3169,7 +3151,6 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context, ...@@ -3169,7 +3151,6 @@ gl::Error Renderer9::genericDrawElements(const gl::Context *context,
ANGLE_TRY(applyTextures(context)); ANGLE_TRY(applyTextures(context));
ANGLE_TRY(applyShaders(context, mode)); ANGLE_TRY(applyShaders(context, mode));
ANGLE_TRY(programD3D->applyUniformBuffers(data));
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
...@@ -3203,7 +3184,6 @@ gl::Error Renderer9::genericDrawArrays(const gl::Context *context, ...@@ -3203,7 +3184,6 @@ gl::Error Renderer9::genericDrawArrays(const gl::Context *context,
ANGLE_TRY(applyVertexBuffer(data.getState(), mode, first, count, instances, nullptr)); ANGLE_TRY(applyVertexBuffer(data.getState(), mode, first, count, instances, nullptr));
ANGLE_TRY(applyTextures(context)); ANGLE_TRY(applyTextures(context));
ANGLE_TRY(applyShaders(context, mode)); ANGLE_TRY(applyShaders(context, mode));
ANGLE_TRY(programD3D->applyUniformBuffers(data));
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
......
...@@ -129,10 +129,6 @@ class Renderer9 : public RendererD3D ...@@ -129,10 +129,6 @@ class Renderer9 : public RendererD3D
int index, int index,
gl::Texture *texture); gl::Texture *texture);
gl::Error setUniformBuffers(const gl::ContextState &data,
const std::vector<GLint> &vertexUniformBuffers,
const std::vector<GLint> &fragmentUniformBuffers) override;
gl::Error updateState(const gl::Context *context, GLenum drawMode); gl::Error updateState(const gl::Context *context, GLenum drawMode);
void setScissorRectangle(const gl::Rectangle &scissor, bool enabled); void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
...@@ -184,8 +180,6 @@ class Renderer9 : public RendererD3D ...@@ -184,8 +180,6 @@ class Renderer9 : public RendererD3D
unsigned int getReservedVertexUniformVectors() const; unsigned int getReservedVertexUniformVectors() const;
unsigned int getReservedFragmentUniformVectors() const; unsigned int getReservedFragmentUniformVectors() const;
unsigned int getReservedVertexUniformBuffers() const override;
unsigned int getReservedFragmentUniformBuffers() const override;
bool getShareHandleSupport() const; bool getShareHandleSupport() const;
......
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