Commit c47a678a by Jamie Madill

Move the storage for uniform blocks to its own class.

With dynamic shaders we may have multiple shader executables per program binary. We must store the uniforms outside the executable, in the program binary, to be consistent between variations. Change-Id: I1bec83dfb83ee9bb422448b157338a46e8e7ba56 Reviewed-on: https://chromium-review.googlesource.com/183585Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent ecc8b6f4
......@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_SHADEREXECUTABLE_H_
#include "common/angleutils.h"
#include "common/debug.h"
namespace rx
{
......@@ -46,6 +47,22 @@ class ShaderExecutable
const size_t mLength;
};
class UniformStorage
{
public:
UniformStorage(size_t initialSize)
: mSize(initialSize)
{
}
virtual ~UniformStorage() {}
size_t size() const { return mSize; }
private:
size_t mSize;
};
}
#endif // LIBGLESV2_RENDERER_SHADEREXECUTABLE9_H_
......@@ -1476,8 +1476,8 @@ void Renderer11::applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArra
}
}
ID3D11Buffer *vertexConstantBuffer = vertexExecutable->getConstantBuffer(mDevice, totalRegisterCountVS);
ID3D11Buffer *pixelConstantBuffer = pixelExecutable->getConstantBuffer(mDevice, totalRegisterCountPS);
ID3D11Buffer *vertexConstantBuffer = vertexExecutable->getConstantBuffer(this, totalRegisterCountVS);
ID3D11Buffer *pixelConstantBuffer = pixelExecutable->getConstantBuffer(this, totalRegisterCountPS);
float (*mapVS)[4] = NULL;
float (*mapPS)[4] = NULL;
......
......@@ -10,7 +10,7 @@
#include "libGLESv2/renderer/d3d11/ShaderExecutable11.h"
#include "common/debug.h"
#include "libGLESv2/renderer/d3d11/Renderer11.h"
namespace rx
{
......@@ -21,8 +21,7 @@ ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D
mPixelExecutable = executable;
mVertexExecutable = NULL;
mGeometryExecutable = NULL;
mConstantBuffer = NULL;
mUniformStorage = NULL;
}
ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable)
......@@ -31,8 +30,7 @@ ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D
mVertexExecutable = executable;
mPixelExecutable = NULL;
mGeometryExecutable = NULL;
mConstantBuffer = NULL;
mUniformStorage = NULL;
}
ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11GeometryShader *executable)
......@@ -41,8 +39,7 @@ ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D
mGeometryExecutable = executable;
mVertexExecutable = NULL;
mPixelExecutable = NULL;
mConstantBuffer = NULL;
mUniformStorage = NULL;
}
ShaderExecutable11::~ShaderExecutable11()
......@@ -50,8 +47,7 @@ ShaderExecutable11::~ShaderExecutable11()
SafeRelease(mVertexExecutable);
SafeRelease(mPixelExecutable);
SafeRelease(mGeometryExecutable);
SafeRelease(mConstantBuffer);
SafeDelete(mUniformStorage);
}
ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable)
......@@ -75,23 +71,49 @@ ID3D11GeometryShader *ShaderExecutable11::getGeometryShader() const
return mGeometryExecutable;
}
ID3D11Buffer *ShaderExecutable11::getConstantBuffer(ID3D11Device *device, unsigned int registerCount)
ID3D11Buffer *ShaderExecutable11::getConstantBuffer(Renderer11 *renderer, unsigned int registerCount)
{
if (!mConstantBuffer && registerCount > 0)
size_t desiredSize = registerCount * 16u;
if (!mUniformStorage)
{
mUniformStorage = new UniformStorage11(renderer, desiredSize);
}
ASSERT(mUniformStorage->size() == desiredSize);
return mUniformStorage->getConstantBuffer();
}
UniformStorage11::UniformStorage11(Renderer11 *renderer, size_t initialSize)
: UniformStorage(initialSize),
mConstantBuffer(NULL)
{
ID3D11Device *d3d11Device = renderer->getDevice();
if (initialSize > 0)
{
D3D11_BUFFER_DESC constantBufferDescription = {0};
constantBufferDescription.ByteWidth = registerCount * sizeof(float[4]);
constantBufferDescription.ByteWidth = initialSize;
constantBufferDescription.Usage = D3D11_USAGE_DYNAMIC;
constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constantBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
constantBufferDescription.MiscFlags = 0;
constantBufferDescription.StructureByteStride = 0;
HRESULT result = device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer);
HRESULT result = d3d11Device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer);
ASSERT(SUCCEEDED(result));
}
}
return mConstantBuffer;
UniformStorage11::~UniformStorage11()
{
SafeRelease(mConstantBuffer);
}
const UniformStorage11 *UniformStorage11::makeUniformStorage11(const UniformStorage *uniformStorage)
{
ASSERT(HAS_DYNAMIC_TYPE(UniformStorage11*, uniformStorage));
return static_cast<const UniformStorage11*>(uniformStorage);
}
}
\ No newline at end of file
......@@ -14,6 +14,8 @@
namespace rx
{
class Renderer11;
class UniformStorage11;
class ShaderExecutable11 : public ShaderExecutable
{
......@@ -30,7 +32,7 @@ class ShaderExecutable11 : public ShaderExecutable
ID3D11VertexShader *getVertexShader() const;
ID3D11GeometryShader *getGeometryShader() const;
ID3D11Buffer *getConstantBuffer(ID3D11Device *device, unsigned int registerCount);
ID3D11Buffer *getConstantBuffer(Renderer11 *renderer, unsigned int registerCount);
private:
DISALLOW_COPY_AND_ASSIGN(ShaderExecutable11);
......@@ -39,6 +41,20 @@ class ShaderExecutable11 : public ShaderExecutable
ID3D11VertexShader *mVertexExecutable;
ID3D11GeometryShader *mGeometryExecutable;
UniformStorage11 *mUniformStorage;
};
class UniformStorage11 : public UniformStorage
{
public:
UniformStorage11(Renderer11 *renderer, size_t initialSize);
virtual ~UniformStorage11();
static const UniformStorage11 *makeUniformStorage11(const UniformStorage *uniformStorage);
ID3D11Buffer *getConstantBuffer() const { return mConstantBuffer; }
private:
ID3D11Buffer *mConstantBuffer;
};
......
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