Make android use the existing shared pointers

This commit is contained in:
Brad Davis 2018-09-12 15:04:27 -07:00
parent 700c6519bf
commit d92c62c742

View file

@ -39,7 +39,6 @@
#define GPU_STEREO_TECHNIQUE_INSTANCED
#endif
// Let these be configured by the one define picked above
#ifdef GPU_STEREO_TECHNIQUE_DOUBLED_SIMPLE
#define GPU_STEREO_DRAWCALL_DOUBLED
@ -57,23 +56,25 @@
//
// GL Backend pointer storage mechanism
// One of the following three defines must be uncommented.
// Equivalent to current state of affairs in master,
// Works pretty well, but ends up creating a lot of needless smart pointer duplication
// which means there's a high aggregate cost of manipulating std::shared_ptr counters
//#define GPU_POINTER_STORAGE_SHARED
// One of the following three defines must be defined.
// GPU_POINTER_STORAGE_SHARED
// The platonic ideal, use references to smart pointers.
// However, this produces artifacts because there are too many places in the code right now that
// create temporary values (undesirable smart pointer duplications) and then those temp variables
// get passed on and have their reference taken, and then invalidated
//#define GPU_POINTER_STORAGE_REF
// GPU_POINTER_STORAGE_REF
// Raw pointer manipulation. Seems more dangerous than the reference wrappers,
// but in practice, the danger of grabbing a reference to a temporary variable
// is causing issues
// GPU_POINTER_STORAGE_RAW
#if defined(USE_GLES)
#define GPU_POINTER_STORAGE_SHARED
#else
#define GPU_POINTER_STORAGE_RAW
#endif
namespace gpu { namespace gl {
@ -209,8 +210,8 @@ class GLBackend : public Backend, public std::enable_shared_from_this<GLBackend>
protected:
explicit GLBackend(bool syncCache);
GLBackend();
public:
public:
#if defined(USE_GLES)
// https://www.khronos.org/registry/OpenGL-Refpages/es3/html/glGet.xhtml
static const GLint MIN_REQUIRED_TEXTURE_IMAGE_UNITS = 16;
@ -251,8 +252,8 @@ public:
// This is the ugly "download the pixels to sysmem for taking a snapshot"
// Just avoid using it, it's ugly and will break performances
virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer,
const Vec4i& region, QImage& destImage) final override;
const Vec4i& region,
QImage& destImage) final override;
// this is the maximum numeber of available input buffers
size_t getNumInputBuffers() const { return _input._invalidBuffers.size(); }
@ -273,7 +274,6 @@ public:
static const int MAX_NUM_RESOURCE_TABLE_TEXTURES = 2;
size_t getMaxNumResourceTextureTables() const { return MAX_NUM_RESOURCE_TABLE_TEXTURES; }
// Draw Stage
virtual void do_draw(const Batch& batch, size_t paramOffset) = 0;
virtual void do_drawIndexed(const Batch& batch, size_t paramOffset) = 0;
@ -325,7 +325,6 @@ public:
// Reset stages
virtual void do_resetStages(const Batch& batch, size_t paramOffset) final;
virtual void do_disableContextViewCorrection(const Batch& batch, size_t paramOffset) final;
virtual void do_restoreContextViewCorrection(const Batch& batch, size_t paramOffset) final;
@ -370,7 +369,9 @@ public:
virtual void do_setStateAntialiasedLineEnable(bool enable) final;
virtual void do_setStateDepthBias(Vec2 bias) final;
virtual void do_setStateDepthTest(State::DepthTest test) final;
virtual void do_setStateStencil(State::StencilActivation activation, State::StencilTest frontTest, State::StencilTest backTest) final;
virtual void do_setStateStencil(State::StencilActivation activation,
State::StencilTest frontTest,
State::StencilTest backTest) final;
virtual void do_setStateAlphaToCoverageEnable(bool enable) final;
virtual void do_setStateSampleMask(uint32 mask) final;
virtual void do_setStateBlend(State::BlendFunction blendFunction) final;
@ -399,7 +400,9 @@ public:
virtual void releaseQuery(GLuint id) const;
virtual void queueLambda(const std::function<void()> lambda) const;
bool isTextureManagementSparseEnabled() const override { return (_textureManagement._sparseCapable && Texture::getEnableSparseTextures()); }
bool isTextureManagementSparseEnabled() const override {
return (_textureManagement._sparseCapable && Texture::getEnableSparseTextures());
}
protected:
virtual GLint getRealUniformLocation(GLint location) const;
@ -498,7 +501,10 @@ protected:
Cameras(){};
Cameras(const TransformCamera& cam) { memcpy(_cams, &cam, sizeof(TransformCamera)); };
Cameras(const TransformCamera& camL, const TransformCamera& camR) { memcpy(_cams, &camL, sizeof(TransformCamera)); memcpy(_cams + 1, &camR, sizeof(TransformCamera)); };
Cameras(const TransformCamera& camL, const TransformCamera& camR) {
memcpy(_cams, &camL, sizeof(TransformCamera));
memcpy(_cams + 1, &camR, sizeof(TransformCamera));
};
};
using CameraBufferElement = Cameras;
@ -523,7 +529,6 @@ protected:
CameraCorrection _correction;
bool _viewCorrectionEnabled{ true };
Mat4 _projection;
Vec4i _viewport{ 0, 0, 1, 1 };
Vec2 _depthRange{ 0.0f, 1.0f };
@ -554,7 +559,11 @@ protected:
GLsizeiptr size{ 0 };
BufferState& operator=(const BufferState& other) = delete;
void reset() { gpu::gl::reset(buffer); offset = 0; size = 0; }
void reset() {
gpu::gl::reset(buffer);
offset = 0;
size = 0;
}
bool compare(const BufferPointer& buffer, GLintptr offset, GLsizeiptr size) {
const auto& self = *this;
return (self.offset == offset && self.size == size && gpu::gl::compare(self.buffer, buffer));
@ -581,7 +590,6 @@ protected:
// do_setResourceTextureTable (in non-bindless mode)
void bindResourceTexture(uint32_t slot, const TexturePointer& texture);
// update resource cache and do the gl unbind call with the current gpu::Texture cached at slot s
void releaseResourceTexture(uint32_t slot);
@ -616,7 +624,8 @@ protected:
bool _invalidProgram{ false };
BufferView _cameraCorrectionBuffer{ gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr)) };
BufferView _cameraCorrectionBufferIdentity { gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr )) };
BufferView _cameraCorrectionBufferIdentity{ gpu::BufferView(
std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr)) };
State::Data _stateCache{ State::DEFAULT };
State::Signature _stateSignatureCache{ 0 };