Eliminated D3DConstantTable.

TRAC #22326 Signed-off-by: Daniel Koch Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1634 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 68aaf936
...@@ -250,8 +250,6 @@ ...@@ -250,8 +250,6 @@
'libGLESv2/Renderbuffer.h', 'libGLESv2/Renderbuffer.h',
'libGLESv2/renderer/Blit.cpp', 'libGLESv2/renderer/Blit.cpp',
'libGLESv2/renderer/Blit.h', 'libGLESv2/renderer/Blit.h',
'libGLESv2/renderer/D3DConstantTable.cpp',
'libGLESv2/renderer/D3DConstantTable.h',
'libGLESv2/renderer/generatemip.h', 'libGLESv2/renderer/generatemip.h',
'libGLESv2/renderer/Image.cpp', 'libGLESv2/renderer/Image.cpp',
'libGLESv2/renderer/Image.h', 'libGLESv2/renderer/Image.h',
......
...@@ -1639,7 +1639,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1639,7 +1639,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
ptr += vertexShaderSize; ptr += vertexShaderSize;
mPixelExecutable = mRenderer->loadExecutable(reinterpret_cast<const DWORD*>(pixelShaderFunction), mPixelExecutable = mRenderer->loadExecutable(reinterpret_cast<const DWORD*>(pixelShaderFunction),
pixelShaderSize, GL_FRAGMENT_SHADER, NULL); pixelShaderSize, GL_FRAGMENT_SHADER);
if (!mPixelExecutable) if (!mPixelExecutable)
{ {
infoLog.append("Could not create pixel shader."); infoLog.append("Could not create pixel shader.");
...@@ -1647,7 +1647,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1647,7 +1647,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
} }
mVertexExecutable = mRenderer->loadExecutable(reinterpret_cast<const DWORD*>(vertexShaderFunction), mVertexExecutable = mRenderer->loadExecutable(reinterpret_cast<const DWORD*>(vertexShaderFunction),
vertexShaderSize, GL_VERTEX_SHADER, NULL); vertexShaderSize, GL_VERTEX_SHADER);
if (!mVertexExecutable) if (!mVertexExecutable)
{ {
infoLog.append("Could not create vertex shader."); infoLog.append("Could not create vertex shader.");
...@@ -1922,160 +1922,6 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &ver ...@@ -1922,160 +1922,6 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &ver
return true; return true;
} }
// Adds the description of a constant found in the binary shader to the list of uniforms
// Returns true if succesful (uniform not already defined)
bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const rx::D3DConstant *constant, const std::string &name,
rx::D3DConstantTable *vsConstantTable, rx::D3DConstantTable *psConstantTable)
{
if (constant->registerSet == rx::D3DConstant::RS_SAMPLER)
{
for (unsigned int i = 0; i < constant->registerCount; i++)
{
const rx::D3DConstant *psConstant = psConstantTable->getConstantByName(constant->name.c_str());
const rx::D3DConstant *vsConstant = vsConstantTable->getConstantByName(constant->name.c_str());
if (psConstant)
{
unsigned int samplerIndex = psConstant->registerIndex + i;
if (samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
{
mSamplersPS[samplerIndex].active = true;
mSamplersPS[samplerIndex].textureType = (constant->type == rx::D3DConstant::PT_SAMPLERCUBE) ? 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;
}
}
if (vsConstant)
{
unsigned int samplerIndex = vsConstant->registerIndex + i;
if (samplerIndex < getContext()->getMaximumVertexTextureImageUnits())
{
mSamplersVS[samplerIndex].active = true;
mSamplersVS[samplerIndex].textureType = (constant->type == rx::D3DConstant::PT_SAMPLERCUBE) ? 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;
}
}
}
}
switch(constant->typeClass)
{
case rx::D3DConstant::CLASS_STRUCT:
{
for (unsigned int arrayIndex = 0; arrayIndex < constant->elements; arrayIndex++)
{
for (unsigned int field = 0; field < constant->structMembers[arrayIndex].size(); field++)
{
const rx::D3DConstant *fieldConstant = constant->structMembers[arrayIndex][field];
std::string structIndex = (constant->elements > 1) ? ("[" + str(arrayIndex) + "]") : "";
if (!defineUniform(infoLog, shader, fieldConstant, name + constant->name + structIndex + ".", vsConstantTable, psConstantTable))
{
return false;
}
}
}
return true;
}
case rx::D3DConstant::CLASS_SCALAR:
case rx::D3DConstant::CLASS_VECTOR:
case rx::D3DConstant::CLASS_MATRIX_COLUMNS:
case rx::D3DConstant::CLASS_OBJECT:
return defineUniform(shader, constant, name + constant->name);
default:
UNREACHABLE();
return false;
}
}
bool ProgramBinary::defineUniform(GLenum shader, const rx::D3DConstant *constant, const std::string &_name)
{
if (_name == "dx_DepthRange")
{
if (shader == GL_VERTEX_SHADER) mDxDepthRangeRegisterVS = constant->registerIndex;
if (shader == GL_FRAGMENT_SHADER) mDxDepthRangeRegisterPS = constant->registerIndex;
return true;
}
if (_name == "dx_DepthFront")
{
mDxDepthFrontRegister = constant->registerIndex;
return true;
}
if (_name == "dx_Coord")
{
mDxCoordRegister = constant->registerIndex;
return true;
}
if (_name == "dx_HalfPixelSize")
{
mDxHalfPixelSizeRegister = constant->registerIndex;
return true;
}
Uniform *uniform = createUniform(constant, _name);
if (!uniform)
{
return false;
}
// Check if already defined
GLint location = getUniformLocation(uniform->name);
GLenum type = uniform->type;
if (location >= 0)
{
delete uniform;
uniform = mUniforms[mUniformIndex[location].index];
}
if (shader == GL_FRAGMENT_SHADER)
{
uniform->ps.registerIndex = constant->registerIndex;
uniform->ps.registerCount = constant->registerCount;
}
else if (shader == GL_VERTEX_SHADER)
{
uniform->vs.registerIndex = constant->registerIndex;
uniform->vs.registerCount = constant->registerCount;
}
else UNREACHABLE();
if (location >= 0)
{
return uniform->type == type;
}
mUniforms.push_back(uniform);
unsigned int uniformIndex = mUniforms.size() - 1;
for (unsigned int i = 0; i < uniform->arraySize; ++i)
{
mUniformIndex.push_back(UniformLocation(_name, i, uniformIndex));
}
return true;
}
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 (constant.name == "dx_DepthRange")
...@@ -2197,81 +2043,6 @@ bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, In ...@@ -2197,81 +2043,6 @@ bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, In
return true; return true;
} }
Uniform *ProgramBinary::createUniform(const rx::D3DConstant *constant, const std::string &_name)
{
if (constant->rows == 1) // Vectors and scalars
{
switch (constant->type)
{
case rx::D3DConstant::PT_SAMPLER2D:
switch (constant->columns)
{
case 1: return new Uniform(GL_SAMPLER_2D, _name, constant->elements);
default: UNREACHABLE();
}
break;
case rx::D3DConstant::PT_SAMPLERCUBE:
switch (constant->columns)
{
case 1: return new Uniform(GL_SAMPLER_CUBE, _name, constant->elements);
default: UNREACHABLE();
}
break;
case rx::D3DConstant::PT_BOOL:
switch (constant->columns)
{
case 1: return new Uniform(GL_BOOL, _name, constant->elements);
case 2: return new Uniform(GL_BOOL_VEC2, _name, constant->elements);
case 3: return new Uniform(GL_BOOL_VEC3, _name, constant->elements);
case 4: return new Uniform(GL_BOOL_VEC4, _name, constant->elements);
default: UNREACHABLE();
}
break;
case rx::D3DConstant::PT_INT:
switch (constant->columns)
{
case 1: return new Uniform(GL_INT, _name, constant->elements);
case 2: return new Uniform(GL_INT_VEC2, _name, constant->elements);
case 3: return new Uniform(GL_INT_VEC3, _name, constant->elements);
case 4: return new Uniform(GL_INT_VEC4, _name, constant->elements);
default: UNREACHABLE();
}
break;
case rx::D3DConstant::PT_FLOAT:
switch (constant->columns)
{
case 1: return new Uniform(GL_FLOAT, _name, constant->elements);
case 2: return new Uniform(GL_FLOAT_VEC2, _name, constant->elements);
case 3: return new Uniform(GL_FLOAT_VEC3, _name, constant->elements);
case 4: return new Uniform(GL_FLOAT_VEC4, _name, constant->elements);
default: UNREACHABLE();
}
break;
default:
UNREACHABLE();
}
}
else if (constant->rows == constant->columns) // Square matrices
{
switch (constant->type)
{
case rx::D3DConstant::PT_FLOAT:
switch (constant->rows)
{
case 2: return new Uniform(GL_FLOAT_MAT2, _name, constant->elements);
case 3: return new Uniform(GL_FLOAT_MAT3, _name, constant->elements);
case 4: return new Uniform(GL_FLOAT_MAT4, _name, constant->elements);
default: UNREACHABLE();
}
break;
default: UNREACHABLE();
}
}
else UNREACHABLE();
return 0;
}
// This method needs to match OutputHLSL::decorate // This method needs to match OutputHLSL::decorate
std::string ProgramBinary::decorateAttribute(const std::string &name) std::string ProgramBinary::decorateAttribute(const std::string &name)
{ {
......
...@@ -118,11 +118,7 @@ class ProgramBinary : public RefCountObject ...@@ -118,11 +118,7 @@ class ProgramBinary : public RefCountObject
bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms); bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms);
bool defineUniform(InfoLog &infoLog, GLenum shader, const rx::D3DConstant *constant, const std::string &name,
rx::D3DConstantTable *vsConstantTable, rx::D3DConstantTable *psConstantTable);
bool defineUniform(GLenum shader, const rx::D3DConstant *constant, const std::string &name);
bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog);
Uniform *createUniform(const rx::D3DConstant *constant, const std::string &name);
rx::Renderer *const mRenderer; rx::Renderer *const mRenderer;
......
...@@ -244,7 +244,6 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -244,7 +244,6 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClCompile Include="..\common\RefCountObject.cpp" /> <ClCompile Include="..\common\RefCountObject.cpp" />
<ClCompile Include="Renderbuffer.cpp" /> <ClCompile Include="Renderbuffer.cpp" />
<ClCompile Include="renderer\Blit.cpp" /> <ClCompile Include="renderer\Blit.cpp" />
<ClCompile Include="renderer\D3DConstantTable.cpp" />
<ClCompile Include="renderer\Image.cpp" /> <ClCompile Include="renderer\Image.cpp" />
<ClCompile Include="renderer\Image9.cpp" /> <ClCompile Include="renderer\Image9.cpp" />
<ClCompile Include="renderer\IndexBuffer.cpp" /> <ClCompile Include="renderer\IndexBuffer.cpp" />
...@@ -299,7 +298,6 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -299,7 +298,6 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<ClInclude Include="..\common\RefCountObject.h" /> <ClInclude Include="..\common\RefCountObject.h" />
<ClInclude Include="Renderbuffer.h" /> <ClInclude Include="Renderbuffer.h" />
<ClInclude Include="renderer\Blit.h" /> <ClInclude Include="renderer\Blit.h" />
<ClInclude Include="renderer\D3DConstantTable.h" />
<ClInclude Include="renderer\generatemip.h" /> <ClInclude Include="renderer\generatemip.h" />
<ClInclude Include="renderer\Image.h" /> <ClInclude Include="renderer\Image.h" />
<ClInclude Include="renderer\Image11.h" /> <ClInclude Include="renderer\Image11.h" />
...@@ -360,4 +358,4 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\" ...@@ -360,4 +358,4 @@ copy "$(OutDir)libGLESv2.lib" "$(ProjectDir)..\..\lib\$(Configuration)\"
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>
\ No newline at end of file
...@@ -119,9 +119,6 @@ ...@@ -119,9 +119,6 @@
<ClCompile Include="renderer\VertexDeclarationCache.cpp"> <ClCompile Include="renderer\VertexDeclarationCache.cpp">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="renderer\D3DConstantTable.cpp">
<Filter>Renderer</Filter>
</ClCompile>
<ClCompile Include="renderer\IndexDataManager.cpp"> <ClCompile Include="renderer\IndexDataManager.cpp">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClCompile> </ClCompile>
...@@ -169,7 +166,7 @@ ...@@ -169,7 +166,7 @@
</ClCompile> </ClCompile>
<ClCompile Include="Uniform.cpp"> <ClCompile Include="Uniform.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="renderer\TextureStorage9.cpp"> <ClCompile Include="renderer\TextureStorage9.cpp">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClCompile> </ClCompile>
...@@ -301,9 +298,6 @@ ...@@ -301,9 +298,6 @@
<ClInclude Include="renderer\VertexDataManager.h"> <ClInclude Include="renderer\VertexDataManager.h">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="renderer\D3DConstantTable.h">
<Filter>Renderer</Filter>
</ClInclude>
<ClInclude Include="renderer\IndexDataManager.h"> <ClInclude Include="renderer\IndexDataManager.h">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClInclude> </ClInclude>
...@@ -351,7 +345,7 @@ ...@@ -351,7 +345,7 @@
</ClInclude> </ClInclude>
<ClInclude Include="Uniform.h"> <ClInclude Include="Uniform.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="renderer\TextureStorage9.h"> <ClInclude Include="renderer\TextureStorage9.h">
<Filter>Renderer</Filter> <Filter>Renderer</Filter>
</ClInclude> </ClInclude>
...@@ -364,4 +358,4 @@ ...@@ -364,4 +358,4 @@
<ItemGroup> <ItemGroup>
<ResourceCompile Include="libGLESv2.rc" /> <ResourceCompile Include="libGLESv2.rc" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
//
// Copyright (c) 2012 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.
//
// D3DConstantTable.cpp: Implements the D3DConstantTable class which parses
// information about constants from the CTAB comment in a D3D shader blob.
// Restructures the constant table as a hierarchy of constants in the same
// way as D3DX.
#include "libGLESv2/renderer/D3DConstantTable.h"
#include <d3d9.h>
#include <d3d9types.h>
#include <windows.h>
#include <mmsystem.h>
#include "libGLESv2/BinaryStream.h"
const static int SHADER_VERSION_MASK = D3DVS_VERSION(0, 0);
const static int FOURCC_CTAB = MAKEFOURCC('C','T','A','B');
namespace rx
{
// These structs and constants correspond to the format of the constant table in a shader binary.
// They match the corresponding structures in d3dx9shader.h.
namespace ctab
{
struct ConstantTable
{
DWORD size;
DWORD creator;
DWORD version;
DWORD constants;
DWORD constantInfos;
DWORD flags;
DWORD target;
};
struct ConstantInfo
{
DWORD name;
WORD registerSet;
WORD registerIndex;
WORD registerCount;
WORD reserved;
DWORD typeInfo;
DWORD defaultValue;
};
struct TypeInfo
{
WORD typeClass;
WORD type;
WORD rows;
WORD columns;
WORD elements;
WORD structMembers;
DWORD structMemberInfos;
};
struct StructMemberInfo
{
DWORD name;
DWORD typeInfo;
};
}
D3DConstant::D3DConstant(const char *base, const ctab::ConstantInfo *constantInfo)
{
const ctab::TypeInfo *typeInfo = reinterpret_cast<const ctab::TypeInfo*>(base + constantInfo->typeInfo);
name = base + constantInfo->name;
registerSet = static_cast<RegisterSet>(constantInfo->registerSet);
registerIndex = constantInfo->registerIndex;
registerCount = constantInfo->registerCount;
typeClass = static_cast<Class>(typeInfo->typeClass);
type = static_cast<Type>(typeInfo->type);
rows = typeInfo->rows;
columns = typeInfo->columns;
elements = typeInfo->elements;
if (typeClass == CLASS_STRUCT)
{
addStructMembers(base, registerSet, registerIndex, registerIndex + registerCount, typeInfo);
}
}
D3DConstant::D3DConstant(const char *base, RegisterSet registerSet, unsigned registerIndex, unsigned maxRegister, const ctab::StructMemberInfo *memberInfo)
: registerSet(registerSet), registerIndex(registerIndex)
{
const ctab::TypeInfo *typeInfo = reinterpret_cast<const ctab::TypeInfo*>(base + memberInfo->typeInfo);
name = base + memberInfo->name;
registerCount = std::min(static_cast<int>(maxRegister - registerIndex), typeInfo->rows * typeInfo->elements);
typeClass = static_cast<Class>(typeInfo->typeClass);
type = static_cast<Type>(typeInfo->type);
rows = typeInfo->rows;
columns = typeInfo->columns;
elements = typeInfo->elements;
if (typeClass == CLASS_STRUCT)
{
registerCount = addStructMembers(base, registerSet, registerIndex, maxRegister, typeInfo);
}
}
D3DConstant::~D3DConstant()
{
for (size_t j = 0; j < structMembers.size(); ++j)
{
for (size_t i = 0; i < structMembers[j].size(); ++i)
{
delete structMembers[j][i];
}
}
}
unsigned D3DConstant::addStructMembers(const char *base, RegisterSet registerSet, unsigned registerIndex, unsigned maxRegister, const ctab::TypeInfo *typeInfo)
{
const ctab::StructMemberInfo *memberInfos = reinterpret_cast<const ctab::StructMemberInfo*>(
base + typeInfo->structMemberInfos);
unsigned memberIndex = registerIndex;
structMembers.resize(elements);
for (unsigned j = 0; j < elements; ++j)
{
structMembers[j].resize(typeInfo->structMembers);
for (unsigned i = 0; i < typeInfo->structMembers; ++i)
{
const ctab::TypeInfo *memberTypeInfo = reinterpret_cast<const ctab::TypeInfo*>(
base + memberInfos[i].typeInfo);
D3DConstant *member = new D3DConstant(base, registerSet, memberIndex, maxRegister, memberInfos + i);
memberIndex += member->registerCount;
structMembers[j][i] = member;
}
}
return memberIndex - registerIndex;
}
D3DConstantTable::D3DConstantTable(void *blob, size_t size) : mError(false)
{
gl::BinaryInputStream stream(blob, size);
int version;
stream.read(&version);
if ((version & SHADER_VERSION_MASK) != SHADER_VERSION_MASK)
{
mError = true;
return;
}
const ctab::ConstantTable* constantTable = NULL;
while (!stream.error())
{
int token;
stream.read(&token);
if ((token & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
{
size_t length = ((token & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT) * sizeof(DWORD);
int fourcc;
stream.read(&fourcc);
if (fourcc == FOURCC_CTAB)
{
constantTable = reinterpret_cast<const ctab::ConstantTable*>(static_cast<const char*>(blob) + stream.offset());
break;
}
stream.skip(length - sizeof(fourcc));
}
else if (token == D3DSIO_END)
{
break;
}
}
mError = !constantTable || stream.error();
if (mError)
{
return;
}
const char *base = reinterpret_cast<const char*>(constantTable);
mConstants.resize(constantTable->constants);
const ctab::ConstantInfo *constantInfos =
reinterpret_cast<const ctab::ConstantInfo*>(base + constantTable->constantInfos);
for (size_t i = 0; i < constantTable->constants; ++i)
{
mConstants[i] = new D3DConstant(base, constantInfos + i);
}
}
D3DConstantTable::~D3DConstantTable()
{
for (size_t i = 0; i < mConstants.size(); ++i)
{
delete mConstants[i];
}
}
const D3DConstant *D3DConstantTable::getConstant(unsigned index) const
{
return mConstants[index];
}
const D3DConstant *D3DConstantTable::getConstantByName(const char *name) const
{
for (size_t i = 0; i < mConstants.size(); ++i)
{
const D3DConstant *constant = getConstant(i);
if (constant->name == name)
{
return constant;
}
}
return NULL;
}
}
//
// Copyright (c) 2012 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.
//
// D3DConstantTable.h: Implements the D3DConstantTable class which parses
// information about constants from the CTAB comment in a D3D shader blob.
// Restructures the constant table as a hierarchy of constants in the same
// way as D3DX.
#ifndef LIBGLESV2_D3DCONSTANTTABLE_H_
#define LIBGLESV2_D3DCONSTANTTABLE_H_
#include <vector>
#include <string>
#include "common/angleutils.h"
namespace rx
{
namespace ctab
{
struct ConstantTable;
struct ConstantInfo;
struct TypeInfo;
struct StructMemberInfo;
}
struct D3DConstant
{
// These enums match those in d3dx9shader.h.
enum Class
{
CLASS_SCALAR,
CLASS_VECTOR,
CLASS_MATRIX_ROWS,
CLASS_MATRIX_COLUMNS,
CLASS_OBJECT,
CLASS_STRUCT,
};
enum RegisterSet
{
RS_BOOL,
RS_INT4,
RS_FLOAT4,
RS_SAMPLER,
};
enum Type
{
PT_VOID,
PT_BOOL,
PT_INT,
PT_FLOAT,
PT_STRING,
PT_TEXTURE,
PT_TEXTURE1D,
PT_TEXTURE2D,
PT_TEXTURE3D,
PT_TEXTURECUBE,
PT_SAMPLER,
PT_SAMPLER1D,
PT_SAMPLER2D,
PT_SAMPLER3D,
PT_SAMPLERCUBE,
PT_PIXELSHADER,
PT_VERTEXSHADER,
PT_PIXELFRAGMENT,
PT_VERTEXFRAGMENT,
PT_UNSUPPORTED,
};
D3DConstant(const char *base, const ctab::ConstantInfo *constantInfo);
~D3DConstant();
std::string name;
RegisterSet registerSet;
unsigned registerIndex;
unsigned registerCount;
Class typeClass;
Type type;
unsigned rows;
unsigned columns;
unsigned elements;
// Array of structure members.
std::vector<std::vector<const D3DConstant*> > structMembers;
private:
D3DConstant(const char *base, RegisterSet registerSet, unsigned registerIndex, unsigned maxRegister, const ctab::StructMemberInfo *memberInfo);
unsigned addStructMembers(const char *base, RegisterSet registerSet, unsigned registerIndex, unsigned maxRegister, const ctab::TypeInfo *typeInfo);
};
class D3DConstantTable
{
public:
D3DConstantTable(void *blob, size_t size);
~D3DConstantTable();
bool error() const { return mError; }
unsigned constants() const { return mConstants.size(); }
const D3DConstant *getConstant(unsigned index) const;
const D3DConstant *getConstantByName(const char *name) const;
private:
DISALLOW_COPY_AND_ASSIGN(D3DConstantTable);
std::vector<const D3DConstant*> mConstants;
bool mError;
};
}
#endif // LIBGLESV2_D3DCONSTANTTABLE_H_
...@@ -167,7 +167,7 @@ class Renderer ...@@ -167,7 +167,7 @@ class Renderer
virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0; virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0;
// Shader operations // Shader operations
virtual ShaderExecutable *loadExecutable(const void *function, size_t length, GLenum type, void *data) = 0; virtual ShaderExecutable *loadExecutable(const void *function, size_t length, GLenum type) = 0;
virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) = 0; virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) = 0;
// Image operations // Image operations
......
...@@ -1347,7 +1347,7 @@ RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum forma ...@@ -1347,7 +1347,7 @@ RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum forma
return NULL; return NULL;
} }
ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, GLenum type, void *data) ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, GLenum type)
{ {
ShaderExecutable11 *executable = NULL; ShaderExecutable11 *executable = NULL;
...@@ -1406,7 +1406,7 @@ ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const ch ...@@ -1406,7 +1406,7 @@ ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const ch
if (!binary) if (!binary)
return NULL; return NULL;
ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type, NULL); ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type);
binary->Release(); binary->Release();
return executable; return executable;
......
...@@ -135,7 +135,7 @@ class Renderer11 : public Renderer ...@@ -135,7 +135,7 @@ class Renderer11 : public Renderer
virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth); virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth);
// Shader operations // Shader operations
virtual ShaderExecutable *loadExecutable(const void *function, size_t length, GLenum type, void *data); virtual ShaderExecutable *loadExecutable(const void *function, size_t length, GLenum type);
virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type); virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type);
// Image operations // Image operations
......
...@@ -2866,10 +2866,9 @@ RenderTarget *Renderer9::createRenderTarget(int width, int height, GLenum format ...@@ -2866,10 +2866,9 @@ RenderTarget *Renderer9::createRenderTarget(int width, int height, GLenum format
return renderTarget; return renderTarget;
} }
ShaderExecutable *Renderer9::loadExecutable(const void *function, size_t length, GLenum type, void *data) ShaderExecutable *Renderer9::loadExecutable(const void *function, size_t length, GLenum type)
{ {
ShaderExecutable9 *executable = NULL; ShaderExecutable9 *executable = NULL;
D3DConstantTable *table = reinterpret_cast<D3DConstantTable *>(data);
switch (type) switch (type)
{ {
...@@ -2878,7 +2877,7 @@ ShaderExecutable *Renderer9::loadExecutable(const void *function, size_t length, ...@@ -2878,7 +2877,7 @@ ShaderExecutable *Renderer9::loadExecutable(const void *function, size_t length,
IDirect3DVertexShader9 *vshader = createVertexShader((DWORD*)function, length); IDirect3DVertexShader9 *vshader = createVertexShader((DWORD*)function, length);
if (vshader) if (vshader)
{ {
executable = new ShaderExecutable9(function, length, vshader, table); executable = new ShaderExecutable9(function, length, vshader);
} }
} }
break; break;
...@@ -2887,7 +2886,7 @@ ShaderExecutable *Renderer9::loadExecutable(const void *function, size_t length, ...@@ -2887,7 +2886,7 @@ ShaderExecutable *Renderer9::loadExecutable(const void *function, size_t length,
IDirect3DPixelShader9 *pshader = createPixelShader((DWORD*)function, length); IDirect3DPixelShader9 *pshader = createPixelShader((DWORD*)function, length);
if (pshader) if (pshader)
{ {
executable = new ShaderExecutable9(function, length, pshader, table); executable = new ShaderExecutable9(function, length, pshader);
} }
} }
break; break;
...@@ -2920,15 +2919,7 @@ ShaderExecutable *Renderer9::compileToExecutable(gl::InfoLog &infoLog, const cha ...@@ -2920,15 +2919,7 @@ ShaderExecutable *Renderer9::compileToExecutable(gl::InfoLog &infoLog, const cha
if (!binary) if (!binary)
return NULL; return NULL;
D3DConstantTable *constantTable = new D3DConstantTable(binary->GetBufferPointer(), binary->GetBufferSize()); ShaderExecutable *executable = loadExecutable(binary->GetBufferPointer(), binary->GetBufferSize(), type);
if (constantTable->error())
{
delete constantTable;
binary->Release();
return NULL;
}
ShaderExecutable *executable = loadExecutable(binary->GetBufferPointer(), binary->GetBufferSize(), type, constantTable);
binary->Release(); binary->Release();
return executable; return executable;
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
namespace rx namespace rx
{ {
class D3DConstantTable;
class VertexDataManager; class VertexDataManager;
class StreamingIndexBufferInterface; class StreamingIndexBufferInterface;
struct TranslatedAttribute; struct TranslatedAttribute;
...@@ -165,7 +164,7 @@ class Renderer9 : public Renderer ...@@ -165,7 +164,7 @@ class Renderer9 : public Renderer
virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth); virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth);
// Shader operations // Shader operations
virtual ShaderExecutable *loadExecutable(const void *function, size_t length, GLenum type, void *data); virtual ShaderExecutable *loadExecutable(const void *function, size_t length, GLenum type);
virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type); virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type);
// Image operations // Image operations
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#define LIBGLESV2_RENDERER_SHADEREXECUTABLE_H_ #define LIBGLESV2_RENDERER_SHADEREXECUTABLE_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libGLESv2/renderer/D3DConstantTable.h"
namespace rx namespace rx
{ {
...@@ -40,8 +39,6 @@ class ShaderExecutable ...@@ -40,8 +39,6 @@ class ShaderExecutable
return mLength; return mLength;
} }
virtual D3DConstantTable *getConstantTable() = 0; // D3D9_REMOVE
private: private:
DISALLOW_COPY_AND_ASSIGN(ShaderExecutable); DISALLOW_COPY_AND_ASSIGN(ShaderExecutable);
......
...@@ -56,9 +56,4 @@ ID3D11PixelShader *ShaderExecutable11::getPixelShader() ...@@ -56,9 +56,4 @@ ID3D11PixelShader *ShaderExecutable11::getPixelShader()
return mPixelExecutable; return mPixelExecutable;
} }
D3DConstantTable *ShaderExecutable11::getConstantTable()
{
return NULL;
}
} }
\ No newline at end of file
...@@ -29,7 +29,6 @@ class ShaderExecutable11 : public ShaderExecutable ...@@ -29,7 +29,6 @@ class ShaderExecutable11 : public ShaderExecutable
ID3D11PixelShader *getPixelShader(); ID3D11PixelShader *getPixelShader();
ID3D11VertexShader *getVertexShader(); ID3D11VertexShader *getVertexShader();
virtual D3DConstantTable *getConstantTable();
private: private:
DISALLOW_COPY_AND_ASSIGN(ShaderExecutable11); DISALLOW_COPY_AND_ASSIGN(ShaderExecutable11);
......
...@@ -14,20 +14,18 @@ ...@@ -14,20 +14,18 @@
namespace rx namespace rx
{ {
ShaderExecutable9::ShaderExecutable9(const void *function, size_t length, IDirect3DPixelShader9 *executable, D3DConstantTable *constantTable) ShaderExecutable9::ShaderExecutable9(const void *function, size_t length, IDirect3DPixelShader9 *executable)
: ShaderExecutable(function, length) : ShaderExecutable(function, length)
{ {
mPixelExecutable = executable; mPixelExecutable = executable;
mVertexExecutable = NULL; mVertexExecutable = NULL;
mConstantTable = constantTable;
} }
ShaderExecutable9::ShaderExecutable9(const void *function, size_t length, IDirect3DVertexShader9 *executable, D3DConstantTable *constantTable) ShaderExecutable9::ShaderExecutable9(const void *function, size_t length, IDirect3DVertexShader9 *executable)
: ShaderExecutable(function, length) : ShaderExecutable(function, length)
{ {
mVertexExecutable = executable; mVertexExecutable = executable;
mPixelExecutable = NULL; mPixelExecutable = NULL;
mConstantTable = constantTable;
} }
ShaderExecutable9::~ShaderExecutable9() ShaderExecutable9::~ShaderExecutable9()
...@@ -40,8 +38,6 @@ ShaderExecutable9::~ShaderExecutable9() ...@@ -40,8 +38,6 @@ ShaderExecutable9::~ShaderExecutable9()
{ {
mPixelExecutable->Release(); mPixelExecutable->Release();
} }
delete mConstantTable;
} }
ShaderExecutable9 *ShaderExecutable9::makeShaderExecutable9(ShaderExecutable *executable) ShaderExecutable9 *ShaderExecutable9::makeShaderExecutable9(ShaderExecutable *executable)
...@@ -60,9 +56,4 @@ IDirect3DPixelShader9 *ShaderExecutable9::getPixelShader() ...@@ -60,9 +56,4 @@ IDirect3DPixelShader9 *ShaderExecutable9::getPixelShader()
return mPixelExecutable; return mPixelExecutable;
} }
D3DConstantTable *ShaderExecutable9::getConstantTable()
{
return mConstantTable;
}
} }
\ No newline at end of file
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <d3d9.h> #include <d3d9.h>
#include "libGLESv2/renderer/ShaderExecutable.h" #include "libGLESv2/renderer/ShaderExecutable.h"
#include "libGLESv2/renderer/D3DConstantTable.h"
namespace rx namespace rx
{ {
...@@ -21,23 +20,20 @@ namespace rx ...@@ -21,23 +20,20 @@ namespace rx
class ShaderExecutable9 : public ShaderExecutable class ShaderExecutable9 : public ShaderExecutable
{ {
public: public:
ShaderExecutable9(const void *function, size_t length, IDirect3DPixelShader9 *executable, D3DConstantTable *constantTable); ShaderExecutable9(const void *function, size_t length, IDirect3DPixelShader9 *executable);
ShaderExecutable9(const void *function, size_t length, IDirect3DVertexShader9 *executable, D3DConstantTable *constantTable); ShaderExecutable9(const void *function, size_t length, IDirect3DVertexShader9 *executable);
virtual ~ShaderExecutable9(); virtual ~ShaderExecutable9();
static ShaderExecutable9 *makeShaderExecutable9(ShaderExecutable *executable); static ShaderExecutable9 *makeShaderExecutable9(ShaderExecutable *executable);
IDirect3DPixelShader9 *getPixelShader(); IDirect3DPixelShader9 *getPixelShader();
IDirect3DVertexShader9 *getVertexShader(); IDirect3DVertexShader9 *getVertexShader();
virtual D3DConstantTable *getConstantTable();
private: private:
DISALLOW_COPY_AND_ASSIGN(ShaderExecutable9); DISALLOW_COPY_AND_ASSIGN(ShaderExecutable9);
IDirect3DPixelShader9 *mPixelExecutable; IDirect3DPixelShader9 *mPixelExecutable;
IDirect3DVertexShader9 *mVertexExecutable; IDirect3DVertexShader9 *mVertexExecutable;
D3DConstantTable *mConstantTable;
}; };
} }
......
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