Commit 1b2a8f96 by Jamie Madill

Fix binary serialization to use explicit size and type.

Loading program binaries across different architectures would cause runtime errors due to use of size_t. Also fix the ANGLE major and minor version that were clobbered in an earlier commit. BUG=angle:647 BUG=371435 Change-Id: I9473cc7e119592fce336aa47881839543e337b69 Reviewed-on: https://chromium-review.googlesource.com/199633Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 43b00426
...@@ -535,6 +535,12 @@ inline bool IsUnsignedMultiplicationSafe(T lhs, T rhs) ...@@ -535,6 +535,12 @@ inline bool IsUnsignedMultiplicationSafe(T lhs, T rhs)
return (lhs == T(0) || rhs == T(0) || (rhs <= std::numeric_limits<T>::max() / lhs)); return (lhs == T(0) || rhs == T(0) || (rhs <= std::numeric_limits<T>::max() / lhs));
} }
template <class SmallIntT, class BigIntT>
inline bool IsIntegerCastSafe(BigIntT bigValue)
{
return (static_cast<BigIntT>(static_cast<SmallIntT>(bigValue)) == bigValue);
}
} }
#endif // LIBGLESV2_MATHUTIL_H_ #endif // LIBGLESV2_MATHUTIL_H_
#include "commit.h" #include "commit.h"
#define ANGLE_MAJOR_VERSION 1 #define ANGLE_MAJOR_VERSION 2
#define ANGLE_MINOR_VERSION 3 #define ANGLE_MINOR_VERSION 1
#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)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define LIBGLESV2_BINARYSTREAM_H_ #define LIBGLESV2_BINARYSTREAM_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "common/mathutil.h"
namespace gl namespace gl
{ {
...@@ -25,42 +26,49 @@ class BinaryInputStream ...@@ -25,42 +26,49 @@ class BinaryInputStream
mLength = length; mLength = length;
} }
template <typename T> // readInt will generate an error for bool types
void read(T *v, size_t num) template <class IntT>
IntT readInt()
{ {
union int value;
{ read(&value);
T dummy; // Compilation error for non-trivial types return static_cast<IntT>(value);
} dummy; }
(void) dummy;
if (mError) template <class IntT>
void readInt(IntT *outValue)
{ {
return; *outValue = readInt<IntT>();
} }
size_t length = num * sizeof(T); bool readBool()
{
int value;
read(&value);
return (value > 0);
}
if (mOffset + length > mLength) void readBool(bool *outValue)
{ {
mError = true; *outValue = readBool();
return;
} }
memcpy(v, mData + mOffset, length); void readBytes(unsigned char outArray[], size_t count)
mOffset += length; {
read<unsigned char>(outArray, count);
} }
template <typename T> std::string readString()
void read(T * v)
{ {
read(v, 1); std::string outString;
readString(&outString);
return outString;
} }
void read(std::string *v) void readString(std::string *v)
{ {
size_t length; size_t length;
read(&length); readInt(&length);
if (mError) if (mError)
{ {
...@@ -109,6 +117,30 @@ class BinaryInputStream ...@@ -109,6 +117,30 @@ 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)
{
META_ASSERT(std::is_fundamental<T>::value);
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
...@@ -118,31 +150,24 @@ class BinaryOutputStream ...@@ -118,31 +150,24 @@ class BinaryOutputStream
{ {
} }
template <typename T> // writeInt also handles bool types
void write(const T *v, size_t num) template <class IntT>
{ void writeInt(IntT param)
union
{ {
T dummy; // Compilation error for non-trivial types ASSERT(rx::IsIntegerCastSafe<int>(param));
} dummy; int intValue = static_cast<int>(param);
(void) dummy; write(&intValue, 1);
const char *asBytes = reinterpret_cast<const char*>(v);
mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
} }
template <typename T> void writeString(const std::string &v)
void write(const T &v)
{ {
write(&v, 1); writeInt(v.length());
write(v.c_str(), v.length());
} }
void write(const std::string &v) void writeBytes(unsigned char *bytes, size_t count)
{ {
size_t length = v.length(); write(bytes, count);
write(length);
write(v.c_str(), length);
} }
size_t length() const size_t length() const
...@@ -158,6 +183,15 @@ class BinaryOutputStream ...@@ -158,6 +183,15 @@ 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)
{
META_ASSERT(std::is_fundamental<T>::value);
const char *asBytes = reinterpret_cast<const char*>(v);
mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
}
}; };
} }
......
...@@ -1065,18 +1065,15 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1065,18 +1065,15 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
{ {
BinaryInputStream stream(binary, length); BinaryInputStream stream(binary, length);
int format = 0; int format = stream.readInt<int>();
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 = 0; int majorVersion = stream.readInt<int>();
int minorVersion = 0; int minorVersion = stream.readInt<int>();
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.");
...@@ -1084,15 +1081,14 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1084,15 +1081,14 @@ 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.read(commitString, ANGLE_COMMIT_HASH_SIZE); stream.readBytes(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 = 0; int compileFlags = stream.readInt<int>();
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.");
...@@ -1101,153 +1097,131 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1101,153 +1097,131 @@ 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.read(&mLinkedAttribute[i].type); stream.readInt(&mLinkedAttribute[i].type);
std::string name; stream.readString(&mLinkedAttribute[i].name);
stream.read(&name); stream.readInt(&mShaderAttributes[i].type);
mLinkedAttribute[i].name = name; stream.readString(&mShaderAttributes[i].name);
stream.read(&mShaderAttributes[i].type); stream.readInt(&mSemanticIndex[i]);
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.read(&mSamplersPS[i].active); stream.readBool(&mSamplersPS[i].active);
stream.read(&mSamplersPS[i].logicalTextureUnit); stream.readInt(&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.read(&mSamplersVS[i].active); stream.readBool(&mSamplersVS[i].active);
stream.read(&mSamplersVS[i].logicalTextureUnit); stream.readInt(&mSamplersVS[i].logicalTextureUnit);
stream.readInt(&mSamplersVS[i].textureType);
int textureType;
stream.read(&textureType);
mSamplersVS[i].textureType = (TextureType) textureType;
} }
stream.read(&mUsedVertexSamplerRange); stream.readInt(&mUsedVertexSamplerRange);
stream.read(&mUsedPixelSamplerRange); stream.readInt(&mUsedPixelSamplerRange);
stream.read(&mUsesPointSize); stream.readBool(&mUsesPointSize);
stream.read(&mShaderVersion); stream.readInt(&mShaderVersion);
size_t size; const unsigned int uniformCount = 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;
} }
mUniforms.resize(size); mUniforms.resize(uniformCount);
for (unsigned int i = 0; i < size; ++i) for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++)
{ {
GLenum type; GLenum type = stream.readInt<GLenum>();
GLenum precision; GLenum precision = stream.readInt<GLenum>();
std::string name; std::string name = stream.readString();
unsigned int arraySize; unsigned int arraySize = stream.readInt<unsigned int>();
int blockIndex; int blockIndex = stream.readInt<int>();
stream.read(&type);
stream.read(&precision);
stream.read(&name);
stream.read(&arraySize);
stream.read(&blockIndex);
int offset; int offset = stream.readInt<int>();
int arrayStride; int arrayStride = stream.readInt<int>();
int matrixStride; int matrixStride = stream.readInt<int>();
bool isRowMajorMatrix; bool isRowMajorMatrix = stream.readBool();
stream.read(&offset);
stream.read(&arrayStride);
stream.read(&matrixStride);
stream.read(&isRowMajorMatrix);
const gl::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix); const gl::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix);
mUniforms[i] = new LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo); LinkedUniform *uniform = new LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo);
stream.readInt(&uniform->psRegisterIndex);
stream.readInt(&uniform->vsRegisterIndex);
stream.readInt(&uniform->registerCount);
stream.readInt(&uniform->registerElement);
stream.read(&mUniforms[i]->psRegisterIndex); mUniforms[uniformIndex] = uniform;
stream.read(&mUniforms[i]->vsRegisterIndex);
stream.read(&mUniforms[i]->registerCount);
stream.read(&mUniforms[i]->registerElement);
} }
stream.read(&size); unsigned int uniformBlockCount = stream.readInt<unsigned int>();
if (stream.error()) if (stream.error())
{ {
infoLog.append("Invalid program binary."); infoLog.append("Invalid program binary.");
return false; return false;
} }
mUniformBlocks.resize(size); mUniformBlocks.resize(uniformBlockCount);
for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < size; ++uniformBlockIndex) for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount; ++uniformBlockIndex)
{ {
std::string name; std::string name = stream.readString();
unsigned int elementIndex; unsigned int elementIndex = stream.readInt<unsigned int>();
unsigned int dataSize; unsigned int dataSize = stream.readInt<unsigned int>();
stream.read(&name); UniformBlock *uniformBlock = new UniformBlock(name, elementIndex, dataSize);
stream.read(&elementIndex);
stream.read(&dataSize);
mUniformBlocks[uniformBlockIndex] = new UniformBlock(name, elementIndex, dataSize); stream.readInt(&uniformBlock->psRegisterIndex);
stream.readInt(&uniformBlock->vsRegisterIndex);
UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex]; unsigned int numMembers = stream.readInt<unsigned int>();
stream.read(&uniformBlock.psRegisterIndex); uniformBlock->memberUniformIndexes.resize(numMembers);
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.read(&uniformBlock.memberUniformIndexes[blockMemberIndex]); stream.readInt(&uniformBlock->memberUniformIndexes[blockMemberIndex]);
} }
mUniformBlocks[uniformBlockIndex] = uniformBlock;
} }
stream.read(&size); const unsigned int uniformIndexCount = stream.readInt<unsigned int>();
if (stream.error()) if (stream.error())
{ {
infoLog.append("Invalid program binary."); infoLog.append("Invalid program binary.");
return false; return false;
} }
mUniformIndex.resize(size); mUniformIndex.resize(uniformIndexCount);
for (unsigned int i = 0; i < size; ++i) for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount; uniformIndexIndex++)
{ {
stream.read(&mUniformIndex[i].name); stream.readString(&mUniformIndex[uniformIndexIndex].name);
stream.read(&mUniformIndex[i].element); stream.readInt(&mUniformIndex[uniformIndexIndex].element);
stream.read(&mUniformIndex[i].index); stream.readInt(&mUniformIndex[uniformIndexIndex].index);
} }
stream.read(&mTransformFeedbackBufferMode); stream.readInt(&mTransformFeedbackBufferMode);
stream.read(&size); const unsigned int transformFeedbackVaryingCount = stream.readInt<unsigned int>();
mTransformFeedbackLinkedVaryings.resize(size); mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount);
for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++) for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++)
{ {
LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i]; LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex];
stream.read(&varying.name); stream.readString(&varying.name);
stream.read(&varying.type); stream.readInt(&varying.type);
stream.read(&varying.size); stream.readInt(&varying.size);
stream.read(&varying.semanticName); stream.readString(&varying.semanticName);
stream.read(&varying.semanticIndex); stream.readInt(&varying.semanticIndex);
stream.read(&varying.semanticIndexCount); stream.readInt(&varying.semanticIndexCount);
} }
stream.read(&mVertexHLSL); stream.readString(&mVertexHLSL);
stream.read(&mVertexWorkarounds);
stream.readInt(&mVertexWorkarounds);
unsigned int vertexShaderCount; const unsigned int vertexShaderCount = stream.readInt<unsigned int>();
stream.read(&vertexShaderCount);
for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++) for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++)
{ {
...@@ -1256,14 +1230,13 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1256,14 +1230,13 @@ 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.read(&vertexInput->mType); stream.readInt(&vertexInput->mType);
stream.read(&vertexInput->mNormalized); stream.readInt(&vertexInput->mNormalized);
stream.read(&vertexInput->mComponents); stream.readInt(&vertexInput->mComponents);
stream.read(&vertexInput->mPureInteger); stream.readBool(&vertexInput->mPureInteger);
} }
unsigned int vertexShaderSize; unsigned int vertexShaderSize = stream.readInt<unsigned int>();
stream.read(&vertexShaderSize);
const char *vertexShaderFunction = (const char*) binary + stream.offset(); const char *vertexShaderFunction = (const char*) binary + stream.offset();
...@@ -1287,8 +1260,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1287,8 +1260,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
stream.skip(vertexShaderSize); stream.skip(vertexShaderSize);
} }
unsigned int pixelShaderSize; unsigned int pixelShaderSize = stream.readInt<unsigned int>();
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),
...@@ -1301,8 +1273,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) ...@@ -1301,8 +1273,7 @@ bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
} }
stream.skip(pixelShaderSize); stream.skip(pixelShaderSize);
unsigned int geometryShaderSize; unsigned int geometryShaderSize = stream.readInt<unsigned int>();
stream.read(&geometryShaderSize);
if (geometryShaderSize > 0) if (geometryShaderSize > 0)
{ {
...@@ -1340,107 +1311,107 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length) ...@@ -1340,107 +1311,107 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length)
{ {
BinaryOutputStream stream; BinaryOutputStream stream;
stream.write(GL_PROGRAM_BINARY_ANGLE); stream.writeInt(GL_PROGRAM_BINARY_ANGLE);
stream.write(ANGLE_MAJOR_VERSION); stream.writeInt(ANGLE_MAJOR_VERSION);
stream.write(ANGLE_MINOR_VERSION); stream.writeInt(ANGLE_MINOR_VERSION);
stream.write(ANGLE_COMMIT_HASH, ANGLE_COMMIT_HASH_SIZE); stream.writeBytes(reinterpret_cast<unsigned char*>(ANGLE_COMMIT_HASH), ANGLE_COMMIT_HASH_SIZE);
stream.write(ANGLE_COMPILE_OPTIMIZATION_LEVEL); stream.writeInt(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.write(mLinkedAttribute[i].type); stream.writeInt(mLinkedAttribute[i].type);
stream.write(mLinkedAttribute[i].name); stream.writeString(mLinkedAttribute[i].name);
stream.write(mShaderAttributes[i].type); stream.writeInt(mShaderAttributes[i].type);
stream.write(mShaderAttributes[i].name); stream.writeString(mShaderAttributes[i].name);
stream.write(mSemanticIndex[i]); stream.writeInt(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.write(mSamplersPS[i].active); stream.writeInt(mSamplersPS[i].active);
stream.write(mSamplersPS[i].logicalTextureUnit); stream.writeInt(mSamplersPS[i].logicalTextureUnit);
stream.write((int) mSamplersPS[i].textureType); stream.writeInt(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.write(mSamplersVS[i].active); stream.writeInt(mSamplersVS[i].active);
stream.write(mSamplersVS[i].logicalTextureUnit); stream.writeInt(mSamplersVS[i].logicalTextureUnit);
stream.write((int) mSamplersVS[i].textureType); stream.writeInt(mSamplersVS[i].textureType);
} }
stream.write(mUsedVertexSamplerRange); stream.writeInt(mUsedVertexSamplerRange);
stream.write(mUsedPixelSamplerRange); stream.writeInt(mUsedPixelSamplerRange);
stream.write(mUsesPointSize); stream.writeInt(mUsesPointSize);
stream.write(mShaderVersion); stream.writeInt(mShaderVersion);
stream.write(mUniforms.size()); stream.writeInt(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.write(uniform.type); stream.writeInt(uniform.type);
stream.write(uniform.precision); stream.writeInt(uniform.precision);
stream.write(uniform.name); stream.writeString(uniform.name);
stream.write(uniform.arraySize); stream.writeInt(uniform.arraySize);
stream.write(uniform.blockIndex); stream.writeInt(uniform.blockIndex);
stream.write(uniform.blockInfo.offset); stream.writeInt(uniform.blockInfo.offset);
stream.write(uniform.blockInfo.arrayStride); stream.writeInt(uniform.blockInfo.arrayStride);
stream.write(uniform.blockInfo.matrixStride); stream.writeInt(uniform.blockInfo.matrixStride);
stream.write(uniform.blockInfo.isRowMajorMatrix); stream.writeInt(uniform.blockInfo.isRowMajorMatrix);
stream.write(uniform.psRegisterIndex); stream.writeInt(uniform.psRegisterIndex);
stream.write(uniform.vsRegisterIndex); stream.writeInt(uniform.vsRegisterIndex);
stream.write(uniform.registerCount); stream.writeInt(uniform.registerCount);
stream.write(uniform.registerElement); stream.writeInt(uniform.registerElement);
} }
stream.write(mUniformBlocks.size()); stream.writeInt(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.write(uniformBlock.name); stream.writeString(uniformBlock.name);
stream.write(uniformBlock.elementIndex); stream.writeInt(uniformBlock.elementIndex);
stream.write(uniformBlock.dataSize); stream.writeInt(uniformBlock.dataSize);
stream.write(uniformBlock.memberUniformIndexes.size()); stream.writeInt(uniformBlock.memberUniformIndexes.size());
for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++) for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++)
{ {
stream.write(uniformBlock.memberUniformIndexes[blockMemberIndex]); stream.writeInt(uniformBlock.memberUniformIndexes[blockMemberIndex]);
} }
stream.write(uniformBlock.psRegisterIndex); stream.writeInt(uniformBlock.psRegisterIndex);
stream.write(uniformBlock.vsRegisterIndex); stream.writeInt(uniformBlock.vsRegisterIndex);
} }
stream.write(mUniformIndex.size()); stream.writeInt(mUniformIndex.size());
for (size_t i = 0; i < mUniformIndex.size(); ++i) for (size_t i = 0; i < mUniformIndex.size(); ++i)
{ {
stream.write(mUniformIndex[i].name); stream.writeString(mUniformIndex[i].name);
stream.write(mUniformIndex[i].element); stream.writeInt(mUniformIndex[i].element);
stream.write(mUniformIndex[i].index); stream.writeInt(mUniformIndex[i].index);
} }
stream.write(mTransformFeedbackBufferMode); stream.writeInt(mTransformFeedbackBufferMode);
stream.write(mTransformFeedbackLinkedVaryings.size()); stream.writeInt(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.write(varying.name); stream.writeString(varying.name);
stream.write(varying.type); stream.writeInt(varying.type);
stream.write(varying.size); stream.writeInt(varying.size);
stream.write(varying.semanticName); stream.writeString(varying.semanticName);
stream.write(varying.semanticIndex); stream.writeInt(varying.semanticIndex);
stream.write(varying.semanticIndexCount); stream.writeInt(varying.semanticIndexCount);
} }
stream.write(mVertexHLSL); stream.writeString(mVertexHLSL);
stream.write(mVertexWorkarounds); stream.writeInt(mVertexWorkarounds);
stream.write(mVertexExecutables.size()); stream.writeInt(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];
...@@ -1448,32 +1419,32 @@ bool ProgramBinary::save(void* binary, GLsizei bufSize, GLsizei *length) ...@@ -1448,32 +1419,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.write(vertexInput.mType); stream.writeInt(vertexInput.mType);
stream.write(vertexInput.mNormalized); stream.writeInt(vertexInput.mNormalized);
stream.write(vertexInput.mComponents); stream.writeInt(vertexInput.mComponents);
stream.write(vertexInput.mPureInteger); stream.writeInt(vertexInput.mPureInteger);
} }
UINT vertexShaderSize = vertexExecutable->shaderExecutable()->getLength(); size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
stream.write(vertexShaderSize); stream.writeInt(vertexShaderSize);
unsigned char *vertexBlob = static_cast<unsigned char *>(vertexExecutable->shaderExecutable()->getFunction()); unsigned char *vertexBlob = static_cast<unsigned char *>(vertexExecutable->shaderExecutable()->getFunction());
stream.write(vertexBlob, vertexShaderSize); stream.writeBytes(vertexBlob, vertexShaderSize);
} }
UINT pixelShaderSize = mPixelExecutable->getLength(); size_t pixelShaderSize = mPixelExecutable->getLength();
stream.write(pixelShaderSize); stream.writeInt(pixelShaderSize);
unsigned char *pixelBlob = static_cast<unsigned char *>(mPixelExecutable->getFunction()); unsigned char *pixelBlob = static_cast<unsigned char *>(mPixelExecutable->getFunction());
stream.write(pixelBlob, pixelShaderSize); stream.writeBytes(pixelBlob, pixelShaderSize);
UINT geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0; size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
stream.write(geometryShaderSize); stream.writeInt(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.write(geometryBlob, geometryShaderSize); stream.writeBytes(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