PR feedback

This commit is contained in:
Brad Davis 2018-09-12 11:47:32 -07:00
parent cfff28ad0a
commit 37cf37e3e1
8 changed files with 108 additions and 119 deletions

View file

@ -150,7 +150,6 @@ void GLBackend::init() {
}); });
} }
GLBackend::GLBackend(bool syncCache) { GLBackend::GLBackend(bool syncCache) {
_pipeline._cameraCorrectionBuffer._buffer->flush(); _pipeline._cameraCorrectionBuffer._buffer->flush();
initShaderBinaryCache(); initShaderBinaryCache();

View file

@ -39,6 +39,7 @@
#define GPU_STEREO_TECHNIQUE_INSTANCED #define GPU_STEREO_TECHNIQUE_INSTANCED
#endif #endif
// Let these be configured by the one define picked above // Let these be configured by the one define picked above
#ifdef GPU_STEREO_TECHNIQUE_DOUBLED_SIMPLE #ifdef GPU_STEREO_TECHNIQUE_DOUBLED_SIMPLE
#define GPU_STEREO_DRAWCALL_DOUBLED #define GPU_STEREO_DRAWCALL_DOUBLED
@ -208,9 +209,8 @@ class GLBackend : public Backend, public std::enable_shared_from_this<GLBackend>
protected: protected:
explicit GLBackend(bool syncCache); explicit GLBackend(bool syncCache);
GLBackend(); GLBackend();
public: public:
#if defined(USE_GLES) #if defined(USE_GLES)
// https://www.khronos.org/registry/OpenGL-Refpages/es3/html/glGet.xhtml // https://www.khronos.org/registry/OpenGL-Refpages/es3/html/glGet.xhtml
static const GLint MIN_REQUIRED_TEXTURE_IMAGE_UNITS = 16; static const GLint MIN_REQUIRED_TEXTURE_IMAGE_UNITS = 16;
@ -251,8 +251,8 @@ public:
// This is the ugly "download the pixels to sysmem for taking a snapshot" // This is the ugly "download the pixels to sysmem for taking a snapshot"
// Just avoid using it, it's ugly and will break performances // Just avoid using it, it's ugly and will break performances
virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer,
const Vec4i& region, const Vec4i& region, QImage& destImage) final override;
QImage& destImage) final override;
// this is the maximum numeber of available input buffers // this is the maximum numeber of available input buffers
size_t getNumInputBuffers() const { return _input._invalidBuffers.size(); } size_t getNumInputBuffers() const { return _input._invalidBuffers.size(); }
@ -273,6 +273,7 @@ public:
static const int MAX_NUM_RESOURCE_TABLE_TEXTURES = 2; static const int MAX_NUM_RESOURCE_TABLE_TEXTURES = 2;
size_t getMaxNumResourceTextureTables() const { return MAX_NUM_RESOURCE_TABLE_TEXTURES; } size_t getMaxNumResourceTextureTables() const { return MAX_NUM_RESOURCE_TABLE_TEXTURES; }
// Draw Stage // Draw Stage
virtual void do_draw(const Batch& batch, size_t paramOffset) = 0; virtual void do_draw(const Batch& batch, size_t paramOffset) = 0;
virtual void do_drawIndexed(const Batch& batch, size_t paramOffset) = 0; virtual void do_drawIndexed(const Batch& batch, size_t paramOffset) = 0;
@ -324,6 +325,7 @@ public:
// Reset stages // Reset stages
virtual void do_resetStages(const Batch& batch, size_t paramOffset) final; 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_disableContextViewCorrection(const Batch& batch, size_t paramOffset) final;
virtual void do_restoreContextViewCorrection(const Batch& batch, size_t paramOffset) final; virtual void do_restoreContextViewCorrection(const Batch& batch, size_t paramOffset) final;
@ -368,9 +370,7 @@ public:
virtual void do_setStateAntialiasedLineEnable(bool enable) final; virtual void do_setStateAntialiasedLineEnable(bool enable) final;
virtual void do_setStateDepthBias(Vec2 bias) final; virtual void do_setStateDepthBias(Vec2 bias) final;
virtual void do_setStateDepthTest(State::DepthTest test) final; virtual void do_setStateDepthTest(State::DepthTest test) final;
virtual void do_setStateStencil(State::StencilActivation activation, virtual void do_setStateStencil(State::StencilActivation activation, State::StencilTest frontTest, State::StencilTest backTest) final;
State::StencilTest frontTest,
State::StencilTest backTest) final;
virtual void do_setStateAlphaToCoverageEnable(bool enable) final; virtual void do_setStateAlphaToCoverageEnable(bool enable) final;
virtual void do_setStateSampleMask(uint32 mask) final; virtual void do_setStateSampleMask(uint32 mask) final;
virtual void do_setStateBlend(State::BlendFunction blendFunction) final; virtual void do_setStateBlend(State::BlendFunction blendFunction) final;
@ -399,9 +399,7 @@ public:
virtual void releaseQuery(GLuint id) const; virtual void releaseQuery(GLuint id) const;
virtual void queueLambda(const std::function<void()> lambda) const; virtual void queueLambda(const std::function<void()> lambda) const;
bool isTextureManagementSparseEnabled() const override { bool isTextureManagementSparseEnabled() const override { return (_textureManagement._sparseCapable && Texture::getEnableSparseTextures()); }
return (_textureManagement._sparseCapable && Texture::getEnableSparseTextures());
}
protected: protected:
virtual GLint getRealUniformLocation(GLint location) const; virtual GLint getRealUniformLocation(GLint location) const;
@ -457,28 +455,22 @@ protected:
BuffersState _invalidBuffers{ 0 }; BuffersState _invalidBuffers{ 0 };
BuffersState _attribBindingBuffers{ 0 }; BuffersState _attribBindingBuffers{ 0 };
std::vector<BufferReference> _buffers{ MAX_NUM_INPUT_BUFFERS, GPU_REFERENCE_INIT_VALUE }; std::array<BufferReference, MAX_NUM_INPUT_BUFFERS> _buffers{};
Offsets _bufferOffsets; std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferOffsets{};
Offsets _bufferStrides; std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferStrides{};
std::vector<GLuint> _bufferVBOs; std::array<GLuint, MAX_NUM_INPUT_BUFFERS> _bufferVBOs{};
glm::vec4 _colorAttribute{ 0.0f }; glm::vec4 _colorAttribute{ 0.0f };
BufferReference _indexBuffer{ GPU_REFERENCE_INIT_VALUE }; BufferReference _indexBuffer{};
Offset _indexBufferOffset { 0 }; Offset _indexBufferOffset { 0 };
Type _indexBufferType { UINT32 }; Type _indexBufferType { UINT32 };
BufferReference _indirectBuffer{ GPU_REFERENCE_INIT_VALUE }; BufferReference _indirectBuffer{};
Offset _indirectBufferOffset{ 0 }; Offset _indirectBufferOffset{ 0 };
Offset _indirectBufferStride{ 0 }; Offset _indirectBufferStride{ 0 };
GLuint _defaultVAO { 0 }; GLuint _defaultVAO { 0 };
InputStageState() {
_bufferOffsets.resize(MAX_NUM_INPUT_BUFFERS, 0);
_bufferStrides.resize(MAX_NUM_INPUT_BUFFERS, 0);
_bufferVBOs.resize(MAX_NUM_INPUT_BUFFERS, 0);
}
} _input; } _input;
virtual void initTransform() = 0; virtual void initTransform() = 0;
@ -506,10 +498,7 @@ protected:
Cameras() {}; Cameras() {};
Cameras(const TransformCamera& cam) { memcpy(_cams, &cam, sizeof(TransformCamera)); }; Cameras(const TransformCamera& cam) { memcpy(_cams, &cam, sizeof(TransformCamera)); };
Cameras(const TransformCamera& camL, const TransformCamera& camR) { Cameras(const TransformCamera& camL, const TransformCamera& camR) { memcpy(_cams, &camL, sizeof(TransformCamera)); memcpy(_cams + 1, &camR, sizeof(TransformCamera)); };
memcpy(_cams, &camL, sizeof(TransformCamera));
memcpy(_cams + 1, &camR, sizeof(TransformCamera));
};
}; };
using CameraBufferElement = Cameras; using CameraBufferElement = Cameras;
@ -534,6 +523,7 @@ protected:
CameraCorrection _correction; CameraCorrection _correction;
bool _viewCorrectionEnabled{ true }; bool _viewCorrectionEnabled{ true };
Mat4 _projection; Mat4 _projection;
Vec4i _viewport { 0, 0, 1, 1 }; Vec4i _viewport { 0, 0, 1, 1 };
Vec2 _depthRange { 0.0f, 1.0f }; Vec2 _depthRange { 0.0f, 1.0f };
@ -559,10 +549,9 @@ protected:
struct UniformStageState { struct UniformStageState {
struct BufferState { struct BufferState {
BufferReference buffer{ GPU_REFERENCE_INIT_VALUE }; BufferReference buffer{};
GLintptr offset{ 0 }; GLintptr offset{ 0 };
GLsizeiptr size{ 0 }; GLsizeiptr size{ 0 };
//BufferState(const BufferPointer& buffer = nullptr, GLintptr offset = 0, GLsizeiptr size = 0);
BufferState& operator=(const BufferState& other) = delete; 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; }
@ -592,15 +581,19 @@ protected:
// do_setResourceTextureTable (in non-bindless mode) // do_setResourceTextureTable (in non-bindless mode)
void bindResourceTexture(uint32_t slot, const TexturePointer& texture); 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 // update resource cache and do the gl unbind call with the current gpu::Texture cached at slot s
void releaseResourceTexture(uint32_t slot); void releaseResourceTexture(uint32_t slot);
void resetResourceStage(); void resetResourceStage();
struct ResourceStageState { struct ResourceStageState {
std::vector<BufferReference> _buffers{ MAX_NUM_RESOURCE_BUFFERS, BufferReference() }; struct TextureState {
std::vector<TextureReference> _textures{ MAX_NUM_RESOURCE_TEXTURES, GPU_REFERENCE_INIT_VALUE }; TextureReference _texture{};
//Textures _textures { { MAX_NUM_RESOURCE_TEXTURES } }; GLenum _target;
};
std::array<BufferReference, MAX_NUM_RESOURCE_BUFFERS> _buffers{};
std::array<TextureState, MAX_NUM_RESOURCE_TEXTURES> _textures{};
int findEmptyTextureSlot() const; int findEmptyTextureSlot() const;
} _resource; } _resource;
@ -615,7 +608,7 @@ protected:
void resetPipelineStage(); void resetPipelineStage();
struct PipelineStageState { struct PipelineStageState {
PipelineReference _pipeline{ GPU_REFERENCE_INIT_VALUE }; PipelineReference _pipeline{};
GLuint _program { 0 }; GLuint _program { 0 };
bool _cameraCorrection { false }; bool _cameraCorrection { false };
@ -623,8 +616,7 @@ protected:
bool _invalidProgram { false }; bool _invalidProgram { false };
BufferView _cameraCorrectionBuffer { gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr )) }; BufferView _cameraCorrectionBuffer { gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr )) };
BufferView _cameraCorrectionBufferIdentity{ gpu::BufferView( BufferView _cameraCorrectionBufferIdentity { gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr )) };
std::make_shared<gpu::Buffer>(sizeof(CameraCorrection), nullptr)) };
State::Data _stateCache{ State::DEFAULT }; State::Data _stateCache{ State::DEFAULT };
State::Signature _stateSignatureCache { 0 }; State::Signature _stateSignatureCache { 0 };
@ -664,7 +656,7 @@ protected:
void resetOutputStage(); void resetOutputStage();
struct OutputStageState { struct OutputStageState {
FramebufferReference _framebuffer{ GPU_REFERENCE_INIT_VALUE }; FramebufferReference _framebuffer{};
GLuint _drawFBO { 0 }; GLuint _drawFBO { 0 };
} _output; } _output;

View file

@ -19,8 +19,8 @@ using namespace gpu::gl;
void GLBackend::do_setInputFormat(const Batch& batch, size_t paramOffset) { void GLBackend::do_setInputFormat(const Batch& batch, size_t paramOffset) {
const auto& format = batch._streamFormats.get(batch._params[paramOffset]._uint); const auto& format = batch._streamFormats.get(batch._params[paramOffset]._uint);
if (!compare(_input._format, format)) { if (!compare(_input._format, format)) {
assign(_input._format, format);
if (format) { if (format) {
assign(_input._format, format);
auto inputFormat = GLInputFormat::sync((*format)); auto inputFormat = GLInputFormat::sync((*format));
assert(inputFormat); assert(inputFormat);
if (_input._formatKey != inputFormat->key) { if (_input._formatKey != inputFormat->key) {
@ -28,6 +28,7 @@ void GLBackend::do_setInputFormat(const Batch& batch, size_t paramOffset) {
_input._invalidFormat = true; _input._invalidFormat = true;
} }
} else { } else {
reset(_input._format);
_input._formatKey.clear(); _input._formatKey.clear();
_input._invalidFormat = true; _input._invalidFormat = true;
} }

View file

@ -25,15 +25,19 @@ using namespace gpu::gl;
void GLBackend::syncOutputStateCache() { void GLBackend::syncOutputStateCache() {
GLint currentFBO; GLint currentFBO;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &currentFBO); glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &currentFBO);
_output._drawFBO = currentFBO; _output._drawFBO = currentFBO;
reset(_output._framebuffer); reset(_output._framebuffer);
} }
void GLBackend::resetOutputStage() { void GLBackend::resetOutputStage() {
if (valid(_output._framebuffer)) {
reset(_output._framebuffer);
_output._drawFBO = 0; _output._drawFBO = 0;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
glEnable(GL_FRAMEBUFFER_SRGB); glEnable(GL_FRAMEBUFFER_SRGB);
reset(_output._framebuffer);
} }
void GLBackend::do_setFramebuffer(const Batch& batch, size_t paramOffset) { void GLBackend::do_setFramebuffer(const Batch& batch, size_t paramOffset) {

View file

@ -140,14 +140,10 @@ void GLBackend::resetPipelineStage() {
void GLBackend::releaseUniformBuffer(uint32_t slot) { void GLBackend::releaseUniformBuffer(uint32_t slot) {
auto& bufferState = _uniform._buffers[slot]; auto& bufferState = _uniform._buffers[slot];
auto buffer = acquire(bufferState.buffer); if (valid(bufferState.buffer)) {
if (buffer) {
auto* object = Backend::getGPUObject<GLBuffer>(*buffer);
if (object) {
glBindBufferBase(GL_UNIFORM_BUFFER, slot, 0); // RELEASE glBindBufferBase(GL_UNIFORM_BUFFER, slot, 0); // RELEASE
(void)CHECK_GL_ERROR(); (void)CHECK_GL_ERROR();
} }
}
bufferState.reset(); bufferState.reset();
} }
@ -201,18 +197,14 @@ void GLBackend::do_setUniformBuffer(const Batch& batch, size_t paramOffset) {
} }
void GLBackend::releaseResourceTexture(uint32_t slot) { void GLBackend::releaseResourceTexture(uint32_t slot) {
auto tex = acquire(_resource._textures[slot]); auto& textureState = _resource._textures[slot];
if (tex) { if (valid(textureState._texture)) {
auto* object = Backend::getGPUObject<GLTexture>(*tex);
if (object) {
GLuint target = object->_target;
glActiveTexture(GL_TEXTURE0 + slot); glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(target, 0); // RELEASE glBindTexture(textureState._target, 0); // RELEASE
(void)CHECK_GL_ERROR(); (void)CHECK_GL_ERROR();
reset(textureState._texture);
} }
} }
reset(_resource._textures[slot]);
}
void GLBackend::resetResourceStage() { void GLBackend::resetResourceStage() {
uint32_t i; uint32_t i;
@ -299,8 +291,9 @@ void GLBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, si
} }
void GLBackend::setResourceTexture(unsigned int slot, const TexturePointer& resourceTexture) { void GLBackend::setResourceTexture(unsigned int slot, const TexturePointer& resourceTexture) {
auto& textureState = _resource._textures[slot];
// check cache before thinking // check cache before thinking
if (compare(_resource._textures[slot], resourceTexture)) { if (compare(textureState._texture, resourceTexture)) {
return; return;
} }
@ -310,15 +303,12 @@ void GLBackend::setResourceTexture(unsigned int slot, const TexturePointer& reso
// Always make sure the GLObject is in sync // Always make sure the GLObject is in sync
GLTexture* object = syncGPUObject(resourceTexture); GLTexture* object = syncGPUObject(resourceTexture);
if (object) { if (object) {
assign(textureState._texture, resourceTexture);
GLuint to = object->_texture; GLuint to = object->_texture;
GLuint target = object->_target; textureState._target = object->_target;
glActiveTexture(GL_TEXTURE0 + slot); glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(target, to); glBindTexture(textureState._target, to);
(void)CHECK_GL_ERROR(); (void)CHECK_GL_ERROR();
assign(_resource._textures[slot], resourceTexture);
_stats._RSAmountTextureMemoryBounded += (int)object->size(); _stats._RSAmountTextureMemoryBounded += (int)object->size();
} else { } else {
@ -343,7 +333,7 @@ void GLBackend::do_setResourceTextureTable(const Batch& batch, size_t paramOffse
int GLBackend::ResourceStageState::findEmptyTextureSlot() const { int GLBackend::ResourceStageState::findEmptyTextureSlot() const {
// start from the end of the slots, try to find an empty one that can be used // start from the end of the slots, try to find an empty one that can be used
for (auto i = MAX_NUM_RESOURCE_TEXTURES - 1; i > 0; i--) { for (auto i = MAX_NUM_RESOURCE_TEXTURES - 1; i > 0; i--) {
if (!valid(_textures[i])) { if (!valid(_textures[i]._texture)) {
return i; return i;
} }
} }

View file

@ -117,7 +117,11 @@ bool GL41Backend::bindResourceBuffer(uint32_t slot, const BufferPointer& buffer)
} }
void GL41Backend::releaseResourceBuffer(uint32_t slot) { void GL41Backend::releaseResourceBuffer(uint32_t slot) {
reset(_resource._buffers[slot]); auto& bufferReference = _resource._buffers[slot];
auto buffer = acquire(bufferReference);
if (buffer) {
glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_BUFFER_SLOT0_TEX_UNIT + slot); glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_BUFFER_SLOT0_TEX_UNIT + slot);
glBindTexture(GL_TEXTURE_BUFFER, 0); glBindTexture(GL_TEXTURE_BUFFER, 0);
reset(bufferReference);
}
} }

View file

@ -74,8 +74,8 @@ void GL41Backend::updateInput() {
bool hasColorAttribute{ false }; bool hasColorAttribute{ false };
const auto& buffers = _input._buffers; const auto& buffers = _input._buffers;
const Offsets& offsets = _input._bufferOffsets; const auto& offsets = _input._bufferOffsets;
const Offsets& strides = _input._bufferStrides; const auto& strides = _input._bufferStrides;
const auto& attributes = format->getAttributes(); const auto& attributes = format->getAttributes();
const auto& inputChannels = format->getChannels(); const auto& inputChannels = format->getChannels();

View file

@ -76,11 +76,10 @@ bool GL45Backend::bindResourceBuffer(uint32_t slot, const BufferPointer& buffer)
} }
void GL45Backend::releaseResourceBuffer(uint32_t slot) { void GL45Backend::releaseResourceBuffer(uint32_t slot) {
auto buf = acquire(_resource._buffers[slot]); auto& bufferReference = _resource._buffers[slot];
if (buf) { auto buffer = acquire(bufferReference);
if (buffer) {
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, slot, 0); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, slot, 0);
reset(_resource._buffers[slot]); reset(bufferReference);
} }
} }