Commit 2e0490ee by Jamie Madill Committed by Commit Bot

Capture/Replay: Serialize float states properly.

Previously we were always casting to int. Instead add a float serialization helper function. Bug: angleproject:5530 Change-Id: Ifc80e1dbad9da8a04b3b013c3a3ffa60444f6d26 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2634829Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 7489bb2e
...@@ -121,6 +121,13 @@ class BinaryInputStream : angle::NonCopyable ...@@ -121,6 +121,13 @@ class BinaryInputStream : angle::NonCopyable
mOffset = checkedOffset.ValueOrDie(); mOffset = checkedOffset.ValueOrDie();
} }
float readFloat()
{
float f;
read(&f, 1);
return f;
}
void skip(size_t length) void skip(size_t length)
{ {
angle::CheckedNumeric<size_t> checkedOffset(mOffset); angle::CheckedNumeric<size_t> checkedOffset(mOffset);
...@@ -197,6 +204,7 @@ class BinaryOutputStream : angle::NonCopyable ...@@ -197,6 +204,7 @@ class BinaryOutputStream : angle::NonCopyable
template <class IntT> template <class IntT>
void writeInt(IntT param) void writeInt(IntT param)
{ {
static_assert(std::is_integral<IntT>::value, "Not an integral type");
static_assert(!std::is_same<bool, std::remove_cv<IntT>()>(), "Use writeBool"); static_assert(!std::is_same<bool, std::remove_cv<IntT>()>(), "Use writeBool");
using PromotedIntT = typename PromotedIntegerType<IntT>::type; using PromotedIntT = typename PromotedIntegerType<IntT>::type;
ASSERT(angle::IsValueInRangeForNumericType<PromotedIntT>(param)); ASSERT(angle::IsValueInRangeForNumericType<PromotedIntT>(param));
...@@ -249,6 +257,8 @@ class BinaryOutputStream : angle::NonCopyable ...@@ -249,6 +257,8 @@ class BinaryOutputStream : angle::NonCopyable
write(&intValue, 1); write(&intValue, 1);
} }
void writeFloat(float value) { write(&value, 1); }
size_t length() const { return mData.size(); } size_t length() const { return mData.size(); }
const void *data() const { return mData.size() ? &mData[0] : nullptr; } const void *data() const { return mData.size() ? &mData[0] : nullptr; }
......
...@@ -36,8 +36,23 @@ namespace angle ...@@ -36,8 +36,23 @@ namespace angle
namespace namespace
{ {
template <typename T> void SerializeColorF(gl::BinaryOutputStream *bos, const ColorF &color)
void SerializeColor(gl::BinaryOutputStream *bos, const Color<T> &color) {
bos->writeFloat(color.red);
bos->writeFloat(color.green);
bos->writeFloat(color.blue);
bos->writeFloat(color.alpha);
}
void SerializeColorI(gl::BinaryOutputStream *bos, const ColorI &color)
{
bos->writeInt(color.red);
bos->writeInt(color.green);
bos->writeInt(color.blue);
bos->writeInt(color.alpha);
}
void SerializeColorUI(gl::BinaryOutputStream *bos, const ColorUI &color)
{ {
bos->writeInt(color.red); bos->writeInt(color.red);
bos->writeInt(color.green); bos->writeInt(color.green);
...@@ -219,8 +234,8 @@ void SerializeRasterizerState(gl::BinaryOutputStream *bos, ...@@ -219,8 +234,8 @@ void SerializeRasterizerState(gl::BinaryOutputStream *bos,
bos->writeEnum(rasterizerState.cullMode); bos->writeEnum(rasterizerState.cullMode);
bos->writeInt(rasterizerState.frontFace); bos->writeInt(rasterizerState.frontFace);
bos->writeBool(rasterizerState.polygonOffsetFill); bos->writeBool(rasterizerState.polygonOffsetFill);
bos->writeInt(rasterizerState.polygonOffsetFactor); bos->writeFloat(rasterizerState.polygonOffsetFactor);
bos->writeInt(rasterizerState.polygonOffsetUnits); bos->writeFloat(rasterizerState.polygonOffsetUnits);
bos->writeBool(rasterizerState.pointDrawMode); bos->writeBool(rasterizerState.pointDrawMode);
bos->writeBool(rasterizerState.multiSample); bos->writeBool(rasterizerState.multiSample);
bos->writeBool(rasterizerState.rasterizerDiscard); bos->writeBool(rasterizerState.rasterizerDiscard);
...@@ -277,10 +292,10 @@ void SerializeVertexAttribCurrentValueData( ...@@ -277,10 +292,10 @@ void SerializeVertexAttribCurrentValueData(
vertexAttribCurrentValueData.Type == gl::VertexAttribType::UnsignedInt); vertexAttribCurrentValueData.Type == gl::VertexAttribType::UnsignedInt);
if (vertexAttribCurrentValueData.Type == gl::VertexAttribType::Float) if (vertexAttribCurrentValueData.Type == gl::VertexAttribType::Float)
{ {
bos->writeInt(vertexAttribCurrentValueData.Values.FloatValues[0]); bos->writeFloat(vertexAttribCurrentValueData.Values.FloatValues[0]);
bos->writeInt(vertexAttribCurrentValueData.Values.FloatValues[1]); bos->writeFloat(vertexAttribCurrentValueData.Values.FloatValues[1]);
bos->writeInt(vertexAttribCurrentValueData.Values.FloatValues[2]); bos->writeFloat(vertexAttribCurrentValueData.Values.FloatValues[2]);
bos->writeInt(vertexAttribCurrentValueData.Values.FloatValues[3]); bos->writeFloat(vertexAttribCurrentValueData.Values.FloatValues[3]);
} }
else if (vertexAttribCurrentValueData.Type == gl::VertexAttribType::Int) else if (vertexAttribCurrentValueData.Type == gl::VertexAttribType::Int)
{ {
...@@ -337,17 +352,17 @@ void SerializeGLContextStates(gl::BinaryOutputStream *bos, const gl::State &stat ...@@ -337,17 +352,17 @@ void SerializeGLContextStates(gl::BinaryOutputStream *bos, const gl::State &stat
bos->writeInt(state.getClientMajorVersion()); bos->writeInt(state.getClientMajorVersion());
bos->writeInt(state.getClientMinorVersion()); bos->writeInt(state.getClientMinorVersion());
SerializeColor(bos, state.getColorClearValue()); SerializeColorF(bos, state.getColorClearValue());
bos->writeInt(state.getDepthClearValue()); bos->writeFloat(state.getDepthClearValue());
bos->writeInt(state.getStencilClearValue()); bos->writeInt(state.getStencilClearValue());
SerializeRasterizerState(bos, state.getRasterizerState()); SerializeRasterizerState(bos, state.getRasterizerState());
bos->writeBool(state.isScissorTestEnabled()); bos->writeBool(state.isScissorTestEnabled());
SerializeRectangle(bos, state.getScissor()); SerializeRectangle(bos, state.getScissor());
SerializeBlendStateExt(bos, state.getBlendStateExt()); SerializeBlendStateExt(bos, state.getBlendStateExt());
SerializeColor(bos, state.getBlendColor()); SerializeColorF(bos, state.getBlendColor());
bos->writeBool(state.isSampleAlphaToCoverageEnabled()); bos->writeBool(state.isSampleAlphaToCoverageEnabled());
bos->writeBool(state.isSampleCoverageEnabled()); bos->writeBool(state.isSampleCoverageEnabled());
bos->writeInt(state.getSampleCoverageValue()); bos->writeFloat(state.getSampleCoverageValue());
bos->writeBool(state.getSampleCoverageInvert()); bos->writeBool(state.getSampleCoverageInvert());
bos->writeBool(state.isSampleMaskEnabled()); bos->writeBool(state.isSampleMaskEnabled());
bos->writeInt(state.getMaxSampleMaskWords()); bos->writeInt(state.getMaxSampleMaskWords());
...@@ -359,15 +374,15 @@ void SerializeGLContextStates(gl::BinaryOutputStream *bos, const gl::State &stat ...@@ -359,15 +374,15 @@ void SerializeGLContextStates(gl::BinaryOutputStream *bos, const gl::State &stat
SerializeDepthStencilState(bos, state.getDepthStencilState()); SerializeDepthStencilState(bos, state.getDepthStencilState());
bos->writeInt(state.getStencilRef()); bos->writeInt(state.getStencilRef());
bos->writeInt(state.getStencilBackRef()); bos->writeInt(state.getStencilBackRef());
bos->writeInt(state.getLineWidth()); bos->writeFloat(state.getLineWidth());
bos->writeInt(state.getGenerateMipmapHint()); bos->writeInt(state.getGenerateMipmapHint());
bos->writeInt(state.getTextureFilteringHint()); bos->writeInt(state.getTextureFilteringHint());
bos->writeInt(state.getFragmentShaderDerivativeHint()); bos->writeInt(state.getFragmentShaderDerivativeHint());
bos->writeBool(state.isBindGeneratesResourceEnabled()); bos->writeBool(state.isBindGeneratesResourceEnabled());
bos->writeBool(state.areClientArraysEnabled()); bos->writeBool(state.areClientArraysEnabled());
SerializeRectangle(bos, state.getViewport()); SerializeRectangle(bos, state.getViewport());
bos->writeInt(state.getNearPlane()); bos->writeFloat(state.getNearPlane());
bos->writeInt(state.getFarPlane()); bos->writeFloat(state.getFarPlane());
if (state.getReadFramebuffer()) if (state.getReadFramebuffer())
{ {
bos->writeInt(state.getReadFramebuffer()->id().value); bos->writeInt(state.getReadFramebuffer()->id().value);
...@@ -477,15 +492,15 @@ void SerializeColorGeneric(gl::BinaryOutputStream *bos, const ColorGeneric &colo ...@@ -477,15 +492,15 @@ void SerializeColorGeneric(gl::BinaryOutputStream *bos, const ColorGeneric &colo
bos->writeEnum(colorGeneric.type); bos->writeEnum(colorGeneric.type);
if (colorGeneric.type == ColorGeneric::Type::Float) if (colorGeneric.type == ColorGeneric::Type::Float)
{ {
SerializeColor(bos, colorGeneric.colorF); SerializeColorF(bos, colorGeneric.colorF);
} }
else if (colorGeneric.type == ColorGeneric::Type::Int) else if (colorGeneric.type == ColorGeneric::Type::Int)
{ {
SerializeColor(bos, colorGeneric.colorI); SerializeColorI(bos, colorGeneric.colorI);
} }
else else
{ {
SerializeColor(bos, colorGeneric.colorUI); SerializeColorUI(bos, colorGeneric.colorUI);
} }
} }
...@@ -496,9 +511,9 @@ void SerializeSamplerState(gl::BinaryOutputStream *bos, const gl::SamplerState & ...@@ -496,9 +511,9 @@ void SerializeSamplerState(gl::BinaryOutputStream *bos, const gl::SamplerState &
bos->writeInt(samplerState.getWrapS()); bos->writeInt(samplerState.getWrapS());
bos->writeInt(samplerState.getWrapT()); bos->writeInt(samplerState.getWrapT());
bos->writeInt(samplerState.getWrapR()); bos->writeInt(samplerState.getWrapR());
bos->writeInt(samplerState.getMaxAnisotropy()); bos->writeFloat(samplerState.getMaxAnisotropy());
bos->writeInt(samplerState.getMinLod()); bos->writeFloat(samplerState.getMinLod());
bos->writeInt(samplerState.getMaxLod()); bos->writeFloat(samplerState.getMaxLod());
bos->writeInt(samplerState.getCompareMode()); bos->writeInt(samplerState.getCompareMode());
bos->writeInt(samplerState.getCompareFunc()); bos->writeInt(samplerState.getCompareFunc());
bos->writeInt(samplerState.getSRGBDecode()); bos->writeInt(samplerState.getSRGBDecode());
......
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