Commit 2dc027da by Jamie Madill Committed by Commit Bot

D3D11: Consolidate constant buffer application.

This will let the StateManager11 work more easily with dirty bits. BUG=angleproject:1390 BUG=angleproject:2052 Change-Id: I9738d02e69e2062feeba4237487ad8e9ae86e78b Reviewed-on: https://chromium-review.googlesource.com/659227 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent d63961d0
......@@ -1084,8 +1084,7 @@ gl::Error Blit11::swizzleTexture(const gl::Context *context,
stateManager->setSingleVertexBuffer(&mVertexBuffer, stride, 0);
// Apply constant buffer
ID3D11Buffer *constantBuffer = mSwizzleCB.get();
deviceContext->PSSetConstantBuffers(0, 1, &constantBuffer);
stateManager->setPixelConstantBuffer(0, &mSwizzleCB);
// Apply state
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
......
......@@ -800,8 +800,7 @@ gl::Error Clear11::clearFramebuffer(const gl::Context *context,
// Apply Shaders
stateManager->setDrawShaders(vs, gs, ps);
ID3D11Buffer *constantBuffer = mConstantBuffer.get();
deviceContext->PSSetConstantBuffers(0, 1, &constantBuffer);
stateManager->setPixelConstantBuffer(0, &mConstantBuffer);
// Bind IL & VB if needed
deviceContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_UNKNOWN, 0);
......
......@@ -207,8 +207,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context,
mParamsData = shaderParams;
}
ID3D11Buffer *paramsBuffer = mParamsConstantBuffer.get();
deviceContext->VSSetConstantBuffers(0, 1, &paramsBuffer);
stateManager->setVertexConstantBuffer(0, &mParamsConstantBuffer);
// Set the viewport
D3D11_VIEWPORT viewport;
......@@ -225,9 +224,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context,
// Unbind shader resources and invalidate state.
stateManager->setShaderResource(gl::SAMPLER_PIXEL, 0, nullptr);
ID3D11Buffer *nullBuffer = nullptr;
deviceContext->VSSetConstantBuffers(0, 1, &nullBuffer);
stateManager->setVertexConstantBuffer(0, nullptr);
mRenderer->markAllStateDirty(context);
......
......@@ -1940,6 +1940,54 @@ void StateManager11::setComputeShader(const d3d11::ComputeShader *shader)
}
}
void StateManager11::setVertexConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer)
{
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
auto &currentSerial = mCurrentConstantBufferVS[slot];
if (buffer)
{
if (currentSerial != buffer->getSerial())
{
deviceContext->VSSetConstantBuffers(slot, 1, buffer->getPointer());
currentSerial = buffer->getSerial();
}
}
else
{
if (!currentSerial.empty())
{
ID3D11Buffer *nullBuffer = nullptr;
deviceContext->VSSetConstantBuffers(slot, 1, &nullBuffer);
currentSerial.clear();
}
}
}
void StateManager11::setPixelConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer)
{
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
auto &currentSerial = mCurrentConstantBufferPS[slot];
if (buffer)
{
if (currentSerial != buffer->getSerial())
{
deviceContext->PSSetConstantBuffers(slot, 1, buffer->getPointer());
currentSerial = buffer->getSerial();
}
}
else
{
if (!currentSerial.empty())
{
ID3D11Buffer *nullBuffer = nullptr;
deviceContext->PSSetConstantBuffers(slot, 1, &nullBuffer);
currentSerial.clear();
}
}
}
// For each Direct3D sampler of either the pixel or vertex stage,
// looks up the corresponding OpenGL texture image unit and texture type,
// and sets the texture and its addressing/filtering state (or NULL when inactive).
......
......@@ -211,6 +211,8 @@ class StateManager11 final : angle::NonCopyable
void setGeometryShader(const d3d11::GeometryShader *shader);
void setPixelShader(const d3d11::PixelShader *shader);
void setComputeShader(const d3d11::ComputeShader *shader);
void setVertexConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer);
void setPixelConstantBuffer(unsigned int slot, const d3d11::Buffer *buffer);
// Not handled by an internal dirty bit because of the extra draw parameters.
gl::Error applyVertexBuffer(const gl::Context *context,
......
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