Make Constants a singleton instead of a global

This cl changes Constants into a singleton. The constructor of Constants previously ran at library load time, and this implementation of the singleton pattern achieves running the construction on first use. This saves startup time, and omits the construction entirely when no draw call or compute invocation is made. Bug: b/175073772 Change-Id: I58727c6e5b8cf9a17d548707222d39cad92fb4c1 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/50849 Commit-Queue: Alexis Hétu <sugoi@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 84b9bb66
...@@ -147,7 +147,7 @@ inline bool setBatchIndices(unsigned int batch[128][3], VkPrimitiveTopology topo ...@@ -147,7 +147,7 @@ inline bool setBatchIndices(unsigned int batch[128][3], VkPrimitiveTopology topo
DrawCall::DrawCall() DrawCall::DrawCall()
{ {
data = (DrawData *)allocate(sizeof(DrawData)); data = (DrawData *)allocate(sizeof(DrawData));
data->constants = &constants; data->constants = &Constants::Get();
} }
DrawCall::~DrawCall() DrawCall::~DrawCall()
......
...@@ -234,7 +234,7 @@ void ComputeProgram::run( ...@@ -234,7 +234,7 @@ void ComputeProgram::run(
data.invocationsPerWorkgroup = invocationsPerWorkgroup; data.invocationsPerWorkgroup = invocationsPerWorkgroup;
data.subgroupsPerWorkgroup = subgroupsPerWorkgroup; data.subgroupsPerWorkgroup = subgroupsPerWorkgroup;
data.pushConstants = pushConstants; data.pushConstants = pushConstants;
data.constants = &sw::constants; data.constants = &sw::Constants::Get();
marl::WaitGroup wg; marl::WaitGroup wg;
const uint32_t batchCount = 16; const uint32_t batchCount = 16;
......
...@@ -21,7 +21,11 @@ ...@@ -21,7 +21,11 @@
namespace sw { namespace sw {
Constants constants; const Constants &Constants::Get()
{
static const Constants constants;
return constants;
}
Constants::Constants() Constants::Constants()
{ {
......
...@@ -23,7 +23,7 @@ namespace sw { ...@@ -23,7 +23,7 @@ namespace sw {
struct Constants struct Constants
{ {
Constants(); static const Constants &Get();
unsigned int transposeBit0[16]; unsigned int transposeBit0[16];
unsigned int transposeBit1[16]; unsigned int transposeBit1[16];
...@@ -138,9 +138,10 @@ struct Constants ...@@ -138,9 +138,10 @@ struct Constants
float4 unscaleFixed; float4 unscaleFixed;
float half2float[65536]; float half2float[65536];
};
extern Constants constants; private:
Constants();
};
} // namespace sw } // namespace sw
......
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