diff --git a/native/.clang-format-ignore b/native/.clang-format-ignore new file mode 100644 index 0000000000..922b6065c5 --- /dev/null +++ b/native/.clang-format-ignore @@ -0,0 +1,2 @@ +# ignore third_party code from clang-format checks +./cocos/bindings/auto/* diff --git a/native/cocos/physics/physx/PhysXSharedBody.cpp b/native/cocos/physics/physx/PhysXSharedBody.cpp index 83c8c4d651..04451b15f4 100644 --- a/native/cocos/physics/physx/PhysXSharedBody.cpp +++ b/native/cocos/physics/physx/PhysXSharedBody.cpp @@ -100,7 +100,12 @@ void PhysXSharedBody::setType(ERigidBodyType v) { if (_mType == v) return; _mType = v; initActor(); - _mImpl.ptr = isStatic() ? reinterpret_cast(_mStaticActor) : reinterpret_cast(_mDynamicActor); + if (isStatic()) { + _mImpl.ptr = reinterpret_cast(_mStaticActor); + } else { + _mImpl.ptr = reinterpret_cast(_mDynamicActor); + _mImpl.rigidDynamic->setRigidBodyFlag(physx::PxRigidBodyFlag::eKINEMATIC, _mType == ERigidBodyType::KINEMATIC); + } } void PhysXSharedBody::reference(bool v) { diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index b2bf73e98f..28583f9094 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -25,6 +25,7 @@ #include "MTLStd.h" +#include #include "MTLBuffer.h" #include "MTLCommandBuffer.h" #include "MTLDescriptorSet.h" @@ -35,7 +36,6 @@ #include "MTLRenderPass.h" #include "MTLSampler.h" #include "MTLTexture.h" -#include namespace cc { namespace gfx { @@ -43,7 +43,7 @@ namespace gfx { CCMTLCommandBuffer::CCMTLCommandBuffer() : CommandBuffer(), _mtlDevice(CCMTLDevice::getInstance()) { - _mtlCommandQueue = id(_mtlDevice->getMTLCommandQueue()); + _mtlCommandQueue = id(_mtlDevice->getMTLCommandQueue()); _indirectDrawSuppotred = _mtlDevice->isIndirectDrawSupported(); const auto setCount = _mtlDevice->bindingMappingInfo().bufferOffsets.size(); @@ -81,15 +81,14 @@ void CCMTLCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer // Only primary command buffer should request command buffer explicitly _mtlCommandBuffer = [[_mtlCommandQueue commandBuffer] retain]; [_mtlCommandBuffer enqueue]; - } - else { + } else { // Secondary command buffer is likely to be recorded in a separated thread if (_autoreleasePool) { [_autoreleasePool drain]; _autoreleasePool = nil; } _autoreleasePool = [[NSAutoreleasePool alloc] init]; - // CC_LOG_INFO("%d CB POOL: %p ALLOCED for %p", [NSThread currentThread], _autoreleasePool, this); + // CC_LOG_INFO("%d CB POOL: %p ALLOCED for %p", [NSThread currentThread], _autoreleasePool, this); } _numTriangles = 0; _numDrawCalls = 0; @@ -100,7 +99,7 @@ void CCMTLCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer dynamicOffset.clear(); } _firstDirtyDescriptorSet = UINT_MAX; - _commandBufferBegan = true; + _commandBufferBegan = true; } void CCMTLCommandBuffer::end() { @@ -115,7 +114,7 @@ void CCMTLCommandBuffer::end() { _renderEncoder.endEncoding(); if (_autoreleasePool) { - // CC_LOG_INFO("%d CB POOL: %p RELEASED for %p", [NSThread currentThread], _autoreleasePool, this); + // CC_LOG_INFO("%d CB POOL: %p RELEASED for %p", [NSThread currentThread], _autoreleasePool, this); [_autoreleasePool drain]; _autoreleasePool = nullptr; } @@ -124,37 +123,48 @@ void CCMTLCommandBuffer::end() { void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { // Sub CommandBuffer shouldn't call begin render pass - if (_isSecondary) - { + if (_isSecondary) { return; } - + auto *ccMtlRenderPass = static_cast(renderPass); - auto isOffscreen = static_cast(fbo)->isOffscreen(); + auto isOffscreen = static_cast(fbo)->isOffscreen(); if (!isOffscreen) { id drawable = (id)_mtlDevice->getCurrentDrawable(); - id dssTex = (id)_mtlDevice->getDSSTexture(); + id dssTex = (id)_mtlDevice->getDSSTexture(); ccMtlRenderPass->setColorAttachment(0, drawable.texture, 0); ccMtlRenderPass->setDepthStencilAttachment(dssTex, 0); + } else { + const TextureList &colorTextures = fbo->getColorTextures(); + for (uint i = 0; i < colorTextures.size(); i++) { + auto *ccMtlTexture = static_cast(colorTextures[i]); + ccMtlRenderPass->setColorAttachment(i, ccMtlTexture->getMTLTexture(), 0); + } + + Texture *dsTexture = fbo->getDepthStencilTexture(); + if (dsTexture) { + auto *ccMtlTexture = static_cast(dsTexture); + ccMtlRenderPass->setDepthStencilAttachment(ccMtlTexture->getMTLTexture(), 0); + } } MTLRenderPassDescriptor *mtlRenderPassDescriptor = static_cast(renderPass)->getMTLRenderPassDescriptor(); if (!isRenderingEntireDrawable(renderArea, static_cast(renderPass))) { //Metal doesn't apply the viewports and scissors to renderpass load-action clearing. mu::clearRenderArea(_mtlDevice, _mtlCommandBuffer, renderPass, renderArea, colors, depth, stencil); } else { - const auto &colorAttachments = renderPass->getColorAttachments(); - const auto colorAttachmentCount = colorAttachments.size(); + const auto &colorAttachments = renderPass->getColorAttachments(); + const auto colorAttachmentCount = colorAttachments.size(); for (size_t slot = 0U; slot < colorAttachmentCount; slot++) { mtlRenderPassDescriptor.colorAttachments[slot].clearColor = mu::toMTLClearColor(colors[slot]); mtlRenderPassDescriptor.colorAttachments[slot].loadAction = colorAttachments[slot].loadOp == LoadOp::CLEAR ? MTLLoadActionClear : MTLLoadActionLoad; } //Metal limits clearDepth at range [0.0, 1.0] //to keep consistent with OpenGL, assume passed value ranges in [-1, 1]; - depth = clampf(depth / 2 + 0.5f, 0.0f, 1.0f); - mtlRenderPassDescriptor.depthAttachment.clearDepth = depth; + depth = clampf(depth / 2 + 0.5f, 0.0f, 1.0f); + mtlRenderPassDescriptor.depthAttachment.clearDepth = depth; mtlRenderPassDescriptor.stencilAttachment.clearStencil = stencil; } - + if (secondaryCBCount > 0) { _parallelEncoder = [[_mtlCommandBuffer parallelRenderCommandEncoderWithDescriptor:mtlRenderPassDescriptor] retain]; // Create command encoders from parallel encoder and assign to command buffers @@ -163,12 +173,11 @@ void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb cmdBuff->_renderEncoder.initialize(_parallelEncoder); cmdBuff->_mtlCommandBuffer = _mtlCommandBuffer; } - } - else { + } else { _renderEncoder.initialize(_mtlCommandBuffer, mtlRenderPassDescriptor); } - Rect scissorArea = renderArea; + Rect scissorArea = renderArea; #if defined(CC_DEBUG) && (CC_DEBUG > 0) const Vec2 renderTargetSize = ccMtlRenderPass->getRenderTargetSizes()[0]; scissorArea.width = MIN(scissorArea.width, renderTargetSize.x - scissorArea.x); @@ -183,8 +192,7 @@ void CCMTLCommandBuffer::endRenderPass() { [_parallelEncoder endEncoding]; [_parallelEncoder release]; _parallelEncoder = nil; - } - else { + } else { _renderEncoder.endEncoding(); } } @@ -279,8 +287,8 @@ void CCMTLCommandBuffer::draw(const DrawInfo &info) { } const auto *indirectBuffer = static_cast(_inputAssembler->getIndirectBuffer()); - const auto *indexBuffer = static_cast(_inputAssembler->getIndexBuffer()); - auto mtlEncoder = _renderEncoder.getMTLEncoder(); + const auto *indexBuffer = static_cast(_inputAssembler->getIndexBuffer()); + auto mtlEncoder = _renderEncoder.getMTLEncoder(); if (indirectBuffer) { const auto indirectMTLBuffer = indirectBuffer->getMTLBuffer(); @@ -290,20 +298,20 @@ void CCMTLCommandBuffer::draw(const DrawInfo &info) { if (indirectBuffer->isDrawIndirectByIndex()) { [mtlEncoder drawIndexedPrimitives:_mtlPrimitiveType indexType:indexBuffer->getIndexType() - indexBuffer:indexBuffer->getMTLBuffer() + indexBuffer:indexBuffer->getMTLBuffer() indexBufferOffset:0 - indirectBuffer:indirectMTLBuffer - indirectBufferOffset:0]; + indirectBuffer:indirectMTLBuffer + indirectBufferOffset:0]; } else { [mtlEncoder drawPrimitives:_mtlPrimitiveType indirectBuffer:indirectMTLBuffer - indirectBufferOffset:0]; + indirectBufferOffset:0]; } } else { - uint stride = indirectBuffer->getStride(); - uint offset = 0; - uint drawInfoCount = indirectBuffer->getCount(); - const auto &drawInfos = indirectBuffer->getDrawInfos(); + uint stride = indirectBuffer->getStride(); + uint offset = 0; + uint drawInfoCount = indirectBuffer->getCount(); + const auto &drawInfos = indirectBuffer->getDrawInfos(); _numDrawCalls += drawInfoCount; for (uint i = 0; i < drawInfoCount; ++i) { @@ -312,28 +320,28 @@ void CCMTLCommandBuffer::draw(const DrawInfo &info) { if (indirectBuffer->isDrawIndirectByIndex()) { if (drawInfo.instanceCount == 0) { [mtlEncoder drawIndexedPrimitives:_mtlPrimitiveType - indexCount:drawInfo.indexCount + indexCount:drawInfo.indexCount indexType:indexBuffer->getIndexType() - indexBuffer:indexBuffer->getMTLBuffer() + indexBuffer:indexBuffer->getMTLBuffer() indexBufferOffset:offset]; } else { [mtlEncoder drawIndexedPrimitives:_mtlPrimitiveType - indexCount:drawInfo.indexCount + indexCount:drawInfo.indexCount indexType:indexBuffer->getIndexType() - indexBuffer:indexBuffer->getMTLBuffer() + indexBuffer:indexBuffer->getMTLBuffer() indexBufferOffset:offset instanceCount:drawInfo.instanceCount]; } } else { if (drawInfo.instanceCount == 0) { [mtlEncoder drawPrimitives:_mtlPrimitiveType - vertexStart:drawInfo.firstIndex - vertexCount:drawInfo.vertexCount]; + vertexStart:drawInfo.firstIndex + vertexCount:drawInfo.vertexCount]; } else { [mtlEncoder drawPrimitives:_mtlPrimitiveType - vertexStart:drawInfo.firstIndex - vertexCount:drawInfo.vertexCount - instanceCount:drawInfo.instanceCount]; + vertexStart:drawInfo.firstIndex + vertexCount:drawInfo.vertexCount + instanceCount:drawInfo.instanceCount]; } } } @@ -344,28 +352,28 @@ void CCMTLCommandBuffer::draw(const DrawInfo &info) { offset += info.firstIndex * indexBuffer->getStride(); if (info.instanceCount == 0) { [mtlEncoder drawIndexedPrimitives:_mtlPrimitiveType - indexCount:info.indexCount + indexCount:info.indexCount indexType:indexBuffer->getIndexType() - indexBuffer:indexBuffer->getMTLBuffer() + indexBuffer:indexBuffer->getMTLBuffer() indexBufferOffset:offset]; } else { [mtlEncoder drawIndexedPrimitives:_mtlPrimitiveType - indexCount:info.indexCount + indexCount:info.indexCount indexType:indexBuffer->getIndexType() - indexBuffer:indexBuffer->getMTLBuffer() + indexBuffer:indexBuffer->getMTLBuffer() indexBufferOffset:offset instanceCount:info.instanceCount]; } } else if (info.vertexCount) { if (info.instanceCount == 0) { [mtlEncoder drawPrimitives:_mtlPrimitiveType - vertexStart:info.firstIndex - vertexCount:info.vertexCount]; + vertexStart:info.firstIndex + vertexCount:info.vertexCount]; } else { [mtlEncoder drawPrimitives:_mtlPrimitiveType - vertexStart:info.firstIndex - vertexCount:info.vertexCount - instanceCount:info.instanceCount]; + vertexStart:info.firstIndex + vertexCount:info.vertexCount + instanceCount:info.instanceCount]; } } @@ -411,41 +419,41 @@ void CCMTLCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Tex return; } - uint totalSize = 0; - vector bufferSize(count); + uint totalSize = 0; + vector bufferSize(count); vector stagingRegions(count); - auto format = texture->getFormat(); - auto *mtlTexture = static_cast(texture); - auto convertedFormat = mtlTexture->getConvertedFormat(); + auto format = texture->getFormat(); + auto * mtlTexture = static_cast(texture); + auto convertedFormat = mtlTexture->getConvertedFormat(); for (size_t i = 0; i < count; i++) { - const auto ®ion = regions[i]; - auto &stagingRegion = stagingRegions[i]; - auto w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; - auto h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; - bufferSize[i] = w * h; - stagingRegion.sourceBytesPerRow = mu::getBytesPerRow(convertedFormat, w); + const auto ®ion = regions[i]; + auto & stagingRegion = stagingRegions[i]; + auto w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; + auto h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; + bufferSize[i] = w * h; + stagingRegion.sourceBytesPerRow = mu::getBytesPerRow(convertedFormat, w); stagingRegion.sourceBytesPerImage = formatSize(convertedFormat, w, h, region.texExtent.depth); - stagingRegion.sourceSize = {w, h, region.texExtent.depth}; - stagingRegion.destinationSlice = region.texSubres.baseArrayLayer; - stagingRegion.destinationLevel = region.texSubres.mipLevel; - stagingRegion.destinationOrigin = { + stagingRegion.sourceSize = {w, h, region.texExtent.depth}; + stagingRegion.destinationSlice = region.texSubres.baseArrayLayer; + stagingRegion.destinationLevel = region.texSubres.mipLevel; + stagingRegion.destinationOrigin = { static_cast(region.texOffset.x), static_cast(region.texOffset.y), static_cast(region.texOffset.z)}; totalSize += stagingRegion.sourceBytesPerImage; } - size_t offset = 0; - id encoder = [_mtlCommandBuffer blitCommandEncoder]; - id dstTexture = mtlTexture->getMTLTexture(); - const bool isArrayTexture = mtlTexture->isArray(); + size_t offset = 0; + id encoder = [_mtlCommandBuffer blitCommandEncoder]; + id dstTexture = mtlTexture->getMTLTexture(); + const bool isArrayTexture = mtlTexture->isArray(); for (size_t i = 0; i < count; i++) { - const auto &stagingRegion = stagingRegions[i]; - const auto *convertedData = mu::convertData(buffers[i], bufferSize[i], format); - const auto sourceBytesPerImage = isArrayTexture ? stagingRegion.sourceBytesPerImage : 0; - MTLRegion region = {stagingRegion.destinationOrigin, stagingRegion.sourceSize}; - auto bytesPerRow = mtlTexture->isPVRTC() ? 0 : stagingRegion.sourceBytesPerRow; - auto bytesPerImage = mtlTexture->isPVRTC() ? 0 : sourceBytesPerImage; + const auto &stagingRegion = stagingRegions[i]; + const auto *convertedData = mu::convertData(buffers[i], bufferSize[i], format); + const auto sourceBytesPerImage = isArrayTexture ? stagingRegion.sourceBytesPerImage : 0; + MTLRegion region = {stagingRegion.destinationOrigin, stagingRegion.sourceSize}; + auto bytesPerRow = mtlTexture->isPVRTC() ? 0 : stagingRegion.sourceBytesPerRow; + auto bytesPerImage = mtlTexture->isPVRTC() ? 0 : sourceBytesPerImage; [dstTexture replaceRegion:region mipmapLevel:stagingRegion.destinationLevel slice:stagingRegion.destinationSlice @@ -476,30 +484,30 @@ void CCMTLCommandBuffer::execute(CommandBuffer *const *commandBuffs, uint32_t co void CCMTLCommandBuffer::bindDescriptorSets() { const auto &vertexBuffers = _inputAssembler->getVertexBuffers(); for (const auto &bindingInfo : _gpuPipelineState->vertexBufferBindingInfo) { - auto index = std::get<0>(bindingInfo); + auto index = std::get<0>(bindingInfo); auto stream = std::get<1>(bindingInfo); static_cast(vertexBuffers[stream])->encodeBuffer(_renderEncoder, 0, index, ShaderStageFlagBit::VERTEX); } const auto &dynamicOffsetIndices = _gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices; - const auto &blocks = _gpuPipelineState->gpuShader->blocks; + const auto &blocks = _gpuPipelineState->gpuShader->blocks; for (const auto &iter : blocks) { const auto &block = iter.second; const auto *gpuDescriptorSet = _GPUDescriptorSets[block.set]; - const auto descriptorIndex = gpuDescriptorSet->descriptorIndices->at(block.binding); - const auto &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[descriptorIndex]; + const auto descriptorIndex = gpuDescriptorSet->descriptorIndices->at(block.binding); + const auto &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[descriptorIndex]; if (!gpuDescriptor.buffer) { CC_LOG_ERROR("Buffer binding %s at set %d binding %d is not bounded.", block.name.c_str(), block.set, block.binding); continue; } - const auto &dynamicOffset = dynamicOffsetIndices[block.set]; - auto dynamicOffsetIndex = (block.binding < dynamicOffset.size()) ? dynamicOffset[block.binding] : -1; + const auto &dynamicOffset = dynamicOffsetIndices[block.set]; + auto dynamicOffsetIndex = (block.binding < dynamicOffset.size()) ? dynamicOffset[block.binding] : -1; if (gpuDescriptor.buffer) { uint offset = (dynamicOffsetIndex >= 0) ? _dynamicOffsets[block.set][dynamicOffsetIndex] : 0; // compute pipeline and render pipeline mutually exlusive - if(_gpuPipelineState->mtlComputePipelineState) { + if (_gpuPipelineState->mtlComputePipelineState) { gpuDescriptor.buffer->encodeBuffer(_computeEncoder, offset, block.mappedBinding, @@ -518,8 +526,8 @@ void CCMTLCommandBuffer::bindDescriptorSets() { const auto &sampler = iter.second; const auto *gpuDescriptorSet = _GPUDescriptorSets[sampler.set]; - const auto descriptorIndex = gpuDescriptorSet->descriptorIndices->at(sampler.binding); - const auto &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[descriptorIndex]; + const auto descriptorIndex = gpuDescriptorSet->descriptorIndices->at(sampler.binding); + const auto &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[descriptorIndex]; if (!gpuDescriptor.texture || !gpuDescriptor.sampler) { CC_LOG_ERROR("Sampler binding %s at set %d binding %d is not bounded.", sampler.name.c_str(), sampler.set, sampler.binding); @@ -536,26 +544,26 @@ void CCMTLCommandBuffer::bindDescriptorSets() { _renderEncoder.setFragmentSampler(gpuDescriptor.sampler->getMTLSamplerState(), sampler.samplerBinding); } - if(hasFlag(sampler.stages, ShaderStageFlagBit::COMPUTE)) { + if (hasFlag(sampler.stages, ShaderStageFlagBit::COMPUTE)) { _computeEncoder.setTexture(gpuDescriptor.texture->getMTLTexture(), sampler.textureBinding); } } } void CCMTLCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { - if(srcTexture && regions) { + if (srcTexture && regions) { id encoder = [_mtlCommandBuffer blitCommandEncoder]; - id src = static_cast(srcTexture)->getMTLTexture(); - id dst = nil; - CCMTLDevice* device = CCMTLDevice::getInstance(); - if(!dstTexture) { + id src = static_cast(srcTexture)->getMTLTexture(); + id dst = nil; + CCMTLDevice * device = CCMTLDevice::getInstance(); + if (!dstTexture) { id currentDrawable = (id)device->getCurrentDrawable(); - dst = [currentDrawable texture]; + dst = [currentDrawable texture]; } else { - dst = static_cast(dstTexture)->getMTLTexture(); + dst = static_cast(dstTexture)->getMTLTexture(); } - if([src pixelFormat] != device->preferredPixelFormat()) { + if ([src pixelFormat] != device->preferredPixelFormat()) { src = [src newTextureViewWithPixelFormat:(MTLPixelFormat)device->preferredPixelFormat()]; } @@ -575,14 +583,13 @@ void CCMTLCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, c } void CCMTLCommandBuffer::dispatch(const DispatchInfo &info) { - if(_firstDirtyDescriptorSet < _GPUDescriptorSets.size()) { + if (_firstDirtyDescriptorSet < _GPUDescriptorSets.size()) { bindDescriptorSets(); } MTLSize groupsPerGrid = MTLSizeMake(info.groupCountX, info.groupCountY, info.groupCountZ); - if(info.indirectBuffer) { - _computeEncoder.dispatch(((CCMTLBuffer*)info.indirectBuffer)->getMTLBuffer(), info.indirectOffset, groupsPerGrid); - } - else { + if (info.indirectBuffer) { + _computeEncoder.dispatch(((CCMTLBuffer *)info.indirectBuffer)->getMTLBuffer(), info.indirectOffset, groupsPerGrid); + } else { _computeEncoder.dispatch(groupsPerGrid); } _computeEncoder.endEncoding(); diff --git a/native/cocos/renderer/pipeline/Define.cpp b/native/cocos/renderer/pipeline/Define.cpp index fbb6f80fc0..74103861b0 100644 --- a/native/cocos/renderer/pipeline/Define.cpp +++ b/native/cocos/renderer/pipeline/Define.cpp @@ -545,6 +545,11 @@ uint nextPow2(uint val) { return val; } +bool supportsHalfFloatTexture(gfx::Device *device) { + return device->hasFeature(gfx::Feature::COLOR_HALF_FLOAT) && + device->hasFeature(gfx::Feature::TEXTURE_HALF_FLOAT); +} + uint getPhaseID(const String &phase) { se::Object *globalObj = se::ScriptEngine::getInstance()->getGlobalObject(); diff --git a/native/cocos/renderer/pipeline/Define.h b/native/cocos/renderer/pipeline/Define.h index 10db8f625b..49360aee14 100644 --- a/native/cocos/renderer/pipeline/Define.h +++ b/native/cocos/renderer/pipeline/Define.h @@ -53,7 +53,7 @@ struct CC_DLL RenderObject { float depth = 0; const ModelView *model = nullptr; }; -using RenderObjectList = vector; +using RenderObjectList = vector; struct CC_DLL RenderTargetInfo { uint width = 0; @@ -69,7 +69,7 @@ struct CC_DLL RenderPass { }; using RenderPassList = vector; -using ColorDesc = gfx::ColorAttachment; +using ColorDesc = gfx::ColorAttachment; using ColorDescList = vector; using DepthStencilDesc = gfx::DepthStencilAttachment; @@ -106,9 +106,9 @@ enum class RenderFlowType : uint8_t { }; using RenderStageList = vector; -using RenderFlowList = vector; -using LightList = vector; -using UintList = vector; +using RenderFlowList = vector; +using LightList = vector; +using UintList = vector; enum class CC_DLL RenderPassStage { DEFAULT = 100, @@ -178,6 +178,31 @@ CC_INLINE bool transparentCompareFn(const RenderPass &a, const RenderPass &b) { return a.shaderID < b.shaderID; } +CC_INLINE uint convertPhase(const StringArray &stages) { + uint phase = 0; + for (const auto &stage : stages) { + phase |= getPhaseID(stage); + } + return phase; +} + +using RenderQueueSortFunc = std::function; + +CC_INLINE RenderQueueSortFunc convertQueueSortFunc(const RenderQueueSortMode &mode) { + std::function sortFunc = opaqueCompareFn; + switch (mode) { + case RenderQueueSortMode::BACK_TO_FRONT: + sortFunc = transparentCompareFn; + break; + case RenderQueueSortMode::FRONT_TO_BACK: + sortFunc = opaqueCompareFn; + default: + break; + } + + return sortFunc; +} + enum class CC_DLL PipelineGlobalBindings { UBO_GLOBAL, UBO_CAMERA, @@ -385,16 +410,16 @@ struct CC_DLL UBOCamera : public Object { }; struct CC_DLL UBOShadow : public Object { - static constexpr uint MAT_LIGHT_PLANE_PROJ_OFFSET = 0; - static constexpr uint MAT_LIGHT_VIEW_OFFSET = MAT_LIGHT_PLANE_PROJ_OFFSET + 16; - static constexpr uint MAT_LIGHT_VIEW_PROJ_OFFSET = UBOShadow::MAT_LIGHT_VIEW_OFFSET + 16; - static constexpr uint SHADOW_NEAR_FAR_LINEAR_SELF_INFO_OFFSET = UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET + 16; - static constexpr uint SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET = UBOShadow::SHADOW_NEAR_FAR_LINEAR_SELF_INFO_OFFSET + 4; + static constexpr uint MAT_LIGHT_PLANE_PROJ_OFFSET = 0; + static constexpr uint MAT_LIGHT_VIEW_OFFSET = MAT_LIGHT_PLANE_PROJ_OFFSET + 16; + static constexpr uint MAT_LIGHT_VIEW_PROJ_OFFSET = UBOShadow::MAT_LIGHT_VIEW_OFFSET + 16; + static constexpr uint SHADOW_NEAR_FAR_LINEAR_SELF_INFO_OFFSET = UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET + 16; + static constexpr uint SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET = UBOShadow::SHADOW_NEAR_FAR_LINEAR_SELF_INFO_OFFSET + 4; static constexpr uint SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET = UBOShadow::SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET + 4; - static constexpr uint SHADOW_COLOR_OFFSET = UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 4; - static constexpr uint COUNT = UBOShadow::SHADOW_COLOR_OFFSET + 4; - static constexpr uint SIZE = UBOShadow::COUNT * 4; - static constexpr uint BINDING = static_cast(PipelineGlobalBindings::UBO_SHADOW); + static constexpr uint SHADOW_COLOR_OFFSET = UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 4; + static constexpr uint COUNT = UBOShadow::SHADOW_COLOR_OFFSET + 4; + static constexpr uint SIZE = UBOShadow::COUNT * 4; + static constexpr uint BINDING = static_cast(PipelineGlobalBindings::UBO_SHADOW); static const gfx::DescriptorSetLayoutBinding DESCRIPTOR; static const gfx::UniformBlock LAYOUT; static const String NAME; @@ -405,7 +430,7 @@ public: static gfx::Sampler *getSampler(uint hash); static uint genSamplerHash(const gfx::SamplerInfo &info); - static void destroyAll(); + static void destroyAll(); protected: static uint defaultSamplerHash; @@ -441,7 +466,9 @@ const uint CAMERA_DEFAULT_MASK = ~static_cast(LayerList::UI_2D) & ~static_ uint nextPow2(uint val); -extern CC_DLL uint skyboxFlag; +bool supportsHalfFloatTexture(gfx::Device *device); + +extern CC_DLL uint skyboxFlag; struct CC_DLL SHADOWMAP : public Object { static constexpr uint BINDING = static_cast(PipelineGlobalBindings::SAMPLER_SHADOWMAP); diff --git a/native/cocos/renderer/pipeline/PipelineUBO.cpp b/native/cocos/renderer/pipeline/PipelineUBO.cpp index 0551b9c171..85b20c1713 100644 --- a/native/cocos/renderer/pipeline/PipelineUBO.cpp +++ b/native/cocos/renderer/pipeline/PipelineUBO.cpp @@ -140,7 +140,7 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, std::array memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_INV_OFFSET, camera->getNode()->worldMatrix.m, sizeof(cc::Mat4)); TO_VEC3(uboCameraView, camera->position, UBOCamera::CAMERA_POS_OFFSET); - + memcpy(uboCameraView.data() + UBOCamera::MAT_PROJ_OFFSET, camera->matProj.m, sizeof(cc::Mat4)); memcpy(uboCameraView.data() + UBOCamera::MAT_PROJ_INV_OFFSET, camera->matProjInv.m, sizeof(cc::Mat4)); memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_PROJ_OFFSET, camera->matViewProj.m, sizeof(cc::Mat4)); @@ -208,16 +208,16 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array matShadowViewProj.multiply(matShadowView); memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET, matShadowViewProj.m, sizeof(matShadowViewProj)); - const auto isTextureHalfFloat = device->hasFeature(cc::gfx::Feature::TEXTURE_HALF_FLOAT); - const auto linear = (static_cast(shadowInfo->linear) && isTextureHalfFloat) ? 1.0F : 0.0F; + const auto isSupportHalfFloat = supportsHalfFloatTexture(device); + const auto linear = (static_cast(shadowInfo->linear) && isSupportHalfFloat) ? 1.0F : 0.0F; float shadowNFLSInfos[4] = {shadowInfo->nearValue, farClamp, linear, static_cast(shadowInfo->selfShadow)}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SELF_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos)); float shadowWHPBInfos[4] = {shadowInfo->size.x, shadowInfo->size.y, static_cast(shadowInfo->pcfType), shadowInfo->bias}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET, &shadowWHPBInfos, sizeof(shadowWHPBInfos)); - const auto packing = static_cast(shadowInfo->packing) ? 1.0F : (isTextureHalfFloat ? 0.0F : 1.0F); - float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F}; + const auto packing = static_cast(shadowInfo->packing) ? 1.0F : (isSupportHalfFloat ? 0.0F : 1.0F); + float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET, &shadowLPNNInfos, sizeof(shadowLPNNInfos)); } else if (mainLight && shadowInfo->getShadowType() == ShadowType::PLANAR) { updateDirLight(shadowInfo, mainLight, shadowUBO); @@ -234,9 +234,9 @@ void PipelineUBO::updateShadowUBOLightView(const RenderPipeline *pipeline, std:: auto * device = gfx::Device::getInstance(); auto * sphere = sceneData->getSphere(); auto & shadowUBO = bufferView; - const auto isTextureHalfFloat = device->hasFeature(cc::gfx::Feature::TEXTURE_HALF_FLOAT); - const auto linear = (static_cast(shadowInfo->linear) && isTextureHalfFloat) ? 1.0F : 0.0F; - const auto packing = static_cast(shadowInfo->packing) ? 1.0F : (isTextureHalfFloat ? 0.0F : 1.0F); + const auto isSupportHalfFloat = supportsHalfFloatTexture(device); + const auto linear = (static_cast(shadowInfo->linear) && isSupportHalfFloat) ? 1.0F : 0.0F; + const auto packing = static_cast(shadowInfo->packing) ? 1.0F : (isSupportHalfFloat ? 0.0F : 1.0F); switch (light->getType()) { case LightType::DIRECTIONAL: { cc::Mat4 matShadowCamera; diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp index b03896203a..8a3a7e39fb 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp @@ -323,9 +323,9 @@ void RenderAdditiveLightQueue::updateLightDescriptorSet(const Camera *camera, gf auto * shadowInfo = sceneData->getSharedData()->getShadows(); const auto *const scene = camera->getScene(); auto * device = gfx::Device::getInstance(); - const auto isTextureHalfFloat = device->hasFeature(cc::gfx::Feature::TEXTURE_HALF_FLOAT); - const auto linear = (static_cast(shadowInfo->linear) && isTextureHalfFloat) ? 1.0F : 0.0F; - const auto packing = static_cast(shadowInfo->packing) ? 1.0F : (isTextureHalfFloat ? 0.0F : 1.0F); + const auto isSupportHalfFloat = supportsHalfFloatTexture(device); + const auto linear = (static_cast(shadowInfo->linear) && isSupportHalfFloat) ? 1.0F : 0.0F; + const auto packing = static_cast(shadowInfo->packing) ? 1.0F : (isSupportHalfFloat ? 0.0F : 1.0F); const Light * mainLight = nullptr; if (scene->mainLightID) mainLight = scene->getMainLight(); diff --git a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp index df3ddfa943..63f0c8df70 100644 --- a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp +++ b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp @@ -152,100 +152,33 @@ void DeferredPipeline::updateQuadVertexData(const gfx::Rect &renderArea) { float vbData[16] = {0}; genQuadVertexData(gfx::SurfaceTransform::IDENTITY, renderArea, vbData); _commandBuffers[0]->updateBuffer(_quadVBOffscreen, vbData); - - genQuadVertexData(_device->getSurfaceTransform(), renderArea, vbData); - _commandBuffers[0]->updateBuffer(_quadVBOnscreen, vbData); } -void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform surfaceTransform, const gfx::Rect &renderArea, float *vbData) { - float minX = float(renderArea.x) / _device->getWidth(); - float maxX = float(renderArea.x + renderArea.width) / _device->getWidth(); - float minY = float(renderArea.y) / _device->getHeight(); - float maxY = float(renderArea.y + renderArea.height) / _device->getHeight(); +void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform /*surfaceTransform*/, const gfx::Rect &renderArea, float *vbData) { + float minX = float(renderArea.x) / _width; + float maxX = float(renderArea.x + renderArea.width) / _width; + float minY = float(renderArea.y) / _height; + float maxY = float(renderArea.y + renderArea.height) / _height; if (_device->getCapabilities().screenSpaceSignY > 0) { std::swap(minY, maxY); } - int n = 0; - switch (surfaceTransform) { - case (gfx::SurfaceTransform::IDENTITY): - n = 0; - vbData[n++] = -1.0; - vbData[n++] = -1.0; - vbData[n++] = minX; // uv - vbData[n++] = maxY; - vbData[n++] = 1.0; - vbData[n++] = -1.0; - vbData[n++] = maxX; - vbData[n++] = maxY; - vbData[n++] = -1.0; - vbData[n++] = 1.0; - vbData[n++] = minX; - vbData[n++] = minY; - vbData[n++] = 1.0; - vbData[n++] = 1.0; - vbData[n++] = maxX; - vbData[n++] = minY; - break; - case (gfx::SurfaceTransform::ROTATE_90): - n = 0; - vbData[n++] = -1.0; - vbData[n++] = -1.0; - vbData[n++] = maxX; // uv - vbData[n++] = maxY; - vbData[n++] = 1.0; - vbData[n++] = -1.0; - vbData[n++] = maxX; - vbData[n++] = minY; - vbData[n++] = -1.0; - vbData[n++] = 1.0; - vbData[n++] = minX; - vbData[n++] = maxY; - vbData[n++] = 1.0; - vbData[n++] = 1.0; - vbData[n++] = minX; - vbData[n++] = minY; - break; - case (gfx::SurfaceTransform::ROTATE_180): - n = 0; - vbData[n++] = -1.0; - vbData[n++] = -1.0; - vbData[n++] = minX; // uv - vbData[n++] = minY; - vbData[n++] = 1.0; - vbData[n++] = -1.0; - vbData[n++] = maxX; - vbData[n++] = minY; - vbData[n++] = -1.0; - vbData[n++] = 1.0; - vbData[n++] = minX; - vbData[n++] = maxY; - vbData[n++] = 1.0; - vbData[n++] = 1.0; - vbData[n++] = maxX; - vbData[n++] = maxY; - break; - case (gfx::SurfaceTransform::ROTATE_270): - n = 0; - vbData[n++] = -1.0; - vbData[n++] = -1.0; - vbData[n++] = minX; // uv - vbData[n++] = minY; - vbData[n++] = 1.0; - vbData[n++] = -1.0; - vbData[n++] = minX; - vbData[n++] = maxY; - vbData[n++] = -1.0; - vbData[n++] = 1.0; - vbData[n++] = maxX; - vbData[n++] = minY; - vbData[n++] = 1.0; - vbData[n++] = 1.0; - vbData[n++] = maxX; - vbData[n++] = maxY; - break; - default: - break; - } + int n = 0; + vbData[n++] = -1.0; + vbData[n++] = -1.0; + vbData[n++] = minX; // uv + vbData[n++] = maxY; + vbData[n++] = 1.0; + vbData[n++] = -1.0; + vbData[n++] = maxX; + vbData[n++] = maxY; + vbData[n++] = -1.0; + vbData[n++] = 1.0; + vbData[n++] = minX; + vbData[n++] = minY; + vbData[n++] = 1.0; + vbData[n++] = 1.0; + vbData[n++] = maxX; + vbData[n++] = minY; } bool DeferredPipeline::createQuadInputAssembler(gfx::Buffer **quadIB, gfx::Buffer **quadVB, gfx::InputAssembler **quadIA) { @@ -312,21 +245,11 @@ void DeferredPipeline::destroyQuadInputAssembler() { _quadIB = nullptr; } - if (_quadVBOnscreen) { - _quadVBOnscreen->destroy(); - _quadVBOnscreen = nullptr; - } - if (_quadVBOffscreen) { _quadVBOffscreen->destroy(); _quadVBOffscreen = nullptr; } - if (_quadIAOnscreen) { - _quadIAOnscreen->destroy(); - _quadIAOnscreen = nullptr; - } - if (_quadIAOffscreen) { _quadIAOffscreen->destroy(); _quadIAOffscreen = nullptr; @@ -366,10 +289,6 @@ bool DeferredPipeline::activeRenderer() { return false; } - if (!createQuadInputAssembler(&_quadIB, &_quadVBOnscreen, &_quadIAOnscreen)) { - return false; - } - gfx::RenderPassInfo gbufferPass; gfx::ColorAttachment color = { @@ -421,14 +340,8 @@ bool DeferredPipeline::activeRenderer() { _lightingRenderPass = _device->createRenderPass(lightPass); - if (_device->getSurfaceTransform() == gfx::SurfaceTransform::IDENTITY || - _device->getSurfaceTransform() == gfx::SurfaceTransform::ROTATE_180) { - _width = _device->getWidth(); - _height = _device->getHeight(); - } else { - _width = _device->getHeight(); - _height = _device->getWidth(); - } + _width = _device->getWidth(); + _height = _device->getHeight(); generateDeferredRenderData(); @@ -564,9 +477,9 @@ void DeferredPipeline::destroyDeferredData() { _deferredRenderData->depthTex = nullptr; } - for (size_t i = 0; i < _deferredRenderData->gbufferRenderTargets.size(); i++) { - _deferredRenderData->gbufferRenderTargets[i]->destroy(); - CC_DELETE(_deferredRenderData->gbufferRenderTargets[i]); + for (auto *target : _deferredRenderData->gbufferRenderTargets) { + target->destroy(); + CC_DELETE(target); } _deferredRenderData->gbufferRenderTargets.clear(); diff --git a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.h b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.h index f512a438aa..3b6f7df60c 100644 --- a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.h +++ b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.h @@ -70,7 +70,6 @@ public: CC_INLINE const gfx::BufferList &getLightBuffers() const { return _lightBuffers; } CC_INLINE const UintList &getLightIndexOffsets() const { return _lightIndexOffsets; } CC_INLINE const UintList &getLightIndices() const { return _lightIndices; } - gfx::InputAssembler * getQuadIAOnScreen() { return _quadIAOnscreen; } gfx::InputAssembler * getQuadIAOffScreen() { return _quadIAOffscreen; } gfx::Rect getRenderArea(Camera *camera, bool onScreen); CC_INLINE DeferredRenderData *getDeferredRenderData() { return _deferredRenderData; }; @@ -94,9 +93,7 @@ private: // light stage gfx::Buffer * _quadIB = nullptr; - gfx::Buffer * _quadVBOnscreen = nullptr; gfx::Buffer * _quadVBOffscreen = nullptr; - gfx::InputAssembler *_quadIAOnscreen = nullptr; gfx::InputAssembler *_quadIAOffscreen = nullptr; DeferredRenderData *_deferredRenderData = nullptr; diff --git a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp index 22812e3d88..844009873e 100644 --- a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp @@ -24,7 +24,6 @@ ****************************************************************************/ #include "GbufferStage.h" -#include "GbufferFlow.h" #include "../BatchedBuffer.h" #include "../InstancedBuffer.h" #include "../PlanarShadowQueue.h" @@ -33,6 +32,7 @@ #include "../RenderQueue.h" #include "../helper/SharedMemory.h" #include "DeferredPipeline.h" +#include "GbufferFlow.h" #include "gfx-base/GFXCommandBuffer.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXFramebuffer.h" @@ -63,7 +63,7 @@ RenderStageInfo GbufferStage::initInfo = { const RenderStageInfo &GbufferStage::getInitializeInfo() { return GbufferStage::initInfo; } GbufferStage::GbufferStage() { - _batchedQueue = CC_NEW(RenderBatchedQueue); + _batchedQueue = CC_NEW(RenderBatchedQueue); _instancedQueue = CC_NEW(RenderInstancedQueue); } @@ -72,33 +72,19 @@ GbufferStage::~GbufferStage() = default; bool GbufferStage::initialize(const RenderStageInfo &info) { RenderStage::initialize(info); _renderQueueDescriptors = info.renderQueues; - _phaseID = getPhaseID("deferred"); + _phaseID = getPhaseID("deferred"); return true; } void GbufferStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { RenderStage::activate(pipeline, flow); + for (const auto &descriptor : _renderQueueDescriptors) { - uint phase = 0; - for (const auto &stage : descriptor.stages) { - phase |= getPhaseID(stage); - } - - std::function sortFunc = opaqueCompareFn; - switch (descriptor.sortMode) { - case RenderQueueSortMode::BACK_TO_FRONT: - sortFunc = transparentCompareFn; - break; - case RenderQueueSortMode::FRONT_TO_BACK: - sortFunc = opaqueCompareFn; - default: - break; - } - - RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; + uint phase = convertPhase(descriptor.stages); + RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor.sortMode); + RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; _renderQueues.emplace_back(CC_NEW(RenderQueue(std::move(info)))); } - _planarShadowQueue = CC_NEW(PlanarShadowQueue(_pipeline)); } @@ -112,7 +98,7 @@ void GbufferStage::destroy() { void GbufferStage::render(Camera *camera) { _instancedQueue->clear(); _batchedQueue->clear(); - auto *pipeline = static_cast(_pipeline); + auto * pipeline = static_cast(_pipeline); const auto &renderObjects = _pipeline->getPipelineSceneData()->getRenderObjects(); if (renderObjects.empty()) { return; @@ -122,13 +108,13 @@ void GbufferStage::render(Camera *camera) { queue->clear(); } - uint m = 0; - uint p = 0; + uint m = 0; + uint p = 0; size_t k = 0; for (auto ro : renderObjects) { - const auto *const model = ro.model; - const auto *const subModelID = model->getSubModelID(); - const auto subModelCount = subModelID[0]; + const auto *const model = ro.model; + const auto *const subModelID = model->getSubModelID(); + const auto subModelCount = subModelID[0]; for (m = 1; m <= subModelCount; ++m) { const auto *const subModel = cc::pipeline::ModelView::getSubModelView(subModelID[m]); for (p = 0; p < subModel->passCount; ++p) { @@ -164,8 +150,8 @@ void GbufferStage::render(Camera *camera) { _renderArea = pipeline->getRenderArea(camera, false); pipeline->updateQuadVertexData(_renderArea); auto *const deferredData = pipeline->getDeferredRenderData(); - auto *framebuffer = deferredData->gbufferFrameBuffer; - auto *renderPass = framebuffer->getRenderPass(); + auto * framebuffer = deferredData->gbufferFrameBuffer; + auto * renderPass = framebuffer->getRenderPass(); cmdBuff->beginRenderPass(renderPass, framebuffer, _renderArea, _clearColors, camera->clearDepth, camera->clearStencil); cmdBuff->bindDescriptorSet(globalSet, _pipeline->getDescriptorSet()); diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index 533e42e409..dca18e16de 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -24,21 +24,21 @@ ****************************************************************************/ #include "LightingStage.h" -#include "LightingFlow.h" #include "../BatchedBuffer.h" #include "../InstancedBuffer.h" +#include "../PipelineStateManager.h" #include "../PlanarShadowQueue.h" #include "../RenderBatchedQueue.h" #include "../RenderInstancedQueue.h" #include "../RenderQueue.h" #include "../helper/SharedMemory.h" #include "DeferredPipeline.h" +#include "LightingFlow.h" #include "gfx-base/GFXCommandBuffer.h" +#include "gfx-base/GFXDescriptorSet.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXFramebuffer.h" #include "gfx-base/GFXQueue.h" -#include "gfx-base/GFXDescriptorSet.h" -#include "../PipelineStateManager.h" namespace cc { namespace pipeline { @@ -64,7 +64,7 @@ RenderStageInfo LightingStage::initInfo = { const RenderStageInfo &LightingStage::getInitializeInfo() { return LightingStage::initInfo; } -LightingStage::LightingStage() = default; +LightingStage::LightingStage() = default; LightingStage::~LightingStage() { _deferredLitsBufs->destroy(); @@ -76,7 +76,8 @@ LightingStage::~LightingStage() { bool LightingStage::initialize(const RenderStageInfo &info) { RenderStage::initialize(info); _renderQueueDescriptors = info.renderQueues; - _phaseID = getPhaseID("default"); + _phaseID = getPhaseID("default"); + _defPhaseID = getPhaseID("deferred"); return true; } @@ -86,34 +87,34 @@ void LightingStage::gatherLights(Camera *camera) { return; } - auto *const sceneData = _pipeline->getPipelineSceneData(); + auto *const sceneData = _pipeline->getPipelineSceneData(); auto *const sharedData = sceneData->getSharedData(); - gfx::CommandBuffer *cmdBuf = pipeline->getCommandBuffers()[0]; - const auto *scene = camera->getScene(); - const auto *const sphereLightArrayID = scene->getSphereLightArrayID(); - auto sphereCount = sphereLightArrayID ? sphereLightArrayID[0] : 0; - const auto *const spotLightArrayID = scene->getSpotLightArrayID(); - auto spotCount = spotLightArrayID ? spotLightArrayID[0] : 0; + gfx::CommandBuffer *cmdBuf = pipeline->getCommandBuffers()[0]; + const auto * scene = camera->getScene(); + const auto *const sphereLightArrayID = scene->getSphereLightArrayID(); + auto sphereCount = sphereLightArrayID ? sphereLightArrayID[0] : 0; + const auto *const spotLightArrayID = scene->getSpotLightArrayID(); + auto spotCount = spotLightArrayID ? spotLightArrayID[0] : 0; - Sphere sphere; - auto exposure = camera->exposure; - uint idx = 0; - int elementLen = sizeof(cc::Vec4) / sizeof(float); - uint fieldLen = elementLen * _maxDeferredLights; - uint offset = 0; + Sphere sphere; + auto exposure = camera->exposure; + uint idx = 0; + int elementLen = sizeof(cc::Vec4) / sizeof(float); + uint fieldLen = elementLen * _maxDeferredLights; + uint offset = 0; cc::Vec4 tmpArray; for (uint i = 1; i <= sphereCount && idx < _maxDeferredLights; i++, idx++) { - const auto *const light = scene->getSphereLight(sphereLightArrayID[i]); + const auto *const light = cc::pipeline::Scene::getSphereLight(sphereLightArrayID[i]); sphere.setCenter(light->position); sphere.setRadius(light->range); if (!sphere_frustum(&sphere, camera->getFrustum())) { continue; } // position - offset = idx * elementLen; - _lightBufferData[offset] = light->position.x; + offset = idx * elementLen; + _lightBufferData[offset] = light->position.x; _lightBufferData[offset + 1] = light->position.y; _lightBufferData[offset + 2] = light->position.z; _lightBufferData[offset + 3] = 0; @@ -139,22 +140,22 @@ void LightingStage::gatherLights(Camera *camera) { _lightBufferData[offset + 3] = tmpArray.w; // size range angle - offset = idx * elementLen + fieldLen * 2; - _lightBufferData[offset] = light->size; + offset = idx * elementLen + fieldLen * 2; + _lightBufferData[offset] = light->size; _lightBufferData[offset + 1] = light->range; _lightBufferData[offset + 2] = 0; } for (uint i = 1; i <= spotCount && idx < _maxDeferredLights; i++, idx++) { - const auto *const light = scene->getSpotLight(spotLightArrayID[i]); + const auto *const light = cc::pipeline::Scene::getSpotLight(spotLightArrayID[i]); sphere.setCenter(light->position); sphere.setRadius(light->range); if (!sphere_frustum(&sphere, camera->getFrustum())) { continue; } // position - offset = idx * elementLen; - _lightBufferData[offset] = light->position.x; + offset = idx * elementLen; + _lightBufferData[offset] = light->position.x; _lightBufferData[offset + 1] = light->position.y; _lightBufferData[offset + 2] = light->position.z; _lightBufferData[offset + 3] = 1; @@ -180,14 +181,14 @@ void LightingStage::gatherLights(Camera *camera) { _lightBufferData[offset + 3] = tmpArray.w; // size range angle - offset = idx * elementLen + fieldLen * 2; - _lightBufferData[offset] = light->size; + offset = idx * elementLen + fieldLen * 2; + _lightBufferData[offset] = light->size; _lightBufferData[offset + 1] = light->range; _lightBufferData[offset + 2] = light->spotAngle; // dir - offset = idx * elementLen + fieldLen * 3; - _lightBufferData[offset] = light->direction.x; + offset = idx * elementLen + fieldLen * 3; + _lightBufferData[offset] = light->direction.x; _lightBufferData[offset + 1] = light->direction.y; _lightBufferData[offset + 2] = light->direction.z; } @@ -218,7 +219,7 @@ void LightingStage::initLightingBuffer() { if (_deferredLitsBufView == nullptr) { gfx::BufferViewInfo bvInfo = {_deferredLitsBufs, 0, totalSize}; - _deferredLitsBufView = device->createBuffer(bvInfo); + _deferredLitsBufView = device->createBuffer(bvInfo); assert(_deferredLitsBufView != nullptr); _descriptorSet->bindBuffer(static_cast(ModelLocalBindings::UBO_FORWARD_LIGHTS), _deferredLitsBufView); } @@ -231,12 +232,19 @@ void LightingStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { auto *const device = pipeline->getDevice(); + for (const auto &descriptor : _renderQueueDescriptors) { + uint phase = convertPhase(descriptor.stages); + RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor.sortMode); + RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; + _renderQueues.emplace_back(CC_NEW(RenderQueue(std::move(info)))); + } + // create descriptorset/layout gfx::DescriptorSetLayoutInfo layoutInfo = {localDescriptorSetLayout.bindings}; - _descLayout = device->createDescriptorSetLayout(layoutInfo); + _descLayout = device->createDescriptorSetLayout(layoutInfo); gfx::DescriptorSetInfo setInfo = {_descLayout}; - _descriptorSet = device->createDescriptorSet(setInfo); + _descriptorSet = device->createDescriptorSet(setInfo); // create lighting buffer and view initLightingBuffer(); @@ -250,9 +258,9 @@ void LightingStage::destroy() { } void LightingStage::render(Camera *camera) { - auto *pipeline = static_cast(_pipeline); - auto *const sceneData = _pipeline->getPipelineSceneData(); - auto *const sharedData = sceneData->getSharedData(); + auto * pipeline = static_cast(_pipeline); + auto *const sceneData = _pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); const auto &renderObjects = sceneData->getRenderObjects(); if (renderObjects.empty()) { @@ -272,7 +280,7 @@ void LightingStage::render(Camera *camera) { gfx::Rect renderArea = pipeline->getRenderArea(camera, false); gfx::Color clearColor = {0.0, 0.0, 0.0, 1.0}; - if (camera->clearFlag & static_cast( gfx::ClearFlagBit::COLOR)) { + if (camera->clearFlag & static_cast(gfx::ClearFlagBit::COLOR)) { if (sharedData->isHDR) { srgbToLinear(&clearColor, camera->clearColor); const auto scale = sharedData->fpScale / camera->exposure; @@ -285,22 +293,22 @@ void LightingStage::render(Camera *camera) { } clearColor.w = 0; - + auto *const deferredData = pipeline->getDeferredRenderData(); - auto *frameBuffer = deferredData->lightingFrameBuff; - auto *renderPass = frameBuffer->getRenderPass(); + auto * frameBuffer = deferredData->lightingFrameBuff; + auto * renderPass = frameBuffer->getRenderPass(); cmdBuff->beginRenderPass(renderPass, frameBuffer, renderArea, &clearColor, - camera->clearDepth, camera->clearStencil); + camera->clearDepth, camera->clearStencil); cmdBuff->bindDescriptorSet(static_cast(SetIndex::GLOBAL), pipeline->getDescriptorSet()); // get pso and draw quad - PassView *pass = sceneData->getSharedData()->getDeferredLightPass(); + PassView * pass = sceneData->getSharedData()->getDeferredLightPass(); gfx::Shader *shader = sceneData->getSharedData()->getDeferredLightPassShader(); - gfx::InputAssembler* inputAssembler = pipeline->getQuadIAOffScreen(); - gfx::PipelineState *pState = PipelineStateManager::getOrCreatePipelineState( + gfx::InputAssembler *inputAssembler = pipeline->getQuadIAOffScreen(); + gfx::PipelineState * pState = PipelineStateManager::getOrCreatePipelineState( pass, shader, inputAssembler, renderPass); assert(pState != nullptr); @@ -308,6 +316,36 @@ void LightingStage::render(Camera *camera) { cmdBuff->bindInputAssembler(inputAssembler); cmdBuff->draw(inputAssembler); + // transparent + for (auto *queue : _renderQueues) { + queue->clear(); + } + + uint m = 0; + uint p = 0; + size_t k = 0; + for (auto ro : renderObjects) { + const auto *const model = ro.model; + const auto *const subModelID = model->getSubModelID(); + const auto subModelCount = subModelID[0]; + for (m = 1; m <= subModelCount; ++m) { + const auto *subModel = cc::pipeline::ModelView::getSubModelView(subModelID[m]); + for (p = 0; p < subModel->passCount; ++p) { + const PassView *pass = subModel->getPassView(p); + // TODO(xwx): need fallback of unlit and gizmo material. + if (pass->phase != _phaseID && pass->phase != _defPhaseID) continue; + for (k = 0; k < _renderQueues.size(); k++) { + _renderQueues[k]->insertRenderPass(ro, m, p); + } + } + } + } + + for (auto *queue : _renderQueues) { + queue->sort(); + queue->recordCommandBuffer(_device, renderPass, cmdBuff); + } + // planerQueue _planarShadowQueue->recordCommandBuffer(_device, renderPass, cmdBuff); diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.h b/native/cocos/renderer/pipeline/deferred/LightingStage.h index 6cae0045f9..26ea87e38c 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.h +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.h @@ -54,21 +54,22 @@ public: private: void gatherLights(Camera *camera); - - static RenderStageInfo initInfo; - PlanarShadowQueue *_planarShadowQueue = nullptr; - gfx::Rect _renderArea; - uint _phaseID = 0; - gfx::Buffer *_deferredLitsBufs = nullptr; - gfx::Buffer *_deferredLitsBufView = nullptr; - std::vector _lightBufferData; - uint _lightBufferStride = 0; - uint _lightBufferElementCount = 0; - float _lightMeterScale = 10000.0; - gfx::DescriptorSet *_descriptorSet = nullptr; - gfx::DescriptorSetLayout *_descLayout = nullptr; - uint _maxDeferredLights = UBODeferredLight::LIGHTS_PER_PASS; + static RenderStageInfo initInfo; + PlanarShadowQueue * _planarShadowQueue = nullptr; + gfx::Rect _renderArea; + uint _phaseID = 0; + uint _defPhaseID = 0; + + gfx::Buffer * _deferredLitsBufs = nullptr; + gfx::Buffer * _deferredLitsBufView = nullptr; + std::vector _lightBufferData; + uint _lightBufferStride = 0; + uint _lightBufferElementCount = 0; + float _lightMeterScale = 10000.0; + gfx::DescriptorSet * _descriptorSet = nullptr; + gfx::DescriptorSetLayout *_descLayout = nullptr; + uint _maxDeferredLights = UBODeferredLight::LIGHTS_PER_PASS; }; } // namespace pipeline diff --git a/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp b/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp index 55a46b918b..278de2df46 100644 --- a/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp @@ -24,14 +24,14 @@ ****************************************************************************/ #include "PostprocessStage.h" -#include "DeferredPipeline.h" -#include "gfx-base/GFXFramebuffer.h" -#include "gfx-base/GFXCommandBuffer.h" -#include "../helper/SharedMemory.h" #include "../PipelineStateManager.h" -#include "gfx-base/GFXDevice.h" -#include "../forward/UIPhase.h" #include "../RenderQueue.h" +#include "../forward/UIPhase.h" +#include "../helper/SharedMemory.h" +#include "DeferredPipeline.h" +#include "gfx-base/GFXCommandBuffer.h" +#include "gfx-base/GFXDevice.h" +#include "gfx-base/GFXFramebuffer.h" namespace cc { namespace pipeline { @@ -42,7 +42,7 @@ RenderStageInfo PostprocessStage::initInfo = { {{true, RenderQueueSortMode::BACK_TO_FRONT, {"default"}}}, }; -PostprocessStage::PostprocessStage() { +PostprocessStage::PostprocessStage() { _uiPhase = CC_NEW(UIPhase); } @@ -85,8 +85,8 @@ void PostprocessStage::destroy() { void PostprocessStage::render(Camera *camera) { auto *pp = dynamic_cast(_pipeline); assert(pp != nullptr); - gfx::Device *device = pp->getDevice(); - gfx::CommandBuffer *cmdBf = pp->getCommandBuffers()[0]; + gfx::Device * device = pp->getDevice(); + gfx::CommandBuffer *cmdBf = pp->getCommandBuffers()[0]; _pipeline->getPipelineUBO()->updateCameraUBO(camera); gfx::Rect renderArea = pp->getRenderArea(camera, !camera->getWindow()->hasOffScreenAttachments); @@ -99,23 +99,22 @@ void PostprocessStage::render(Camera *camera) { _clearColors[0].w = camera->clearColor.w; - gfx::Framebuffer *fb = camera->getWindow()->getFramebuffer(); - const auto &colorTextures = fb->getColorTextures(); - gfx::RenderPass *rp = !colorTextures.empty() && colorTextures[0] ? - fb->getRenderPass() : pp->getOrCreateRenderPass(static_cast(camera->clearFlag)); + gfx::Framebuffer *fb = camera->getWindow()->getFramebuffer(); + const auto & colorTextures = fb->getColorTextures(); + gfx::RenderPass * rp = !colorTextures.empty() && colorTextures[0] ? fb->getRenderPass() : pp->getOrCreateRenderPass(static_cast(camera->clearFlag)); cmdBf->beginRenderPass(rp, fb, renderArea, _clearColors, camera->clearDepth, camera->clearStencil); cmdBf->bindDescriptorSet(static_cast(SetIndex::GLOBAL), pp->getDescriptorSet()); // post proces - auto *const sceneData = _pipeline->getPipelineSceneData(); - PassView *pv = sceneData->getSharedData()->getDeferredPostPass(); - gfx::Shader *sd = sceneData->getSharedData()->getDeferredPostPassShader(); - const auto &renderObjects = sceneData->getRenderObjects(); + auto *const sceneData = _pipeline->getPipelineSceneData(); + PassView * pv = sceneData->getSharedData()->getDeferredPostPass(); + gfx::Shader *sd = sceneData->getSharedData()->getDeferredPostPassShader(); + const auto & renderObjects = sceneData->getRenderObjects(); if (!renderObjects.empty()) { - gfx::InputAssembler *ia = camera->getWindow()->hasOffScreenAttachments ? pp->getQuadIAOffScreen() : pp->getQuadIAOnScreen(); - gfx::PipelineState *pso = PipelineStateManager::getOrCreatePipelineState(pv, sd, ia, rp); + gfx::InputAssembler *ia = pp->getQuadIAOffScreen(); + gfx::PipelineState * pso = PipelineStateManager::getOrCreatePipelineState(pv, sd, ia, rp); assert(pso != nullptr); cmdBf->bindPipelineState(pso); @@ -123,36 +122,6 @@ void PostprocessStage::render(Camera *camera) { cmdBf->draw(ia); } - // transparent - for (auto *queue : _renderQueues) { - queue->clear(); - } - - uint m = 0; - uint p = 0; - size_t k = 0; - for (auto ro : renderObjects) { - const auto *const model = ro.model; - const auto *const subModelID = model->getSubModelID(); - const auto subModelCount = subModelID[0]; - for (m = 1; m <= subModelCount; ++m) { - const auto *subModel = cc::pipeline::ModelView::getSubModelView(subModelID[m]); - for (p = 0; p < subModel->passCount; ++p) { - const PassView *pass = subModel->getPassView(p); - // TODO(xwx): need fallback of ulit and gizmo material. - if (pass->phase != _phaseID) continue; - for (k = 0; k < _renderQueues.size(); k++) { - _renderQueues[k]->insertRenderPass(ro, m, p); - } - } - } - } - - for (auto *queue : _renderQueues) { - queue->sort(); - queue->recordCommandBuffer(_device, rp, cmdBf); - } - _uiPhase->render(camera, rp); cmdBf->endRenderPass(); } diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index bcadf0d6e0..bdb24e84d1 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -33,11 +33,11 @@ #include "../RenderQueue.h" #include "../helper/SharedMemory.h" #include "ForwardPipeline.h" +#include "UIPhase.h" #include "gfx-base/GFXCommandBuffer.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXFramebuffer.h" #include "gfx-base/GFXQueue.h" -#include "UIPhase.h" namespace cc { namespace pipeline { @@ -63,10 +63,10 @@ RenderStageInfo ForwardStage::initInfo = { {true, RenderQueueSortMode::BACK_TO_FRONT, {"default", "planarShadow"}}}}; const RenderStageInfo &ForwardStage::getInitializeInfo() { return ForwardStage::initInfo; } -ForwardStage::ForwardStage() { - _batchedQueue = CC_NEW(RenderBatchedQueue); +ForwardStage::ForwardStage() { + _batchedQueue = CC_NEW(RenderBatchedQueue); _instancedQueue = CC_NEW(RenderInstancedQueue); - _uiPhase = CC_NEW(UIPhase); + _uiPhase = CC_NEW(UIPhase); } ForwardStage::~ForwardStage() = default; @@ -74,36 +74,22 @@ ForwardStage::~ForwardStage() = default; bool ForwardStage::initialize(const RenderStageInfo &info) { RenderStage::initialize(info); _renderQueueDescriptors = info.renderQueues; - _phaseID = getPhaseID("default"); + _phaseID = getPhaseID("default"); return true; } void ForwardStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { RenderStage::activate(pipeline, flow); + for (const auto &descriptor : _renderQueueDescriptors) { - uint phase = 0; - for (const auto &stage : descriptor.stages) { - phase |= getPhaseID(stage); - } - - std::function sortFunc = opaqueCompareFn; - switch (descriptor.sortMode) { - case RenderQueueSortMode::BACK_TO_FRONT: - sortFunc = transparentCompareFn; - break; - case RenderQueueSortMode::FRONT_TO_BACK: - sortFunc = opaqueCompareFn; - break; - default: - break; - } - - RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; + uint phase = convertPhase(descriptor.stages); + RenderQueueSortFunc sortFunc = convertQueueSortFunc(descriptor.sortMode); + RenderQueueCreateInfo info = {descriptor.isTransparent, phase, sortFunc}; _renderQueues.emplace_back(CC_NEW(RenderQueue(std::move(info)))); } _additiveLightQueue = CC_NEW(RenderAdditiveLightQueue(_pipeline)); - _planarShadowQueue = CC_NEW(PlanarShadowQueue(_pipeline)); + _planarShadowQueue = CC_NEW(PlanarShadowQueue(_pipeline)); _uiPhase->activate(pipeline); } @@ -119,22 +105,22 @@ void ForwardStage::destroy() { void ForwardStage::render(Camera *camera) { _instancedQueue->clear(); _batchedQueue->clear(); - auto *pipeline = static_cast(_pipeline); - auto *const sceneData = _pipeline->getPipelineSceneData(); - auto *const sharedData = sceneData->getSharedData(); + auto * pipeline = static_cast(_pipeline); + auto *const sceneData = _pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); const auto &renderObjects = sceneData->getRenderObjects(); for (auto *queue : _renderQueues) { queue->clear(); } - uint m = 0; - uint p = 0; + uint m = 0; + uint p = 0; size_t k = 0; for (auto ro : renderObjects) { - const auto *const model = ro.model; - const auto *const subModelID = model->getSubModelID(); - const auto subModelCount = subModelID[0]; + const auto *const model = ro.model; + const auto *const subModelID = model->getSubModelID(); + const auto subModelCount = subModelID[0]; for (m = 1; m <= subModelCount; ++m) { const auto *subModel = cc::pipeline::ModelView::getSubModelView(subModelID[m]); for (p = 0; p < subModel->passCount; ++p) { @@ -169,11 +155,11 @@ void ForwardStage::render(Camera *camera) { _planarShadowQueue->gatherShadowPasses(camera, cmdBuff); // render area is not oriented - uint w = camera->getWindow()->hasOnScreenAttachments && static_cast(_device->getSurfaceTransform()) % 2 ? camera->height : camera->width; - uint h = camera->getWindow()->hasOnScreenAttachments && static_cast(_device->getSurfaceTransform()) % 2 ? camera->width : camera->height; - _renderArea.x = static_cast(camera->viewportX * w); - _renderArea.y = static_cast(camera->viewportY * h); - _renderArea.width = static_cast(camera->viewportWidth * w * sharedData->shadingScale); + uint w = camera->getWindow()->hasOnScreenAttachments && static_cast(_device->getSurfaceTransform()) % 2 ? camera->height : camera->width; + uint h = camera->getWindow()->hasOnScreenAttachments && static_cast(_device->getSurfaceTransform()) % 2 ? camera->width : camera->height; + _renderArea.x = static_cast(camera->viewportX * w); + _renderArea.y = static_cast(camera->viewportY * h); + _renderArea.width = static_cast(camera->viewportWidth * w * sharedData->shadingScale); _renderArea.height = static_cast(camera->viewportHeight * h * sharedData->shadingScale); if (hasFlag(static_cast(camera->clearFlag), gfx::ClearFlagBit::COLOR)) { @@ -192,7 +178,7 @@ void ForwardStage::render(Camera *camera) { _clearColors[0].w = camera->clearColor.w; - auto *framebuffer = camera->getWindow()->getFramebuffer(); + auto * framebuffer = camera->getWindow()->getFramebuffer(); const auto &colorTextures = framebuffer->getColorTextures(); auto *renderPass = !colorTextures.empty() && colorTextures[0] ? framebuffer->getRenderPass() : pipeline->getOrCreateRenderPass(static_cast(camera->clearFlag)); diff --git a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp index ed9c93b243..bbc723948f 100644 --- a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp +++ b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp @@ -117,7 +117,7 @@ void ShadowFlow::resizeShadowMap(const Light *light, const Shadows *shadowInfo){ auto * device = gfx::Device::getInstance(); const auto width = static_cast(shadowInfo->size.x); const auto height = static_cast(shadowInfo->size.y); - const auto format = device->hasFeature(gfx::Feature::TEXTURE_HALF_FLOAT) + const auto format = supportsHalfFloatTexture(device) ? (shadowInfo->packing ? gfx::Format::RGBA8 : gfx::Format::RGBA16F) : gfx::Format::RGBA8; @@ -172,7 +172,7 @@ void ShadowFlow::initShadowFrameBuffer(RenderPipeline *pipeline, const Light *li const auto shadowMapSize = shadowInfo->size; const auto width = static_cast(shadowMapSize.x); const auto height = static_cast(shadowMapSize.y); - const auto format = device->hasFeature(gfx::Feature::TEXTURE_HALF_FLOAT) + const auto format = supportsHalfFloatTexture(device) ? (shadowInfo->packing ? gfx::Format::RGBA8 : gfx::Format::RGBA16F) : gfx::Format::RGBA8; diff --git a/native/templates/cocos2dx_files.json b/native/templates/cocos2dx_files.json index 11c05d714d..5950a71830 100644 --- a/native/templates/cocos2dx_files.json +++ b/native/templates/cocos2dx_files.json @@ -2,6 +2,7 @@ "common": [ ".browserslistrc", ".clang-format", + ".clang-format-ignore", ".clang-tidy", ".github/workflows/clang-format.yml", ".github/workflows/clangtidy-android.yml", diff --git a/native/templates/common/Classes/Game.cpp b/native/templates/common/Classes/Game.cpp index 74e68e708a..e22f743dd4 100644 --- a/native/templates/common/Classes/Game.cpp +++ b/native/templates/common/Classes/Game.cpp @@ -31,7 +31,7 @@ #include "cocos/bindings/manual/jsb_module_register.h" #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) - #include "platform/device.h" + #include "platform/Device.h" #endif Game::Game(int width, int height) : cc::Application(width, height) {} diff --git a/native/tools/tojs/pipeline.ini b/native/tools/tojs/pipeline.ini index da179a288c..a1db1a481f 100644 --- a/native/tools/tojs/pipeline.ini +++ b/native/tools/tojs/pipeline.ini @@ -49,7 +49,7 @@ skip = ForwardPipeline::[getOrCreateRenderPass getLightsUBO getValidLights getLi ShadowFlow::[initialize activate destroy render], ShadowStage::[initialize activate destroy render clearFramebuffer], InstancedBuffer::[merge uploadBuffers clear getInstances getPass hasPendingModels dynamicOffsets], - DeferredPipeline::[getOrCreateRenderPass getLightsUBO getValidLights getLightBuffers getLightIndexOffsets getLightIndices getQuadIAOnScreen getQuadIAOffScreen setDepth getDepth getRenderArea createQuadInputAssembler destroyQuadInputAssembler getDeferredRenderData updateQuadVertexData genQuadVertexData], + DeferredPipeline::[getOrCreateRenderPass getLightsUBO getValidLights getLightBuffers getLightIndexOffsets getLightIndices getQuadIAOffScreen setDepth getDepth getRenderArea createQuadInputAssembler destroyQuadInputAssembler getDeferredRenderData updateQuadVertexData genQuadVertexData], GbufferFlow::[initialize activate destroy render getFrameBuffer createRenderPass createRenderTargets], GbufferStage::[initialize activate destroy render], LightingFlow::[initialize activate destroy render createRenderPass createFrameBuffer getLightingFrameBuffer], diff --git a/native/tools/travis-scripts/run-script.sh b/native/tools/travis-scripts/run-script.sh index 3be3ffc76d..e590f897bb 100755 --- a/native/tools/travis-scripts/run-script.sh +++ b/native/tools/travis-scripts/run-script.sh @@ -84,7 +84,9 @@ function build_android() sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$COCOS2DX_ROOT@g" gradle.properties - sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86@g" gradle.properties + # To speedup CI, compile arm64-v8a only + # sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86@g" gradle.properties + sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=arm64-v8a@g" gradle.properties #echo "Compile Android - ndk-build ..." #./gradlew assembleDebug --quiet @@ -191,10 +193,10 @@ function build_windows() cd build-win32 RES_DIR=$COCOS2DX_ROOT/templates/win32/build-win32 cmake ../ -G"Visual Studio 15 2017" -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT - cmake --build . --config Debug - echo "Compile Win32 Debug Done!" + # cmake --build . --config Debug + # echo "Compile Win32 Debug Done!" cmake --build . --config Release - echo "Compile Win32 Debug Done!" + echo "Compile Win32 Release Done!" }