Implemented support for DX11 integer and boolean uniforms.

TRAC #22364 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1686 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 90c634ac
...@@ -965,10 +965,9 @@ void ProgramBinary::applyUniforms() ...@@ -965,10 +965,9 @@ void ProgramBinary::applyUniforms()
int count = targetUniform->elementCount(); int count = targetUniform->elementCount();
GLint *v = (GLint*)targetUniform->data; GLint *v = (GLint*)targetUniform->data;
if (targetUniform->ps.registerCount) if (targetUniform->psRegisterIndex >= 0)
{ {
ASSERT(targetUniform->ps.registerIndex >= 0); unsigned int firstIndex = targetUniform->psRegisterIndex;
unsigned int firstIndex = targetUniform->ps.registerIndex;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
...@@ -982,10 +981,9 @@ void ProgramBinary::applyUniforms() ...@@ -982,10 +981,9 @@ void ProgramBinary::applyUniforms()
} }
} }
if (targetUniform->vs.registerCount) if (targetUniform->vsRegisterIndex >= 0)
{ {
ASSERT(targetUniform->vs.registerIndex >= 0); unsigned int firstIndex = targetUniform->vsRegisterIndex;
unsigned int firstIndex = targetUniform->vs.registerIndex;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
...@@ -1581,11 +1579,9 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1581,11 +1579,9 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
mUniforms[i] = new Uniform(type, name, arraySize); mUniforms[i] = new Uniform(type, name, arraySize);
stream.read(&mUniforms[i]->ps.registerIndex); stream.read(&mUniforms[i]->psRegisterIndex);
stream.read(&mUniforms[i]->ps.registerCount); stream.read(&mUniforms[i]->vsRegisterIndex);
stream.read(&mUniforms[i]->registerCount);
stream.read(&mUniforms[i]->vs.registerIndex);
stream.read(&mUniforms[i]->vs.registerCount);
} }
stream.read(&size); stream.read(&size);
...@@ -1687,11 +1683,9 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length) ...@@ -1687,11 +1683,9 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length)
stream.write(mUniforms[i]->name); stream.write(mUniforms[i]->name);
stream.write(mUniforms[i]->arraySize); stream.write(mUniforms[i]->arraySize);
stream.write(mUniforms[i]->ps.registerIndex); stream.write(mUniforms[i]->psRegisterIndex);
stream.write(mUniforms[i]->ps.registerCount); stream.write(mUniforms[i]->vsRegisterIndex);
stream.write(mUniforms[i]->registerCount);
stream.write(mUniforms[i]->vs.registerIndex);
stream.write(mUniforms[i]->vs.registerCount);
} }
stream.write(mUniformIndex.size()); stream.write(mUniformIndex.size());
...@@ -1976,13 +1970,11 @@ bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, In ...@@ -1976,13 +1970,11 @@ bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, In
if (shader == GL_FRAGMENT_SHADER) if (shader == GL_FRAGMENT_SHADER)
{ {
uniform->ps.registerIndex = constant.registerIndex; uniform->psRegisterIndex = constant.registerIndex;
uniform->ps.registerCount = uniform->registerCount();
} }
else if (shader == GL_VERTEX_SHADER) else if (shader == GL_VERTEX_SHADER)
{ {
uniform->vs.registerIndex = constant.registerIndex; uniform->vsRegisterIndex = constant.registerIndex;
uniform->vs.registerCount = uniform->registerCount();
} }
else UNREACHABLE(); else UNREACHABLE();
......
// //
// Copyright (c) 2010-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2010-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.
// //
...@@ -18,6 +18,10 @@ Uniform::Uniform(GLenum type, const std::string &name, unsigned int arraySize) ...@@ -18,6 +18,10 @@ Uniform::Uniform(GLenum type, const std::string &name, unsigned int arraySize)
data = new unsigned char[bytes]; data = new unsigned char[bytes];
memset(data, 0, bytes); memset(data, 0, bytes);
dirty = true; dirty = true;
psRegisterIndex = -1;
vsRegisterIndex = -1;
registerCount = VariableRowCount(type) * elementCount();
} }
Uniform::~Uniform() Uniform::~Uniform()
...@@ -35,9 +39,4 @@ unsigned int Uniform::elementCount() const ...@@ -35,9 +39,4 @@ unsigned int Uniform::elementCount() const
return arraySize > 0 ? arraySize : 1; return arraySize > 0 ? arraySize : 1;
} }
unsigned int Uniform::registerCount() const
{
return VariableRowCount(type) * elementCount();
}
} }
// //
// Copyright (c) 2010-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2010-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.
// //
...@@ -27,7 +27,6 @@ struct Uniform ...@@ -27,7 +27,6 @@ struct Uniform
bool isArray() const; bool isArray() const;
unsigned int elementCount() const; unsigned int elementCount() const;
unsigned int registerCount() const;
const GLenum type; const GLenum type;
const std::string name; const std::string name;
...@@ -36,20 +35,9 @@ struct Uniform ...@@ -36,20 +35,9 @@ struct Uniform
unsigned char *data; unsigned char *data;
bool dirty; bool dirty;
struct RegisterInfo int psRegisterIndex;
{ int vsRegisterIndex;
RegisterInfo()
{
registerIndex = -1;
registerCount = 0;
}
int registerIndex;
unsigned int registerCount; unsigned int registerCount;
};
RegisterInfo ps;
RegisterInfo vs;
}; };
typedef std::vector<Uniform*> UniformArray; typedef std::vector<Uniform*> UniformArray;
......
...@@ -257,7 +257,7 @@ void Renderer11::deleteConfigs(ConfigDesc *configDescList) ...@@ -257,7 +257,7 @@ void Renderer11::deleteConfigs(ConfigDesc *configDescList)
void Renderer11::sync(bool block) void Renderer11::sync(bool block)
{ {
// TODO // TODO
UNIMPLEMENTED(); // UNIMPLEMENTED();
} }
SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat)
...@@ -893,13 +893,9 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_Ve ...@@ -893,13 +893,9 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_Ve
result = mDeviceContext->Map(constantBufferPS, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapPS); result = mDeviceContext->Map(constantBufferPS, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapPS);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
float (*cVS)[4] = (float(*)[4])mapVS.pData;
float (*cPS)[4] = (float(*)[4])mapPS.pData;
for (gl::UniformArray::const_iterator uniform_iterator = uniformArray->begin(); uniform_iterator != uniformArray->end(); uniform_iterator++) for (gl::UniformArray::const_iterator uniform_iterator = uniformArray->begin(); uniform_iterator != uniformArray->end(); uniform_iterator++)
{ {
const gl::Uniform *uniform = *uniform_iterator; const gl::Uniform *uniform = *uniform_iterator;
GLfloat (*f)[4] = (GLfloat(*)[4])uniform->data;
switch (uniform->type) switch (uniform->type)
{ {
...@@ -913,36 +909,107 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_Ve ...@@ -913,36 +909,107 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_Ve
case GL_FLOAT_MAT2: case GL_FLOAT_MAT2:
case GL_FLOAT_MAT3: case GL_FLOAT_MAT3:
case GL_FLOAT_MAT4: case GL_FLOAT_MAT4:
if (uniform->vs.registerCount) if (uniform->vsRegisterIndex >= 0)
{
GLfloat (*c)[4] = (GLfloat(*)[4])mapVS.pData;
float (*f)[4] = (float(*)[4])uniform->data;
for (unsigned int i = 0; i < uniform->registerCount; i++)
{
c[uniform->vsRegisterIndex + i][0] = f[i][0];
c[uniform->vsRegisterIndex + i][1] = f[i][1];
c[uniform->vsRegisterIndex + i][2] = f[i][2];
c[uniform->vsRegisterIndex + i][3] = f[i][3];
}
}
if (uniform->psRegisterIndex >= 0)
{ {
for (unsigned int i = 0; i < uniform->vs.registerCount; i++) GLfloat (*c)[4] = (GLfloat(*)[4])mapPS.pData;
float (*f)[4] = (float(*)[4])uniform->data;
for (unsigned int i = 0; i < uniform->registerCount; i++)
{ {
cVS[uniform->vs.registerIndex + i][0] = f[i][0]; c[uniform->psRegisterIndex + i][0] = f[i][0];
cVS[uniform->vs.registerIndex + i][1] = f[i][1]; c[uniform->psRegisterIndex + i][1] = f[i][1];
cVS[uniform->vs.registerIndex + i][2] = f[i][2]; c[uniform->psRegisterIndex + i][2] = f[i][2];
cVS[uniform->vs.registerIndex + i][3] = f[i][3]; c[uniform->psRegisterIndex + i][3] = f[i][3];
} }
} }
if (uniform->ps.registerCount) break;
case GL_INT:
case GL_INT_VEC2:
case GL_INT_VEC3:
case GL_INT_VEC4:
if (uniform->vsRegisterIndex >= 0)
{ {
for (unsigned int i = 0; i < uniform->ps.registerCount; i++) int (*c)[4] = (int(*)[4])mapVS.pData;
GLint *x = (GLint*)uniform->data;
int count = gl::VariableColumnCount(uniform->type);
for (unsigned int i = 0; i < uniform->registerCount; i++)
{
if (count >= 1) c[uniform->vsRegisterIndex + i][0] = x[i * count + 0];
if (count >= 2) c[uniform->vsRegisterIndex + i][1] = x[i * count + 1];
if (count >= 3) c[uniform->vsRegisterIndex + i][2] = x[i * count + 2];
if (count >= 4) c[uniform->vsRegisterIndex + i][3] = x[i * count + 3];
}
}
if (uniform->psRegisterIndex >= 0)
{
int (*c)[4] = (int(*)[4])mapPS.pData;
GLint *x = (GLint*)uniform->data;
int count = gl::VariableColumnCount(uniform->type);
for (unsigned int i = 0; i < uniform->registerCount; i++)
{
if (count >= 1) c[uniform->psRegisterIndex + i][0] = x[i * count + 0];
if (count >= 2) c[uniform->psRegisterIndex + i][1] = x[i * count + 1];
if (count >= 3) c[uniform->psRegisterIndex + i][2] = x[i * count + 2];
if (count >= 4) c[uniform->psRegisterIndex + i][3] = x[i * count + 3];
}
}
break;
case GL_BOOL:
case GL_BOOL_VEC2:
case GL_BOOL_VEC3:
case GL_BOOL_VEC4:
if (uniform->vsRegisterIndex >= 0)
{
int (*c)[4] = (int(*)[4])mapVS.pData;
GLboolean *b = (GLboolean*)uniform->data;
int count = gl::VariableColumnCount(uniform->type);
for (unsigned int i = 0; i < uniform->registerCount; i++)
{
if (count >= 1) c[uniform->vsRegisterIndex + i][0] = b[i * count + 0];
if (count >= 2) c[uniform->vsRegisterIndex + i][1] = b[i * count + 1];
if (count >= 3) c[uniform->vsRegisterIndex + i][2] = b[i * count + 2];
if (count >= 4) c[uniform->vsRegisterIndex + i][3] = b[i * count + 3];
}
}
if (uniform->psRegisterIndex >= 0)
{
int (*c)[4] = (int(*)[4])mapPS.pData;
GLboolean *b = (GLboolean*)uniform->data;
int count = gl::VariableColumnCount(uniform->type);
for (unsigned int i = 0; i < uniform->registerCount; i++)
{ {
cPS[uniform->ps.registerIndex + i][0] = f[i][0]; if (count >= 1) c[uniform->psRegisterIndex + i][0] = b[i * count + 0];
cPS[uniform->ps.registerIndex + i][1] = f[i][1]; if (count >= 2) c[uniform->psRegisterIndex + i][1] = b[i * count + 1];
cPS[uniform->ps.registerIndex + i][2] = f[i][2]; if (count >= 3) c[uniform->psRegisterIndex + i][2] = b[i * count + 2];
cPS[uniform->ps.registerIndex + i][3] = f[i][3]; if (count >= 4) c[uniform->psRegisterIndex + i][3] = b[i * count + 3];
} }
} }
break; break;
default: default:
UNIMPLEMENTED(); // FIXME
UNREACHABLE(); UNREACHABLE();
} }
} }
// Driver uniforms // Driver uniforms
memcpy(cVS, &vertexConstants, sizeof(dx_VertexConstants)); memcpy(mapVS.pData, &vertexConstants, sizeof(dx_VertexConstants));
memcpy(cPS, &pixelConstants, sizeof(dx_PixelConstants)); memcpy(mapPS.pData, &pixelConstants, sizeof(dx_PixelConstants));
mDeviceContext->Unmap(constantBufferVS, 0); mDeviceContext->Unmap(constantBufferVS, 0);
mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS); mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS);
......
...@@ -1611,7 +1611,7 @@ void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int w ...@@ -1611,7 +1611,7 @@ void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int w
{ {
float vector[gl::D3D9_MAX_FLOAT_CONSTANTS * 4]; float vector[gl::D3D9_MAX_FLOAT_CONSTANTS * 4];
if (targetUniform->ps.registerIndex >= 0 || targetUniform->vs.registerIndex >= 0) if (targetUniform->psRegisterIndex >= 0 || targetUniform->vsRegisterIndex >= 0)
{ {
ASSERT(count <= gl::D3D9_MAX_FLOAT_CONSTANTS); ASSERT(count <= gl::D3D9_MAX_FLOAT_CONSTANTS);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
...@@ -1635,16 +1635,14 @@ void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int w ...@@ -1635,16 +1635,14 @@ void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int w
void Renderer9::applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v) void Renderer9::applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v)
{ {
if (targetUniform->ps.registerCount) if (targetUniform->psRegisterIndex >= 0)
{ {
ASSERT(targetUniform->ps.registerIndex >= 0); mDevice->SetPixelShaderConstantF(targetUniform->psRegisterIndex, v, targetUniform->registerCount);
mDevice->SetPixelShaderConstantF(targetUniform->ps.registerIndex, v, targetUniform->ps.registerCount);
} }
if (targetUniform->vs.registerCount) if (targetUniform->vsRegisterIndex >= 0)
{ {
ASSERT(targetUniform->vs.registerIndex >= 0); mDevice->SetVertexShaderConstantF(targetUniform->vsRegisterIndex, v, targetUniform->registerCount);
mDevice->SetVertexShaderConstantF(targetUniform->vs.registerIndex, v, targetUniform->vs.registerCount);
} }
} }
......
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