Commit 9959f544 by Jamie Madill Committed by Commit Bot

Cleanups to ResourceSerial.

Allow for "empty" bindings, which are valid but represent when no object is bound. BUG=angleproject:2052 Change-Id: I0a41d1f0db3f5736e9e8f8ca3a74f41b748fd2d2 Reviewed-on: https://chromium-review.googlesource.com/659225 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent af01602e
...@@ -175,6 +175,7 @@ class Resource11Base : angle::NonCopyable ...@@ -175,6 +175,7 @@ class Resource11Base : angle::NonCopyable
{ {
public: public:
T *get() const { return mData->object; } T *get() const { return mData->object; }
T *const *getPointer() const { return &mData->object; }
void setDebugName(const char *name) { d3d11::SetDebugName(mData->object, name); } void setDebugName(const char *name) { d3d11::SetDebugName(mData->object, name); }
......
...@@ -1689,10 +1689,10 @@ void StateManager11::setInputLayout(const d3d11::InputLayout *inputLayout) ...@@ -1689,10 +1689,10 @@ void StateManager11::setInputLayout(const d3d11::InputLayout *inputLayout)
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
if (inputLayout == nullptr) if (inputLayout == nullptr)
{ {
if (mCurrentInputLayout != 0) if (!mCurrentInputLayout.empty())
{ {
deviceContext->IASetInputLayout(nullptr); deviceContext->IASetInputLayout(nullptr);
mCurrentInputLayout = 0; mCurrentInputLayout.clear();
mInputLayoutIsDirty = true; mInputLayoutIsDirty = true;
} }
} }
...@@ -1878,7 +1878,7 @@ void StateManager11::setDrawShaders(const d3d11::VertexShader *vertexShader, ...@@ -1878,7 +1878,7 @@ void StateManager11::setDrawShaders(const d3d11::VertexShader *vertexShader,
void StateManager11::setVertexShader(const d3d11::VertexShader *shader) void StateManager11::setVertexShader(const d3d11::VertexShader *shader)
{ {
ResourceSerial serial = shader ? shader->getSerial() : 0; ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0);
if (serial != mAppliedVertexShader) if (serial != mAppliedVertexShader)
{ {
...@@ -1890,7 +1890,7 @@ void StateManager11::setVertexShader(const d3d11::VertexShader *shader) ...@@ -1890,7 +1890,7 @@ void StateManager11::setVertexShader(const d3d11::VertexShader *shader)
void StateManager11::setGeometryShader(const d3d11::GeometryShader *shader) void StateManager11::setGeometryShader(const d3d11::GeometryShader *shader)
{ {
ResourceSerial serial = shader ? shader->getSerial() : 0; ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0);
if (serial != mAppliedGeometryShader) if (serial != mAppliedGeometryShader)
{ {
...@@ -1902,7 +1902,7 @@ void StateManager11::setGeometryShader(const d3d11::GeometryShader *shader) ...@@ -1902,7 +1902,7 @@ void StateManager11::setGeometryShader(const d3d11::GeometryShader *shader)
void StateManager11::setPixelShader(const d3d11::PixelShader *shader) void StateManager11::setPixelShader(const d3d11::PixelShader *shader)
{ {
ResourceSerial serial = shader ? shader->getSerial() : 0; ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0);
if (serial != mAppliedPixelShader) if (serial != mAppliedPixelShader)
{ {
...@@ -1914,7 +1914,7 @@ void StateManager11::setPixelShader(const d3d11::PixelShader *shader) ...@@ -1914,7 +1914,7 @@ void StateManager11::setPixelShader(const d3d11::PixelShader *shader)
void StateManager11::setComputeShader(const d3d11::ComputeShader *shader) void StateManager11::setComputeShader(const d3d11::ComputeShader *shader)
{ {
ResourceSerial serial = shader ? shader->getSerial() : 0; ResourceSerial serial = shader ? shader->getSerial() : ResourceSerial(0);
if (serial != mAppliedComputeShader) if (serial != mAppliedComputeShader)
{ {
...@@ -2422,20 +2422,20 @@ gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D) ...@@ -2422,20 +2422,20 @@ gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D)
deviceContext->Unmap(pixelConstantBuffer->get(), 0); deviceContext->Unmap(pixelConstantBuffer->get(), 0);
} }
ID3D11Buffer *appliedVertexConstants = vertexConstantBuffer->get(); if (mCurrentVertexConstantBuffer != vertexConstantBuffer->getSerial())
if (mCurrentVertexConstantBuffer != reinterpret_cast<uintptr_t>(appliedVertexConstants))
{ {
deviceContext->VSSetConstantBuffers( deviceContext->VSSetConstantBuffers(
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1, &appliedVertexConstants); d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1,
mCurrentVertexConstantBuffer = reinterpret_cast<uintptr_t>(appliedVertexConstants); vertexConstantBuffer->getPointer());
mCurrentVertexConstantBuffer = vertexConstantBuffer->getSerial();
} }
ID3D11Buffer *appliedPixelConstants = pixelConstantBuffer->get(); if (mCurrentPixelConstantBuffer != pixelConstantBuffer->getSerial())
if (mCurrentPixelConstantBuffer != reinterpret_cast<uintptr_t>(appliedPixelConstants))
{ {
deviceContext->PSSetConstantBuffers( deviceContext->PSSetConstantBuffers(
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1, &appliedPixelConstants); d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1,
mCurrentPixelConstantBuffer = reinterpret_cast<uintptr_t>(appliedPixelConstants); pixelConstantBuffer->getPointer());
mCurrentPixelConstantBuffer = pixelConstantBuffer->getSerial();
} }
programD3D->markUniformsClean(); programD3D->markUniformsClean();
...@@ -2484,12 +2484,11 @@ gl::Error StateManager11::applyDriverUniforms(const ProgramD3D &programD3D, GLen ...@@ -2484,12 +2484,11 @@ gl::Error StateManager11::applyDriverUniforms(const ProgramD3D &programD3D, GLen
if (programD3D.usesGeometryShader(drawMode)) if (programD3D.usesGeometryShader(drawMode))
{ {
// needed for the point sprite geometry shader // needed for the point sprite geometry shader
ID3D11Buffer *appliedGeometryConstants = mDriverConstantBufferPS.get(); if (mCurrentGeometryConstantBuffer != mDriverConstantBufferPS.getSerial())
if (mCurrentGeometryConstantBuffer != reinterpret_cast<uintptr_t>(appliedGeometryConstants))
{ {
ASSERT(mDriverConstantBufferPS.valid()); ASSERT(mDriverConstantBufferPS.valid());
deviceContext->GSSetConstantBuffers(0, 1, &appliedGeometryConstants); deviceContext->GSSetConstantBuffers(0, 1, mDriverConstantBufferPS.getPointer());
mCurrentGeometryConstantBuffer = reinterpret_cast<uintptr_t>(appliedGeometryConstants); mCurrentGeometryConstantBuffer = mDriverConstantBufferPS.getSerial();
} }
} }
...@@ -2502,10 +2501,8 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) ...@@ -2502,10 +2501,8 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D)
GetAs<UniformStorage11>(&programD3D->getComputeUniformStorage()); GetAs<UniformStorage11>(&programD3D->getComputeUniformStorage());
ASSERT(computeUniformStorage); ASSERT(computeUniformStorage);
const d3d11::Buffer *computeConstantBufferObj = nullptr; const d3d11::Buffer *constantBuffer = nullptr;
ANGLE_TRY(computeUniformStorage->getConstantBuffer(mRenderer, &computeConstantBufferObj)); ANGLE_TRY(computeUniformStorage->getConstantBuffer(mRenderer, &constantBuffer));
ID3D11Buffer *computeConstantBuffer = computeConstantBufferObj->get();
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
...@@ -2513,18 +2510,19 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) ...@@ -2513,18 +2510,19 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D)
{ {
D3D11_MAPPED_SUBRESOURCE map = {0}; D3D11_MAPPED_SUBRESOURCE map = {0};
HRESULT result = HRESULT result =
deviceContext->Map(computeConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); deviceContext->Map(constantBuffer->get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
memcpy(map.pData, computeUniformStorage->getDataPointer(0, 0), memcpy(map.pData, computeUniformStorage->getDataPointer(0, 0),
computeUniformStorage->size()); computeUniformStorage->size());
deviceContext->Unmap(computeConstantBuffer, 0); deviceContext->Unmap(constantBuffer->get(), 0);
} }
if (mCurrentComputeConstantBuffer != reinterpret_cast<uintptr_t>(computeConstantBuffer)) if (mCurrentComputeConstantBuffer != constantBuffer->getSerial())
{ {
deviceContext->CSSetConstantBuffers( deviceContext->CSSetConstantBuffers(
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1, &computeConstantBuffer); d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DEFAULT_UNIFORM_BLOCK, 1,
mCurrentComputeConstantBuffer = reinterpret_cast<uintptr_t>(computeConstantBuffer); constantBuffer->getPointer());
mCurrentComputeConstantBuffer = constantBuffer->getSerial();
} }
if (!mDriverConstantBufferCS.valid()) if (!mDriverConstantBufferCS.valid())
......
...@@ -41,14 +41,19 @@ class ResourceSerial ...@@ -41,14 +41,19 @@ class ResourceSerial
{ {
public: public:
constexpr ResourceSerial() : mValue(kDirty) {} constexpr ResourceSerial() : mValue(kDirty) {}
constexpr ResourceSerial(uintptr_t value) : mValue(value) {} explicit constexpr ResourceSerial(uintptr_t value) : mValue(value) {}
constexpr bool operator==(ResourceSerial other) const { return mValue == other.mValue; } constexpr bool operator==(ResourceSerial other) const { return mValue == other.mValue; }
constexpr bool operator!=(ResourceSerial other) const { return mValue != other.mValue; } constexpr bool operator!=(ResourceSerial other) const { return mValue != other.mValue; }
void dirty() { mValue = kDirty; } void dirty() { mValue = kDirty; }
void clear() { mValue = kEmpty; }
constexpr bool valid() const { return mValue != kEmpty && mValue != kDirty; }
constexpr bool empty() const { return mValue == kEmpty; }
private: private:
constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max(); constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max();
constexpr static uintptr_t kEmpty = 0;
uintptr_t mValue; uintptr_t mValue;
}; };
......
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