Commit 11c3b30f by Geoff Lang

Revert "Fix binary serialization to use explicit size and type."

This reverts commit 26198851. Change-Id: I959ca14fcbb257f12005f7f0b64a600e906a118c Reviewed-on: https://chromium-review.googlesource.com/199630Tested-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent c8f7232e
#include "commit.h" #include "commit.h"
#define ANGLE_MAJOR_VERSION 2 #define ANGLE_MAJOR_VERSION 1
#define ANGLE_MINOR_VERSION 1 #define ANGLE_MINOR_VERSION 3
#define ANGLE_STRINGIFY(x) #x #define ANGLE_STRINGIFY(x) #x
#define ANGLE_MACRO_STRINGIFY(x) ANGLE_STRINGIFY(x) #define ANGLE_MACRO_STRINGIFY(x) ANGLE_STRINGIFY(x)
......
...@@ -25,50 +25,39 @@ class BinaryInputStream ...@@ -25,50 +25,39 @@ class BinaryInputStream
mLength = length; mLength = length;
} }
// readInt will generate an error for bool types template <typename T>
template <class IntT> void read(T *v, size_t num)
IntT readInt()
{ {
int value; union
read(&value);
return static_cast<IntT>(value);
}
template <class IntT>
void readInt(IntT *outValue)
{ {
int value; T dummy; // Compilation error for non-trivial types
read(&value); } dummy;
*outValue = static_cast<IntT>(value); (void) dummy;
}
bool readBool() if (mError)
{ {
int value; return;
read(&value);
return (value > 0);
} }
void readBool(bool *outValue) size_t length = num * sizeof(T);
if (mOffset + length > mLength)
{ {
int value; mError = true;
read(&value); return;
*outValue = (value > 0);
} }
void readBytes(unsigned char outArray[], size_t count) memcpy(v, mData + mOffset, length);
{ mOffset += length;
read<unsigned char>(outArray, count);
} }
std::string readString() template <typename T>
void read(T * v)
{ {
std::string outString; read(v, 1);
readString(&outString);
return outString;
} }
void readString(std::string *v) void read(std::string *v)
{ {
size_t length; size_t length;
read(&length); read(&length);
...@@ -120,39 +109,6 @@ class BinaryInputStream ...@@ -120,39 +109,6 @@ class BinaryInputStream
size_t mOffset; size_t mOffset;
const char *mData; const char *mData;
size_t mLength; size_t mLength;
template <typename T>
void read(T *v, size_t num)
{
union
{
T dummy; // Compilation error for non-POD types
} dummy;
(void)dummy;
if (mError)
{
return;
}
size_t length = num * sizeof(T);
if (mOffset + length > mLength)
{
mError = true;
return;
}
memcpy(v, mData + mOffset, length);
mOffset += length;
}
template <typename T>
void read(T * v)
{
read(v, 1);
}
}; };
class BinaryOutputStream class BinaryOutputStream
...@@ -162,23 +118,31 @@ class BinaryOutputStream ...@@ -162,23 +118,31 @@ class BinaryOutputStream
{ {
} }
// writeInt also handles bool types template <typename T>
template <class IntT> void write(const T *v, size_t num)
void writeInt(IntT v)
{ {
int intValue = static_cast<int>(v); union
write(&v, 1); {
T dummy; // Compilation error for non-trivial types
} dummy;
(void) dummy;
const char *asBytes = reinterpret_cast<const char*>(v);
mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
} }
void writeString(const std::string &v) template <typename T>
void write(const T &v)
{ {
writeInt(v.length()); write(&v, 1);
write(v.c_str(), v.length());
} }
void writeBytes(unsigned char *bytes, size_t count) void write(const std::string &v)
{ {
write(bytes, count); size_t length = v.length();
write(length);
write(v.c_str(), length);
} }
size_t length() const size_t length() const
...@@ -194,20 +158,6 @@ class BinaryOutputStream ...@@ -194,20 +158,6 @@ class BinaryOutputStream
private: private:
DISALLOW_COPY_AND_ASSIGN(BinaryOutputStream); DISALLOW_COPY_AND_ASSIGN(BinaryOutputStream);
std::vector<char> mData; std::vector<char> mData;
template <typename T>
void write(const T *v, size_t num)
{
union
{
T dummy; // Compilation error for non-POD types
} dummy;
(void) dummy;
const char *asBytes = reinterpret_cast<const char*>(v);
mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
}
}; };
} }
......
...@@ -1053,15 +1053,18 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1053,15 +1053,18 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
{ {
BinaryInputStream stream(binary, length); BinaryInputStream stream(binary, length);
int format = stream.readInt<int>(); int format = 0;
stream.read(&format);
if (format != GL_PROGRAM_BINARY_ANGLE) if (format != GL_PROGRAM_BINARY_ANGLE)
{ {
infoLog.append("Invalid program binary format."); infoLog.append("Invalid program binary format.");
return false; return false;
} }
int majorVersion = stream.readInt<int>(); int majorVersion = 0;
int minorVersion = stream.readInt<int>(); int minorVersion = 0;
stream.read(&majorVersion);
stream.read(&minorVersion);
if (majorVersion != ANGLE_MAJOR_VERSION || minorVersion != ANGLE_MINOR_VERSION) if (majorVersion != ANGLE_MAJOR_VERSION || minorVersion != ANGLE_MINOR_VERSION)
{ {
infoLog.append("Invalid program binary version."); infoLog.append("Invalid program binary version.");
...@@ -1069,14 +1072,15 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1069,14 +1072,15 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
} }
unsigned char commitString[ANGLE_COMMIT_HASH_SIZE]; unsigned char commitString[ANGLE_COMMIT_HASH_SIZE];
stream.readBytes(commitString, ANGLE_COMMIT_HASH_SIZE); stream.read(commitString, ANGLE_COMMIT_HASH_SIZE);
if (memcmp(commitString, ANGLE_COMMIT_HASH, sizeof(unsigned char) * ANGLE_COMMIT_HASH_SIZE) != 0) if (memcmp(commitString, ANGLE_COMMIT_HASH, sizeof(unsigned char) * ANGLE_COMMIT_HASH_SIZE) != 0)
{ {
infoLog.append("Invalid program binary version."); infoLog.append("Invalid program binary version.");
return false; return false;
} }
int compileFlags = stream.readInt<int>(); int compileFlags = 0;
stream.read(&compileFlags);
if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL) if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL)
{ {
infoLog.append("Mismatched compilation flags."); infoLog.append("Mismatched compilation flags.");
...@@ -1085,131 +1089,153 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1085,131 +1089,153 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
for (int i = 0; i < MAX_VERTEX_ATTRIBS; ++i) for (int i = 0; i < MAX_VERTEX_ATTRIBS; ++i)
{ {
stream.readInt(&mLinkedAttribute[i].type); stream.read(&mLinkedAttribute[i].type);
stream.readString(&mLinkedAttribute[i].name); std::string name;
stream.readInt(&mShaderAttributes[i].type); stream.read(&name);
stream.readString(&mShaderAttributes[i].name); mLinkedAttribute[i].name = name;
stream.readInt(&mSemanticIndex[i]); stream.read(&mShaderAttributes[i].type);
stream.read(&mShaderAttributes[i].name);
stream.read(&mSemanticIndex[i]);
} }
initAttributesByLayout(); initAttributesByLayout();
for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i) for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i)
{ {
stream.readBool(&mSamplersPS[i].active); stream.read(&mSamplersPS[i].active);
stream.readInt(&mSamplersPS[i].logicalTextureUnit); stream.read(&mSamplersPS[i].logicalTextureUnit);
stream.readInt(&mSamplersPS[i].textureType);
int textureType;
stream.read(&textureType);
mSamplersPS[i].textureType = (TextureType) textureType;
} }
for (unsigned int i = 0; i < IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++i) for (unsigned int i = 0; i < IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++i)
{ {
stream.readBool(&mSamplersVS[i].active); stream.read(&mSamplersVS[i].active);
stream.readInt(&mSamplersVS[i].logicalTextureUnit); stream.read(&mSamplersVS[i].logicalTextureUnit);
stream.readInt(&mSamplersVS[i].textureType);
int textureType;
stream.read(&textureType);
mSamplersVS[i].textureType = (TextureType) textureType;
} }
stream.readInt(&mUsedVertexSamplerRange); stream.read(&mUsedVertexSamplerRange);
stream.readInt(&mUsedPixelSamplerRange); stream.read(&mUsedPixelSamplerRange);
stream.readBool(&mUsesPointSize); stream.read(&mUsesPointSize);
stream.readInt(&mShaderVersion); stream.read(&mShaderVersion);
const unsigned int uniformCount = stream.readInt<unsigned int>(); size_t size;
stream.read(&size);
if (stream.error()) if (stream.error())
{ {
infoLog.append("Invalid program binary."); infoLog.append("Invalid program binary.");
return false; return false;
} }
mUniforms.resize(uniformCount); mUniforms.resize(size);
for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++) for (unsigned int i = 0; i < size; ++i)
{ {
GLenum type = stream.readInt<GLenum>(); GLenum type;
GLenum precision = stream.readInt<GLenum>(); GLenum precision;
std::string name = stream.readString(); std::string name;
unsigned int arraySize = stream.readInt<unsigned int>(); unsigned int arraySize;
int blockIndex = stream.readInt<int>(); int blockIndex;
int offset = stream.readInt<int>(); stream.read(&type);
int arrayStride = stream.readInt<int>(); stream.read(&precision);
int matrixStride = stream.readInt<int>(); stream.read(&name);
bool isRowMajorMatrix = stream.readBool(); stream.read(&arraySize);
stream.read(&blockIndex);
const gl::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix); int offset;
int arrayStride;
int matrixStride;
bool isRowMajorMatrix;
LinkedUniform *uniform = new LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo); stream.read(&offset);
stream.read(&arrayStride);
stream.read(&matrixStride);
stream.read(&isRowMajorMatrix);
const gl::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix);
stream.readInt(&uniform->psRegisterIndex); mUniforms[i] = new LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo);
stream.readInt(&uniform->vsRegisterIndex);
stream.readInt(&uniform->registerCount);
stream.readInt(&uniform->registerElement);
mUniforms[uniformIndex] = uniform; stream.read(&mUniforms[i]->psRegisterIndex);
stream.read(&mUniforms[i]->vsRegisterIndex);
stream.read(&mUniforms[i]->registerCount);
stream.read(&mUniforms[i]->registerElement);
} }
unsigned int uniformBlockCount = stream.readInt<unsigned int>(); stream.read(&size);
if (stream.error()) if (stream.error())
{ {
infoLog.append("Invalid program binary."); infoLog.append("Invalid program binary.");
return false; return false;
} }
mUniformBlocks.resize(uniformBlockCount); mUniformBlocks.resize(size);
for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount; ++uniformBlockIndex) for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < size; ++uniformBlockIndex)
{ {
std::string name = stream.readString(); std::string name;
unsigned int elementIndex = stream.readInt<unsigned int>(); unsigned int elementIndex;
unsigned int dataSize = stream.readInt<unsigned int>(); unsigned int dataSize;
UniformBlock *uniformBlock = new UniformBlock(name, elementIndex, dataSize); stream.read(&name);
stream.read(&elementIndex);
stream.read(&dataSize);
stream.readInt(&uniformBlock->psRegisterIndex); mUniformBlocks[uniformBlockIndex] = new UniformBlock(name, elementIndex, dataSize);
stream.readInt(&uniformBlock->vsRegisterIndex);
unsigned int numMembers = stream.readInt<unsigned int>(); UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex];
uniformBlock->memberUniformIndexes.resize(numMembers); stream.read(&uniformBlock.psRegisterIndex);
stream.read(&uniformBlock.vsRegisterIndex);
size_t numMembers;
stream.read(&numMembers);
uniformBlock.memberUniformIndexes.resize(numMembers);
for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++) for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++)
{ {
stream.readInt(&uniformBlock->memberUniformIndexes[blockMemberIndex]); stream.read(&uniformBlock.memberUniformIndexes[blockMemberIndex]);
} }
mUniformBlocks[uniformBlockIndex] = uniformBlock;
} }
const unsigned int uniformIndexCount = stream.readInt<unsigned int>(); stream.read(&size);
if (stream.error()) if (stream.error())
{ {
infoLog.append("Invalid program binary."); infoLog.append("Invalid program binary.");
return false; return false;
} }
mUniformIndex.resize(uniformIndexCount); mUniformIndex.resize(size);
for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount; uniformIndexIndex++) for (unsigned int i = 0; i < size; ++i)
{ {
stream.readString(&mUniformIndex[uniformIndexIndex].name); stream.read(&mUniformIndex[i].name);
stream.readInt(&mUniformIndex[uniformIndexIndex].element); stream.read(&mUniformIndex[i].element);
stream.readInt(&mUniformIndex[uniformIndexIndex].index); stream.read(&mUniformIndex[i].index);
} }
stream.readInt(&mTransformFeedbackBufferMode); stream.read(&mTransformFeedbackBufferMode);
const unsigned int transformFeedbackVaryingCount = stream.readInt<unsigned int>(); stream.read(&size);
mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount); mTransformFeedbackLinkedVaryings.resize(size);
for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++) for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++)
{ {
LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex]; LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i];
stream.readString(&varying.name); stream.read(&varying.name);
stream.readInt(&varying.type); stream.read(&varying.type);
stream.readInt(&varying.size); stream.read(&varying.size);
stream.readString(&varying.semanticName); stream.read(&varying.semanticName);
stream.readInt(&varying.semanticIndex); stream.read(&varying.semanticIndex);
stream.readInt(&varying.semanticIndexCount); stream.read(&varying.semanticIndexCount);
} }
stream.readString(&mVertexHLSL); stream.read(&mVertexHLSL);
stream.read(&mVertexWorkarounds);
stream.readInt(&mVertexWorkarounds);
const unsigned int vertexShaderCount = stream.readInt<unsigned int>(); unsigned int vertexShaderCount;
stream.read(&vertexShaderCount);
for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++) for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++)
{ {
...@@ -1218,13 +1244,14 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1218,13 +1244,14 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
for (size_t inputIndex = 0; inputIndex < MAX_VERTEX_ATTRIBS; inputIndex++) for (size_t inputIndex = 0; inputIndex < MAX_VERTEX_ATTRIBS; inputIndex++)
{ {
VertexFormat *vertexInput = &inputLayout[inputIndex]; VertexFormat *vertexInput = &inputLayout[inputIndex];
stream.readInt(&vertexInput->mType); stream.read(&vertexInput->mType);
stream.readInt(&vertexInput->mNormalized); stream.read(&vertexInput->mNormalized);
stream.readInt(&vertexInput->mComponents); stream.read(&vertexInput->mComponents);
stream.readBool(&vertexInput->mPureInteger); stream.read(&vertexInput->mPureInteger);
} }
unsigned int vertexShaderSize = stream.readInt<unsigned int>(); unsigned int vertexShaderSize;
stream.read(&vertexShaderSize);
const char *vertexShaderFunction = (const char*) binary + stream.offset(); const char *vertexShaderFunction = (const char*) binary + stream.offset();
...@@ -1248,7 +1275,8 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1248,7 +1275,8 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
stream.skip(vertexShaderSize); stream.skip(vertexShaderSize);
} }
unsigned int pixelShaderSize = stream.readInt<unsigned int>(); unsigned int pixelShaderSize;
stream.read(&pixelShaderSize);
const char *pixelShaderFunction = (const char*) binary + stream.offset(); const char *pixelShaderFunction = (const char*) binary + stream.offset();
mPixelExecutable = mRenderer->loadExecutable(reinterpret_cast<const DWORD*>(pixelShaderFunction), mPixelExecutable = mRenderer->loadExecutable(reinterpret_cast<const DWORD*>(pixelShaderFunction),
...@@ -1261,7 +1289,8 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1261,7 +1289,8 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
} }
stream.skip(pixelShaderSize); stream.skip(pixelShaderSize);
unsigned int geometryShaderSize = stream.readInt<unsigned int>(); unsigned int geometryShaderSize;
stream.read(&geometryShaderSize);
if (geometryShaderSize > 0) if (geometryShaderSize > 0)
{ {
...@@ -1299,107 +1328,107 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length) ...@@ -1299,107 +1328,107 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length)
{ {
BinaryOutputStream stream; BinaryOutputStream stream;
stream.writeInt(GL_PROGRAM_BINARY_ANGLE); stream.write(GL_PROGRAM_BINARY_ANGLE);
stream.writeInt(ANGLE_MAJOR_VERSION); stream.write(ANGLE_MAJOR_VERSION);
stream.writeInt(ANGLE_MINOR_VERSION); stream.write(ANGLE_MINOR_VERSION);
stream.writeBytes(reinterpret_cast<unsigned char*>(ANGLE_COMMIT_HASH), ANGLE_COMMIT_HASH_SIZE); stream.write(ANGLE_COMMIT_HASH, ANGLE_COMMIT_HASH_SIZE);
stream.writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL); stream.write(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
for (unsigned int i = 0; i < MAX_VERTEX_ATTRIBS; ++i) for (unsigned int i = 0; i < MAX_VERTEX_ATTRIBS; ++i)
{ {
stream.writeInt(mLinkedAttribute[i].type); stream.write(mLinkedAttribute[i].type);
stream.writeString(mLinkedAttribute[i].name); stream.write(mLinkedAttribute[i].name);
stream.writeInt(mShaderAttributes[i].type); stream.write(mShaderAttributes[i].type);
stream.writeString(mShaderAttributes[i].name); stream.write(mShaderAttributes[i].name);
stream.writeInt(mSemanticIndex[i]); stream.write(mSemanticIndex[i]);
} }
for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i) for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i)
{ {
stream.writeInt(mSamplersPS[i].active); stream.write(mSamplersPS[i].active);
stream.writeInt(mSamplersPS[i].logicalTextureUnit); stream.write(mSamplersPS[i].logicalTextureUnit);
stream.writeInt(mSamplersPS[i].textureType); stream.write((int) mSamplersPS[i].textureType);
} }
for (unsigned int i = 0; i < IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++i) for (unsigned int i = 0; i < IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++i)
{ {
stream.writeInt(mSamplersVS[i].active); stream.write(mSamplersVS[i].active);
stream.writeInt(mSamplersVS[i].logicalTextureUnit); stream.write(mSamplersVS[i].logicalTextureUnit);
stream.writeInt(mSamplersVS[i].textureType); stream.write((int) mSamplersVS[i].textureType);
} }
stream.writeInt(mUsedVertexSamplerRange); stream.write(mUsedVertexSamplerRange);
stream.writeInt(mUsedPixelSamplerRange); stream.write(mUsedPixelSamplerRange);
stream.writeInt(mUsesPointSize); stream.write(mUsesPointSize);
stream.writeInt(mShaderVersion); stream.write(mShaderVersion);
stream.writeInt(mUniforms.size()); stream.write(mUniforms.size());
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); ++uniformIndex) for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); ++uniformIndex)
{ {
const LinkedUniform &uniform = *mUniforms[uniformIndex]; const LinkedUniform &uniform = *mUniforms[uniformIndex];
stream.writeInt(uniform.type); stream.write(uniform.type);
stream.writeInt(uniform.precision); stream.write(uniform.precision);
stream.writeString(uniform.name); stream.write(uniform.name);
stream.writeInt(uniform.arraySize); stream.write(uniform.arraySize);
stream.writeInt(uniform.blockIndex); stream.write(uniform.blockIndex);
stream.writeInt(uniform.blockInfo.offset); stream.write(uniform.blockInfo.offset);
stream.writeInt(uniform.blockInfo.arrayStride); stream.write(uniform.blockInfo.arrayStride);
stream.writeInt(uniform.blockInfo.matrixStride); stream.write(uniform.blockInfo.matrixStride);
stream.writeInt(uniform.blockInfo.isRowMajorMatrix); stream.write(uniform.blockInfo.isRowMajorMatrix);
stream.writeInt(uniform.psRegisterIndex); stream.write(uniform.psRegisterIndex);
stream.writeInt(uniform.vsRegisterIndex); stream.write(uniform.vsRegisterIndex);
stream.writeInt(uniform.registerCount); stream.write(uniform.registerCount);
stream.writeInt(uniform.registerElement); stream.write(uniform.registerElement);
} }
stream.writeInt(mUniformBlocks.size()); stream.write(mUniformBlocks.size());
for (size_t uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); ++uniformBlockIndex) for (size_t uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); ++uniformBlockIndex)
{ {
const UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex]; const UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex];
stream.writeString(uniformBlock.name); stream.write(uniformBlock.name);
stream.writeInt(uniformBlock.elementIndex); stream.write(uniformBlock.elementIndex);
stream.writeInt(uniformBlock.dataSize); stream.write(uniformBlock.dataSize);
stream.writeInt(uniformBlock.memberUniformIndexes.size()); stream.write(uniformBlock.memberUniformIndexes.size());
for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++) for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++)
{ {
stream.writeInt(uniformBlock.memberUniformIndexes[blockMemberIndex]); stream.write(uniformBlock.memberUniformIndexes[blockMemberIndex]);
} }
stream.writeInt(uniformBlock.psRegisterIndex); stream.write(uniformBlock.psRegisterIndex);
stream.writeInt(uniformBlock.vsRegisterIndex); stream.write(uniformBlock.vsRegisterIndex);
} }
stream.writeInt(mUniformIndex.size()); stream.write(mUniformIndex.size());
for (size_t i = 0; i < mUniformIndex.size(); ++i) for (size_t i = 0; i < mUniformIndex.size(); ++i)
{ {
stream.writeString(mUniformIndex[i].name); stream.write(mUniformIndex[i].name);
stream.writeInt(mUniformIndex[i].element); stream.write(mUniformIndex[i].element);
stream.writeInt(mUniformIndex[i].index); stream.write(mUniformIndex[i].index);
} }
stream.writeInt(mTransformFeedbackBufferMode); stream.write(mTransformFeedbackBufferMode);
stream.writeInt(mTransformFeedbackLinkedVaryings.size()); stream.write(mTransformFeedbackLinkedVaryings.size());
for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++) for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++)
{ {
const LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i]; const LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i];
stream.writeString(varying.name); stream.write(varying.name);
stream.writeInt(varying.type); stream.write(varying.type);
stream.writeInt(varying.size); stream.write(varying.size);
stream.writeString(varying.semanticName); stream.write(varying.semanticName);
stream.writeInt(varying.semanticIndex); stream.write(varying.semanticIndex);
stream.writeInt(varying.semanticIndexCount); stream.write(varying.semanticIndexCount);
} }
stream.writeString(mVertexHLSL); stream.write(mVertexHLSL);
stream.writeInt(mVertexWorkarounds); stream.write(mVertexWorkarounds);
stream.writeInt(mVertexExecutables.size()); stream.write(mVertexExecutables.size());
for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size(); vertexExecutableIndex++) for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size(); vertexExecutableIndex++)
{ {
VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex]; VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex];
...@@ -1407,32 +1436,32 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length) ...@@ -1407,32 +1436,32 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length)
for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++) for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++)
{ {
const VertexFormat &vertexInput = vertexExecutable->inputs()[inputIndex]; const VertexFormat &vertexInput = vertexExecutable->inputs()[inputIndex];
stream.writeInt(vertexInput.mType); stream.write(vertexInput.mType);
stream.writeInt(vertexInput.mNormalized); stream.write(vertexInput.mNormalized);
stream.writeInt(vertexInput.mComponents); stream.write(vertexInput.mComponents);
stream.writeInt(vertexInput.mPureInteger); stream.write(vertexInput.mPureInteger);
} }
size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength(); UINT vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
stream.writeInt(vertexShaderSize); stream.write(vertexShaderSize);
unsigned char *vertexBlob = static_cast<unsigned char *>(vertexExecutable->shaderExecutable()->getFunction()); unsigned char *vertexBlob = static_cast<unsigned char *>(vertexExecutable->shaderExecutable()->getFunction());
stream.writeBytes(vertexBlob, vertexShaderSize); stream.write(vertexBlob, vertexShaderSize);
} }
size_t pixelShaderSize = mPixelExecutable->getLength(); UINT pixelShaderSize = mPixelExecutable->getLength();
stream.writeInt(pixelShaderSize); stream.write(pixelShaderSize);
unsigned char *pixelBlob = static_cast<unsigned char *>(mPixelExecutable->getFunction()); unsigned char *pixelBlob = static_cast<unsigned char *>(mPixelExecutable->getFunction());
stream.writeBytes(pixelBlob, pixelShaderSize); stream.write(pixelBlob, pixelShaderSize);
size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0; UINT geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
stream.writeInt(geometryShaderSize); stream.write(geometryShaderSize);
if (mGeometryExecutable != NULL && geometryShaderSize > 0) if (mGeometryExecutable != NULL && geometryShaderSize > 0)
{ {
unsigned char *geometryBlob = static_cast<unsigned char *>(mGeometryExecutable->getFunction()); unsigned char *geometryBlob = static_cast<unsigned char *>(mGeometryExecutable->getFunction());
stream.writeBytes(geometryBlob, geometryShaderSize); stream.write(geometryBlob, geometryShaderSize);
} }
GUID identifier = mRenderer->getAdapterIdentifier(); GUID identifier = mRenderer->getAdapterIdentifier();
......
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