Implemented support for DX11 sampler uniforms.

TRAC #22242 Signed-off-by: Daniel Koch Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1630 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent e6d12e9d
...@@ -22,7 +22,7 @@ struct Uniform ...@@ -22,7 +22,7 @@ struct Uniform
GLenum type; GLenum type;
std::string name; std::string name;
int arraySize; unsigned int arraySize;
int registerIndex; int registerIndex;
}; };
......
...@@ -1839,7 +1839,7 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin ...@@ -1839,7 +1839,7 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
{ {
for (sh::ActiveUniforms::const_iterator uniform = vertexShader->getUniforms().begin(); uniform != vertexShader->getUniforms().end(); uniform++) for (sh::ActiveUniforms::const_iterator uniform = vertexShader->getUniforms().begin(); uniform != vertexShader->getUniforms().end(); uniform++)
{ {
if (!defineUniform(GL_VERTEX_SHADER, *uniform)) if (!defineUniform(GL_VERTEX_SHADER, *uniform, infoLog))
{ {
success = false; success = false;
break; break;
...@@ -1848,7 +1848,7 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin ...@@ -1848,7 +1848,7 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
for (sh::ActiveUniforms::const_iterator uniform = fragmentShader->getUniforms().begin(); uniform != fragmentShader->getUniforms().end(); uniform++) for (sh::ActiveUniforms::const_iterator uniform = fragmentShader->getUniforms().begin(); uniform != fragmentShader->getUniforms().end(); uniform++)
{ {
if (!defineUniform(GL_FRAGMENT_SHADER, *uniform)) if (!defineUniform(GL_FRAGMENT_SHADER, *uniform, infoLog))
{ {
success = false; success = false;
break; break;
...@@ -2110,8 +2110,52 @@ bool ProgramBinary::defineUniform(GLenum shader, const rx::D3DConstant *constant ...@@ -2110,8 +2110,52 @@ bool ProgramBinary::defineUniform(GLenum shader, const rx::D3DConstant *constant
return true; return true;
} }
bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant) bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog)
{ {
if (constant.type == GL_SAMPLER_2D ||
constant.type == GL_SAMPLER_CUBE)
{
unsigned int samplerIndex = constant.registerIndex;
do
{
if (shader == GL_VERTEX_SHADER)
{
if (samplerIndex < getContext()->getMaximumVertexTextureImageUnits())
{
mSamplersVS[samplerIndex].active = true;
mSamplersVS[samplerIndex].textureType = (constant.type == GL_SAMPLER_CUBE) ? TEXTURE_CUBE : TEXTURE_2D;
mSamplersVS[samplerIndex].logicalTextureUnit = 0;
mUsedVertexSamplerRange = std::max(samplerIndex + 1, mUsedVertexSamplerRange);
}
else
{
infoLog.append("Vertex shader sampler count exceeds MAX_VERTEX_TEXTURE_IMAGE_UNITS (%d).", getContext()->getMaximumVertexTextureImageUnits());
return false;
}
}
else if (shader == GL_FRAGMENT_SHADER)
{
if (samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
{
mSamplersPS[samplerIndex].active = true;
mSamplersPS[samplerIndex].textureType = (constant.type == GL_SAMPLER_CUBE) ? TEXTURE_CUBE : TEXTURE_2D;
mSamplersPS[samplerIndex].logicalTextureUnit = 0;
mUsedPixelSamplerRange = std::max(samplerIndex + 1, mUsedPixelSamplerRange);
}
else
{
infoLog.append("Pixel shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS (%d).", MAX_TEXTURE_IMAGE_UNITS);
return false;
}
}
else UNREACHABLE();
samplerIndex++;
}
while (samplerIndex < constant.registerIndex + constant.arraySize);
}
Uniform *uniform = NULL; Uniform *uniform = NULL;
GLint location = getUniformLocation(constant.name); GLint location = getUniformLocation(constant.name);
......
...@@ -121,7 +121,7 @@ class ProgramBinary : public RefCountObject ...@@ -121,7 +121,7 @@ class ProgramBinary : public RefCountObject
bool defineUniform(InfoLog &infoLog, GLenum shader, const rx::D3DConstant *constant, const std::string &name, bool defineUniform(InfoLog &infoLog, GLenum shader, const rx::D3DConstant *constant, const std::string &name,
rx::D3DConstantTable *vsConstantTable, rx::D3DConstantTable *psConstantTable); rx::D3DConstantTable *vsConstantTable, rx::D3DConstantTable *psConstantTable);
bool defineUniform(GLenum shader, const rx::D3DConstant *constant, const std::string &name); bool defineUniform(GLenum shader, const rx::D3DConstant *constant, const std::string &name);
bool defineUniform(GLenum shader, const sh::Uniform &constant); bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog);
Uniform *createUniform(const rx::D3DConstant *constant, const std::string &name); Uniform *createUniform(const rx::D3DConstant *constant, const std::string &name);
rx::Renderer *const mRenderer; rx::Renderer *const mRenderer;
......
...@@ -78,7 +78,7 @@ ID3DBlob *Renderer::compileToBinary(gl::InfoLog &infoLog, const char *hlsl, cons ...@@ -78,7 +78,7 @@ ID3DBlob *Renderer::compileToBinary(gl::InfoLog &infoLog, const char *hlsl, cons
} }
HRESULT result = S_OK; HRESULT result = S_OK;
UINT flags = 0; UINT flags = D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY; // Enables using legacy sampler syntax for Shader Model 4+
std::string sourceText; std::string sourceText;
if (gl::perfActive()) if (gl::perfActive())
{ {
......
...@@ -828,6 +828,9 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray) ...@@ -828,6 +828,9 @@ void Renderer11::applyUniforms(const gl::UniformArray *uniformArray)
switch (uniform->type) switch (uniform->type)
{ {
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
break;
case GL_FLOAT: case GL_FLOAT:
case GL_FLOAT_VEC2: case GL_FLOAT_VEC2:
case GL_FLOAT_VEC3: case GL_FLOAT_VEC3:
......
...@@ -163,6 +163,8 @@ int VariableRowCount(GLenum type) ...@@ -163,6 +163,8 @@ int VariableRowCount(GLenum type)
case GL_BOOL_VEC4: case GL_BOOL_VEC4:
case GL_FLOAT_VEC4: case GL_FLOAT_VEC4:
case GL_INT_VEC4: case GL_INT_VEC4:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
return 1; return 1;
case GL_FLOAT_MAT2: case GL_FLOAT_MAT2:
return 2; return 2;
......
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