Move dirty DX constant tracking from Context to the Renderers.

TRAC #22308 Signed-off-by: Geoff Lang Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1713 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent f06e539a
......@@ -178,8 +178,6 @@ Context::Context(const gl::Context *shareContext, rx::Renderer *renderer, bool n
mSupportsEventQueries = false;
mSupportsOcclusionQueries = false;
mNumCompressedTextureFormats = 0;
markAllStateDirty();
}
Context::~Context()
......@@ -314,19 +312,6 @@ void Context::makeCurrent(egl::Surface *surface)
Framebuffer *framebufferZero = new DefaultFramebuffer(mRenderer, colorbufferZero, depthStencilbufferZero);
setFramebufferZero(framebufferZero);
markAllStateDirty();
}
// This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
void Context::markAllStateDirty()
{
mDxUniformsDirty = true;
}
void Context::markDxUniformsDirty()
{
mDxUniformsDirty = true;
}
// NOTE: this function should not assume that this context is current!
......@@ -933,7 +918,6 @@ void Context::useProgram(GLuint program)
Program *newProgram = mResourceManager->getProgram(program);
Program *oldProgram = mResourceManager->getProgram(priorProgram);
mCurrentProgramBinary.set(NULL);
mDxUniformsDirty = true;
if (newProgram)
{
......@@ -959,7 +943,6 @@ void Context::linkProgram(GLuint program)
if (linked && program == mState.currentProgram)
{
mCurrentProgramBinary.set(programObject->getProgramBinary());
mDxUniformsDirty = true;
}
}
......@@ -974,7 +957,6 @@ void Context::setProgramBinary(GLuint program, const void *binary, GLint length)
if (loaded && program == mState.currentProgram)
{
mCurrentProgramBinary.set(programObject->getProgramBinary());
mDxUniformsDirty = true;
}
}
......@@ -1719,11 +1701,10 @@ bool Context::applyRenderTarget(GLenum drawMode, bool ignoreViewport)
ProgramBinary *programBinary = mState.currentProgram ? getCurrentProgramBinary() : NULL;
if (!mRenderer->setViewport(mState.viewport, mState.zNear, mState.zFar, drawMode, mState.rasterizer.frontFace,
ignoreViewport, programBinary, mDxUniformsDirty))
ignoreViewport, programBinary))
{
return false;
}
mDxUniformsDirty = false;
mRenderer->setScissorRectangle(mState.scissor, mState.scissorTest);
......
......@@ -191,9 +191,6 @@ class Context
void makeCurrent(egl::Surface *surface);
virtual void markAllStateDirty();
void markDxUniformsDirty();
virtual void markContextLost();
bool isContextLost();
......@@ -486,7 +483,6 @@ class Context
GLenum mResetStrategy;
bool mRobustAccess;
bool mDxUniformsDirty;
BindingPointer<ProgramBinary> mCurrentProgramBinary;
Framebuffer *mBoundDrawFramebuffer;
......
......@@ -1000,7 +1000,7 @@ void ProgramBinary::applyUniforms()
}
}
mRenderer->applyUniforms(&mUniforms, mVertexConstants, mPixelConstants);
mRenderer->applyUniforms(&mUniforms);
}
// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
......@@ -1813,9 +1813,6 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
success = false;
}
Context *context = getContext();
context->markDxUniformsDirty();
return success;
}
......@@ -2241,38 +2238,6 @@ bool ProgramBinary::validateSamplers(InfoLog *infoLog)
return true;
}
void ProgramBinary::applyDxDepthRange(float near, float far, float diff)
{
mVertexConstants.depthRange[0] = near;
mVertexConstants.depthRange[1] = far;
mVertexConstants.depthRange[2] = diff;
mPixelConstants.depthRange[0] = near;
mPixelConstants.depthRange[1] = far;
mPixelConstants.depthRange[2] = diff;
}
void ProgramBinary::applyDxDepthFront(float range, float start, float frontCCW)
{
mPixelConstants.depthFront[0] = range;
mPixelConstants.depthFront[1] = start;
mPixelConstants.depthFront[2] = frontCCW;
}
void ProgramBinary::applyDxCoord(float halfWidth, float halfHeight, float x0, float y0)
{
mPixelConstants.coord[0] = halfWidth;
mPixelConstants.coord[1] = halfHeight;
mPixelConstants.coord[2] = x0;
mPixelConstants.coord[3] = y0;
}
void ProgramBinary::applyDxHalfPixelSize(float width, float height)
{
mVertexConstants.halfPixelSize[0] = width;
mVertexConstants.halfPixelSize[1] = height;
}
ProgramBinary::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(TEXTURE_2D)
{
}
......
......@@ -78,11 +78,6 @@ class ProgramBinary : public RefCountObject
bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params);
bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
void applyDxDepthRange(float near, float far, float diff);
void applyDxDepthFront(float range, float start, float frontCCW);
void applyDxCoord(float halfWidth, float halfHeight, float x0, float y0);
void applyDxHalfPixelSize(float width, float height);
void dirtyAllUniforms();
void applyUniforms();
......@@ -147,9 +142,6 @@ class ProgramBinary : public RefCountObject
typedef std::vector<UniformLocation> UniformIndex;
UniformIndex mUniformIndex;
rx::dx_VertexConstants mVertexConstants;
rx::dx_PixelConstants mPixelConstants;
bool mValidated;
const unsigned int mSerial;
......
......@@ -107,11 +107,11 @@ class Renderer
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
bool ignoreViewport, gl::ProgramBinary *currentProgram) = 0;
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants) = 0;
virtual void applyUniforms(const gl::UniformArray *uniformArray) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
......
......@@ -489,7 +489,7 @@ void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
}
bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms)
bool ignoreViewport, gl::ProgramBinary *currentProgram)
{
gl::Rectangle actualViewport = viewport;
float actualZNear = gl::clamp01(zNear);
......@@ -517,8 +517,8 @@ bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float z
return false; // Nothing to render
}
bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
actualZNear != mCurNear || actualZFar != mCurFar;
bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
actualZNear != mCurNear || actualZFar != mCurFar;
if (viewportChanged)
{
......@@ -529,20 +529,42 @@ bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float z
mCurFar = actualZFar;
}
if (currentProgram && (viewportChanged || forceSetUniforms))
if (currentProgram)
{
currentProgram->applyDxHalfPixelSize(0.0f, 0.0f);
dx_VertexConstants vc = {0};
dx_PixelConstants pc = {0};
// These values are used for computing gl_FragCoord in Program::linkVaryings().
currentProgram->applyDxCoord(actualViewport.width * 0.5f,
actualViewport.height * 0.5f,
actualViewport.x + (actualViewport.width * 0.5f),
actualViewport.y + (actualViewport.height * 0.5f));
vc.halfPixelSize[0] = 0.0f;
vc.halfPixelSize[1] = 0.0f;
GLfloat ccw = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);
currentProgram->applyDxDepthFront((actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw);
pc.coord[0] = actualViewport.width * 0.5f;
pc.coord[1] = actualViewport.height * 0.5f;
pc.coord[2] = actualViewport.x + (actualViewport.width * 0.5f);
pc.coord[3] = actualViewport.y + (actualViewport.height * 0.5f);
currentProgram->applyDxDepthRange(actualZNear, actualZFar, actualZFar - actualZNear);
pc.depthFront[0] = (actualZFar - actualZNear) * 0.5f;
pc.depthFront[1] = (actualZNear + actualZFar) * 0.5f;
pc.depthFront[2] = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);;
vc.depthRange[0] = actualZNear;
vc.depthRange[1] = actualZFar;
vc.depthRange[2] = actualZFar - actualZNear;
pc.depthRange[0] = actualZNear;
pc.depthRange[1] = actualZFar;
pc.depthRange[2] = actualZFar - actualZNear;
if (memcmp(&vc, &mVertexConstants, sizeof(dx_VertexConstants)) != 0)
{
mVertexConstants = vc;
mDxUniformsDirty = true;
}
if (memcmp(&pc, &mPixelConstants, sizeof(dx_PixelConstants)) != 0)
{
mPixelConstants = pc;
mDxUniformsDirty = true;
}
}
mForceSetViewport = false;
......@@ -999,12 +1021,13 @@ void Renderer11::applyShaders(gl::ProgramBinary *programBinary)
mDeviceContext->PSSetShader(pixelShader, NULL, 0);
mDeviceContext->VSSetShader(vertexShader, NULL, 0);
programBinary->dirtyAllUniforms();
mDxUniformsDirty = true;
mAppliedProgramBinarySerial = programBinarySerial;
}
}
void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants)
void Renderer11::applyUniforms(const gl::UniformArray *uniformArray)
{
D3D11_BUFFER_DESC constantBufferDescription = {0};
constantBufferDescription.ByteWidth = D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]);
......@@ -1145,8 +1168,8 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_Ve
}
// Driver uniforms
memcpy(mapVS.pData, &vertexConstants, sizeof(dx_VertexConstants));
memcpy(mapPS.pData, &pixelConstants, sizeof(dx_PixelConstants));
memcpy(mapVS.pData, &mVertexConstants, sizeof(dx_VertexConstants));
memcpy(mapPS.pData, &mPixelConstants, sizeof(dx_PixelConstants));
mDeviceContext->Unmap(constantBufferVS, 0);
mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS);
......@@ -1302,6 +1325,7 @@ void Renderer11::markAllStateDirty()
mAppliedIBOffset = 0;
mAppliedProgramBinarySerial = 0;
mDxUniformsDirty = true;
}
void Renderer11::releaseDeviceResources()
......
......@@ -62,12 +62,12 @@ class Renderer11 : public Renderer
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms);
bool ignoreViewport, gl::ProgramBinary *currentProgram);
virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants);
virtual void applyUniforms(const gl::UniformArray *uniformArray);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances);
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
......@@ -230,6 +230,10 @@ class Renderer11 : public Renderer
unsigned int mAppliedProgramBinarySerial;
rx::dx_VertexConstants mVertexConstants;
rx::dx_PixelConstants mPixelConstants;
bool mDxUniformsDirty;
// Vertex, index and input layouts
VertexDataManager *mVertexDataManager;
IndexDataManager *mIndexDataManager;
......
......@@ -1027,7 +1027,7 @@ void Renderer9::setScissorRectangle(const gl::Rectangle &scissor, bool enabled)
}
bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms)
bool ignoreViewport, gl::ProgramBinary *currentProgram)
{
gl::Rectangle actualViewport = viewport;
float actualZNear = gl::clamp01(zNear);
......@@ -1055,8 +1055,8 @@ bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zF
return false; // Nothing to render
}
bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
actualZNear != mCurNear || actualZFar != mCurFar;
bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
actualZNear != mCurNear || actualZFar != mCurFar;
if (viewportChanged)
{
mDevice->SetViewport(&dxViewport);
......@@ -1066,20 +1066,42 @@ bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zF
mCurFar = actualZFar;
}
if (currentProgram && (viewportChanged || forceSetUniforms))
if (currentProgram)
{
currentProgram->applyDxHalfPixelSize(1.0f / dxViewport.Width, -1.0f / dxViewport.Height);
dx_VertexConstants vc = {0};
dx_PixelConstants pc = {0};
// These values are used for computing gl_FragCoord in Program::linkVaryings().
currentProgram->applyDxCoord(actualViewport.width * 0.5f,
actualViewport.height * 0.5f,
actualViewport.x + (actualViewport.width * 0.5f),
actualViewport.y + (actualViewport.height * 0.5f));
vc.halfPixelSize[0] = 1.0f / dxViewport.Width;
vc.halfPixelSize[1] = -1.0f / dxViewport.Height;
GLfloat ccw = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);
currentProgram->applyDxDepthFront((actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw);
pc.coord[0] = actualViewport.width * 0.5f;
pc.coord[1] = actualViewport.height * 0.5f;
pc.coord[2] = actualViewport.x + (actualViewport.width * 0.5f);
pc.coord[3] = actualViewport.y + (actualViewport.height * 0.5f);
currentProgram->applyDxDepthRange(actualZNear, actualZFar, actualZFar - actualZNear);
pc.depthFront[0] = (actualZFar - actualZNear) * 0.5f;
pc.depthFront[1] = (actualZNear + actualZFar) * 0.5f;
pc.depthFront[2] = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);;
vc.depthRange[0] = actualZNear;
vc.depthRange[1] = actualZFar;
vc.depthRange[2] = actualZFar - actualZNear;
pc.depthRange[0] = actualZNear;
pc.depthRange[1] = actualZFar;
pc.depthRange[2] = actualZFar - actualZNear;
if (memcmp(&vc, &mVertexConstants, sizeof(dx_VertexConstants)) != 0)
{
mVertexConstants = vc;
mDxUniformsDirty = true;
}
if (memcmp(&pc, &mPixelConstants, sizeof(dx_PixelConstants)) != 0)
{
mPixelConstants = pc;
mDxUniformsDirty = true;
}
}
mForceSetViewport = false;
......@@ -1579,12 +1601,13 @@ void Renderer9::applyShaders(gl::ProgramBinary *programBinary)
mDevice->SetPixelShader(pixelShader);
mDevice->SetVertexShader(vertexShader);
programBinary->dirtyAllUniforms();
mDxUniformsDirty = true;
mAppliedProgramBinarySerial = programBinarySerial;
}
}
void Renderer9::applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants)
void Renderer9::applyUniforms(const gl::UniformArray *uniformArray)
{
for (std::vector<gl::Uniform*>::const_iterator ub = uniformArray->begin(), ue = uniformArray->end(); ub != ue; ++ub)
{
......@@ -1626,8 +1649,12 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray, const dx_Ver
}
// Driver uniforms
mDevice->SetVertexShaderConstantF(0, (float*)&vertexConstants, sizeof(dx_VertexConstants) / sizeof(float[4]));
mDevice->SetPixelShaderConstantF(0, (float*)&pixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4]));
if (mDxUniformsDirty)
{
mDevice->SetVertexShaderConstantF(0, (float*)&mVertexConstants, sizeof(dx_VertexConstants) / sizeof(float[4]));
mDevice->SetPixelShaderConstantF(0, (float*)&mPixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4]));
mDxUniformsDirty = false;
}
}
void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int width, const GLboolean *v)
......@@ -1938,6 +1965,7 @@ void Renderer9::markAllStateDirty()
mAppliedIBSerial = 0;
mAppliedProgramBinarySerial = 0;
mDxUniformsDirty = true;
mVertexDeclarationCache.markStateDirty();
}
......
......@@ -86,11 +86,11 @@ class Renderer9 : public Renderer
virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms);
bool ignoreViewport, gl::ProgramBinary *currentProgram);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants);
virtual void applyUniforms(const gl::UniformArray *uniformArray);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances);
virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
......@@ -308,6 +308,10 @@ class Renderer9 : public Renderer
unsigned int mAppliedIBSerial;
unsigned int mAppliedProgramBinarySerial;
rx::dx_VertexConstants mVertexConstants;
rx::dx_PixelConstants mPixelConstants;
bool mDxUniformsDirty;
// A pool of event queries that are currently unused.
std::vector<IDirect3DQuery9*> mEventQueryPool;
......
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -472,12 +472,6 @@ EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
static ID3D11RenderTargetView *const nullRTV = NULL;
deviceContext->OMSetRenderTargets(1, &nullRTV, NULL);
// Mark context and renderer dirty flags
gl::Context *glContext = static_cast<gl::Context*>(glGetCurrentContext());
if (glContext)
{
glContext->markAllStateDirty();
}
mRenderer->markAllStateDirty();
return EGL_SUCCESS;
......
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -337,11 +337,6 @@ EGLint SwapChain9::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
HRESULT result = mSwapChain->Present(&rect, &rect, NULL, NULL, 0);
gl::Context *context = static_cast<gl::Context*>(glGetCurrentContext());
if (context)
{
context->markAllStateDirty();
}
mRenderer->markAllStateDirty();
if (isDeviceLostError(result))
......
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