Commit e899321b by Nicolas Capens Committed by Nicolas Capens

Refactor remaining cases of memset(this, ...)

Use Memset<T> as the first base class of cache key types to ensure they get initialized before any other base classes or members get constructed. Bug: b/134932616 Change-Id: I8f28252696d6e017db11da068180d2425cdf1d57 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33249Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 302a9723
......@@ -20,16 +20,16 @@
#include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkImageView.hpp"
#include <string.h>
#include <cstring>
namespace sw
{
unsigned int PixelProcessor::States::computeHash()
uint32_t PixelProcessor::States::computeHash()
{
unsigned int *state = (unsigned int*)this;
unsigned int hash = 0;
uint32_t *state = reinterpret_cast<uint32_t*>(this);
uint32_t hash = 0;
for(unsigned int i = 0; i < sizeof(States) / 4; i++)
for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++)
{
hash ^= state[i];
}
......@@ -37,11 +37,6 @@ namespace sw
return hash;
}
PixelProcessor::State::State()
{
memset(this, 0, sizeof(State));
}
bool PixelProcessor::State::operator==(const State &state) const
{
if(hash != state.hash)
......@@ -49,6 +44,7 @@ namespace sw
return false;
}
static_assert(is_memcmparable<State>::value, "Cannot memcmp State");
return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
}
......
......@@ -30,9 +30,11 @@ namespace sw
class PixelProcessor
{
public:
struct States
struct States : Memset<States>
{
unsigned int computeHash();
States() : Memset(this, 0) {}
uint32_t computeHash();
uint64_t shaderID;
......@@ -70,8 +72,6 @@ namespace sw
struct State : States
{
State();
bool operator==(const State &state) const;
int colorWriteActive(int index) const
......@@ -79,7 +79,7 @@ namespace sw
return (colorWriteMask >> (index * 4)) & 0xF;
}
unsigned int hash;
uint32_t hash;
};
struct Stencil
......
......@@ -23,14 +23,16 @@
#include "Vulkan/VkDebug.hpp"
#include "Pipeline/SpirvShader.hpp"
#include <cstring>
namespace sw
{
unsigned int SetupProcessor::States::computeHash()
uint32_t SetupProcessor::States::computeHash()
{
unsigned int *state = (unsigned int*)this;
unsigned int hash = 0;
uint32_t *state = reinterpret_cast<uint32_t*>(this);
uint32_t hash = 0;
for(unsigned int i = 0; i < sizeof(States) / 4; i++)
for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++)
{
hash ^= state[i];
}
......@@ -38,11 +40,6 @@ namespace sw
return hash;
}
SetupProcessor::State::State(int i)
{
memset(this, 0, sizeof(State));
}
bool SetupProcessor::State::operator==(const State &state) const
{
if(hash != state.hash)
......@@ -50,6 +47,7 @@ namespace sw
return false;
}
static_assert(is_memcmparable<State>::value, "Cannot memcmp States");
return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
}
......
......@@ -32,9 +32,11 @@ namespace sw
class SetupProcessor
{
public:
struct States
struct States : Memset<States>
{
unsigned int computeHash();
States() : Memset(this, 0) {}
uint32_t computeHash();
bool isDrawPoint : 1;
bool isDrawLine : 1;
......@@ -53,11 +55,9 @@ namespace sw
struct State : States
{
State(int i = 0);
bool operator==(const State &states) const;
unsigned int hash;
uint32_t hash;
};
typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw);
......
......@@ -19,7 +19,7 @@
#include "System/Math.hpp"
#include "Vulkan/VkDebug.hpp"
#include <string.h>
#include <cstring>
namespace sw
{
......@@ -31,12 +31,12 @@ namespace sw
}
}
unsigned int VertexProcessor::States::computeHash()
uint32_t VertexProcessor::States::computeHash()
{
unsigned int *state = (unsigned int*)this;
unsigned int hash = 0;
uint32_t *state = reinterpret_cast<uint32_t*>(this);
uint32_t hash = 0;
for(unsigned int i = 0; i < sizeof(States) / 4; i++)
for(unsigned int i = 0; i < sizeof(States) / sizeof(uint32_t); i++)
{
hash ^= state[i];
}
......@@ -44,11 +44,6 @@ namespace sw
return hash;
}
VertexProcessor::State::State()
{
memset(this, 0, sizeof(State));
}
bool VertexProcessor::State::operator==(const State &state) const
{
if(hash != state.hash)
......@@ -56,6 +51,7 @@ namespace sw
return false;
}
static_assert(is_memcmparable<State>::value, "Cannot memcmp States");
return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
}
......
......@@ -49,9 +49,11 @@ namespace sw
class VertexProcessor
{
public:
struct States
struct States : Memset<States>
{
unsigned int computeHash();
States() : Memset(this, 0) {}
uint32_t computeHash();
uint64_t shaderID;
......@@ -73,11 +75,9 @@ namespace sw
struct State : States
{
State();
bool operator==(const State &state) const;
unsigned int hash;
uint32_t hash;
};
typedef void (*RoutinePointer)(Vertex *output, unsigned int *batch, VertexTask *vertexTask, DrawData *draw);
......
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