Implemented support for DX11 driver uniforms by assigning fixed register slots.

TRAC #22369 Signed-off-by: Daniel Koch Signed-off-by: Geoff Lang Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1682 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent cc47bc06
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 1 #define MINOR_VERSION 1
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1565 #define BUILD_REVISION 1643
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -90,7 +90,15 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr ...@@ -90,7 +90,15 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr
mExcessiveLoopIndex = NULL; mExcessiveLoopIndex = NULL;
mUniformRegister = 0; if (mContext.shaderType == SH_FRAGMENT_SHADER)
{
mUniformRegister = 3; // Reserve registers for dx_DepthRange, dx_Coord and dx_DepthFront
}
else
{
mUniformRegister = 2; // Reserve registers for dx_DepthRange and dx_HalfPixelSize
}
mSamplerRegister = 0; mSamplerRegister = 0;
} }
...@@ -199,12 +207,12 @@ void OutputHLSL::header() ...@@ -199,12 +207,12 @@ void OutputHLSL::header()
if (mUsesFragCoord) if (mUsesFragCoord)
{ {
out << "uniform float4 dx_Coord : register(" + dx_RegisterString(GL_FLOAT_VEC4, "dx_Coord") + ");\n"; out << "uniform float4 dx_Coord : register(c1);\n";
} }
if (mUsesFragCoord || mUsesFrontFacing) if (mUsesFragCoord || mUsesFrontFacing)
{ {
out << "uniform float3 dx_DepthFront : register(" + dx_RegisterString(GL_FLOAT_VEC3, "dx_DepthFront") + ");\n"; out << "uniform float3 dx_DepthFront : register(c2);\n";
} }
out << "\n"; out << "\n";
...@@ -357,7 +365,7 @@ void OutputHLSL::header() ...@@ -357,7 +365,7 @@ void OutputHLSL::header()
"// Varyings\n"; "// Varyings\n";
out << varyings; out << varyings;
out << "\n" out << "\n"
"uniform float2 dx_HalfPixelSize : register(" + dx_RegisterString(GL_FLOAT_VEC2, "dx_HalfPixelSize") + ");\n" "uniform float2 dx_HalfPixelSize : register(c1);\n"
"\n"; "\n";
out << uniforms; out << uniforms;
out << "\n"; out << "\n";
...@@ -456,7 +464,7 @@ void OutputHLSL::header() ...@@ -456,7 +464,7 @@ void OutputHLSL::header()
" float diff;\n" " float diff;\n"
"};\n" "};\n"
"\n" "\n"
"uniform float3 dx_DepthRange : register(" + dx_RegisterString(GL_FLOAT_VEC3, "dx_DepthRange") + ");" "uniform float3 dx_DepthRange : register(c0);"
"static gl_DepthRangeParameters gl_DepthRange = {dx_DepthRange.x, dx_DepthRange.y, dx_DepthRange.z};\n" "static gl_DepthRangeParameters gl_DepthRange = {dx_DepthRange.x, dx_DepthRange.y, dx_DepthRange.z};\n"
"\n"; "\n";
} }
...@@ -2609,17 +2617,6 @@ TString OutputHLSL::registerString(TIntermSymbol *operand) ...@@ -2609,17 +2617,6 @@ TString OutputHLSL::registerString(TIntermSymbol *operand)
return "c" + str(uniformRegister(operand)); return "c" + str(uniformRegister(operand));
} }
TString OutputHLSL::dx_RegisterString(GLenum type, const char *name)
{
ASSERT(type >= GL_FLOAT_VEC2 && type <= GL_FLOAT_VEC4); // Only single (uniform) registers handled
int index = mUniformRegister;
mUniformRegister += 1;
mActiveUniforms.push_back(Uniform(type, name, 0, index));
return "c" + str(index);
}
int OutputHLSL::samplerRegister(TIntermSymbol *sampler) int OutputHLSL::samplerRegister(TIntermSymbol *sampler)
{ {
const TType &type = sampler->getType(); const TType &type = sampler->getType();
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -158,7 +158,6 @@ class OutputHLSL : public TIntermTraverser ...@@ -158,7 +158,6 @@ class OutputHLSL : public TIntermTraverser
int mSamplerRegister; int mSamplerRegister;
TString registerString(TIntermSymbol *operand); TString registerString(TIntermSymbol *operand);
TString dx_RegisterString(GLenum type, const char *name);
int samplerRegister(TIntermSymbol *sampler); int samplerRegister(TIntermSymbol *sampler);
int uniformRegister(TIntermSymbol *uniform); int uniformRegister(TIntermSymbol *uniform);
void declareUniform(const TType &type, const TString &name, int index); void declareUniform(const TType &type, const TString &name, int index);
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -61,12 +61,6 @@ ProgramBinary::ProgramBinary(rx::Renderer *renderer) : mRenderer(renderer), RefC ...@@ -61,12 +61,6 @@ ProgramBinary::ProgramBinary(rx::Renderer *renderer) : mRenderer(renderer), RefC
mUsedVertexSamplerRange = 0; mUsedVertexSamplerRange = 0;
mUsedPixelSamplerRange = 0; mUsedPixelSamplerRange = 0;
mDxDepthRangeRegisterVS = -1;
mDxDepthRangeRegisterPS = -1;
mDxDepthFrontRegister = -1;
mDxCoordRegister = -1;
mDxHalfPixelSizeRegister = -1;
} }
ProgramBinary::~ProgramBinary() ProgramBinary::~ProgramBinary()
...@@ -1008,7 +1002,7 @@ void ProgramBinary::applyUniforms() ...@@ -1008,7 +1002,7 @@ void ProgramBinary::applyUniforms()
} }
} }
mRenderer->applyUniforms(&mUniforms); mRenderer->applyUniforms(&mUniforms, mVertexConstants, mPixelConstants);
} }
// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111 // Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
...@@ -1609,12 +1603,6 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1609,12 +1603,6 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
stream.read(&mUniformIndex[i].index); stream.read(&mUniformIndex[i].index);
} }
stream.read(&mDxDepthRangeRegisterVS);
stream.read(&mDxDepthRangeRegisterPS);
stream.read(&mDxDepthFrontRegister);
stream.read(&mDxCoordRegister);
stream.read(&mDxHalfPixelSizeRegister);
unsigned int pixelShaderSize; unsigned int pixelShaderSize;
stream.read(&pixelShaderSize); stream.read(&pixelShaderSize);
...@@ -1714,12 +1702,6 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length) ...@@ -1714,12 +1702,6 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length)
stream.write(mUniformIndex[i].index); stream.write(mUniformIndex[i].index);
} }
stream.write(mDxDepthRangeRegisterVS);
stream.write(mDxDepthRangeRegisterPS);
stream.write(mDxDepthFrontRegister);
stream.write(mDxCoordRegister);
stream.write(mDxHalfPixelSizeRegister);
UINT pixelShaderSize = mPixelExecutable->getLength(); UINT pixelShaderSize = mPixelExecutable->getLength();
stream.write(pixelShaderSize); stream.write(pixelShaderSize);
...@@ -1926,31 +1908,6 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &ver ...@@ -1926,31 +1908,6 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &ver
bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog) bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog)
{ {
if (constant.name == "dx_DepthRange")
{
if (shader == GL_VERTEX_SHADER) mDxDepthRangeRegisterVS = constant.registerIndex;
if (shader == GL_FRAGMENT_SHADER) mDxDepthRangeRegisterPS = constant.registerIndex;
return true;
}
if (constant.name == "dx_DepthFront")
{
mDxDepthFrontRegister = constant.registerIndex;
return true;
}
if (constant.name == "dx_Coord")
{
mDxCoordRegister = constant.registerIndex;
return true;
}
if (constant.name == "dx_HalfPixelSize")
{
mDxHalfPixelSizeRegister = constant.registerIndex;
return true;
}
if (constant.type == GL_SAMPLER_2D || if (constant.type == GL_SAMPLER_2D ||
constant.type == GL_SAMPLER_CUBE) constant.type == GL_SAMPLER_CUBE)
{ {
...@@ -2284,56 +2241,34 @@ bool ProgramBinary::validateSamplers(InfoLog *infoLog) ...@@ -2284,56 +2241,34 @@ bool ProgramBinary::validateSamplers(InfoLog *infoLog)
void ProgramBinary::applyDxDepthRange(float near, float far, float diff) void ProgramBinary::applyDxDepthRange(float near, float far, float diff)
{ {
if (dynamic_cast<rx::Renderer9*>(mRenderer) == NULL) return; // UNIMPLEMENTED mVertexConstants.depthRange[0] = near;
IDirect3DDevice9 *device = rx::Renderer9::makeRenderer9(mRenderer)->getDevice(); // D3D9_REPLACE mVertexConstants.depthRange[1] = far;
mVertexConstants.depthRange[2] = diff;
if (mDxDepthRangeRegisterVS >= 0) mPixelConstants.depthRange[0] = near;
{ mPixelConstants.depthRange[1] = far;
float nearFarDiff[4] = {near, far, diff}; mPixelConstants.depthRange[2] = diff;
device->SetVertexShaderConstantF(mDxDepthRangeRegisterVS, nearFarDiff, 1);
}
if (mDxDepthRangeRegisterPS >= 0)
{
float nearFarDiff[4] = {near, far, diff};
device->SetPixelShaderConstantF(mDxDepthRangeRegisterPS, nearFarDiff, 1);
}
} }
void ProgramBinary::applyDxDepthFront(float range, float start, float frontCCW) void ProgramBinary::applyDxDepthFront(float range, float start, float frontCCW)
{ {
if (mDxDepthFrontRegister >= 0) mPixelConstants.depthFront[0] = range;
{ mPixelConstants.depthFront[1] = start;
if (dynamic_cast<rx::Renderer9*>(mRenderer) == NULL) return; // UNIMPLEMENTED mPixelConstants.depthFront[2] = frontCCW;
IDirect3DDevice9 *device = rx::Renderer9::makeRenderer9(mRenderer)->getDevice(); // D3D9_REPLACE
GLfloat dz[4] = {range, start, frontCCW};
device->SetPixelShaderConstantF(mDxDepthFrontRegister, dz, 1);
}
} }
void ProgramBinary::applyDxCoord(float halfWidth, float halfHeight, float x0, float y0) void ProgramBinary::applyDxCoord(float halfWidth, float halfHeight, float x0, float y0)
{ {
if (mDxCoordRegister >= 0) mPixelConstants.coord[0] = halfWidth;
{ mPixelConstants.coord[1] = halfHeight;
if (dynamic_cast<rx::Renderer9*>(mRenderer) == NULL) return; // UNIMPLEMENTED mPixelConstants.coord[2] = x0;
IDirect3DDevice9 *device = rx::Renderer9::makeRenderer9(mRenderer)->getDevice(); // D3D9_REPLACE mPixelConstants.coord[3] = y0;
GLfloat whxy[4] = {halfWidth,halfHeight, x0, y0};
device->SetPixelShaderConstantF(mDxCoordRegister, whxy, 1);
}
} }
void ProgramBinary::applyDxHalfPixelSize(float width, float height) void ProgramBinary::applyDxHalfPixelSize(float width, float height)
{ {
if (mDxHalfPixelSizeRegister >= 0) mVertexConstants.halfPixelSize[0] = width;
{ mVertexConstants.halfPixelSize[1] = height;
if (dynamic_cast<rx::Renderer9*>(mRenderer) == NULL) return; // UNIMPLEMENTED
IDirect3DDevice9 *device = rx::Renderer9::makeRenderer9(mRenderer)->getDevice(); // D3D9_REPLACE
GLfloat xy[4] = {width, height};
device->SetVertexShaderConstantF(mDxHalfPixelSizeRegister, xy, 1);
}
} }
ProgramBinary::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(TEXTURE_2D) ProgramBinary::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(TEXTURE_2D)
......
...@@ -147,11 +147,8 @@ class ProgramBinary : public RefCountObject ...@@ -147,11 +147,8 @@ class ProgramBinary : public RefCountObject
typedef std::vector<UniformLocation> UniformIndex; typedef std::vector<UniformLocation> UniformIndex;
UniformIndex mUniformIndex; UniformIndex mUniformIndex;
int mDxDepthRangeRegisterVS; rx::dx_VertexConstants mVertexConstants;
int mDxDepthRangeRegisterPS; rx::dx_PixelConstants mPixelConstants;
int mDxDepthFrontRegister;
int mDxCoordRegister;
int mDxHalfPixelSizeRegister;
bool mValidated; bool mValidated;
......
// //
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -67,6 +67,19 @@ struct ConfigDesc ...@@ -67,6 +67,19 @@ struct ConfigDesc
bool fastConfig; bool fastConfig;
}; };
struct dx_VertexConstants
{
float depthRange[4];
float halfPixelSize[4];
};
struct dx_PixelConstants
{
float depthRange[4];
float coord[4];
float depthFront[4];
};
class Renderer class Renderer
{ {
public: public:
...@@ -98,7 +111,7 @@ class Renderer ...@@ -98,7 +111,7 @@ class Renderer
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0; virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
virtual void applyShaders(gl::ProgramBinary *programBinary) = 0; virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
virtual void applyUniforms(const gl::UniformArray *uniformArray) = 0; virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 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 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; virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
......
...@@ -867,7 +867,7 @@ void Renderer11::applyShaders(gl::ProgramBinary *programBinary) ...@@ -867,7 +867,7 @@ void Renderer11::applyShaders(gl::ProgramBinary *programBinary)
} }
} }
void Renderer11::applyUniforms(const gl::UniformArray *uniformArray) void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants)
{ {
D3D11_BUFFER_DESC constantBufferDescription = {0}; D3D11_BUFFER_DESC constantBufferDescription = {0};
constantBufferDescription.ByteWidth = D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]); constantBufferDescription.ByteWidth = D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]);
...@@ -940,6 +940,10 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -940,6 +940,10 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray)
} }
} }
// Driver uniforms
memcpy(cVS, &vertexConstants, sizeof(dx_VertexConstants));
memcpy(cPS, &pixelConstants, sizeof(dx_PixelConstants));
mDeviceContext->Unmap(constantBufferVS, 0); mDeviceContext->Unmap(constantBufferVS, 0);
mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS); mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS);
constantBufferVS->Release(); constantBufferVS->Release();
......
// //
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -67,7 +67,7 @@ class Renderer11 : public Renderer ...@@ -67,7 +67,7 @@ class Renderer11 : public Renderer
virtual bool applyPrimitiveType(GLenum mode, GLsizei count); virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary); virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(const gl::UniformArray *uniformArray); virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances); 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); virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
......
...@@ -1561,7 +1561,7 @@ void Renderer9::applyShaders(gl::ProgramBinary *programBinary) ...@@ -1561,7 +1561,7 @@ void Renderer9::applyShaders(gl::ProgramBinary *programBinary)
} }
} }
void Renderer9::applyUniforms(const gl::UniformArray *uniformArray) void Renderer9::applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants)
{ {
for (std::vector<gl::Uniform*>::const_iterator ub = uniformArray->begin(), ue = uniformArray->end(); ub != ue; ++ub) for (std::vector<gl::Uniform*>::const_iterator ub = uniformArray->begin(), ue = uniformArray->end(); ub != ue; ++ub)
{ {
...@@ -1601,6 +1601,10 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -1601,6 +1601,10 @@ void Renderer9::applyUniforms(const gl::UniformArray *uniformArray)
targetUniform->dirty = false; targetUniform->dirty = false;
} }
} }
// Driver uniforms
mDevice->SetVertexShaderConstantF(0, (float*)&vertexConstants, sizeof(dx_VertexConstants) / sizeof(float[4]));
mDevice->SetPixelShaderConstantF(0, (float*)&pixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4]));
} }
void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int width, const GLboolean *v) void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int width, const GLboolean *v)
......
...@@ -90,7 +90,7 @@ class Renderer9 : public Renderer ...@@ -90,7 +90,7 @@ class Renderer9 : public Renderer
virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer); virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
virtual void applyShaders(gl::ProgramBinary *programBinary); virtual void applyShaders(gl::ProgramBinary *programBinary);
virtual void applyUniforms(const gl::UniformArray *uniformArray); virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount); virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances); 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); virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
......
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