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) {
_pipeline._cameraCorrectionBuffer._buffer->flush();
initShaderBinaryCache();

View file

@ -39,6 +39,7 @@
#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
@ -208,9 +209,8 @@ class GLBackend : public Backend, public std::enable_shared_from_this<GLBackend>
protected:
explicit GLBackend(bool syncCache);
GLBackend();
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 +251,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,6 +273,7 @@ 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;
@ -324,6 +325,7 @@ 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;
@ -368,9 +370,7 @@ 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,9 +399,7 @@ 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;
@ -413,8 +411,8 @@ protected:
virtual bool supportsBindless() const { return false; }
static const size_t INVALID_OFFSET = (size_t)-1;
bool _inRenderTransferPass{ false };
int _currentDraw{ -1 };
bool _inRenderTransferPass { false };
int _currentDraw { -1 };
std::list<std::string> profileRanges;
mutable Mutex _trashMutex;
@ -443,42 +441,36 @@ protected:
virtual void updateInput() = 0;
struct InputStageState {
bool _invalidFormat{ true };
bool _invalidFormat { true };
bool _lastUpdateStereoState{ false };
bool _hadColorAttribute{ true };
FormatReference _format{ GPU_REFERENCE_INIT_VALUE };
std::string _formatKey;
typedef std::bitset<MAX_NUM_ATTRIBUTES> ActivationCache;
ActivationCache _attributeActivation{ 0 };
ActivationCache _attributeActivation { 0 };
typedef std::bitset<MAX_NUM_INPUT_BUFFERS> BuffersState;
BuffersState _invalidBuffers{ 0 };
BuffersState _attribBindingBuffers{ 0 };
std::vector<BufferReference> _buffers{ MAX_NUM_INPUT_BUFFERS, GPU_REFERENCE_INIT_VALUE };
Offsets _bufferOffsets;
Offsets _bufferStrides;
std::vector<GLuint> _bufferVBOs;
std::array<BufferReference, MAX_NUM_INPUT_BUFFERS> _buffers{};
std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferOffsets{};
std::array<Offset, MAX_NUM_INPUT_BUFFERS> _bufferStrides{};
std::array<GLuint, MAX_NUM_INPUT_BUFFERS> _bufferVBOs{};
glm::vec4 _colorAttribute{ 0.0f };
BufferReference _indexBuffer{ GPU_REFERENCE_INIT_VALUE };
Offset _indexBufferOffset{ 0 };
Type _indexBufferType{ UINT32 };
BufferReference _indexBuffer{};
Offset _indexBufferOffset { 0 };
Type _indexBufferType { UINT32 };
BufferReference _indirectBuffer{ GPU_REFERENCE_INIT_VALUE };
BufferReference _indirectBuffer{};
Offset _indirectBufferOffset{ 0 };
Offset _indirectBufferStride{ 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);
}
GLuint _defaultVAO { 0 };
} _input;
virtual void initTransform() = 0;
@ -504,12 +496,9 @@ protected:
struct Cameras {
TransformCamera _cams[2];
Cameras(){};
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,24 +512,25 @@ protected:
mutable std::map<std::string, GLvoid*> _drawCallInfoOffsets;
GLuint _objectBuffer{ 0 };
GLuint _cameraBuffer{ 0 };
GLuint _drawCallInfoBuffer{ 0 };
GLuint _objectBufferTexture{ 0 };
size_t _cameraUboSize{ 0 };
GLuint _objectBuffer { 0 };
GLuint _cameraBuffer { 0 };
GLuint _drawCallInfoBuffer { 0 };
GLuint _objectBufferTexture { 0 };
size_t _cameraUboSize { 0 };
bool _viewIsCamera{ false };
bool _skybox{ false };
bool _skybox { false };
Transform _view;
CameraCorrection _correction;
bool _viewCorrectionEnabled{ true };
Mat4 _projection;
Vec4i _viewport{ 0, 0, 1, 1 };
Vec2 _depthRange{ 0.0f, 1.0f };
Vec4i _viewport { 0, 0, 1, 1 };
Vec2 _depthRange { 0.0f, 1.0f };
Vec2 _projectionJitter{ 0.0f, 0.0f };
bool _invalidView{ false };
bool _invalidProj{ false };
bool _invalidViewport{ false };
bool _invalidView { false };
bool _invalidProj { false };
bool _invalidViewport { false };
bool _enabledDrawcallInfoBuffer{ false };
@ -559,10 +549,9 @@ protected:
struct UniformStageState {
struct BufferState {
BufferReference buffer{ GPU_REFERENCE_INIT_VALUE };
BufferReference buffer{};
GLintptr offset{ 0 };
GLsizeiptr size{ 0 };
//BufferState(const BufferPointer& buffer = nullptr, GLintptr offset = 0, GLsizeiptr size = 0);
BufferState& operator=(const BufferState& other) = delete;
void reset() { gpu::gl::reset(buffer); offset = 0; size = 0; }
@ -592,15 +581,19 @@ 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);
void resetResourceStage();
struct ResourceStageState {
std::vector<BufferReference> _buffers{ MAX_NUM_RESOURCE_BUFFERS, BufferReference() };
std::vector<TextureReference> _textures{ MAX_NUM_RESOURCE_TEXTURES, GPU_REFERENCE_INIT_VALUE };
//Textures _textures { { MAX_NUM_RESOURCE_TEXTURES } };
struct TextureState {
TextureReference _texture{};
GLenum _target;
};
std::array<BufferReference, MAX_NUM_RESOURCE_BUFFERS> _buffers{};
std::array<TextureState, MAX_NUM_RESOURCE_TEXTURES> _textures{};
int findEmptyTextureSlot() const;
} _resource;
@ -615,22 +608,21 @@ protected:
void resetPipelineStage();
struct PipelineStageState {
PipelineReference _pipeline{ GPU_REFERENCE_INIT_VALUE };
PipelineReference _pipeline{};
GLuint _program{ 0 };
bool _cameraCorrection{ false };
GLShader* _programShader{ nullptr };
bool _invalidProgram{ false };
GLuint _program { 0 };
bool _cameraCorrection { false };
GLShader* _programShader { nullptr };
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 _cameraCorrectionBuffer { 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 };
State::Signature _stateSignatureCache { 0 };
GLState* _state{ nullptr };
bool _invalidState{ false };
GLState* _state { nullptr };
bool _invalidState { false };
PipelineStageState() {
_cameraCorrectionBuffer.edit<CameraCorrection>() = CameraCorrection();
@ -664,13 +656,13 @@ protected:
void resetOutputStage();
struct OutputStageState {
FramebufferReference _framebuffer{ GPU_REFERENCE_INIT_VALUE };
GLuint _drawFBO{ 0 };
FramebufferReference _framebuffer{};
GLuint _drawFBO { 0 };
} _output;
void resetQueryStage();
struct QueryStageState {
uint32_t _rangeQueryDepth{ 0 };
uint32_t _rangeQueryDepth { 0 };
} _queryStage;
void resetStages();
@ -689,7 +681,7 @@ protected:
virtual void killShaderBinaryCache();
struct TextureManagementStageState {
bool _sparseCapable{ false };
bool _sparseCapable { false };
GLTextureTransferEnginePointer _transferEngine;
} _textureManagement;
virtual void initTextureManagementStage();

View file

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

View file

@ -25,15 +25,19 @@ using namespace gpu::gl;
void GLBackend::syncOutputStateCache() {
GLint currentFBO;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &currentFBO);
_output._drawFBO = currentFBO;
reset(_output._framebuffer);
}
void GLBackend::resetOutputStage() {
if (valid(_output._framebuffer)) {
reset(_output._framebuffer);
_output._drawFBO = 0;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
glEnable(GL_FRAMEBUFFER_SRGB);
reset(_output._framebuffer);
}
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) {
auto& bufferState = _uniform._buffers[slot];
auto buffer = acquire(bufferState.buffer);
if (buffer) {
auto* object = Backend::getGPUObject<GLBuffer>(*buffer);
if (object) {
if (valid(bufferState.buffer)) {
glBindBufferBase(GL_UNIFORM_BUFFER, slot, 0); // RELEASE
(void)CHECK_GL_ERROR();
}
}
bufferState.reset();
}
@ -201,17 +197,13 @@ void GLBackend::do_setUniformBuffer(const Batch& batch, size_t paramOffset) {
}
void GLBackend::releaseResourceTexture(uint32_t slot) {
auto tex = acquire(_resource._textures[slot]);
if (tex) {
auto* object = Backend::getGPUObject<GLTexture>(*tex);
if (object) {
GLuint target = object->_target;
auto& textureState = _resource._textures[slot];
if (valid(textureState._texture)) {
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(target, 0); // RELEASE
glBindTexture(textureState._target, 0); // RELEASE
(void)CHECK_GL_ERROR();
reset(textureState._texture);
}
}
reset(_resource._textures[slot]);
}
void GLBackend::resetResourceStage() {
@ -299,8 +291,9 @@ void GLBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, si
}
void GLBackend::setResourceTexture(unsigned int slot, const TexturePointer& resourceTexture) {
auto& textureState = _resource._textures[slot];
// check cache before thinking
if (compare(_resource._textures[slot], resourceTexture)) {
if (compare(textureState._texture, resourceTexture)) {
return;
}
@ -310,15 +303,12 @@ void GLBackend::setResourceTexture(unsigned int slot, const TexturePointer& reso
// Always make sure the GLObject is in sync
GLTexture* object = syncGPUObject(resourceTexture);
if (object) {
assign(textureState._texture, resourceTexture);
GLuint to = object->_texture;
GLuint target = object->_target;
textureState._target = object->_target;
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(target, to);
glBindTexture(textureState._target, to);
(void)CHECK_GL_ERROR();
assign(_resource._textures[slot], resourceTexture);
_stats._RSAmountTextureMemoryBounded += (int)object->size();
} else {
@ -343,7 +333,7 @@ void GLBackend::do_setResourceTextureTable(const Batch& batch, size_t paramOffse
int GLBackend::ResourceStageState::findEmptyTextureSlot() const {
// 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--) {
if (!valid(_textures[i])) {
if (!valid(_textures[i]._texture)) {
return i;
}
}

View file

@ -117,7 +117,11 @@ bool GL41Backend::bindResourceBuffer(uint32_t slot, const BufferPointer& buffer)
}
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);
glBindTexture(GL_TEXTURE_BUFFER, 0);
reset(bufferReference);
}
}

View file

@ -74,8 +74,8 @@ void GL41Backend::updateInput() {
bool hasColorAttribute{ false };
const auto& buffers = _input._buffers;
const Offsets& offsets = _input._bufferOffsets;
const Offsets& strides = _input._bufferStrides;
const auto& offsets = _input._bufferOffsets;
const auto& strides = _input._bufferStrides;
const auto& attributes = format->getAttributes();
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) {
auto buf = acquire(_resource._buffers[slot]);
if (buf) {
auto& bufferReference = _resource._buffers[slot];
auto buffer = acquire(bufferReference);
if (buffer) {
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, slot, 0);
reset(_resource._buffers[slot]);
reset(bufferReference);
}
}