Commit 197e2514 by Ben Clayton

Device: Use std::unique_ptr instead of raw pointers

Instead of using raw pointers, use `std::unique_ptr`. Bug: b/126126820 Change-Id: Ia095f6aec1448c2153a0b0159f25a2946054e64b Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43813Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 78ec0ea4
...@@ -50,16 +50,9 @@ bool PixelProcessor::State::operator==(const State &state) const ...@@ -50,16 +50,9 @@ bool PixelProcessor::State::operator==(const State &state) const
PixelProcessor::PixelProcessor() PixelProcessor::PixelProcessor()
{ {
routineCache = nullptr;
setRoutineCacheSize(1024); setRoutineCacheSize(1024);
} }
PixelProcessor::~PixelProcessor()
{
delete routineCache;
routineCache = nullptr;
}
void PixelProcessor::setBlendConstant(const float4 &blendConstant) void PixelProcessor::setBlendConstant(const float4 &blendConstant)
{ {
// TODO(b/140935644): Check if clamp is required // TODO(b/140935644): Check if clamp is required
...@@ -86,8 +79,7 @@ void PixelProcessor::setBlendConstant(const float4 &blendConstant) ...@@ -86,8 +79,7 @@ void PixelProcessor::setBlendConstant(const float4 &blendConstant)
void PixelProcessor::setRoutineCacheSize(int cacheSize) void PixelProcessor::setRoutineCacheSize(int cacheSize)
{ {
delete routineCache; routineCache = std::make_unique<RoutineCacheType>(clamp(cacheSize, 1, 65536));
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
} }
const PixelProcessor::State PixelProcessor::update(const Context *context) const const PixelProcessor::State PixelProcessor::update(const Context *context) const
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "Memset.hpp" #include "Memset.hpp"
#include "RoutineCache.hpp" #include "RoutineCache.hpp"
#include <memory>
namespace sw { namespace sw {
class PixelShader; class PixelShader;
...@@ -146,8 +148,6 @@ public: ...@@ -146,8 +148,6 @@ public:
PixelProcessor(); PixelProcessor();
virtual ~PixelProcessor();
void setBlendConstant(const float4 &blendConstant); void setBlendConstant(const float4 &blendConstant);
const State update(const Context *context) const; const State update(const Context *context) const;
...@@ -160,7 +160,7 @@ public: ...@@ -160,7 +160,7 @@ public:
private: private:
using RoutineCacheType = RoutineCache<State, RasterizerFunction::CFunctionType>; using RoutineCacheType = RoutineCache<State, RasterizerFunction::CFunctionType>;
RoutineCacheType *routineCache; std::unique_ptr<RoutineCacheType> routineCache;
}; };
} // namespace sw } // namespace sw
......
...@@ -52,16 +52,9 @@ bool SetupProcessor::State::operator==(const State &state) const ...@@ -52,16 +52,9 @@ bool SetupProcessor::State::operator==(const State &state) const
SetupProcessor::SetupProcessor() SetupProcessor::SetupProcessor()
{ {
routineCache = nullptr;
setRoutineCacheSize(1024); setRoutineCacheSize(1024);
} }
SetupProcessor::~SetupProcessor()
{
delete routineCache;
routineCache = nullptr;
}
SetupProcessor::State SetupProcessor::update(const sw::Context *context) const SetupProcessor::State SetupProcessor::update(const sw::Context *context) const
{ {
State state; State state;
...@@ -117,8 +110,7 @@ SetupProcessor::RoutineType SetupProcessor::routine(const State &state) ...@@ -117,8 +110,7 @@ SetupProcessor::RoutineType SetupProcessor::routine(const State &state)
void SetupProcessor::setRoutineCacheSize(int cacheSize) void SetupProcessor::setRoutineCacheSize(int cacheSize)
{ {
delete routineCache; routineCache = std::make_unique<RoutineCacheType>(clamp(cacheSize, 1, 65536));
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
} }
} // namespace sw } // namespace sw
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "System/Types.hpp" #include "System/Types.hpp"
#include <Pipeline/SpirvShader.hpp> #include <Pipeline/SpirvShader.hpp>
#include <memory>
namespace sw { namespace sw {
struct Primitive; struct Primitive;
...@@ -71,8 +73,6 @@ public: ...@@ -71,8 +73,6 @@ public:
SetupProcessor(); SetupProcessor();
~SetupProcessor();
State update(const sw::Context *context) const; State update(const sw::Context *context) const;
RoutineType routine(const State &state); RoutineType routine(const State &state);
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
private: private:
using RoutineCacheType = RoutineCache<State, SetupFunction::CFunctionType>; using RoutineCacheType = RoutineCache<State, SetupFunction::CFunctionType>;
RoutineCacheType *routineCache; std::unique_ptr<RoutineCacheType> routineCache;
}; };
} // namespace sw } // namespace sw
......
...@@ -57,20 +57,12 @@ bool VertexProcessor::State::operator==(const State &state) const ...@@ -57,20 +57,12 @@ bool VertexProcessor::State::operator==(const State &state) const
VertexProcessor::VertexProcessor() VertexProcessor::VertexProcessor()
{ {
routineCache = nullptr;
setRoutineCacheSize(1024); setRoutineCacheSize(1024);
} }
VertexProcessor::~VertexProcessor()
{
delete routineCache;
routineCache = nullptr;
}
void VertexProcessor::setRoutineCacheSize(int cacheSize) void VertexProcessor::setRoutineCacheSize(int cacheSize)
{ {
delete routineCache; routineCache = std::make_unique<RoutineCacheType>(clamp(cacheSize, 1, 65536));
routineCache = new RoutineCacheType(clamp(cacheSize, 1, 65536));
} }
const VertexProcessor::State VertexProcessor::update(const sw::Context *context) const VertexProcessor::State VertexProcessor::update(const sw::Context *context)
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "Vertex.hpp" #include "Vertex.hpp"
#include "Pipeline/SpirvShader.hpp" #include "Pipeline/SpirvShader.hpp"
#include <memory>
namespace sw { namespace sw {
struct DrawData; struct DrawData;
...@@ -92,8 +94,6 @@ public: ...@@ -92,8 +94,6 @@ public:
VertexProcessor(); VertexProcessor();
virtual ~VertexProcessor();
const State update(const sw::Context *context); const State update(const sw::Context *context);
RoutineType routine(const State &state, vk::PipelineLayout const *pipelineLayout, RoutineType routine(const State &state, vk::PipelineLayout const *pipelineLayout,
SpirvShader const *vertexShader, const vk::DescriptorSet::Bindings &descriptorSets); SpirvShader const *vertexShader, const vk::DescriptorSet::Bindings &descriptorSets);
...@@ -102,7 +102,7 @@ public: ...@@ -102,7 +102,7 @@ public:
private: private:
using RoutineCacheType = RoutineCache<State, VertexRoutineFunction::CFunctionType>; using RoutineCacheType = RoutineCache<State, VertexRoutineFunction::CFunctionType>;
RoutineCacheType *routineCache; std::unique_ptr<RoutineCacheType> routineCache;
}; };
} // 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