From 162bbcf4747e67dd4a57a16c8ff320fd249fc473 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Fri, 27 Nov 2020 12:42:48 +0800 Subject: [PATCH] GLES3: immediate submission --- .../core/gfx-proxy/GFXCommandBufferProxy.h | 7 - .../core/gfx-proxy/GFXDeviceProxy.cpp | 11 +- .../renderer/core/gfx-proxy/GFXDeviceProxy.h | 16 +- native/cocos/renderer/core/gfx/GFXDevice.h | 2 +- .../renderer/core/thread/CommandEncoder.cpp | 3 - .../renderer/core/thread/CommandEncoder.h | 1 + .../cocos/renderer/gfx-gles2/GLES2Device.cpp | 2 +- native/cocos/renderer/gfx-gles2/GLES2Device.h | 2 +- .../renderer/gfx-gles3/GLES3CommandBuffer.cpp | 12 +- .../renderer/gfx-gles3/GLES3CommandBuffer.h | 7 +- .../renderer/gfx-gles3/GLES3Commands.cpp | 401 ++++++++++-------- .../cocos/renderer/gfx-gles3/GLES3Commands.h | 17 +- .../cocos/renderer/gfx-gles3/GLES3Device.cpp | 47 +- native/cocos/renderer/gfx-gles3/GLES3Device.h | 2 +- .../gfx-gles3/GLES3PipelineLayout.cpp | 2 +- .../gfx-gles3/GLES3PrimaryCommandBuffer.cpp | 62 +-- .../gfx-gles3/GLES3PrimaryCommandBuffer.h | 34 +- .../cocos/renderer/gfx-gles3/GLES3Queue.cpp | 16 +- 18 files changed, 309 insertions(+), 335 deletions(-) diff --git a/native/cocos/renderer/core/gfx-proxy/GFXCommandBufferProxy.h b/native/cocos/renderer/core/gfx-proxy/GFXCommandBufferProxy.h index 6267fb179f..40c95053fe 100755 --- a/native/cocos/renderer/core/gfx-proxy/GFXCommandBufferProxy.h +++ b/native/cocos/renderer/core/gfx-proxy/GFXCommandBufferProxy.h @@ -33,13 +33,6 @@ public: virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) override; - using CommandBuffer::begin; - using CommandBuffer::updateBuffer; - using CommandBuffer::execute; - using CommandBuffer::bindDescriptorSet; - using CommandBuffer::beginRenderPass; - using CommandBuffer::copyBuffersToTexture; - virtual uint getNumDrawCalls() const override { return _remote->getNumDrawCalls(); } virtual uint getNumInstances() const override { return _remote->getNumInstances(); } virtual uint getNumTris() const override { return _remote->getNumTris(); } diff --git a/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.cpp b/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.cpp index ca4c7c524b..13467ecd17 100755 --- a/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.cpp +++ b/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.cpp @@ -71,18 +71,13 @@ bool DeviceProxy::initialize(const DeviceInfo &info) { cbInfo.queue = _queue; for (auto &context : _contexts) { - context.commandBuffer = createCommandBuffer(cbInfo); + context.commandBuffer = createCommandBuffer(); + context.commandBuffer->initialize(cbInfo); context.encoder = CC_NEW(CommandEncoder); context.encoder->RunConsumerThread(); } - ENCODE_COMMAND_1( - getMainEncoder(), - DeviceMakeCurrent, - remote, getRemote(), - { - remote->makeCurrent(); - }); + setImmediateMode(false); return true; } diff --git a/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.h b/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.h index 4967b0077b..9235b45d51 100755 --- a/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.h +++ b/native/cocos/renderer/core/gfx-proxy/GFXDeviceProxy.h @@ -20,21 +20,6 @@ struct SubmitContext final { class CC_DLL DeviceProxy : public Proxy { public: - using Device::copyBuffersToTexture; - using Device::createBuffer; - using Device::createCommandBuffer; - using Device::createDescriptorSet; - using Device::createDescriptorSetLayout; - using Device::createFence; - using Device::createFramebuffer; - using Device::createInputAssembler; - using Device::createPipelineLayout; - using Device::createPipelineState; - using Device::createQueue; - using Device::createRenderPass; - using Device::createSampler; - using Device::createShader; - using Device::createTexture; using Proxy::Proxy; virtual bool initialize(const DeviceInfo &info) override; @@ -59,6 +44,7 @@ public: virtual PipelineState *createPipelineState() override; virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; + virtual void setImmediateMode(bool immediateMode) { return _remote->setImmediateMode(immediateMode); } virtual SurfaceTransform getSurfaceTransform() const override { return _remote->getSurfaceTransform(); } virtual uint getWidth() const override { return _remote->getWidth(); } virtual uint getHeight() const override { return _remote->getHeight(); } diff --git a/native/cocos/renderer/core/gfx/GFXDevice.h b/native/cocos/renderer/core/gfx/GFXDevice.h index a401428220..b5700601a3 100755 --- a/native/cocos/renderer/core/gfx/GFXDevice.h +++ b/native/cocos/renderer/core/gfx/GFXDevice.h @@ -70,7 +70,7 @@ public: copyBuffersToTexture(buffers.data(), dst, regions.data(), static_cast(regions.size()) ); } - virtual void makeCurrent() {} + virtual void setImmediateMode(bool immediateMode) {} virtual SurfaceTransform getSurfaceTransform() const { return _transform; } virtual uint getWidth() const { return _width; } virtual uint getHeight() const { return _height; } diff --git a/native/cocos/renderer/core/thread/CommandEncoder.cpp b/native/cocos/renderer/core/thread/CommandEncoder.cpp index 078f210ea3..2aabd229e9 100644 --- a/native/cocos/renderer/core/thread/CommandEncoder.cpp +++ b/native/cocos/renderer/core/thread/CommandEncoder.cpp @@ -79,9 +79,6 @@ void CommandEncoder::MemoryAllocator::Free(uint8_t* const chunk) noexcept CommandEncoder::CommandEncoder() { - //mImmediateMode = true; - //mFreeChunksByUser = false; - uint8_t* const chunk = MemoryAllocator::GetInstance().Request(); mW.mCurrentMemoryChunk = chunk; diff --git a/native/cocos/renderer/core/thread/CommandEncoder.h b/native/cocos/renderer/core/thread/CommandEncoder.h index ecb1a2678f..eb8990c341 100644 --- a/native/cocos/renderer/core/thread/CommandEncoder.h +++ b/native/cocos/renderer/core/thread/CommandEncoder.h @@ -113,6 +113,7 @@ public: void RecycleMemoryChunk(uint8_t* const chunk) const noexcept; static void FreeChunksInFreeQueue(CommandEncoder* const mainCommandbuffer) noexcept; + inline void SetImmediateMode(bool immediateMode) noexcept { mImmediateMode = immediateMode; } inline int GetPendingCommandCount() const noexcept { return mW.mPendingCommandCount; } inline int GetWrittenCommandCount() const noexcept { return mW.mWrittenCommandCount; } inline int GetNewCommandCount() const noexcept { return mR.mNewCommandCount; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index a22ea683a6..4c2ba82715 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -227,7 +227,7 @@ void GLES2Device::present() { queue->_numTriangles = 0; } -void GLES2Device::makeCurrent() { +void GLES2Device::setImmediateMode(bool immediateMode) { if (!_renderContext) { ContextInfo ctxInfo; ctxInfo.windowHandle = _windowHandle; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.h b/native/cocos/renderer/gfx-gles2/GLES2Device.h index 49ba0f20db..fa190afb27 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.h @@ -80,7 +80,7 @@ public: virtual PipelineLayout *createPipelineLayout() override; virtual PipelineState *createPipelineState() override; virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - virtual void makeCurrent() override; + virtual void setImmediateMode(bool immediateMode) override; CC_INLINE bool useVAO() const { return _useVAO; } CC_INLINE bool useDrawInstanced() const { return _useDrawInstanced; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp index 206b2b361c..9f357e973a 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp @@ -53,7 +53,6 @@ bool GLES3CommandBuffer::initialize(const CommandBufferInfo &info) { size_t setCount = ((GLES3Device *)_device)->bindingMappingInfo().bufferOffsets.size(); _curGPUDescriptorSets.resize(setCount); _curDynamicOffsets.resize(setCount); - _curDynamicOffsetCounts.resize(setCount); return true; } @@ -85,7 +84,6 @@ void GLES3CommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); - _curDynamicOffsetCounts.assign(_curDynamicOffsetCounts.size(), 0u); _numDrawCalls = 0; _numInstances = 0; @@ -147,7 +145,6 @@ void GLES3CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSe } if (dynamicOffsetCount) { _curDynamicOffsets[set] = dynamicOffsets; - _curDynamicOffsetCounts[set] = dynamicOffsetCount; _isStateInvalid = true; } } @@ -368,13 +365,8 @@ void GLES3CommandBuffer::BindStates() { GLES3CmdBindStates *cmd = _cmdAllocator->bindStatesCmdPool.alloc(); cmd->gpuPipelineState = _curGPUPipelineState; cmd->gpuInputAssembler = _curGPUInputAssember; - cmd->gpuDescriptorSets.push_back(_curGPUDescriptorSets[0]); - for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { - const uint *dynamicOffset = _curDynamicOffsets[i]; - uint count = _curDynamicOffsetCounts[i]; - cmd->dynamicOffsets.insert(cmd->dynamicOffsets.end(), dynamicOffset, dynamicOffset + count); - } - + cmd->gpuDescriptorSets = _curGPUDescriptorSets; + cmd->dynamicOffsets = _curDynamicOffsets; cmd->viewport = _curViewport; cmd->scissor = _curScissor; cmd->lineWidth = _curLineWidth; diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h index 597bead4aa..7c4ef22e3f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h @@ -64,16 +64,13 @@ public: protected: virtual void BindStates(); - GLES3GPUCommandAllocator *_cmdAllocator = nullptr; - GLES3CmdPackage *_curCmdPackage = nullptr; - queue _pendingPackages, _freePackages; - + GLES3CmdPackage *_cmdPackage = nullptr; + GLES3GPUCommandAllocator *_gles3Allocator = nullptr; bool _isInRenderPass = false; GLES3GPUPipelineState *_curGPUPipelineState = nullptr; GLES3GPUInputAssembler *_curGPUInputAssember = nullptr; vector _curGPUDescriptorSets; vector _curDynamicOffsets; - vector _curDynamicOffsetCounts; Viewport _curViewport; Rect _curScissor; float _curLineWidth = 1.0f; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index 6de0a7c00d..049f457fb9 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -1453,7 +1453,6 @@ void GLES3CmdFuncDestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gp } void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFramebuffer, const Rect &renderArea, size_t numClearColors, const Color *clearColors, float clearDepth, int clearStencil) { - GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; gfxStateCache.gpuRenderPass = gpuRenderPass; gfxStateCache.gpuFramebuffer = gpuFramebuffer; gfxStateCache.numClearColors = numClearColors; @@ -1464,17 +1463,17 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen if (gpuFramebuffer && gpuRenderPass) { if (cache->glFramebuffer != gpuFramebuffer->glFramebuffer) { - GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, gpuFramebuffer->glFramebuffer)); + glBindFramebuffer(GL_FRAMEBUFFER, gpuFramebuffer->glFramebuffer); cache->glFramebuffer = gpuFramebuffer->glFramebuffer; // render targets are drawn with flipped-Y - gfxStateCache.reverseCW = gpuFramebuffer->isOffscreen; + gfxStateCache.reverseCW = !!gpuFramebuffer->glFramebuffer; } if (cache->viewport.left != renderArea.x || cache->viewport.top != renderArea.y || cache->viewport.width != renderArea.width || cache->viewport.height != renderArea.height) { - GL_CHECK(glViewport(renderArea.x, renderArea.y, renderArea.width, renderArea.height)); + glViewport(renderArea.x, renderArea.y, renderArea.width, renderArea.height); cache->viewport.left = renderArea.x; cache->viewport.top = renderArea.y; cache->viewport.width = renderArea.width; @@ -1485,7 +1484,7 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen cache->scissor.y != renderArea.y || cache->scissor.width != renderArea.width || cache->scissor.height != renderArea.height) { - GL_CHECK(glScissor(renderArea.x, renderArea.y, renderArea.width, renderArea.height)); + glScissor(renderArea.x, renderArea.y, renderArea.width, renderArea.height); cache->scissor.x = renderArea.x; cache->scissor.y = renderArea.y; cache->scissor.width = renderArea.width; @@ -1501,8 +1500,8 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen switch (colorAttachment.loadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: { - if (cache->bs.targets[0].blendColorMask != ColorMask::ALL) { - GL_CHECK(glColorMask(true, true, true, true)); + if (cache->bs.targets[0]->blendColorMask != ColorMask::ALL) { + glColorMask(true, true, true, true); } if (gpuFramebuffer->isOffscreen) { @@ -1511,10 +1510,10 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen fColors[1] = clearColors[j].y; fColors[2] = clearColors[j].z; fColors[3] = clearColors[j].w; - GL_CHECK(glClearBufferfv(GL_COLOR, j, fColors)); + glClearBufferfv(GL_COLOR, j, fColors); } else { const Color &color = clearColors[j]; - GL_CHECK(glClearColor(color.x, color.y, color.z, color.w)); + glClearColor(color.x, color.y, color.z, color.w); glClears |= GL_COLOR_BUFFER_BIT; } break; @@ -1535,10 +1534,9 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: { - if (!cache->dss.depthWrite) { - GL_CHECK(glDepthMask(true)); - } - GL_CHECK(glClearDepthf(clearDepth)); + glDepthMask(true); + cache->dss.depthWrite = true; + glClearDepthf(clearDepth); glClears |= GL_DEPTH_BUFFER_BIT; break; } @@ -1556,12 +1554,12 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: { if (!cache->dss.stencilWriteMaskFront) { - GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff)); + glStencilMaskSeparate(GL_FRONT, 0xffffffff); } if (!cache->dss.stencilWriteMaskBack) { - GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff)); + glStencilMaskSeparate(GL_BACK, 0xffffffff); } - GL_CHECK(glClearStencil(clearStencil)); + glClearStencil(clearStencil); glClears |= GL_STENCIL_BUFFER_BIT; break; } @@ -1576,41 +1574,40 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen } if (numAttachments) { - GL_CHECK(glInvalidateFramebuffer(GL_FRAMEBUFFER, numAttachments, invalidAttachments)); + glInvalidateFramebuffer(GL_FRAMEBUFFER, numAttachments, invalidAttachments); } if (glClears) { - GL_CHECK(glClear(glClears)); + glClear(glClears); } // restore states if (glClears & GL_COLOR_BUFFER_BIT) { - ColorMask colorMask = cache->bs.targets[0].blendColorMask; + ColorMask colorMask = cache->bs.targets[0]->blendColorMask; if (colorMask != ColorMask::ALL) { - GL_CHECK(glColorMask((GLboolean)(colorMask & ColorMask::R), - (GLboolean)(colorMask & ColorMask::G), - (GLboolean)(colorMask & ColorMask::B), - (GLboolean)(colorMask & ColorMask::A))); + glColorMask((GLboolean)(colorMask & ColorMask::R), + (GLboolean)(colorMask & ColorMask::G), + (GLboolean)(colorMask & ColorMask::B), + (GLboolean)(colorMask & ColorMask::A)); } } - if ((glClears & GL_DEPTH_BUFFER_BIT) && !cache->dss.depthWrite) { - GL_CHECK(glDepthMask(false)); + if ((glClears & GL_COLOR_BUFFER_BIT) && !cache->dss.depthWrite) { + glDepthMask(false); } if (glClears & GL_STENCIL_BUFFER_BIT) { if (!cache->dss.stencilWriteMaskFront) { - GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0)); + glStencilMaskSeparate(GL_FRONT, 0); } if (!cache->dss.stencilWriteMaskBack) { - GL_CHECK(glStencilMaskSeparate(GL_BACK, 0)); + glStencilMaskSeparate(GL_BACK, 0); } } } } void GLES3CmdFuncEndRenderPass(GLES3Device *device) { - GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; size_t numClearColors = gfxStateCache.numClearColors; GLES3GPURenderPass *gpuRenderPass = gfxStateCache.gpuRenderPass; GLES3GPUFramebuffer *gpuFramebuffer = gfxStateCache.gpuFramebuffer; @@ -1660,15 +1657,14 @@ void GLES3CmdFuncEndRenderPass(GLES3Device *device) { } if (numAttachments) { - GL_CHECK(glInvalidateFramebuffer(GL_FRAMEBUFFER, numAttachments, invalidAttachments)); + glInvalidateFramebuffer(GL_FRAMEBUFFER, numAttachments, invalidAttachments); } } void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipelineState, GLES3GPUInputAssembler *gpuInputAssembler, - vector &gpuDescriptorSets, vector &dynamicOffsets, Viewport &viewport, Rect &scissor, + vector &gpuDescriptorSets, vector &dynamicOffsets, Viewport &viewport, Rect &scissor, float lineWidth, bool depthBiasEnabled, GLES3DepthBias &depthBias, Color &blendConstants, GLES3DepthBounds &depthBounds, GLES3StencilWriteMask &stencilWriteMask, GLES3StencilCompareMask &stencilCompareMask) { - GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLES3GPUStateCache *cache = device->stateCache(); bool isShaderChanged = false; @@ -1679,7 +1675,7 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (gpuPipelineState->gpuShader) { if (cache->glProgram != gpuPipelineState->gpuShader->glProgram) { - GL_CHECK(glUseProgram(gpuPipelineState->gpuShader->glProgram)); + glUseProgram(gpuPipelineState->gpuShader->glProgram); cache->glProgram = gpuPipelineState->gpuShader->glProgram; isShaderChanged = true; } @@ -1690,23 +1686,23 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli switch (gpuPipelineState->rs.cullMode) { case CullMode::NONE: { if (cache->isCullFaceEnabled) { - GL_CHECK(glDisable(GL_CULL_FACE)); + glDisable(GL_CULL_FACE); cache->isCullFaceEnabled = false; } } break; case CullMode::FRONT: { if (!cache->isCullFaceEnabled) { - GL_CHECK(glEnable(GL_CULL_FACE)); + glEnable(GL_CULL_FACE); cache->isCullFaceEnabled = true; } - GL_CHECK(glCullFace(GL_FRONT)); + glCullFace(GL_FRONT); } break; case CullMode::BACK: { if (!cache->isCullFaceEnabled) { - GL_CHECK(glEnable(GL_CULL_FACE)); + glEnable(GL_CULL_FACE); cache->isCullFaceEnabled = true; } - GL_CHECK(glCullFace(GL_BACK)); + glCullFace(GL_BACK); } break; default: break; @@ -1715,56 +1711,56 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } bool isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW != gfxStateCache.reverseCW; if (cache->rs.isFrontFaceCCW != isFrontFaceCCW) { - GL_CHECK(glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW)); + glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW); cache->rs.isFrontFaceCCW = isFrontFaceCCW; } if ((cache->rs.depthBias != gpuPipelineState->rs.depthBias) || (cache->rs.depthBiasSlop != gpuPipelineState->rs.depthBiasSlop)) { - GL_CHECK(glPolygonOffset(cache->rs.depthBias, cache->rs.depthBiasSlop)); + glPolygonOffset(cache->rs.depthBias, cache->rs.depthBiasSlop); cache->rs.depthBiasSlop = gpuPipelineState->rs.depthBiasSlop; } if (cache->rs.lineWidth != gpuPipelineState->rs.lineWidth) { - GL_CHECK(glLineWidth(gpuPipelineState->rs.lineWidth)); + glLineWidth(gpuPipelineState->rs.lineWidth); cache->rs.lineWidth = gpuPipelineState->rs.lineWidth; } // bind depth-stencil state if (cache->dss.depthTest != gpuPipelineState->dss.depthTest) { if (gpuPipelineState->dss.depthTest) { - GL_CHECK(glEnable(GL_DEPTH_TEST)); + glEnable(GL_DEPTH_TEST); } else { - GL_CHECK(glDisable(GL_DEPTH_TEST)); + glDisable(GL_DEPTH_TEST); } cache->dss.depthTest = gpuPipelineState->dss.depthTest; } if (cache->dss.depthWrite != gpuPipelineState->dss.depthWrite) { - GL_CHECK(glDepthMask(gpuPipelineState->dss.depthWrite)); + glDepthMask(gpuPipelineState->dss.depthWrite); cache->dss.depthWrite = gpuPipelineState->dss.depthWrite; } if (cache->dss.depthFunc != gpuPipelineState->dss.depthFunc) { - GL_CHECK(glDepthFunc(GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.depthFunc])); + glDepthFunc(GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.depthFunc]); cache->dss.depthFunc = gpuPipelineState->dss.depthFunc; } // bind depth-stencil state - front if (gpuPipelineState->dss.stencilTestFront || gpuPipelineState->dss.stencilTestBack) { if (!cache->isStencilTestEnabled) { - GL_CHECK(glEnable(GL_STENCIL_TEST)); + glEnable(GL_STENCIL_TEST); cache->isStencilTestEnabled = true; } } else { if (cache->isStencilTestEnabled) { - GL_CHECK(glDisable(GL_STENCIL_TEST)); + glDisable(GL_STENCIL_TEST); cache->isStencilTestEnabled = false; } } if (cache->dss.stencilFuncFront != gpuPipelineState->dss.stencilFuncFront || cache->dss.stencilRefFront != gpuPipelineState->dss.stencilRefFront || cache->dss.stencilReadMaskFront != gpuPipelineState->dss.stencilReadMaskFront) { - GL_CHECK(glStencilFuncSeparate(GL_FRONT, - GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncFront], - gpuPipelineState->dss.stencilRefFront, - gpuPipelineState->dss.stencilReadMaskFront)); + glStencilFuncSeparate(GL_FRONT, + GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncFront], + gpuPipelineState->dss.stencilRefFront, + gpuPipelineState->dss.stencilReadMaskFront); cache->dss.stencilFuncFront = gpuPipelineState->dss.stencilFuncFront; cache->dss.stencilRefFront = gpuPipelineState->dss.stencilRefFront; cache->dss.stencilReadMaskFront = gpuPipelineState->dss.stencilReadMaskFront; @@ -1772,16 +1768,16 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (cache->dss.stencilFailOpFront != gpuPipelineState->dss.stencilFailOpFront || cache->dss.stencilZFailOpFront != gpuPipelineState->dss.stencilZFailOpFront || cache->dss.stencilPassOpFront != gpuPipelineState->dss.stencilPassOpFront) { - GL_CHECK(glStencilOpSeparate(GL_FRONT, - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpFront], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpFront], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpFront])); + glStencilOpSeparate(GL_FRONT, + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpFront], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpFront], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpFront]); cache->dss.stencilFailOpFront = gpuPipelineState->dss.stencilFailOpFront; cache->dss.stencilZFailOpFront = gpuPipelineState->dss.stencilZFailOpFront; cache->dss.stencilPassOpFront = gpuPipelineState->dss.stencilPassOpFront; } if (cache->dss.stencilWriteMaskFront != gpuPipelineState->dss.stencilWriteMaskFront) { - GL_CHECK(glStencilMaskSeparate(GL_FRONT, gpuPipelineState->dss.stencilWriteMaskFront)); + glStencilMaskSeparate(GL_FRONT, gpuPipelineState->dss.stencilWriteMaskFront); cache->dss.stencilWriteMaskFront = gpuPipelineState->dss.stencilWriteMaskFront; } @@ -1789,10 +1785,10 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (cache->dss.stencilFuncBack != gpuPipelineState->dss.stencilFuncBack || cache->dss.stencilRefBack != gpuPipelineState->dss.stencilRefBack || cache->dss.stencilReadMaskBack != gpuPipelineState->dss.stencilReadMaskBack) { - GL_CHECK(glStencilFuncSeparate(GL_BACK, - GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncBack], - gpuPipelineState->dss.stencilRefBack, - gpuPipelineState->dss.stencilReadMaskBack)); + glStencilFuncSeparate(GL_BACK, + GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncBack], + gpuPipelineState->dss.stencilRefBack, + gpuPipelineState->dss.stencilReadMaskBack); cache->dss.stencilFuncBack = gpuPipelineState->dss.stencilFuncBack; cache->dss.stencilRefBack = gpuPipelineState->dss.stencilRefBack; cache->dss.stencilReadMaskBack = gpuPipelineState->dss.stencilReadMaskBack; @@ -1800,25 +1796,25 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (cache->dss.stencilFailOpBack != gpuPipelineState->dss.stencilFailOpBack || cache->dss.stencilZFailOpBack != gpuPipelineState->dss.stencilZFailOpBack || cache->dss.stencilPassOpBack != gpuPipelineState->dss.stencilPassOpBack) { - GL_CHECK(glStencilOpSeparate(GL_BACK, - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpBack], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpBack], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpBack])); + glStencilOpSeparate(GL_BACK, + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpBack], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpBack], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpBack]); cache->dss.stencilFailOpBack = gpuPipelineState->dss.stencilFailOpBack; cache->dss.stencilZFailOpBack = gpuPipelineState->dss.stencilZFailOpBack; cache->dss.stencilPassOpBack = gpuPipelineState->dss.stencilPassOpBack; } if (cache->dss.stencilWriteMaskBack != gpuPipelineState->dss.stencilWriteMaskBack) { - GL_CHECK(glStencilMaskSeparate(GL_BACK, gpuPipelineState->dss.stencilWriteMaskBack)); + glStencilMaskSeparate(GL_BACK, gpuPipelineState->dss.stencilWriteMaskBack); cache->dss.stencilWriteMaskBack = gpuPipelineState->dss.stencilWriteMaskBack; } // bind blend state if (cache->bs.isA2C != gpuPipelineState->bs.isA2C) { if (cache->bs.isA2C) { - GL_CHECK(glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE)); + glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); } else { - GL_CHECK(glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE)); + glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); } cache->bs.isA2C = gpuPipelineState->bs.isA2C; } @@ -1827,49 +1823,49 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli cache->bs.blendColor.z != gpuPipelineState->bs.blendColor.z || cache->bs.blendColor.w != gpuPipelineState->bs.blendColor.w) { - GL_CHECK(glBlendColor(gpuPipelineState->bs.blendColor.x, - gpuPipelineState->bs.blendColor.y, - gpuPipelineState->bs.blendColor.z, - gpuPipelineState->bs.blendColor.w)); + glBlendColor(gpuPipelineState->bs.blendColor.x, + gpuPipelineState->bs.blendColor.y, + gpuPipelineState->bs.blendColor.z, + gpuPipelineState->bs.blendColor.w); cache->bs.blendColor = gpuPipelineState->bs.blendColor; } - BlendTarget &cacheTarget = cache->bs.targets[0]; - const BlendTarget &target = gpuPipelineState->bs.targets[0]; - if (cacheTarget.blend != target.blend) { - if (!cacheTarget.blend) { - GL_CHECK(glEnable(GL_BLEND)); + BlendTarget *cacheTarget = cache->bs.targets[0]; + const BlendTarget *target = gpuPipelineState->bs.targets[0]; + if (cacheTarget->blend != target->blend) { + if (!cacheTarget->blend) { + glEnable(GL_BLEND); } else { - GL_CHECK(glDisable(GL_BLEND)); + glDisable(GL_BLEND); } - cacheTarget.blend = target.blend; + cacheTarget->blend = target->blend; } - if (cacheTarget.blendEq != target.blendEq || - cacheTarget.blendAlphaEq != target.blendAlphaEq) { - GL_CHECK(glBlendEquationSeparate(GLES3_BLEND_OPS[(int)target.blendEq], - GLES3_BLEND_OPS[(int)target.blendAlphaEq])); - cacheTarget.blendEq = target.blendEq; - cacheTarget.blendAlphaEq = target.blendAlphaEq; + if (cacheTarget->blendEq != target->blendEq || + cacheTarget->blendAlphaEq != target->blendAlphaEq) { + glBlendEquationSeparate(GLES3_BLEND_OPS[(int)target->blendEq], + GLES3_BLEND_OPS[(int)target->blendAlphaEq]); + cacheTarget->blendEq = target->blendEq; + cacheTarget->blendAlphaEq = target->blendAlphaEq; } - if (cacheTarget.blendSrc != target.blendSrc || - cacheTarget.blendDst != target.blendDst || - cacheTarget.blendSrcAlpha != target.blendSrcAlpha || - cacheTarget.blendDstAlpha != target.blendDstAlpha) { - GL_CHECK(glBlendFuncSeparate(GLES3_BLEND_FACTORS[(int)target.blendSrc], - GLES3_BLEND_FACTORS[(int)target.blendDst], - GLES3_BLEND_FACTORS[(int)target.blendSrcAlpha], - GLES3_BLEND_FACTORS[(int)target.blendDstAlpha])); - cacheTarget.blendSrc = target.blendSrc; - cacheTarget.blendDst = target.blendDst; - cacheTarget.blendSrcAlpha = target.blendSrcAlpha; - cacheTarget.blendDstAlpha = target.blendDstAlpha; + if (cacheTarget->blendSrc != target->blendSrc || + cacheTarget->blendDst != target->blendDst || + cacheTarget->blendSrcAlpha != target->blendSrcAlpha || + cacheTarget->blendDstAlpha != target->blendDstAlpha) { + glBlendFuncSeparate(GLES3_BLEND_FACTORS[(int)target->blendSrc], + GLES3_BLEND_FACTORS[(int)target->blendDst], + GLES3_BLEND_FACTORS[(int)target->blendSrcAlpha], + GLES3_BLEND_FACTORS[(int)target->blendDstAlpha]); + cacheTarget->blendSrc = target->blendSrc; + cacheTarget->blendDst = target->blendDst; + cacheTarget->blendSrcAlpha = target->blendSrcAlpha; + cacheTarget->blendDstAlpha = target->blendDstAlpha; } - if (cacheTarget.blendColorMask != target.blendColorMask) { - GL_CHECK(glColorMask((GLboolean)(target.blendColorMask & ColorMask::R), - (GLboolean)(target.blendColorMask & ColorMask::G), - (GLboolean)(target.blendColorMask & ColorMask::B), - (GLboolean)(target.blendColorMask & ColorMask::A))); - cacheTarget.blendColorMask = target.blendColorMask; + if (cacheTarget->blendColorMask != target->blendColorMask) { + glColorMask((GLboolean)(target->blendColorMask & ColorMask::R), + (GLboolean)(target->blendColorMask & ColorMask::G), + (GLboolean)(target->blendColorMask & ColorMask::B), + (GLboolean)(target->blendColorMask & ColorMask::A)); + cacheTarget->blendColorMask = target->blendColorMask; } } // if @@ -1897,15 +1893,15 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli const vector &dynamicOffsetSetIndices = dynamicOffsetIndices[glBlock.set]; int dynamicOffsetIndex = glBlock.binding < dynamicOffsetSetIndices.size() ? dynamicOffsetSetIndices[glBlock.binding] : -1; - if (dynamicOffsetIndex >= 0) offset += dynamicOffsets[dynamicOffsetIndex]; + if (dynamicOffsetIndex >= 0) offset += dynamicOffsets[glBlock.set][dynamicOffsetIndex]; if (cache->glBindUBOs[glBlock.glBinding] != gpuDescriptor.gpuBuffer->glBuffer || cache->glBindUBOOffsets[glBlock.glBinding] != offset) { if (offset) { - GL_CHECK(glBindBufferRange(GL_UNIFORM_BUFFER, glBlock.glBinding, gpuDescriptor.gpuBuffer->glBuffer, - offset, gpuDescriptor.gpuBuffer->size)); + glBindBufferRange(GL_UNIFORM_BUFFER, glBlock.glBinding, gpuDescriptor.gpuBuffer->glBuffer, + offset, gpuDescriptor.gpuBuffer->size); } else { - GL_CHECK(glBindBufferBase(GL_UNIFORM_BUFFER, glBlock.glBinding, gpuDescriptor.gpuBuffer->glBuffer)); + glBindBufferBase(GL_UNIFORM_BUFFER, glBlock.glBinding, gpuDescriptor.gpuBuffer->glBuffer); } cache->glUniformBuffer = cache->glBindUBOs[glBlock.glBinding] = gpuDescriptor.gpuBuffer->glBuffer; cache->glBindUBOOffsets[glBlock.glBinding] = offset; @@ -1934,15 +1930,15 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli GLuint glTexture = gpuDescriptor->gpuTexture->glTexture; if (cache->glTextures[unit] != glTexture) { if (cache->texUint != unit) { - GL_CHECK(glActiveTexture(GL_TEXTURE0 + unit)); + glActiveTexture(GL_TEXTURE0 + unit); cache->texUint = unit; } - GL_CHECK(glBindTexture(gpuDescriptor->gpuTexture->glTarget, glTexture)); + glBindTexture(gpuDescriptor->gpuTexture->glTarget, glTexture); cache->glTextures[unit] = glTexture; } if (cache->glSamplers[unit] != gpuDescriptor->gpuSampler->glSampler) { - GL_CHECK(glBindSampler(unit, gpuDescriptor->gpuSampler->glSampler)); + glBindSampler(unit, gpuDescriptor->gpuSampler->glSampler); cache->glSamplers[unit] = gpuDescriptor->gpuSampler->glSampler; } } @@ -1951,34 +1947,33 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } // if // bind vao - if (gpuInputAssembler && gpuPipelineState && gpuPipelineState->gpuShader && + if (gpuInputAssembler && gpuPipelineState->gpuShader && (isShaderChanged || gpuInputAssembler != gfxStateCache.gpuInputAssembler)) { gfxStateCache.gpuInputAssembler = gpuInputAssembler; if (USE_VAO) { - GLuint hash = gpuPipelineState->gpuShader->glProgram ^ device->getThreadID(); - GLuint glVAO = gpuInputAssembler->glVAOs[hash]; + GLuint glVAO = gpuInputAssembler->glVAOs[gpuPipelineState->gpuShader->glProgram]; if (!glVAO) { - GL_CHECK(glGenVertexArrays(1, &glVAO)); - gpuInputAssembler->glVAOs[hash] = glVAO; - GL_CHECK(glBindVertexArray(glVAO)); - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0)); - GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glGenVertexArrays(1, &glVAO); + gpuInputAssembler->glVAOs[gpuPipelineState->gpuShader->glProgram] = glVAO; + glBindVertexArray(glVAO); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); for (size_t j = 0; j < gpuPipelineState->gpuShader->glInputs.size(); ++j) { const GLES3GPUInput &gpuInput = gpuPipelineState->gpuShader->glInputs[j]; for (size_t a = 0; a < gpuInputAssembler->attributes.size(); ++a) { const GLES3GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[a]; if (gpuAttribute.name == gpuInput.name) { - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer)); + glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer); for (uint c = 0; c < gpuAttribute.componentCount; ++c) { GLint glLoc = gpuInput.glLoc + c; uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; - GL_CHECK(glEnableVertexAttribArray(glLoc)); + glEnableVertexAttribArray(glLoc); cache->glEnabledAttribLocs[glLoc] = true; - GL_CHECK(glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset))); - GL_CHECK(glVertexAttribDivisor(glLoc, gpuAttribute.isInstanced ? 1 : 0)); + glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset)); + glVertexAttribDivisor(glLoc, gpuAttribute.isInstanced ? 1 : 0); } break; } @@ -1986,19 +1981,19 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } if (gpuInputAssembler->gpuIndexBuffer) { - GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gpuInputAssembler->gpuIndexBuffer->glBuffer)); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gpuInputAssembler->gpuIndexBuffer->glBuffer); } - GL_CHECK(glBindVertexArray(0)); - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0)); - GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); cache->glVAO = 0; cache->glArrayBuffer = 0; cache->glElementArrayBuffer = 0; } if (cache->glVAO != glVAO) { - GL_CHECK(glBindVertexArray(glVAO)); + glBindVertexArray(glVAO); cache->glVAO = glVAO; } } else { @@ -2012,18 +2007,18 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli const GLES3GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[a]; if (gpuAttribute.name == gpuInput.name) { if (cache->glArrayBuffer != gpuAttribute.glBuffer) { - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer)); + glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer); cache->glArrayBuffer = gpuAttribute.glBuffer; } for (uint c = 0; c < gpuAttribute.componentCount; ++c) { GLint glLoc = gpuInput.glLoc + c; uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; - GL_CHECK(glEnableVertexAttribArray(glLoc)); + glEnableVertexAttribArray(glLoc); cache->glCurrentAttribLocs[glLoc] = true; cache->glEnabledAttribLocs[glLoc] = true; - GL_CHECK(glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset))); - GL_CHECK(glVertexAttribDivisor(glLoc, gpuAttribute.isInstanced ? 1 : 0)); + glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset)); + glVertexAttribDivisor(glLoc, gpuAttribute.isInstanced ? 1 : 0); } break; } @@ -2032,53 +2027,53 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (gpuInputAssembler->gpuIndexBuffer) { if (cache->glElementArrayBuffer != gpuInputAssembler->gpuIndexBuffer->glBuffer) { - GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gpuInputAssembler->gpuIndexBuffer->glBuffer)); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gpuInputAssembler->gpuIndexBuffer->glBuffer); cache->glElementArrayBuffer = gpuInputAssembler->gpuIndexBuffer->glBuffer; } } for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) { if (cache->glEnabledAttribLocs[a] != cache->glCurrentAttribLocs[a]) { - GL_CHECK(glDisableVertexAttribArray(a)); + glDisableVertexAttribArray(a); cache->glEnabledAttribLocs[a] = false; } } } } // if - if (gpuPipelineState && !gpuPipelineState->dynamicStates.empty()) { + if (gpuPipelineState) { for (DynamicStateFlagBit dynamicState : gpuPipelineState->dynamicStates) { switch (dynamicState) { case DynamicStateFlagBit::VIEWPORT: if (cache->viewport != viewport) { - GL_CHECK(glViewport(viewport.left, viewport.top, viewport.width, viewport.height)); + glViewport(viewport.left, viewport.top, viewport.width, viewport.height); cache->viewport = viewport; } break; case DynamicStateFlagBit::SCISSOR: if (cache->scissor != scissor) { - GL_CHECK(glScissor(scissor.x, scissor.y, scissor.width, scissor.height)); + glScissor(scissor.x, scissor.y, scissor.width, scissor.height); cache->scissor = scissor; } break; case DynamicStateFlagBit::LINE_WIDTH: if (cache->rs.lineWidth != lineWidth) { - GL_CHECK(glLineWidth(lineWidth)); + glLineWidth(lineWidth); cache->rs.lineWidth = lineWidth; } break; case DynamicStateFlagBit::DEPTH_BIAS: if (cache->rs.depthBiasEnabled != depthBiasEnabled) { if (depthBiasEnabled) - GL_CHECK(glEnable(GL_POLYGON_OFFSET_FILL)); + glEnable(GL_POLYGON_OFFSET_FILL); else - GL_CHECK(glDisable(GL_POLYGON_OFFSET_FILL)); + glDisable(GL_POLYGON_OFFSET_FILL); cache->rs.depthBiasEnabled = depthBiasEnabled; } if ((cache->rs.depthBias != depthBias.constant) || (cache->rs.depthBiasSlop != depthBias.slope)) { - GL_CHECK(glPolygonOffset(depthBias.constant, depthBias.slope)); + glPolygonOffset(depthBias.constant, depthBias.slope); cache->rs.depthBias = depthBias.constant; cache->rs.depthBiasSlop = depthBias.slope; } @@ -2088,10 +2083,10 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli (cache->bs.blendColor.y != gpuPipelineState->bs.blendColor.y) || (cache->bs.blendColor.z != gpuPipelineState->bs.blendColor.z) || (cache->bs.blendColor.w != gpuPipelineState->bs.blendColor.w)) { - GL_CHECK(glBlendColor(gpuPipelineState->bs.blendColor.x, - gpuPipelineState->bs.blendColor.y, - gpuPipelineState->bs.blendColor.z, - gpuPipelineState->bs.blendColor.w)); + glBlendColor(gpuPipelineState->bs.blendColor.x, + gpuPipelineState->bs.blendColor.y, + gpuPipelineState->bs.blendColor.z, + gpuPipelineState->bs.blendColor.w); cache->bs.blendColor = gpuPipelineState->bs.blendColor; } break; @@ -2099,20 +2094,20 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli switch (stencilWriteMask.face) { case StencilFace::FRONT: if (cache->dss.stencilWriteMaskFront != stencilWriteMask.writeMask) { - GL_CHECK(glStencilMaskSeparate(GL_FRONT, stencilWriteMask.writeMask)); + glStencilMaskSeparate(GL_FRONT, stencilWriteMask.writeMask); cache->dss.stencilWriteMaskFront = stencilWriteMask.writeMask; } break; case StencilFace::BACK: if (cache->dss.stencilWriteMaskBack != stencilWriteMask.writeMask) { - GL_CHECK(glStencilMaskSeparate(GL_BACK, stencilWriteMask.writeMask)); + glStencilMaskSeparate(GL_BACK, stencilWriteMask.writeMask); cache->dss.stencilWriteMaskBack = stencilWriteMask.writeMask; } break; case StencilFace::ALL: if ((cache->dss.stencilWriteMaskFront != stencilWriteMask.writeMask) || (cache->dss.stencilWriteMaskBack != stencilWriteMask.writeMask)) { - GL_CHECK(glStencilMask(stencilWriteMask.writeMask)); + glStencilMask(stencilWriteMask.writeMask); cache->dss.stencilWriteMaskFront = stencilWriteMask.writeMask; cache->dss.stencilWriteMaskBack = stencilWriteMask.writeMask; } @@ -2124,10 +2119,10 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli case StencilFace::FRONT: if ((cache->dss.stencilRefFront != (uint)stencilCompareMask.refrence) || (cache->dss.stencilReadMaskFront != stencilCompareMask.compareMask)) { - GL_CHECK(glStencilFuncSeparate(GL_FRONT, - GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], - stencilCompareMask.refrence, - stencilCompareMask.compareMask)); + glStencilFuncSeparate(GL_FRONT, + GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], + stencilCompareMask.refrence, + stencilCompareMask.compareMask); cache->dss.stencilRefFront = stencilCompareMask.refrence; cache->dss.stencilReadMaskFront = stencilCompareMask.compareMask; } @@ -2135,10 +2130,10 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli case StencilFace::BACK: if ((cache->dss.stencilRefBack != (uint)stencilCompareMask.refrence) || (cache->dss.stencilReadMaskBack != stencilCompareMask.compareMask)) { - GL_CHECK(glStencilFuncSeparate(GL_BACK, - GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack], - stencilCompareMask.refrence, - stencilCompareMask.compareMask)); + glStencilFuncSeparate(GL_BACK, + GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack], + stencilCompareMask.refrence, + stencilCompareMask.compareMask); cache->dss.stencilRefBack = stencilCompareMask.refrence; cache->dss.stencilReadMaskBack = stencilCompareMask.compareMask; } @@ -2148,14 +2143,14 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli (cache->dss.stencilReadMaskFront != stencilCompareMask.compareMask) || (cache->dss.stencilRefBack != (uint)stencilCompareMask.refrence) || (cache->dss.stencilReadMaskBack != stencilCompareMask.compareMask)) { - GL_CHECK(glStencilFuncSeparate(GL_FRONT, - GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], - stencilCompareMask.refrence, - stencilCompareMask.compareMask)); - GL_CHECK(glStencilFuncSeparate(GL_BACK, - GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack], - stencilCompareMask.refrence, - stencilCompareMask.compareMask)); + glStencilFuncSeparate(GL_FRONT, + GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], + stencilCompareMask.refrence, + stencilCompareMask.compareMask); + glStencilFuncSeparate(GL_BACK, + GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack], + stencilCompareMask.refrence, + stencilCompareMask.compareMask); cache->dss.stencilRefFront = stencilCompareMask.refrence; cache->dss.stencilReadMaskFront = stencilCompareMask.compareMask; cache->dss.stencilRefBack = stencilCompareMask.refrence; @@ -2173,7 +2168,6 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { - GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLES3GPUPipelineState *gpuPipelineState = gfxStateCache.gpuPipelineState; GLES3GPUInputAssembler *gpuInputAssembler = gfxStateCache.gpuInputAssembler; GLenum glPrimitive = gfxStateCache.glPrimitive; @@ -2185,16 +2179,16 @@ void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { uint8_t *offset = 0; offset += drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; if (drawInfo.instanceCount == 0) { - GL_CHECK(glDrawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler->glIndexType, offset)); + glDrawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler->glIndexType, offset); } else { - GL_CHECK(glDrawElementsInstanced(glPrimitive, drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, drawInfo.instanceCount)); + glDrawElementsInstanced(glPrimitive, drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, drawInfo.instanceCount); } } } else if (drawInfo.vertexCount > 0) { if (drawInfo.instanceCount == 0) { - GL_CHECK(glDrawArrays(glPrimitive, drawInfo.firstIndex, drawInfo.vertexCount)); + glDrawArrays(glPrimitive, drawInfo.firstIndex, drawInfo.vertexCount); } else { - GL_CHECK(glDrawArraysInstanced(glPrimitive, drawInfo.firstIndex, drawInfo.vertexCount, drawInfo.instanceCount)); + glDrawArraysInstanced(glPrimitive, drawInfo.firstIndex, drawInfo.vertexCount, drawInfo.instanceCount); } } } else { @@ -2205,16 +2199,16 @@ void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { uint8_t *offset = 0; offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; if (draw.instanceCount == 0) { - GL_CHECK(glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset)); + glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset); } else { - GL_CHECK(glDrawElementsInstanced(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset, draw.instanceCount)); + glDrawElementsInstanced(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset, draw.instanceCount); } } } else if (draw.vertexCount > 0) { if (draw.instanceCount == 0) { - GL_CHECK(glDrawArrays(glPrimitive, draw.firstIndex, draw.vertexCount)); + glDrawArrays(glPrimitive, draw.firstIndex, draw.vertexCount); } else { - GL_CHECK(glDrawArraysInstanced(glPrimitive, draw.firstIndex, draw.vertexCount, draw.instanceCount)); + glDrawArraysInstanced(glPrimitive, draw.firstIndex, draw.vertexCount, draw.instanceCount); } } } @@ -2223,7 +2217,6 @@ void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { } void GLES3CmdFuncUpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size) { - GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { memcpy((uint8_t *)gpuBuffer->indirects.data() + offset, buffer, size); } else if (gpuBuffer->usage & BufferUsageBit::TRANSFER_SRC) { @@ -2232,33 +2225,36 @@ void GLES3CmdFuncUpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, co switch (gpuBuffer->glTarget) { case GL_ARRAY_BUFFER: { if (device->stateCache()->glVAO) { - GL_CHECK(glBindVertexArray(0)); + glBindVertexArray(0); device->stateCache()->glVAO = 0; gfxStateCache.gpuInputAssembler = nullptr; } if (device->stateCache()->glArrayBuffer != gpuBuffer->glBuffer) { - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, gpuBuffer->glBuffer)); + glBindBuffer(GL_ARRAY_BUFFER, gpuBuffer->glBuffer); device->stateCache()->glArrayBuffer = gpuBuffer->glBuffer; } - GL_CHECK(glBufferSubData(GL_ARRAY_BUFFER, offset, size, buffer)); + glBufferSubData(GL_ARRAY_BUFFER, offset, size, buffer); break; } case GL_ELEMENT_ARRAY_BUFFER: { if (device->stateCache()->glVAO) { - GL_CHECK(glBindVertexArray(0)); + glBindVertexArray(0); device->stateCache()->glVAO = 0; gfxStateCache.gpuInputAssembler = nullptr; } if (device->stateCache()->glElementArrayBuffer != gpuBuffer->glBuffer) { - GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gpuBuffer->glBuffer)); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gpuBuffer->glBuffer); device->stateCache()->glElementArrayBuffer = gpuBuffer->glBuffer; } - GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, buffer)); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, buffer); break; } - case GFXCmdType::COPY_BUFFER_TO_TEXTURE: { - GLES3CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; - GLES3CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); + case GL_UNIFORM_BUFFER: { + if (device->stateCache()->glUniformBuffer != gpuBuffer->glBuffer) { + glBindBuffer(GL_UNIFORM_BUFFER, gpuBuffer->glBuffer); + device->stateCache()->glUniformBuffer = gpuBuffer->glBuffer; + } + glBufferSubData(GL_UNIFORM_BUFFER, offset, size, buffer); break; } default: @@ -2477,5 +2473,50 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } } +void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { + static uint cmdIndices[(int)GFXCmdType::COUNT] = {0}; + memset(cmdIndices, 0, sizeof(cmdIndices)); + + for (uint i = 0; i < cmdPackage->cmds.size(); ++i) { + GFXCmdType cmdType = cmdPackage->cmds[i]; + uint &cmdIdx = cmdIndices[(int)cmdType]; + + switch (cmdType) { + case GFXCmdType::BEGIN_RENDER_PASS: { + GLES3CmdBeginRenderPass *cmd = cmdPackage->beginRenderPassCmds[cmdIdx]; + GLES3CmdFuncBeginRenderPass(device, cmd->gpuRenderPass, cmd->gpuFBO, cmd->renderArea, cmd->numClearColors, cmd->clearColors, cmd->clearDepth, cmd->clearStencil); + break; + } + case GFXCmdType::END_RENDER_PASS: { + GLES3CmdFuncEndRenderPass(device); + break; + } + case GFXCmdType::BIND_STATES: { + GLES3CmdBindStates *cmd = cmdPackage->bindStatesCmds[cmdIdx]; + GLES3CmdFuncBindState(device, cmd->gpuPipelineState, cmd->gpuInputAssembler, cmd->gpuDescriptorSets, cmd->dynamicOffsets, cmd->viewport, cmd->scissor, cmd->lineWidth, cmd->depthBiasEnabled, cmd->depthBias, cmd->blendConstants, cmd->depthBounds, cmd->stencilWriteMask, cmd->stencilCompareMask); + break; + } // case BIND_STATES + case GFXCmdType::DRAW: { + GLES3CmdDraw *cmd = cmdPackage->drawCmds[cmdIdx]; + GLES3CmdFuncDraw(device, cmd->drawInfo); + break; + } + case GFXCmdType::UPDATE_BUFFER: { + GLES3CmdUpdateBuffer *cmd = cmdPackage->updateBufferCmds[cmdIdx]; + GLES3CmdFuncUpdateBuffer(device, cmd->gpuBuffer, cmd->buffer, cmd->offset, cmd->size); + break; + } + case GFXCmdType::COPY_BUFFER_TO_TEXTURE: { + GLES3CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; + GLES3CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); + break; + } + default: + break; + } + cmdIdx++; + } +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index 7bb350162e..0c47dc2537 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -31,7 +31,18 @@ namespace gfx { class GLES3Device; -struct GLES3DepthBias final { +struct GLES3ObjectCache { + size_t numClearColors = 0u; + GLES3GPURenderPass *gpuRenderPass = nullptr; + GLES3GPUFramebuffer *gpuFramebuffer = nullptr; + GLES3GPUPipelineState *gpuPipelineState = nullptr; + GLES3GPUInputAssembler *gpuInputAssembler = nullptr; + bool reverseCW = false; + GLenum glPrimitive = 0; + GLenum invalidAttachments[GFX_MAX_ATTACHMENTS]; +}; + +struct GLES3DepthBias { float constant = 0.0f; float clamp = 0.0f; float slope = 0.0f; @@ -104,7 +115,7 @@ public: GLES3GPUPipelineState *gpuPipelineState = nullptr; GLES3GPUInputAssembler *gpuInputAssembler = nullptr; vector gpuDescriptorSets; - vector dynamicOffsets; + vector dynamicOffsets; Viewport viewport; Rect scissor; float lineWidth = 1.0f; @@ -231,7 +242,7 @@ CC_GLES3_API void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURende const Rect &renderArea, size_t numClearColors, const Color *clearColors, float clearDepth, int clearStencil); CC_GLES3_API void GLES3CmdFuncEndRenderPass(GLES3Device *device); CC_GLES3_API void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipelineState, GLES3GPUInputAssembler *gpuInputAssembler, - vector &gpuDescriptorSets, vector &dynamicOffsets, + vector &gpuDescriptorSets, vector &dynamicOffsets, Viewport &viewport, Rect &scissor, float lineWidth, bool depthBiasEnabled, GLES3DepthBias &depthBias, Color &blendConstants, GLES3DepthBounds &depthBounds, GLES3StencilWriteMask &stencilWriteMask, GLES3StencilCompareMask &stencilCompareMask); CC_GLES3_API void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index acb3e5aeef..001a5eb449 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "GLES3Buffer.h" #include "GLES3CommandBuffer.h" +#include "GLES3PrimaryCommandBuffer.h" #include "GLES3Context.h" #include "GLES3DescriptorSet.h" #include "GLES3DescriptorSetLayout.h" @@ -79,7 +80,7 @@ bool GLES3Device::initialize(const DeviceInfo &info) { destroy(); return false; } - bindRenderContext(true); + _context = _initContext; String extStr = (const char *)glGetString(GL_EXTENSIONS); _extensions = StringUtil::Split(extStr, " "); @@ -171,9 +172,6 @@ bool GLES3Device::initialize(const DeviceInfo &info) { _gpuStateCache->initialize(_maxTextureUnits, _maxUniformBufferBindings, _maxVertexAttributes); - _initContext->MakeCurrent(false); - _context = _initContext; - return true; } @@ -216,22 +214,41 @@ void GLES3Device::present() { queue->_numTriangles = 0; } -void GLES3Device::makeCurrent() { - if (!_renderContext) { - ContextInfo ctxInfo; - ctxInfo.windowHandle = _windowHandle; - ctxInfo.sharedCtx = _initContext; - - _renderContext = CC_NEW(GLES3Context(this)); - _renderContext->initialize(ctxInfo); - _context = _renderContext; +void GLES3Device::setImmediateMode(bool immediateMode) { + if (immediateMode) { + _renderContext->MakeCurrent(false); + _initContext->MakeCurrent(); } else { - _renderContext->MakeCurrent(); + _initContext->MakeCurrent(false); + + /*if (!_renderContext) { + ENCODE_COMMAND_1( + getMainEncoder(), + DeviceInitThread, + device, this, + { + ContextInfo ctxInfo; + ctxInfo.windowHandle = _windowHandle; + ctxInfo.sharedCtx = _initContext; + + device->_renderContext = CC_NEW(GLES3Context(device)); + device->_renderContext->initialize(ctxInfo); + device->_context = device->_renderContext; + }); + } else { + ENCODE_COMMAND_1( + getMainEncoder(), + DeviceInitThread, + device, this, + { + _renderContext->MakeCurrent(); + }); + }*/ } } CommandBuffer *GLES3Device::createCommandBuffer() { - return CC_NEW(GLES3CommandBuffer(this)); + return CC_NEW(GLES3PrimaryCommandBuffer(this)); } Fence *GLES3Device::createFence() { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.h b/native/cocos/renderer/gfx-gles3/GLES3Device.h index 05a67be22c..682ecba4cd 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.h @@ -72,7 +72,7 @@ public: virtual PipelineLayout *createPipelineLayout() override; virtual PipelineState *createPipelineState() override; virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - virtual void makeCurrent() override; + virtual void setImmediateMode(bool immediateMode) override; CC_INLINE GLES3GPUStateCache *stateCache() const { return _gpuStateCache; } CC_INLINE GLES3GPUStagingBufferPool *stagingBufferPool() const { return _gpuStagingBufferPool; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp index 28a6bcda54..5195315a26 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp @@ -55,7 +55,7 @@ bool GLES3PipelineLayout::initialize(const PipelineLayoutInfo &info) { for (uint j = 0u; j < dynamicCount; j++) { uint binding = gpuSetLayout->dynamicBindings[j]; - if (indices[binding] < 0) indices[binding] = offset + j; + if (indices[binding] < 0) indices[binding] = j; } _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); _gpuPipelineLayout->setLayouts.push_back(gpuSetLayout); diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp index 2b05dc1fe5..984498fb02 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp @@ -1,26 +1,3 @@ -/**************************************************************************** -Copyright (c) 2020 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ #include "GLES3Std.h" #include "GLES3Buffer.h" @@ -43,7 +20,7 @@ GLES3PrimaryCommandBuffer::GLES3PrimaryCommandBuffer(Device *device) GLES3PrimaryCommandBuffer::~GLES3PrimaryCommandBuffer() { } -void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) { +void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) { _isInRenderPass = true; GLES3GPURenderPass *gpuRenderPass = ((GLES3RenderPass *)renderPass)->gpuRenderPass(); GLES3GPUFramebuffer *gpuFramebuffer = ((GLES3Framebuffer *)fbo)->gpuFBO(); @@ -62,18 +39,7 @@ void GLES3PrimaryCommandBuffer::draw(InputAssembler *ia) { (_type == CommandBufferType::SECONDARY)) { if (_isStateInvalid) { - vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; - vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; - for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { - size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; - //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); - count = std::min(count, _curDynamicOffsets[i].size()); - if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); - } - GLES3CmdFuncBindState((GLES3Device *)_device, _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, - _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); - - _isStateInvalid = false; + BindStates(); } DrawInfo drawInfo; @@ -102,13 +68,13 @@ void GLES3PrimaryCommandBuffer::draw(InputAssembler *ia) { } } -void GLES3PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { +void GLES3PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size, uint offset) { if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) || (_type == CommandBufferType::SECONDARY)) { GLES3GPUBuffer *gpuBuffer = ((GLES3Buffer *)buff)->gpuBuffer(); if (gpuBuffer) { - GLES3CmdFuncUpdateBuffer((GLES3Device *)_device, gpuBuffer, data, 0u, size); + GLES3CmdFuncUpdateBuffer((GLES3Device *)_device, gpuBuffer, data, offset, size); } } else { CC_LOG_ERROR("Command 'updateBuffer' must be recorded outside a render pass."); @@ -131,18 +97,20 @@ void GLES3PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffe void GLES3PrimaryCommandBuffer::execute(const CommandBuffer *const *cmdBuffs, uint32_t count) { for (uint i = 0; i < count; ++i) { GLES3PrimaryCommandBuffer *cmdBuff = (GLES3PrimaryCommandBuffer *)cmdBuffs[i]; - GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); + GLES3CmdFuncExecuteCmds((GLES3Device *)_device, cmdBuff->_cmdPackage); - GLES3CmdFuncExecuteCmds((GLES3Device *)_device, cmdPackage); - - _numDrawCalls += cmdBuff->_numDrawCalls; - _numInstances += cmdBuff->_numInstances; - _numTriangles += cmdBuff->_numTriangles; - - cmdBuff->_pendingPackages.pop(); - cmdBuff->_freePackages.push(cmdPackage); + _numDrawCalls += cmdBuff->getNumDrawCalls(); + _numInstances += cmdBuff->getNumInstances(); + _numTriangles += cmdBuff->getNumTris(); } } +void GLES3PrimaryCommandBuffer::BindStates() { + GLES3CmdFuncBindState((GLES3Device *)_device, _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, _curDynamicOffsets, + _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); + + _isStateInvalid = false; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h index a4af97b926..2215d6a825 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h @@ -1,26 +1,3 @@ -/**************************************************************************** -Copyright (c) 2020 Xiamen Yaji Software Co., Ltd. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ #ifndef CC_GFXGLES3_PRIMARY_COMMAND_BUFFER_H_ #define CC_GFXGLES3_PRIMARY_COMMAND_BUFFER_H_ @@ -29,19 +6,24 @@ THE SOFTWARE. namespace cc { namespace gfx { -class CC_GLES3_API GLES3PrimaryCommandBuffer final : public GLES3CommandBuffer { +class CC_GLES3_API GLES3PrimaryCommandBuffer : public GLES3CommandBuffer { friend class GLES3Queue; public: GLES3PrimaryCommandBuffer(Device *device); ~GLES3PrimaryCommandBuffer(); - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) override; + virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) override; virtual void endRenderPass() override; virtual void draw(InputAssembler *ia) override; - virtual void updateBuffer(Buffer *buff, const void *data, uint size) override; + virtual void updateBuffer(Buffer *buff, const void *data, uint size, uint offset) override; virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) override; + +protected: + virtual void BindStates() override; + +private: }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp index ab536ec121..efe55d7678 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp @@ -48,17 +48,11 @@ void GLES3Queue::destroy() { void GLES3Queue::submit(const CommandBuffer *const *cmdBuffs, uint count, Fence *fence) { if (!_isAsync) { for (uint i = 0; i < count; ++i) { - GLES3CommandBuffer *cmdBuff = (GLES3CommandBuffer *)cmdBuffs[i]; - GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - - GLES3CmdFuncExecuteCmds((GLES3Device *)_device, cmdPackage); - - _numDrawCalls += cmdBuff->_numDrawCalls; - _numInstances += cmdBuff->_numInstances; - _numTriangles += cmdBuff->_numTriangles; - - cmdBuff->_pendingPackages.pop(); - cmdBuff->_freePackages.push(cmdPackage); + GLES3CommandBuffer *cmdBuffer = (GLES3CommandBuffer *)cmdBuffs[i]; + //GLES3CmdFuncExecuteCmds((GLES3Device *)_device, cmdBuffer->_cmdPackage); + _numDrawCalls += cmdBuffer->_numDrawCalls; + _numInstances += cmdBuffer->_numInstances; + _numTriangles += cmdBuffer->_numTriangles; } } }