Commit 60dafe8f by apatrick@chromium.org

Implement D3DConstantTable.

Remove ProgramBinary dependencies on D3DX. Review URL: https://codereview.appspot.com/6485061 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1271 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent aa48067a
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1270 #define BUILD_REVISION 1271
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -80,6 +80,17 @@ class BinaryInputStream ...@@ -80,6 +80,17 @@ class BinaryInputStream
mOffset += length; mOffset += length;
} }
void skip(size_t length)
{
if (mOffset + length > mLength)
{
mError = true;
return;
}
mOffset += length;
}
size_t offset() const size_t offset() const
{ {
return mOffset; return mOffset;
......
//
// 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/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 gl
{
// 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, typeInfo);
}
}
D3DConstant::D3DConstant(const char *base, RegisterSet registerSet, unsigned registerIndex, 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 = 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, 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, 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, memberInfos + i);
memberIndex += member->registerCount;
structMembers[j][i] = member;
}
}
return memberIndex - registerIndex;
}
D3DConstantTable::D3DConstantTable(void *blob, size_t size) : mError(false)
{
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 "common/angleutils.h"
namespace gl
{
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, const ctab::StructMemberInfo *memberInfo);
unsigned addStructMembers(const char *base, RegisterSet registerSet, unsigned registerIndex, 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_
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#ifndef LIBGLESV2_PROGRAM_H_ #ifndef LIBGLESV2_PROGRAM_H_
#define LIBGLESV2_PROGRAM_H_ #define LIBGLESV2_PROGRAM_H_
#include <d3dx9.h>
#include <string> #include <string>
#include <set> #include <set>
......
...@@ -108,15 +108,8 @@ ProgramBinary::~ProgramBinary() ...@@ -108,15 +108,8 @@ ProgramBinary::~ProgramBinary()
mVertexExecutable->Release(); mVertexExecutable->Release();
} }
if (mConstantTablePS) delete mConstantTablePS;
{ delete mConstantTableVS;
mConstantTablePS->Release();
}
if (mConstantTableVS)
{
mConstantTableVS->Release();
}
while (!mUniforms.empty()) while (!mUniforms.empty())
{ {
...@@ -1036,7 +1029,7 @@ void ProgramBinary::applyUniforms() ...@@ -1036,7 +1029,7 @@ void ProgramBinary::applyUniforms()
} }
// Compiles the HLSL code of the attached shaders into executable binaries // Compiles the HLSL code of the attached shaders into executable binaries
ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, const char *profile, ID3DXConstantTable **constantTable) ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, const char *profile, D3DConstantTable **constantTable)
{ {
if (!hlsl) if (!hlsl)
{ {
...@@ -1090,21 +1083,17 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c ...@@ -1090,21 +1083,17 @@ ID3D10Blob *ProgramBinary::compileToBinary(InfoLog &infoLog, const char *hlsl, c
return NULL; return NULL;
} }
result = D3DXGetShaderConstantTable(static_cast<const DWORD*>(binary->GetBufferPointer()), constantTable); D3DConstantTable *table = new D3DConstantTable(binary->GetBufferPointer(), binary->GetBufferSize());
if (table->error())
if (FAILED(result))
{ {
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) delete table;
{
error(GL_OUT_OF_MEMORY);
}
binary->Release(); binary->Release();
return NULL; return NULL;
} }
*constantTable = table;
return binary; return binary;
} }
...@@ -2030,22 +2019,13 @@ bool ProgramBinary::linkAttributes(InfoLog &infoLog, const AttributeBindings &at ...@@ -2030,22 +2019,13 @@ bool ProgramBinary::linkAttributes(InfoLog &infoLog, const AttributeBindings &at
return true; return true;
} }
bool ProgramBinary::linkUniforms(InfoLog &infoLog, GLenum shader, ID3DXConstantTable *constantTable) bool ProgramBinary::linkUniforms(InfoLog &infoLog, GLenum shader, D3DConstantTable *constantTable)
{ {
D3DXCONSTANTTABLE_DESC constantTableDescription; for (unsigned int constantIndex = 0; constantIndex < constantTable->constants(); constantIndex++)
constantTable->GetDesc(&constantTableDescription);
for (unsigned int constantIndex = 0; constantIndex < constantTableDescription.Constants; constantIndex++)
{ {
D3DXHANDLE constantHandle = constantTable->GetConstant(0, constantIndex); const D3DConstant *constant = constantTable->getConstant(constantIndex);
D3DXCONSTANT_DESC constantDescription; if (!defineUniform(infoLog, shader, constant))
UINT descriptionCount = 1;
HRESULT result = constantTable->GetConstantDesc(constantHandle, &constantDescription, &descriptionCount);
ASSERT(SUCCEEDED(result));
if (!defineUniform(infoLog, shader, constantHandle, constantDescription))
{ {
return false; return false;
} }
...@@ -2056,23 +2036,23 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, GLenum shader, ID3DXConstantT ...@@ -2056,23 +2036,23 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, GLenum shader, ID3DXConstantT
// Adds the description of a constant found in the binary shader to the list of uniforms // Adds the description of a constant found in the binary shader to the list of uniforms
// Returns true if succesful (uniform not already defined) // Returns true if succesful (uniform not already defined)
bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name) bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DConstant *constant, std::string name)
{ {
if (constantDescription.RegisterSet == D3DXRS_SAMPLER) if (constant->registerSet == D3DConstant::RS_SAMPLER)
{ {
for (unsigned int i = 0; i < constantDescription.RegisterCount; i++) for (unsigned int i = 0; i < constant->registerCount; i++)
{ {
D3DXHANDLE psConstant = mConstantTablePS->GetConstantByName(NULL, constantDescription.Name); const D3DConstant *psConstant = mConstantTablePS->getConstantByName(constant->name.c_str());
D3DXHANDLE vsConstant = mConstantTableVS->GetConstantByName(NULL, constantDescription.Name); const D3DConstant *vsConstant = mConstantTableVS->getConstantByName(constant->name.c_str());
if (psConstant) if (psConstant)
{ {
unsigned int samplerIndex = mConstantTablePS->GetSamplerIndex(psConstant) + i; unsigned int samplerIndex = psConstant->registerIndex + i;
if (samplerIndex < MAX_TEXTURE_IMAGE_UNITS) if (samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
{ {
mSamplersPS[samplerIndex].active = true; mSamplersPS[samplerIndex].active = true;
mSamplersPS[samplerIndex].textureType = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D; mSamplersPS[samplerIndex].textureType = (constant->type == D3DConstant::PT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D;
mSamplersPS[samplerIndex].logicalTextureUnit = 0; mSamplersPS[samplerIndex].logicalTextureUnit = 0;
mUsedPixelSamplerRange = std::max(samplerIndex + 1, mUsedPixelSamplerRange); mUsedPixelSamplerRange = std::max(samplerIndex + 1, mUsedPixelSamplerRange);
} }
...@@ -2085,12 +2065,12 @@ bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHAN ...@@ -2085,12 +2065,12 @@ bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHAN
if (vsConstant) if (vsConstant)
{ {
unsigned int samplerIndex = mConstantTableVS->GetSamplerIndex(vsConstant) + i; unsigned int samplerIndex = vsConstant->registerIndex + i;
if (samplerIndex < getContext()->getMaximumVertexTextureImageUnits()) if (samplerIndex < getContext()->getMaximumVertexTextureImageUnits())
{ {
mSamplersVS[samplerIndex].active = true; mSamplersVS[samplerIndex].active = true;
mSamplersVS[samplerIndex].textureType = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D; mSamplersVS[samplerIndex].textureType = (constant->type == D3DConstant::PT_SAMPLERCUBE) ? TEXTURE_CUBE : TEXTURE_2D;
mSamplersVS[samplerIndex].logicalTextureUnit = 0; mSamplersVS[samplerIndex].logicalTextureUnit = 0;
mUsedVertexSamplerRange = std::max(samplerIndex + 1, mUsedVertexSamplerRange); mUsedVertexSamplerRange = std::max(samplerIndex + 1, mUsedVertexSamplerRange);
} }
...@@ -2103,27 +2083,19 @@ bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHAN ...@@ -2103,27 +2083,19 @@ bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHAN
} }
} }
switch(constantDescription.Class) switch(constant->typeClass)
{ {
case D3DXPC_STRUCT: case D3DConstant::CLASS_STRUCT:
{ {
for (unsigned int arrayIndex = 0; arrayIndex < constantDescription.Elements; arrayIndex++) for (unsigned int arrayIndex = 0; arrayIndex < constant->elements; arrayIndex++)
{ {
D3DXHANDLE elementHandle = mConstantTablePS->GetConstantElement(constantHandle, arrayIndex); for (unsigned int field = 0; field < constant->structMembers[arrayIndex].size(); field++)
for (unsigned int field = 0; field < constantDescription.StructMembers; field++)
{ {
D3DXHANDLE fieldHandle = mConstantTablePS->GetConstant(elementHandle, field); const D3DConstant *fieldConstant = constant->structMembers[arrayIndex][field];
D3DXCONSTANT_DESC fieldDescription;
UINT descriptionCount = 1;
HRESULT result = mConstantTablePS->GetConstantDesc(fieldHandle, &fieldDescription, &descriptionCount);
ASSERT(SUCCEEDED(result));
std::string structIndex = (constantDescription.Elements > 1) ? ("[" + str(arrayIndex) + "]") : ""; std::string structIndex = (fieldConstant->elements > 1) ? ("[" + str(arrayIndex) + "]") : "";
if (!defineUniform(infoLog, shader, fieldHandle, fieldDescription, name + constantDescription.Name + structIndex + ".")) if (!defineUniform(infoLog, shader, fieldConstant, name + constant->name + structIndex + "."))
{ {
return false; return false;
} }
...@@ -2132,20 +2104,20 @@ bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHAN ...@@ -2132,20 +2104,20 @@ bool ProgramBinary::defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHAN
return true; return true;
} }
case D3DXPC_SCALAR: case D3DConstant::CLASS_SCALAR:
case D3DXPC_VECTOR: case D3DConstant::CLASS_VECTOR:
case D3DXPC_MATRIX_COLUMNS: case D3DConstant::CLASS_MATRIX_COLUMNS:
case D3DXPC_OBJECT: case D3DConstant::CLASS_OBJECT:
return defineUniform(shader, constantDescription, name + constantDescription.Name); return defineUniform(shader, constant, name + constant->name);
default: default:
UNREACHABLE(); UNREACHABLE();
return false; return false;
} }
} }
bool ProgramBinary::defineUniform(GLenum shader, const D3DXCONSTANT_DESC &constantDescription, const std::string &_name) bool ProgramBinary::defineUniform(GLenum shader, const D3DConstant *constant, const std::string &_name)
{ {
Uniform *uniform = createUniform(constantDescription, _name); Uniform *uniform = createUniform(constant, _name);
if(!uniform) if(!uniform)
{ {
...@@ -2162,8 +2134,8 @@ bool ProgramBinary::defineUniform(GLenum shader, const D3DXCONSTANT_DESC &consta ...@@ -2162,8 +2134,8 @@ bool ProgramBinary::defineUniform(GLenum shader, const D3DXCONSTANT_DESC &consta
uniform = mUniforms[mUniformIndex[location].index]; uniform = mUniforms[mUniformIndex[location].index];
} }
if (shader == GL_FRAGMENT_SHADER) uniform->ps.set(constantDescription); if (shader == GL_FRAGMENT_SHADER) uniform->ps.set(constant);
if (shader == GL_VERTEX_SHADER) uniform->vs.set(constantDescription); if (shader == GL_VERTEX_SHADER) uniform->vs.set(constant);
if (location >= 0) if (location >= 0)
{ {
...@@ -2181,53 +2153,53 @@ bool ProgramBinary::defineUniform(GLenum shader, const D3DXCONSTANT_DESC &consta ...@@ -2181,53 +2153,53 @@ bool ProgramBinary::defineUniform(GLenum shader, const D3DXCONSTANT_DESC &consta
return true; return true;
} }
Uniform *ProgramBinary::createUniform(const D3DXCONSTANT_DESC &constantDescription, const std::string &_name) Uniform *ProgramBinary::createUniform(const D3DConstant *constant, const std::string &_name)
{ {
if (constantDescription.Rows == 1) // Vectors and scalars if (constant->rows == 1) // Vectors and scalars
{ {
switch (constantDescription.Type) switch (constant->type)
{ {
case D3DXPT_SAMPLER2D: case D3DConstant::PT_SAMPLER2D:
switch (constantDescription.Columns) switch (constant->columns)
{ {
case 1: return new Uniform(GL_SAMPLER_2D, _name, constantDescription.Elements); case 1: return new Uniform(GL_SAMPLER_2D, _name, constant->elements);
default: UNREACHABLE(); default: UNREACHABLE();
} }
break; break;
case D3DXPT_SAMPLERCUBE: case D3DConstant::PT_SAMPLERCUBE:
switch (constantDescription.Columns) switch (constant->columns)
{ {
case 1: return new Uniform(GL_SAMPLER_CUBE, _name, constantDescription.Elements); case 1: return new Uniform(GL_SAMPLER_CUBE, _name, constant->elements);
default: UNREACHABLE(); default: UNREACHABLE();
} }
break; break;
case D3DXPT_BOOL: case D3DConstant::PT_BOOL:
switch (constantDescription.Columns) switch (constant->columns)
{ {
case 1: return new Uniform(GL_BOOL, _name, constantDescription.Elements); case 1: return new Uniform(GL_BOOL, _name, constant->elements);
case 2: return new Uniform(GL_BOOL_VEC2, _name, constantDescription.Elements); case 2: return new Uniform(GL_BOOL_VEC2, _name, constant->elements);
case 3: return new Uniform(GL_BOOL_VEC3, _name, constantDescription.Elements); case 3: return new Uniform(GL_BOOL_VEC3, _name, constant->elements);
case 4: return new Uniform(GL_BOOL_VEC4, _name, constantDescription.Elements); case 4: return new Uniform(GL_BOOL_VEC4, _name, constant->elements);
default: UNREACHABLE(); default: UNREACHABLE();
} }
break; break;
case D3DXPT_INT: case D3DConstant::PT_INT:
switch (constantDescription.Columns) switch (constant->columns)
{ {
case 1: return new Uniform(GL_INT, _name, constantDescription.Elements); case 1: return new Uniform(GL_INT, _name, constant->elements);
case 2: return new Uniform(GL_INT_VEC2, _name, constantDescription.Elements); case 2: return new Uniform(GL_INT_VEC2, _name, constant->elements);
case 3: return new Uniform(GL_INT_VEC3, _name, constantDescription.Elements); case 3: return new Uniform(GL_INT_VEC3, _name, constant->elements);
case 4: return new Uniform(GL_INT_VEC4, _name, constantDescription.Elements); case 4: return new Uniform(GL_INT_VEC4, _name, constant->elements);
default: UNREACHABLE(); default: UNREACHABLE();
} }
break; break;
case D3DXPT_FLOAT: case D3DConstant::PT_FLOAT:
switch (constantDescription.Columns) switch (constant->columns)
{ {
case 1: return new Uniform(GL_FLOAT, _name, constantDescription.Elements); case 1: return new Uniform(GL_FLOAT, _name, constant->elements);
case 2: return new Uniform(GL_FLOAT_VEC2, _name, constantDescription.Elements); case 2: return new Uniform(GL_FLOAT_VEC2, _name, constant->elements);
case 3: return new Uniform(GL_FLOAT_VEC3, _name, constantDescription.Elements); case 3: return new Uniform(GL_FLOAT_VEC3, _name, constant->elements);
case 4: return new Uniform(GL_FLOAT_VEC4, _name, constantDescription.Elements); case 4: return new Uniform(GL_FLOAT_VEC4, _name, constant->elements);
default: UNREACHABLE(); default: UNREACHABLE();
} }
break; break;
...@@ -2235,16 +2207,16 @@ Uniform *ProgramBinary::createUniform(const D3DXCONSTANT_DESC &constantDescripti ...@@ -2235,16 +2207,16 @@ Uniform *ProgramBinary::createUniform(const D3DXCONSTANT_DESC &constantDescripti
UNREACHABLE(); UNREACHABLE();
} }
} }
else if (constantDescription.Rows == constantDescription.Columns) // Square matrices else if (constant->rows == constant->columns) // Square matrices
{ {
switch (constantDescription.Type) switch (constant->type)
{ {
case D3DXPT_FLOAT: case D3DConstant::PT_FLOAT:
switch (constantDescription.Rows) switch (constant->rows)
{ {
case 2: return new Uniform(GL_FLOAT_MAT2, _name, constantDescription.Elements); case 2: return new Uniform(GL_FLOAT_MAT2, _name, constant->elements);
case 3: return new Uniform(GL_FLOAT_MAT3, _name, constantDescription.Elements); case 3: return new Uniform(GL_FLOAT_MAT3, _name, constant->elements);
case 4: return new Uniform(GL_FLOAT_MAT4, _name, constantDescription.Elements); case 4: return new Uniform(GL_FLOAT_MAT4, _name, constant->elements);
default: UNREACHABLE(); default: UNREACHABLE();
} }
break; break;
...@@ -2366,11 +2338,11 @@ bool ProgramBinary::applyUniformnfv(Uniform *targetUniform, const GLfloat *v) ...@@ -2366,11 +2338,11 @@ bool ProgramBinary::applyUniformnfv(Uniform *targetUniform, const GLfloat *v)
bool ProgramBinary::applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v) bool ProgramBinary::applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{ {
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS); ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS]; Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
vector[i] = D3DXVECTOR4((float)v[i], 0, 0, 0); vector[i] = Vector4((float)v[i], 0, 0, 0);
} }
if (targetUniform->ps.registerCount) if (targetUniform->ps.registerCount)
...@@ -2427,11 +2399,11 @@ bool ProgramBinary::applyUniform1iv(Uniform *targetUniform, GLsizei count, const ...@@ -2427,11 +2399,11 @@ bool ProgramBinary::applyUniform1iv(Uniform *targetUniform, GLsizei count, const
bool ProgramBinary::applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v) bool ProgramBinary::applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{ {
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS); ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS]; Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
vector[i] = D3DXVECTOR4((float)v[0], (float)v[1], 0, 0); vector[i] = Vector4((float)v[0], (float)v[1], 0, 0);
v += 2; v += 2;
} }
...@@ -2444,11 +2416,11 @@ bool ProgramBinary::applyUniform2iv(Uniform *targetUniform, GLsizei count, const ...@@ -2444,11 +2416,11 @@ bool ProgramBinary::applyUniform2iv(Uniform *targetUniform, GLsizei count, const
bool ProgramBinary::applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v) bool ProgramBinary::applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{ {
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS); ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS]; Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
vector[i] = D3DXVECTOR4((float)v[0], (float)v[1], (float)v[2], 0); vector[i] = Vector4((float)v[0], (float)v[1], (float)v[2], 0);
v += 3; v += 3;
} }
...@@ -2461,11 +2433,11 @@ bool ProgramBinary::applyUniform3iv(Uniform *targetUniform, GLsizei count, const ...@@ -2461,11 +2433,11 @@ bool ProgramBinary::applyUniform3iv(Uniform *targetUniform, GLsizei count, const
bool ProgramBinary::applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v) bool ProgramBinary::applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v)
{ {
ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS); ASSERT(count <= D3D9_MAX_FLOAT_CONSTANTS);
D3DXVECTOR4 vector[D3D9_MAX_FLOAT_CONSTANTS]; Vector4 vector[D3D9_MAX_FLOAT_CONSTANTS];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
vector[i] = D3DXVECTOR4((float)v[0], (float)v[1], (float)v[2], (float)v[3]); vector[i] = Vector4((float)v[0], (float)v[1], (float)v[2], (float)v[3]);
v += 4; v += 4;
} }
...@@ -2475,7 +2447,7 @@ bool ProgramBinary::applyUniform4iv(Uniform *targetUniform, GLsizei count, const ...@@ -2475,7 +2447,7 @@ bool ProgramBinary::applyUniform4iv(Uniform *targetUniform, GLsizei count, const
return true; return true;
} }
void ProgramBinary::applyUniformniv(Uniform *targetUniform, GLsizei count, const D3DXVECTOR4 *vector) void ProgramBinary::applyUniformniv(Uniform *targetUniform, GLsizei count, const Vector4 *vector)
{ {
if (targetUniform->ps.registerCount) if (targetUniform->ps.registerCount)
{ {
......
...@@ -14,13 +14,14 @@ ...@@ -14,13 +14,14 @@
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include <d3dx9.h>
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include "libGLESv2/Shader.h"
#include "libGLESv2/Context.h" #include "libGLESv2/Context.h"
#include "libGLESv2/D3DConstantTable.h"
#include "libGLESv2/mathutil.h"
#include "libGLESv2/Shader.h"
namespace gl namespace gl
{ {
...@@ -54,18 +55,18 @@ struct Uniform ...@@ -54,18 +55,18 @@ struct Uniform
registerCount = 0; registerCount = 0;
} }
void set(const D3DXCONSTANT_DESC &constantDescription) void set(const D3DConstant *constant)
{ {
switch(constantDescription.RegisterSet) switch(constant->registerSet)
{ {
case D3DXRS_BOOL: boolIndex = constantDescription.RegisterIndex; break; case D3DConstant::RS_BOOL: boolIndex = constant->registerIndex; break;
case D3DXRS_FLOAT4: float4Index = constantDescription.RegisterIndex; break; case D3DConstant::RS_FLOAT4: float4Index = constant->registerIndex; break;
case D3DXRS_SAMPLER: samplerIndex = constantDescription.RegisterIndex; break; case D3DConstant::RS_SAMPLER: samplerIndex = constant->registerIndex; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
ASSERT(registerCount == 0 || registerCount == (int)constantDescription.RegisterCount); ASSERT(registerCount == 0 || registerCount == (int)constant->registerCount);
registerCount = constantDescription.RegisterCount; registerCount = constant->registerCount;
} }
int float4Index; int float4Index;
...@@ -163,23 +164,23 @@ class ProgramBinary : public RefCountObject ...@@ -163,23 +164,23 @@ class ProgramBinary : public RefCountObject
private: private:
DISALLOW_COPY_AND_ASSIGN(ProgramBinary); DISALLOW_COPY_AND_ASSIGN(ProgramBinary);
ID3D10Blob *compileToBinary(InfoLog &infoLog, const char *hlsl, const char *profile, ID3DXConstantTable **constantTable); ID3D10Blob *compileToBinary(InfoLog &infoLog, const char *hlsl, const char *profile, D3DConstantTable **constantTable);
int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader); int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader);
bool linkVaryings(InfoLog &infoLog, std::string& pixelHLSL, std::string& vertexHLSL, FragmentShader *fragmentShader, VertexShader *vertexShader); bool linkVaryings(InfoLog &infoLog, std::string& pixelHLSL, std::string& vertexHLSL, FragmentShader *fragmentShader, VertexShader *vertexShader);
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, GLenum shader, ID3DXConstantTable *constantTable); bool linkUniforms(InfoLog &infoLog, GLenum shader, D3DConstantTable *constantTable);
bool defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = ""); bool defineUniform(InfoLog &infoLog, GLenum shader, const D3DConstant *constant, std::string name = "");
bool defineUniform(GLenum shader, const D3DXCONSTANT_DESC &constantDescription, const std::string &name); bool defineUniform(GLenum shader, const D3DConstant *constant, const std::string &name);
Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, const std::string &name); Uniform *createUniform( const D3DConstant *constant, const std::string &name);
bool applyUniformnfv(Uniform *targetUniform, const GLfloat *v); bool applyUniformnfv(Uniform *targetUniform, const GLfloat *v);
bool applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform1iv(Uniform *targetUniform, GLsizei count, const GLint *v);
bool applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform2iv(Uniform *targetUniform, GLsizei count, const GLint *v);
bool applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform3iv(Uniform *targetUniform, GLsizei count, const GLint *v);
bool applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v); bool applyUniform4iv(Uniform *targetUniform, GLsizei count, const GLint *v);
void applyUniformniv(Uniform *targetUniform, GLsizei count, const D3DXVECTOR4 *vector); void applyUniformniv(Uniform *targetUniform, GLsizei count, const Vector4 *vector);
void applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v); void applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v);
IDirect3DDevice9 *mDevice; IDirect3DDevice9 *mDevice;
...@@ -188,8 +189,8 @@ class ProgramBinary : public RefCountObject ...@@ -188,8 +189,8 @@ class ProgramBinary : public RefCountObject
IDirect3DVertexShader9 *mVertexExecutable; IDirect3DVertexShader9 *mVertexExecutable;
// These are only used during linking. // These are only used during linking.
ID3DXConstantTable *mConstantTablePS; D3DConstantTable *mConstantTablePS;
ID3DXConstantTable *mConstantTableVS; D3DConstantTable *mConstantTableVS;
Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS];
int mSemanticIndex[MAX_VERTEX_ATTRIBS]; int mSemanticIndex[MAX_VERTEX_ATTRIBS];
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#define GL_APICALL #define GL_APICALL
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <d3dx9.h>
#include <string> #include <string>
#include <list> #include <list>
#include <vector> #include <vector>
......
...@@ -373,6 +373,10 @@ ...@@ -373,6 +373,10 @@
> >
</File> </File>
<File <File
RelativePath=".\D3DConstantTable.cpp"
>
</File>
<File
RelativePath=".\Fence.cpp" RelativePath=".\Fence.cpp"
> >
</File> </File>
...@@ -467,6 +471,10 @@ ...@@ -467,6 +471,10 @@
> >
</File> </File>
<File <File
RelativePath=".\D3DConstantTable.h"
>
</File>
<File
RelativePath=".\Fence.h" RelativePath=".\Fence.h"
> >
</File> </File>
......
...@@ -15,6 +15,17 @@ ...@@ -15,6 +15,17 @@
namespace gl namespace gl
{ {
struct Vector4
{
Vector4() {}
Vector4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
float x;
float y;
float z;
float w;
};
inline bool isPow2(int x) inline bool isPow2(int x)
{ {
return (x & (x - 1)) == 0 && (x != 0); return (x & (x - 1)) == 0 && (x != 0);
......
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