Commit 3ae14613 by Jamie Madill Committed by Commit Bot

Buffer11: Refactor constant buffer range getter.

This getter will now return the offset to bind along with the ID3D11Buffer pointer. This encapsulates the logic of the emulation so that we only actually check the capabilities of the driver in a single place. This solves the issue of needing to edit the code in multiple places when trying to force the caps for debugging, and also encapsulates the offset calculation in the Buffer11 class. BUG=chromium:593024 Change-Id: Idb09d560868ae12b98bcaf4ea031c4e0b6c82b4a Reviewed-on: https://chromium-review.googlesource.com/411918Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 16e54098
...@@ -38,6 +38,28 @@ enum class CopyResult ...@@ -38,6 +38,28 @@ enum class CopyResult
NOT_RECREATED, NOT_RECREATED,
}; };
void CalculateConstantBufferParams(GLintptr offset,
GLsizeiptr size,
UINT *outFirstConstant,
UINT *outNumConstants)
{
// The offset must be aligned to 256 bytes (should have been enforced by glBindBufferRange).
ASSERT(offset % 256 == 0);
// firstConstant and numConstants are expressed in constants of 16-bytes. Furthermore they must
// be a multiple of 16 constants.
*outFirstConstant = static_cast<UINT>(offset / 16);
// The GL size is not required to be aligned to a 256 bytes boundary.
// Round the size up to a 256 bytes boundary then express the results in constants of 16-bytes.
*outNumConstants = static_cast<UINT>(rx::roundUp(size, static_cast<GLsizeiptr>(256)) / 16);
// Since the size is rounded up, firstConstant + numConstants may be bigger than the actual size
// of the buffer. This behaviour is explictly allowed according to the documentation on
// ID3D11DeviceContext1::PSSetConstantBuffers1
// https://msdn.microsoft.com/en-us/library/windows/desktop/hh404649%28v=vs.85%29.aspx
}
} // anonymous namespace } // anonymous namespace
namespace gl_d3d11 namespace gl_d3d11
...@@ -583,20 +605,29 @@ gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getEmulatedIndexedBuffer( ...@@ -583,20 +605,29 @@ gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getEmulatedIndexedBuffer(
return nativeStorage; return nativeStorage;
} }
gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getConstantBufferRange(GLintptr offset, GLsizeiptr size) gl::Error Buffer11::getConstantBufferRange(GLintptr offset,
GLsizeiptr size,
ID3D11Buffer **bufferOut,
UINT *firstConstantOut,
UINT *numConstantsOut)
{ {
BufferStorage *bufferStorage = nullptr; BufferStorage *bufferStorage = nullptr;
if (offset == 0 || mRenderer->getRenderer11DeviceCaps().supportsConstantBufferOffsets) if (offset == 0 || mRenderer->getRenderer11DeviceCaps().supportsConstantBufferOffsets)
{ {
ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_UNIFORM), bufferStorage); ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_UNIFORM), bufferStorage);
CalculateConstantBufferParams(offset, size, firstConstantOut, numConstantsOut);
} }
else else
{ {
ANGLE_TRY_RESULT(getConstantBufferRangeStorage(offset, size), bufferStorage); ANGLE_TRY_RESULT(getConstantBufferRangeStorage(offset, size), bufferStorage);
*firstConstantOut = 0;
*numConstantsOut = 0;
} }
return GetAs<NativeStorage>(bufferStorage)->getNativeStorage(); *bufferOut = GetAs<NativeStorage>(bufferStorage)->getNativeStorage();
return gl::NoError();
} }
gl::ErrorOrResult<ID3D11ShaderResourceView *> Buffer11::getSRV(DXGI_FORMAT srvFormat) gl::ErrorOrResult<ID3D11ShaderResourceView *> Buffer11::getSRV(DXGI_FORMAT srvFormat)
......
...@@ -55,7 +55,11 @@ class Buffer11 : public BufferD3D ...@@ -55,7 +55,11 @@ class Buffer11 : public BufferD3D
gl::ErrorOrResult<ID3D11Buffer *> getEmulatedIndexedBuffer(SourceIndexData *indexInfo, gl::ErrorOrResult<ID3D11Buffer *> getEmulatedIndexedBuffer(SourceIndexData *indexInfo,
const TranslatedAttribute &attribute, const TranslatedAttribute &attribute,
GLint startVertex); GLint startVertex);
gl::ErrorOrResult<ID3D11Buffer *> getConstantBufferRange(GLintptr offset, GLsizeiptr size); gl::Error getConstantBufferRange(GLintptr offset,
GLsizeiptr size,
ID3D11Buffer **bufferOut,
UINT *firstConstantOut,
UINT *numConstantsOut);
gl::ErrorOrResult<ID3D11ShaderResourceView *> getSRV(DXGI_FORMAT srvFormat); gl::ErrorOrResult<ID3D11ShaderResourceView *> getSRV(DXGI_FORMAT srvFormat);
bool isMapped() const { return mMappedStorage != nullptr; } bool isMapped() const { return mMappedStorage != nullptr; }
gl::Error packPixels(const gl::FramebufferAttachment &readAttachment, gl::Error packPixels(const gl::FramebufferAttachment &readAttachment,
......
...@@ -98,28 +98,6 @@ enum ...@@ -98,28 +98,6 @@ enum
MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16 MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16
}; };
void CalculateConstantBufferParams(GLintptr offset,
GLsizeiptr size,
UINT *outFirstConstant,
UINT *outNumConstants)
{
// The offset must be aligned to 256 bytes (should have been enforced by glBindBufferRange).
ASSERT(offset % 256 == 0);
// firstConstant and numConstants are expressed in constants of 16-bytes. Furthermore they must
// be a multiple of 16 constants.
*outFirstConstant = static_cast<UINT>(offset / 16);
// The GL size is not required to be aligned to a 256 bytes boundary.
// Round the size up to a 256 bytes boundary then express the results in constants of 16-bytes.
*outNumConstants = static_cast<UINT>(rx::roundUp(size, static_cast<GLsizeiptr>(256)) / 16);
// Since the size is rounded up, firstConstant + numConstants may be bigger than the actual size
// of the buffer. This behaviour is explictly allowed according to the documentation on
// ID3D11DeviceContext1::PSSetConstantBuffers1
// https://msdn.microsoft.com/en-us/library/windows/desktop/hh404649%28v=vs.85%29.aspx
}
enum ANGLEFeatureLevel enum ANGLEFeatureLevel
{ {
ANGLE_FEATURE_LEVEL_INVALID, ANGLE_FEATURE_LEVEL_INVALID,
...@@ -1491,10 +1469,12 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data, ...@@ -1491,10 +1469,12 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get()); Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get());
ID3D11Buffer *constantBuffer = nullptr; ID3D11Buffer *constantBuffer = nullptr;
UINT firstConstant = 0;
UINT numConstants = 0;
ANGLE_TRY_RESULT( ANGLE_TRY(bufferStorage->getConstantBufferRange(uniformBufferOffset, uniformBufferSize,
bufferStorage->getConstantBufferRange(uniformBufferOffset, uniformBufferSize), &constantBuffer, &firstConstant,
constantBuffer); &numConstants));
if (!constantBuffer) if (!constantBuffer)
{ {
...@@ -1505,11 +1485,9 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data, ...@@ -1505,11 +1485,9 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
mCurrentConstantBufferVSOffset[uniformBufferIndex] != uniformBufferOffset || mCurrentConstantBufferVSOffset[uniformBufferIndex] != uniformBufferOffset ||
mCurrentConstantBufferVSSize[uniformBufferIndex] != uniformBufferSize) mCurrentConstantBufferVSSize[uniformBufferIndex] != uniformBufferSize)
{ {
if (mRenderer11DeviceCaps.supportsConstantBufferOffsets && uniformBufferSize != 0) if (firstConstant != 0 && uniformBufferSize != 0)
{ {
UINT firstConstant = 0, numConstants = 0; ASSERT(numConstants != 0);
CalculateConstantBufferParams(uniformBufferOffset, uniformBufferSize,
&firstConstant, &numConstants);
mDeviceContext1->VSSetConstantBuffers1( mDeviceContext1->VSSetConstantBuffers1(
getReservedVertexUniformBuffers() + getReservedVertexUniformBuffers() +
static_cast<unsigned int>(uniformBufferIndex), static_cast<unsigned int>(uniformBufferIndex),
...@@ -1551,10 +1529,12 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data, ...@@ -1551,10 +1529,12 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get()); Buffer11 *bufferStorage = GetImplAs<Buffer11>(uniformBuffer.get());
ID3D11Buffer *constantBuffer = nullptr; ID3D11Buffer *constantBuffer = nullptr;
UINT firstConstant = 0;
UINT numConstants = 0;
ANGLE_TRY_RESULT( ANGLE_TRY(bufferStorage->getConstantBufferRange(uniformBufferOffset, uniformBufferSize,
bufferStorage->getConstantBufferRange(uniformBufferOffset, uniformBufferSize), &constantBuffer, &firstConstant,
constantBuffer); &numConstants));
if (!constantBuffer) if (!constantBuffer)
{ {
...@@ -1565,11 +1545,8 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data, ...@@ -1565,11 +1545,8 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
mCurrentConstantBufferPSOffset[uniformBufferIndex] != uniformBufferOffset || mCurrentConstantBufferPSOffset[uniformBufferIndex] != uniformBufferOffset ||
mCurrentConstantBufferPSSize[uniformBufferIndex] != uniformBufferSize) mCurrentConstantBufferPSSize[uniformBufferIndex] != uniformBufferSize)
{ {
if (mRenderer11DeviceCaps.supportsConstantBufferOffsets && uniformBufferSize != 0) if (firstConstant != 0 && uniformBufferSize != 0)
{ {
UINT firstConstant = 0, numConstants = 0;
CalculateConstantBufferParams(uniformBufferOffset, uniformBufferSize,
&firstConstant, &numConstants);
mDeviceContext1->PSSetConstantBuffers1( mDeviceContext1->PSSetConstantBuffers1(
getReservedFragmentUniformBuffers() + getReservedFragmentUniformBuffers() +
static_cast<unsigned int>(uniformBufferIndex), static_cast<unsigned int>(uniformBufferIndex),
......
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