Commit aa0a5446 by Jamie Madill Committed by Commit Bot

Ensure gl State structs are zero filled.

In some cases we would hash or memcmp against structs with bools or other non-filled data. This could have implementation differences, and may have been causing cache errors on Clang. BUG=chromium:721648 BUG=angleproject:2044 Change-Id: I981a1e6e8d50a33f7fade568497b72b919accfce Reviewed-on: https://chromium-review.googlesource.com/516383Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 80616218
......@@ -155,4 +155,4 @@ rx::SamplerImpl *Sampler::getImplementation() const
return mImpl;
}
}
} // namespace gl
......@@ -87,53 +87,17 @@ void State::initialize(const Caps &caps,
mDepthClearValue = 1.0f;
mStencilClearValue = 0;
mRasterizer.rasterizerDiscard = false;
mRasterizer.cullFace = false;
mRasterizer.cullMode = GL_BACK;
mRasterizer.frontFace = GL_CCW;
mRasterizer.polygonOffsetFill = false;
mRasterizer.polygonOffsetFactor = 0.0f;
mRasterizer.polygonOffsetUnits = 0.0f;
mRasterizer.pointDrawMode = false;
mRasterizer.multiSample = false;
mScissorTest = false;
mScissor.x = 0;
mScissor.y = 0;
mScissor.width = 0;
mScissor.height = 0;
mBlend.blend = false;
mBlend.sourceBlendRGB = GL_ONE;
mBlend.sourceBlendAlpha = GL_ONE;
mBlend.destBlendRGB = GL_ZERO;
mBlend.destBlendAlpha = GL_ZERO;
mBlend.blendEquationRGB = GL_FUNC_ADD;
mBlend.blendEquationAlpha = GL_FUNC_ADD;
mBlend.sampleAlphaToCoverage = false;
mBlend.dither = true;
mBlendColor.red = 0;
mBlendColor.green = 0;
mBlendColor.blue = 0;
mBlendColor.alpha = 0;
mDepthStencil.depthTest = false;
mDepthStencil.depthFunc = GL_LESS;
mDepthStencil.depthMask = true;
mDepthStencil.stencilTest = false;
mDepthStencil.stencilFunc = GL_ALWAYS;
mDepthStencil.stencilMask = static_cast<GLuint>(-1);
mDepthStencil.stencilWritemask = static_cast<GLuint>(-1);
mDepthStencil.stencilBackFunc = GL_ALWAYS;
mDepthStencil.stencilBackMask = static_cast<GLuint>(-1);
mDepthStencil.stencilBackWritemask = static_cast<GLuint>(-1);
mDepthStencil.stencilFail = GL_KEEP;
mDepthStencil.stencilPassDepthFail = GL_KEEP;
mDepthStencil.stencilPassDepthPass = GL_KEEP;
mDepthStencil.stencilBackFail = GL_KEEP;
mDepthStencil.stencilBackPassDepthFail = GL_KEEP;
mDepthStencil.stencilBackPassDepthPass = GL_KEEP;
mStencilRef = 0;
mStencilBackRef = 0;
......
......@@ -39,19 +39,103 @@ PrimitiveType GetPrimitiveType(GLenum drawMode)
}
}
RasterizerState::RasterizerState()
{
memset(this, 0, sizeof(RasterizerState));
rasterizerDiscard = false;
cullFace = false;
cullMode = GL_BACK;
frontFace = GL_CCW;
polygonOffsetFill = false;
polygonOffsetFactor = 0.0f;
polygonOffsetUnits = 0.0f;
pointDrawMode = false;
multiSample = false;
}
bool operator==(const RasterizerState &a, const RasterizerState &b)
{
return memcmp(&a, &b, sizeof(RasterizerState)) == 0;
}
bool operator!=(const RasterizerState &a, const RasterizerState &b)
{
return !(a == b);
}
BlendState::BlendState()
{
memset(this, 0, sizeof(BlendState));
blend = false;
sourceBlendRGB = GL_ONE;
sourceBlendAlpha = GL_ONE;
destBlendRGB = GL_ZERO;
destBlendAlpha = GL_ZERO;
blendEquationRGB = GL_FUNC_ADD;
blendEquationAlpha = GL_FUNC_ADD;
sampleAlphaToCoverage = false;
dither = true;
}
bool operator==(const BlendState &a, const BlendState &b)
{
return memcmp(&a, &b, sizeof(BlendState)) == 0;
}
bool operator!=(const BlendState &a, const BlendState &b)
{
return !(a == b);
}
DepthStencilState::DepthStencilState()
{
memset(this, 0, sizeof(DepthStencilState));
depthTest = false;
depthFunc = GL_LESS;
depthMask = true;
stencilTest = false;
stencilFunc = GL_ALWAYS;
stencilMask = static_cast<GLuint>(-1);
stencilWritemask = static_cast<GLuint>(-1);
stencilBackFunc = GL_ALWAYS;
stencilBackMask = static_cast<GLuint>(-1);
stencilBackWritemask = static_cast<GLuint>(-1);
stencilFail = GL_KEEP;
stencilPassDepthFail = GL_KEEP;
stencilPassDepthPass = GL_KEEP;
stencilBackFail = GL_KEEP;
stencilBackPassDepthFail = GL_KEEP;
stencilBackPassDepthPass = GL_KEEP;
}
bool operator==(const DepthStencilState &a, const DepthStencilState &b)
{
return memcmp(&a, &b, sizeof(DepthStencilState)) == 0;
}
bool operator!=(const DepthStencilState &a, const DepthStencilState &b)
{
return !(a == b);
}
SamplerState::SamplerState()
: minFilter(GL_NEAREST_MIPMAP_LINEAR),
magFilter(GL_LINEAR),
wrapS(GL_REPEAT),
wrapT(GL_REPEAT),
wrapR(GL_REPEAT),
maxAnisotropy(1.0f),
minLod(-1000.0f),
maxLod(1000.0f),
compareMode(GL_NONE),
compareFunc(GL_LEQUAL),
sRGBDecode(GL_DECODE_EXT)
{
memset(this, 0, sizeof(SamplerState));
minFilter = GL_NEAREST_MIPMAP_LINEAR;
magFilter = GL_LINEAR;
wrapS = GL_REPEAT;
wrapT = GL_REPEAT;
wrapR = GL_REPEAT;
maxAnisotropy = 1.0f;
minLod = -1000.0f;
maxLod = 1000.0f;
compareMode = GL_NONE;
compareFunc = GL_LEQUAL;
sRGBDecode = GL_DECODE_EXT;
}
// static
......@@ -141,4 +225,4 @@ bool operator!=(const Extents &lhs, const Extents &rhs)
{
return !(lhs == rhs);
}
}
} // namespace gl
......@@ -111,9 +111,11 @@ struct Box
bool operator!=(const Box &other) const;
};
struct RasterizerState
struct RasterizerState final
{
// This will zero-initialize the struct, including padding.
RasterizerState();
bool cullFace;
GLenum cullMode;
GLenum frontFace;
......@@ -128,8 +130,14 @@ struct RasterizerState
bool rasterizerDiscard;
};
struct BlendState
bool operator==(const RasterizerState &a, const RasterizerState &b);
bool operator!=(const RasterizerState &a, const RasterizerState &b);
struct BlendState final
{
// This will zero-initialize the struct, including padding.
BlendState();
bool blend;
GLenum sourceBlendRGB;
GLenum destBlendRGB;
......@@ -148,8 +156,14 @@ struct BlendState
bool dither;
};
struct DepthStencilState
bool operator==(const BlendState &a, const BlendState &b);
bool operator!=(const BlendState &a, const BlendState &b);
struct DepthStencilState final
{
// This will zero-initialize the struct, including padding.
DepthStencilState();
bool depthTest;
GLenum depthFunc;
bool depthMask;
......@@ -169,31 +183,15 @@ struct DepthStencilState
GLuint stencilBackWritemask;
};
struct DrawArraysIndirectCommand
{
GLuint count;
GLuint instanceCount;
GLuint first;
GLuint baseInstance;
};
static_assert(sizeof(DrawArraysIndirectCommand) == 16,
"Unexpected size of DrawArraysIndirectCommand");
struct DrawElementsIndirectCommand
{
GLuint count;
GLuint primCount;
GLuint firstIndex;
GLint baseVertex;
GLuint baseInstance;
};
static_assert(sizeof(DrawElementsIndirectCommand) == 20,
"Unexpected size of DrawElementsIndirectCommand");
bool operator==(const DepthStencilState &a, const DepthStencilState &b);
bool operator!=(const DepthStencilState &a, const DepthStencilState &b);
// State from Table 6.10 (state per sampler object)
struct SamplerState
struct SamplerState final
{
// This will zero-initialize the struct, including padding.
SamplerState();
static SamplerState CreateDefaultForTarget(GLenum target);
GLenum minFilter;
......@@ -218,6 +216,27 @@ struct SamplerState
bool operator==(const SamplerState &a, const SamplerState &b);
bool operator!=(const SamplerState &a, const SamplerState &b);
struct DrawArraysIndirectCommand
{
GLuint count;
GLuint instanceCount;
GLuint first;
GLuint baseInstance;
};
static_assert(sizeof(DrawArraysIndirectCommand) == 16,
"Unexpected size of DrawArraysIndirectCommand");
struct DrawElementsIndirectCommand
{
GLuint count;
GLuint primCount;
GLuint firstIndex;
GLint baseVertex;
GLuint baseInstance;
};
static_assert(sizeof(DrawElementsIndirectCommand) == 20,
"Unexpected size of DrawElementsIndirectCommand");
struct PixelStoreStateBase
{
BindingPointer<Buffer> pixelBuffer;
......
......@@ -24,16 +24,7 @@ inline bool operator!=(const Rectangle &a, const Rectangle &b)
inline bool operator==(const SamplerState &a, const SamplerState &b)
{
return a.minFilter == b.minFilter &&
a.magFilter == b.magFilter &&
a.wrapS == b.wrapS &&
a.wrapT == b.wrapT &&
a.wrapR == b.wrapR &&
a.maxAnisotropy == b.maxAnisotropy &&
a.minLod == b.minLod &&
a.maxLod == b.maxLod &&
a.compareMode == b.compareMode &&
a.compareFunc == b.compareFunc;
return memcmp(&a, &b, sizeof(SamplerState)) == 0;
}
inline bool operator!=(const SamplerState &a, const SamplerState &b)
......@@ -41,4 +32,4 @@ inline bool operator!=(const SamplerState &a, const SamplerState &b)
return !(a == b);
}
}
} // namespace gl
......@@ -36,12 +36,10 @@ const unsigned int RenderStateCache::kMaxSamplerStates = 2048;
RenderStateCache::RenderStateCache(Renderer11 *renderer)
: mRenderer(renderer),
mCounter(0),
mBlendStateCache(kMaxBlendStates, HashBlendState, CompareBlendStates),
mRasterizerStateCache(kMaxRasterizerStates, HashRasterizerState, CompareRasterizerStates),
mDepthStencilStateCache(kMaxDepthStencilStates,
HashDepthStencilState,
CompareDepthStencilStates),
mSamplerStateCache(kMaxSamplerStates, HashSamplerState, CompareSamplerStates)
mBlendStateCache(kMaxBlendStates, HashBlendState),
mRasterizerStateCache(kMaxRasterizerStates, HashRasterizerState),
mDepthStencilStateCache(kMaxDepthStencilStates, HashDepthStencilState),
mSamplerStateCache(kMaxSamplerStates, HashSamplerState)
{
}
......@@ -68,13 +66,6 @@ std::size_t RenderStateCache::HashBlendState(const d3d11::BlendStateKey &blendSt
}
// static
bool RenderStateCache::CompareBlendStates(const d3d11::BlendStateKey &a,
const d3d11::BlendStateKey &b)
{
return memcmp(&a, &b, sizeof(d3d11::BlendStateKey)) == 0;
}
// static
d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState)
{
......@@ -184,25 +175,19 @@ gl::Error RenderStateCache::getBlendState(const d3d11::BlendStateKey &key,
}
// static
std::size_t RenderStateCache::HashRasterizerState(const RasterizerStateKey &rasterState)
std::size_t RenderStateCache::HashRasterizerState(const d3d11::RasterizerStateKey &rasterState)
{
static const unsigned int seed = 0xABCDEF98;
std::size_t hash = 0;
MurmurHash3_x86_32(&rasterState, sizeof(RasterizerStateKey), seed, &hash);
MurmurHash3_x86_32(&rasterState, sizeof(d3d11::RasterizerStateKey), seed, &hash);
return hash;
}
// static
bool RenderStateCache::CompareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b)
{
return memcmp(&a, &b, sizeof(RasterizerStateKey)) == 0;
}
gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState)
{
RasterizerStateKey key = {};
d3d11::RasterizerStateKey key;
key.rasterizerState = rasterState;
key.scissorEnabled = scissorEnabled;
......@@ -281,12 +266,6 @@ std::size_t RenderStateCache::HashDepthStencilState(const gl::DepthStencilState
return hash;
}
// static
bool RenderStateCache::CompareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b)
{
return memcmp(&a, &b, sizeof(gl::DepthStencilState)) == 0;
}
gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &glState,
ID3D11DepthStencilState **outDSState)
{
......@@ -350,12 +329,6 @@ std::size_t RenderStateCache::HashSamplerState(const gl::SamplerState &samplerSt
return hash;
}
// static
bool RenderStateCache::CompareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b)
{
return memcmp(&a, &b, sizeof(gl::SamplerState)) == 0;
}
gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState)
{
SamplerStateMap::iterator keyIter = mSamplerStateCache.find(samplerState);
......
......@@ -48,62 +48,46 @@ class RenderStateCache : angle::NonCopyable
// Blend state cache
static std::size_t HashBlendState(const d3d11::BlendStateKey &blendState);
static bool CompareBlendStates(const d3d11::BlendStateKey &a, const d3d11::BlendStateKey &b);
static const unsigned int kMaxBlendStates;
typedef std::size_t (*BlendStateHashFunction)(const d3d11::BlendStateKey &);
typedef bool (*BlendStateEqualityFunction)(const d3d11::BlendStateKey &,
const d3d11::BlendStateKey &);
typedef std::pair<d3d11::BlendState, unsigned long long> BlendStateCounterPair;
typedef std::unordered_map<d3d11::BlendStateKey,
BlendStateCounterPair,
BlendStateHashFunction,
BlendStateEqualityFunction>
typedef std::unordered_map<d3d11::BlendStateKey, BlendStateCounterPair, BlendStateHashFunction>
BlendStateMap;
BlendStateMap mBlendStateCache;
// Rasterizer state cache
struct RasterizerStateKey
{
gl::RasterizerState rasterizerState;
bool scissorEnabled;
};
static std::size_t HashRasterizerState(const RasterizerStateKey &rasterState);
static bool CompareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b);
static std::size_t HashRasterizerState(const d3d11::RasterizerStateKey &rasterState);
static const unsigned int kMaxRasterizerStates;
typedef std::size_t (*RasterizerStateHashFunction)(const RasterizerStateKey &);
typedef bool (*RasterizerStateEqualityFunction)(const RasterizerStateKey &, const RasterizerStateKey &);
typedef std::size_t (*RasterizerStateHashFunction)(const d3d11::RasterizerStateKey &);
typedef std::pair<d3d11::RasterizerState, unsigned long long> RasterizerStateCounterPair;
typedef std::unordered_map<RasterizerStateKey, RasterizerStateCounterPair, RasterizerStateHashFunction, RasterizerStateEqualityFunction> RasterizerStateMap;
typedef std::unordered_map<d3d11::RasterizerStateKey,
RasterizerStateCounterPair,
RasterizerStateHashFunction>
RasterizerStateMap;
RasterizerStateMap mRasterizerStateCache;
// Depth stencil state cache
static std::size_t HashDepthStencilState(const gl::DepthStencilState &dsState);
static bool CompareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b);
static const unsigned int kMaxDepthStencilStates;
typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &);
typedef bool (*DepthStencilStateEqualityFunction)(const gl::DepthStencilState &, const gl::DepthStencilState &);
typedef std::pair<d3d11::DepthStencilState, unsigned long long> DepthStencilStateCounterPair;
typedef std::unordered_map<gl::DepthStencilState,
DepthStencilStateCounterPair,
DepthStencilStateHashFunction,
DepthStencilStateEqualityFunction> DepthStencilStateMap;
DepthStencilStateHashFunction>
DepthStencilStateMap;
DepthStencilStateMap mDepthStencilStateCache;
// Sample state cache
static std::size_t HashSamplerState(const gl::SamplerState &samplerState);
static bool CompareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b);
static const unsigned int kMaxSamplerStates;
typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &);
typedef bool (*SamplerStateEqualityFunction)(const gl::SamplerState &, const gl::SamplerState &);
typedef std::pair<d3d11::SamplerState, unsigned long long> SamplerStateCounterPair;
typedef std::unordered_map<gl::SamplerState,
SamplerStateCounterPair,
SamplerStateHashFunction,
SamplerStateEqualityFunction> SamplerStateMap;
typedef std::unordered_map<gl::SamplerState, SamplerStateCounterPair, SamplerStateHashFunction>
SamplerStateMap;
SamplerStateMap mSamplerStateCache;
};
......
......@@ -1872,6 +1872,36 @@ void SetPositionLayerTexCoord3DVertex(PositionLayerTexCoord3DVertex* vertex, flo
vertex->s = s;
}
BlendStateKey::BlendStateKey()
{
memset(this, 0, sizeof(BlendStateKey));
}
bool operator==(const BlendStateKey &a, const BlendStateKey &b)
{
return memcmp(&a, &b, sizeof(BlendStateKey)) == 0;
}
bool operator!=(const BlendStateKey &a, const BlendStateKey &b)
{
return !(a == b);
}
RasterizerStateKey::RasterizerStateKey()
{
memset(this, 0, sizeof(RasterizerStateKey));
}
bool operator==(const RasterizerStateKey &a, const RasterizerStateKey &b)
{
return memcmp(&a, &b, sizeof(RasterizerStateKey)) == 0;
}
bool operator!=(const RasterizerStateKey &a, const RasterizerStateKey &b)
{
return !(a == b);
}
HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name)
{
#if defined(_DEBUG)
......
......@@ -120,13 +120,31 @@ struct PositionVertex
float x, y, z, w;
};
struct BlendStateKey
struct BlendStateKey final
{
// This will zero-initialize the struct, including padding.
BlendStateKey();
gl::BlendState blendState;
bool mrt;
uint8_t rtvMasks[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
};
bool operator==(const BlendStateKey &a, const BlendStateKey &b);
bool operator!=(const BlendStateKey &a, const BlendStateKey &b);
struct RasterizerStateKey final
{
// This will zero-initialize the struct, including padding.
RasterizerStateKey();
gl::RasterizerState rasterizerState;
bool scissorEnabled;
};
bool operator==(const RasterizerStateKey &a, const RasterizerStateKey &b);
bool operator!=(const RasterizerStateKey &a, const RasterizerStateKey &b);
HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name);
template <typename T>
......
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