From 9e00d512aed00333015d4a335fa59c799925cc1d Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Wed, 24 May 2023 14:27:28 +0800 Subject: [PATCH] render pipeline add subpass (#15141) --- cocos/rendering/custom/pipeline.ts | 236 +++++++++++--- cocos/rendering/custom/private.ts | 27 +- cocos/rendering/custom/render-graph.ts | 5 +- cocos/rendering/custom/types.ts | 27 ++ editor/exports/offline-mappings.ts | 3 + .../cocos/renderer/gfx-base/GFXDef-common.h | 18 +- .../cocos/renderer/gfx-gles2/GLES2Device.cpp | 7 + .../renderer/gfx-gles3/GLES3CommandBuffer.h | 1 + .../renderer/gfx-gles3/GLES3Commands.cpp | 299 ++++++------------ .../cocos/renderer/gfx-gles3/GLES3Commands.h | 2 +- .../cocos/renderer/gfx-gles3/GLES3Device.cpp | 12 +- .../renderer/gfx-gles3/GLES3GPUContext.cpp | 5 +- .../renderer/gfx-gles3/GLES3GPUObjects.h | 27 +- .../renderer/gfx-gles3/GLES3PipelineState.cpp | 43 ++- .../gfx-gles3/GLES3PrimaryCommandBuffer.cpp | 9 +- .../gfx-validator/DeviceValidator.cpp | 20 -- .../cocos/renderer/gfx-vulkan/VKCommands.cpp | 6 +- native/cocos/renderer/gfx-vulkan/VKDevice.cpp | 26 +- native/cocos/renderer/gfx-vulkan/VKDevice.h | 1 + native/cocos/renderer/gfx-vulkan/VKUtils.cpp | 8 + native/cocos/renderer/gfx-vulkan/VKUtils.h | 1 + .../gfx-vulkan/states/VKTextureBarrier.cpp | 3 +- .../pipeline/custom/FrameGraphDispatcher.cpp | 175 +++++++--- .../pipeline/custom/NativeExecutor.cpp | 142 +++++++-- .../pipeline/custom/NativePipeline.cpp | 18 ++ .../pipeline/custom/NativePipelineTypes.h | 35 +- .../pipeline/custom/NativeProgramLibrary.cpp | 7 +- .../pipeline/custom/NativeRenderGraph.cpp | 68 ++-- .../pipeline/custom/NativeResourceGraph.cpp | 17 + .../renderer/pipeline/custom/PrivateTypes.h | 2 +- .../pipeline/custom/RenderCommonFwd.h | 1 + .../pipeline/custom/RenderCommonJsb.cpp | 67 ++++ .../pipeline/custom/RenderCommonJsb.h | 5 + .../pipeline/custom/RenderCommonNames.h | 1 + .../pipeline/custom/RenderCommonTypes.cpp | 21 ++ .../pipeline/custom/RenderCommonTypes.h | 24 ++ .../pipeline/custom/RenderGraphTypes.cpp | 9 +- .../pipeline/custom/RenderGraphTypes.h | 6 +- .../pipeline/custom/RenderInterfaceTypes.h | 65 +--- .../renderer/pipeline/custom/test/test.h | 9 +- 40 files changed, 931 insertions(+), 527 deletions(-) diff --git a/cocos/rendering/custom/pipeline.ts b/cocos/rendering/custom/pipeline.ts index b9e45505aa..2a1e40e41c 100644 --- a/cocos/rendering/custom/pipeline.ts +++ b/cocos/rendering/custom/pipeline.ts @@ -36,7 +36,7 @@ import { GlobalDSManager } from '../global-descriptor-set-manager'; import { Mat4, Quat, Vec2, Vec4 } from '../../core/math'; import { MacroRecord } from '../../render-scene/core/pass-utils'; import { PipelineSceneData } from '../pipeline-scene-data'; -import { AccessType, ClearValue, ClearValueType, ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResolvePair, ResourceResidency, SceneFlags, TaskType, UpdateFrequency } from './types'; +import { AccessType, ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResolvePair, ResourceResidency, SceneFlags, TaskType, UpdateFrequency, UploadPair } from './types'; import { RenderScene } from '../../render-scene/core/render-scene'; import { RenderWindow } from '../../render-scene/core/render-window'; import { Model } from '../../render-scene/scene'; @@ -120,10 +120,20 @@ export interface RenderQueueBuilder extends Setter { /** * @deprecated method will be removed in 3.8.0 */ - addSceneOfCamera (camera: Camera, light: LightInfo, sceneFlags?: SceneFlags): void; + addSceneOfCamera ( + camera: Camera, + light: LightInfo, + sceneFlags?: SceneFlags): void; addScene (scene: RenderScene, sceneFlags?: SceneFlags): void; - addFullscreenQuad (material: Material, passID: number, sceneFlags?: SceneFlags): void; - addCameraQuad (camera: Camera, material: Material, passID: number, sceneFlags?: SceneFlags): void; + addFullscreenQuad ( + material: Material, + passID: number, + sceneFlags?: SceneFlags): void; + addCameraQuad ( + camera: Camera, + material: Material, + passID: number, + sceneFlags?: SceneFlags): void; clearRenderTarget (name: string, color?: Color): void; setViewport (viewport: Viewport): void; /** @@ -133,9 +143,23 @@ export interface RenderQueueBuilder extends Setter { } export interface BasicRenderPassBuilder extends Setter { - addRenderTarget (name: string, loadOp?: LoadOp, storeOp?: StoreOp, color?: Color): void; - addDepthStencil (name: string, loadOp?: LoadOp, storeOp?: StoreOp, depth?: number, stencil?: number, clearFlags?: ClearFlagBit): void; - addTexture (name: string, slotName: string, sampler?: Sampler | null, plane?: number): void; + addRenderTarget ( + name: string, + loadOp?: LoadOp, + storeOp?: StoreOp, + color?: Color): void; + addDepthStencil ( + name: string, + loadOp?: LoadOp, + storeOp?: StoreOp, + depth?: number, + stencil?: number, + clearFlags?: ClearFlagBit): void; + addTexture ( + name: string, + slotName: string, + sampler?: Sampler | null, + plane?: number): void; /** * @deprecated method will be removed in 3.8.0 */ @@ -159,28 +183,89 @@ export interface BasicPipeline extends PipelineRuntime { /** * @deprecated method will be removed in 3.8.0 */ - addRenderTexture (name: string, format: Format, width: number, height: number, renderWindow: RenderWindow): number; - addRenderWindow (name: string, format: Format, width: number, height: number, renderWindow: RenderWindow): number; + addRenderTexture ( + name: string, + format: Format, + width: number, + height: number, + renderWindow: RenderWindow): number; + addRenderWindow ( + name: string, + format: Format, + width: number, + height: number, + renderWindow: RenderWindow): number; updateRenderWindow (name: string, renderWindow: RenderWindow): void; - addRenderTarget (name: string, format: Format, width: number, height: number, residency?: ResourceResidency): number; - addDepthStencil (name: string, format: Format, width: number, height: number, residency?: ResourceResidency): number; - updateRenderTarget (name: string, width: number, height: number, format?: Format): void; - updateDepthStencil (name: string, width: number, height: number, format?: Format): void; + addRenderTarget ( + name: string, + format: Format, + width: number, + height: number, + residency?: ResourceResidency): number; + addDepthStencil ( + name: string, + format: Format, + width: number, + height: number, + residency?: ResourceResidency): number; + updateRenderTarget ( + name: string, + width: number, + height: number, + format?: Format): void; + updateDepthStencil ( + name: string, + width: number, + height: number, + format?: Format): void; beginFrame (): void; endFrame (): void; - addRenderPass (width: number, height: number, layoutName?: string): BasicRenderPassBuilder; - addMultisampleRenderPass (width: number, height: number, count: number, quality: number, layoutName?: string): BasicRenderPassBuilder; + addRenderPass ( + width: number, + height: number, + layoutName?: string): BasicRenderPassBuilder; + addMultisampleRenderPass ( + width: number, + height: number, + count: number, + quality: number, + layoutName?: string): BasicRenderPassBuilder; addResolvePass (resolvePairs: ResolvePair[]): void; addCopyPass (copyPairs: CopyPair[]): void; getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout | null; } export interface RenderSubpassBuilder extends Setter { - addRenderTarget (name: string, accessType: AccessType, slotName?: string, loadOp?: LoadOp, storeOp?: StoreOp, color?: Color): void; - addDepthStencil (name: string, accessType: AccessType, depthSlotName?: string, stencilSlotName?: string, loadOp?: LoadOp, storeOp?: StoreOp, depth?: number, stencil?: number, clearFlags?: ClearFlagBit): void; - addTexture (name: string, slotName: string, sampler?: Sampler | null, plane?: number): void; - addStorageBuffer (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; - addStorageImage (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; + addRenderTarget ( + name: string, + accessType: AccessType, + slotName?: string, + loadOp?: LoadOp, + storeOp?: StoreOp, + color?: Color): void; + addDepthStencil ( + name: string, + accessType: AccessType, + depthSlotName?: string, + stencilSlotName?: string, + loadOp?: LoadOp, + storeOp?: StoreOp, + depth?: number, + stencil?: number, + clearFlags?: ClearFlagBit): void; + addTexture ( + name: string, + slotName: string, + sampler?: Sampler | null, + plane?: number): void; + addStorageBuffer ( + name: string, + accessType: AccessType, + slotName: string): void; + addStorageImage ( + name: string, + accessType: AccessType, + slotName: string): void; /** * @deprecated method will be removed in 3.8.0 */ @@ -196,18 +281,37 @@ export interface RenderSubpassBuilder extends Setter { export interface MultisampleRenderSubpassBuilder extends RenderSubpassBuilder { resolveRenderTarget (source: string, target: string): void; - resolveDepthStencil (source: string, target: string, depthMode?: ResolveMode, stencilMode?: ResolveMode): void; + resolveDepthStencil ( + source: string, + target: string, + depthMode?: ResolveMode, + stencilMode?: ResolveMode): void; } export interface ComputeQueueBuilder extends Setter { - addDispatch (threadGroupCountX: number, threadGroupCountY: number, threadGroupCountZ: number, material?: Material, passID?: number): void; + addDispatch ( + threadGroupCountX: number, + threadGroupCountY: number, + threadGroupCountZ: number, + material?: Material, + passID?: number): void; } export interface ComputeSubpassBuilder extends Setter { addRenderTarget (name: string, slotName: string): void; - addTexture (name: string, slotName: string, sampler?: Sampler | null, plane?: number): void; - addStorageBuffer (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; - addStorageImage (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; + addTexture ( + name: string, + slotName: string, + sampler?: Sampler | null, + plane?: number): void; + addStorageBuffer ( + name: string, + accessType: AccessType, + slotName: string): void; + addStorageImage ( + name: string, + accessType: AccessType, + slotName: string): void; /** * @deprecated method will be removed in 3.8.0 */ @@ -220,10 +324,19 @@ export interface ComputeSubpassBuilder extends Setter { } export interface RenderPassBuilder extends BasicRenderPassBuilder { - addStorageBuffer (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; - addStorageImage (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; + addStorageBuffer ( + name: string, + accessType: AccessType, + slotName: string): void; + addStorageImage ( + name: string, + accessType: AccessType, + slotName: string): void; addRenderSubpass (layoutName?: string): RenderSubpassBuilder; - addMultisampleRenderSubpass (count: number, quality: number, layoutName?: string): MultisampleRenderSubpassBuilder; + addMultisampleRenderSubpass ( + count: number, + quality: number, + layoutName?: string): MultisampleRenderSubpassBuilder; addComputeSubpass (layoutName?: string): ComputeSubpassBuilder; /** * @beta function signature might change @@ -232,9 +345,19 @@ export interface RenderPassBuilder extends BasicRenderPassBuilder { } export interface ComputePassBuilder extends Setter { - addTexture (name: string, slotName: string, sampler?: Sampler | null, plane?: number): void; - addStorageBuffer (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; - addStorageImage (name: string, accessType: AccessType, slotName: string, clearType?: ClearValueType, clearValue?: ClearValue): void; + addTexture ( + name: string, + slotName: string, + sampler?: Sampler | null, + plane?: number): void; + addStorageBuffer ( + name: string, + accessType: AccessType, + slotName: string): void; + addStorageImage ( + name: string, + accessType: AccessType, + slotName: string): void; /** * @deprecated method will be removed in 3.8.0 */ @@ -270,23 +393,56 @@ export interface SceneTransversal { } export interface Pipeline extends BasicPipeline { - addStorageBuffer (name: string, format: Format, size: number, residency?: ResourceResidency): number; - addStorageTexture (name: string, format: Format, width: number, height: number, residency?: ResourceResidency): number; - addShadingRateTexture (name: string, width: number, height: number, residency?: ResourceResidency): number; - updateStorageBuffer (name: string, size: number, format?: Format): void; - updateStorageTexture (name: string, width: number, height: number, format?: Format): void; - updateShadingRateTexture (name: string, width: number, height: number): void; - addRenderPass (width: number, height: number, layoutName?: string): RenderPassBuilder; + addStorageBuffer ( + name: string, + format: Format, + size: number, + residency?: ResourceResidency): number; + addStorageTexture ( + name: string, + format: Format, + width: number, + height: number, + residency?: ResourceResidency): number; + addShadingRateTexture ( + name: string, + width: number, + height: number, + residency?: ResourceResidency): number; + updateStorageBuffer ( + name: string, + size: number, + format?: Format): void; + updateStorageTexture ( + name: string, + width: number, + height: number, + format?: Format): void; + updateShadingRateTexture ( + name: string, + width: number, + height: number): void; + addRenderPass ( + width: number, + height: number, + layoutName?: string): RenderPassBuilder; addComputePass (layoutName: string): ComputePassBuilder; + addUploadPass (uploadPairs: UploadPair[]): void; addMovePass (movePairs: MovePair[]): void; /** * @beta function signature might change */ - addCustomBuffer (name: string, info: BufferInfo, type: string): number; + addCustomBuffer ( + name: string, + info: BufferInfo, + type: string): number; /** * @beta function signature might change */ - addCustomTexture (name: string, info: TextureInfo, type: string): number; + addCustomTexture ( + name: string, + info: TextureInfo, + type: string): number; } export interface PipelineBuilder { diff --git a/cocos/rendering/custom/private.ts b/cocos/rendering/custom/private.ts index eb74c69bb6..62e2393c62 100644 --- a/cocos/rendering/custom/private.ts +++ b/cocos/rendering/custom/private.ts @@ -41,13 +41,30 @@ export interface ProgramProxy { export interface ProgramLibrary { addEffect (effectAsset: EffectAsset): void; precompileEffect (device: Device, effectAsset: EffectAsset): void; - getKey (phaseID: number, programName: string, defines: MacroRecord): string; - getPipelineLayout (device: Device, phaseID: number, programName: string): PipelineLayout; - getMaterialDescriptorSetLayout (device: Device, phaseID: number, programName: string): DescriptorSetLayout; - getLocalDescriptorSetLayout (device: Device, phaseID: number, programName: string): DescriptorSetLayout; + getKey ( + phaseID: number, + programName: string, + defines: MacroRecord): string; + getPipelineLayout ( + device: Device, + phaseID: number, + programName: string): PipelineLayout; + getMaterialDescriptorSetLayout ( + device: Device, + phaseID: number, + programName: string): DescriptorSetLayout; + getLocalDescriptorSetLayout ( + device: Device, + phaseID: number, + programName: string): DescriptorSetLayout; getProgramInfo (phaseID: number, programName: string): IProgramInfo; getShaderInfo (phaseID: number, programName: string): ShaderInfo; - getProgramVariant (device: Device, phaseID: number, name: string, defines: MacroRecord, key?: string | null): ProgramProxy | null; + getProgramVariant ( + device: Device, + phaseID: number, + name: string, + defines: MacroRecord, + key?: string | null): ProgramProxy | null; getBlockSizes (phaseID: number, programName: string): number[]; getHandleMap (phaseID: number, programName: string): Record; getProgramID (phaseID: number, programName: string): number; diff --git a/cocos/rendering/custom/render-graph.ts b/cocos/rendering/custom/render-graph.ts index f64e9aeb81..7559d52490 100644 --- a/cocos/rendering/custom/render-graph.ts +++ b/cocos/rendering/custom/render-graph.ts @@ -32,8 +32,9 @@ import { AdjI, AdjacencyGraph, BidirectionalGraph, ComponentGraph, ED, InEI, Mut import { Material } from '../../asset/assets'; import { Camera } from '../../render-scene/scene/camera'; import { AccessFlagBit, Buffer, ClearFlagBit, Color, Format, Framebuffer, RenderPass, SampleCount, Sampler, SamplerInfo, Swapchain, Texture, TextureFlagBit, Viewport } from '../../gfx'; -import { ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags } from './types'; +import { ComputeView, CopyPair, LightInfo, MovePair, QueueHint, RasterView, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UploadPair } from './types'; import { RenderScene } from '../../render-scene/core/render-scene'; +import { RenderWindow } from '../../render-scene/core/render-window'; export class ResourceDesc { dimension: ResourceDimension = ResourceDimension.BUFFER; @@ -60,6 +61,7 @@ export class RenderSwapchain { this.swapchain = swapchain; } /*pointer*/ swapchain: Swapchain | null; + /*pointer*/ renderWindow: RenderWindow | null = null; currentID = 0; numBackBuffers = 0; generation = 0xFFFFFFFF; @@ -1084,6 +1086,7 @@ export class ResolvePass { export class CopyPass { readonly copyPairs: CopyPair[] = []; + readonly uploadPairs: UploadPair[] = []; } export class MovePass { diff --git a/cocos/rendering/custom/types.ts b/cocos/rendering/custom/types.ts index 494f8941a4..73c04ffb94 100644 --- a/cocos/rendering/custom/types.ts +++ b/cocos/rendering/custom/types.ts @@ -495,6 +495,33 @@ export class CopyPair { targetPlaneSlice: number; } +export class UploadPair { + constructor ( + source: Uint8Array = new Uint8Array(0), + target = '', + mipLevels = 0xFFFFFFFF, + numSlices = 0xFFFFFFFF, + targetMostDetailedMip = 0, + targetFirstSlice = 0, + targetPlaneSlice = 0, + ) { + this.source = source; + this.target = target; + this.mipLevels = mipLevels; + this.numSlices = numSlices; + this.targetMostDetailedMip = targetMostDetailedMip; + this.targetFirstSlice = targetFirstSlice; + this.targetPlaneSlice = targetPlaneSlice; + } + readonly source: Uint8Array; + target: string; + mipLevels: number; + numSlices: number; + targetMostDetailedMip: number; + targetFirstSlice: number; + targetPlaneSlice: number; +} + export class MovePair { constructor ( source = '', diff --git a/editor/exports/offline-mappings.ts b/editor/exports/offline-mappings.ts index 9bfa066fb4..8fd9989787 100644 --- a/editor/exports/offline-mappings.ts +++ b/editor/exports/offline-mappings.ts @@ -95,7 +95,10 @@ typeMap.usampler3D = Type.SAMPLER3D; typeMap.isamplerCube = Type.SAMPLER_CUBE; typeMap.usamplerCube = Type.SAMPLER_CUBE; typeMap.samplerCubeShadow = Type.SAMPLER_CUBE; +typeMap.iimage2D = Type.IMAGE2D; typeMap.uimage2D = Type.IMAGE2D; +typeMap.usubpassInput = Type.SUBPASS_INPUT; +typeMap.isubpassInput = Type.SUBPASS_INPUT; const isSampler = (type) => type >= Type.SAMPLER1D; const isPaddedMatrix = (type) => type >= Type.MAT2 && type < Type.MAT4; diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index cc07b8fa6a..621ba6d41c 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -173,21 +173,11 @@ enum class Feature : uint32_t { MULTIPLE_RENDER_TARGETS, BLEND_MINMAX, COMPUTE_SHADER, - // This flag indicates whether the device can benefit from subpass-style usages. - // Specifically, this only differs on the GLES backends: the Framebuffer Fetch - // extension is used to simulate input attachments, so the flag is not set when - // the extension is not supported, and you should switch to the fallback branch - // (without the extension requirement) in GLSL shader sources accordingly. - // Everything else can remain the same. - // - // Another caveat when using the Framebuffer Fetch extensions in shaders is that - // for subpasses with exactly 4 inout attachments the output is automatically set - // to the last attachment (taking advantage of 'inout' property), and a separate - // blit operation (if needed) will be added for you afterwards to transfer the - // rendering result to the correct subpass output texture. This is to ameliorate - // the max number of attachment limit(4) situation for many devices, and shader - // sources inside this kind of subpass must match this behavior. + // @deprecated INPUT_ATTACHMENT_BENEFIT, + SUBPASS_COLOR_INPUT, + SUBPASS_DEPTH_STENCIL_INPUT, + RASTERIZATION_ORDER_COHERENT, COUNT, }; CC_ENUM_CONVERSION_OPERATOR(Feature); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index 6f31b9d64a..18f21f5a10 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -147,9 +147,16 @@ bool GLES2Device::doInit(const DeviceInfo & /*info*/) { } else if (checkExtension(CC_TOSTR(GL_EXT_shader_framebuffer_fetch))) { // we only care about EXT_shader_framebuffer_fetch, the ARM version does not support MRT _gpuConstantRegistry->mFBF = FBFSupportLevel::COHERENT; + _features[toNumber(Feature::RASTERIZATION_ORDER_COHERENT)] = true; fbfLevelStr = "COHERENT"; } _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = _gpuConstantRegistry->mFBF != FBFSupportLevel::NONE; + _features[toNumber(Feature::SUBPASS_COLOR_INPUT)] = true; + } + + if (checkExtension(CC_TOSTR(ARM_shader_framebuffer_fetch_depth_stencil))) { + _features[toNumber(Feature::SUBPASS_DEPTH_STENCIL_INPUT)] = true; + fbfLevelStr += "_DEPTH_STENCIL"; } #endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h index 5050ac8933..594a8e059f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h @@ -36,6 +36,7 @@ struct GLES3CmdPackage; struct GLES3GPUPipelineState; struct GLES3GPUInputAssembler; struct GLES3GPUDescriptorSet; +struct GLES3GPURenderPass; class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer { public: diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index 33aea2b405..1b1be5ba6a 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -1394,7 +1394,7 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader, GL gpuImage.name = image.name; gpuImage.type = image.type; gpuImage.count = image.count; - gpuImage.glMemoryAccess = GL_MEMORY_ACCESS[toNumber(image.memoryAccess)]; + gpuImage.glMemoryAccess = GL_MEMORY_ACCESS[toNumber(image.memoryAccess) - 1]; gpuImage.units.resize(gpuImage.count); gpuImage.glLoc = glLoc; // storage image units are immutable @@ -1419,76 +1419,48 @@ void cmdFuncGLES3DestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } void cmdFuncGLES3CreateRenderPass(GLES3Device * /*device*/, GLES3GPURenderPass *gpuRenderPass) { - // calculate the life cycle of each attachments - auto updateLifeCycle = [](GLES3GPURenderPass::AttachmentStatistics &statistics, size_t index) { - if (statistics.loadSubpass == SUBPASS_EXTERNAL) statistics.loadSubpass = utils::toUint(index); - statistics.storeSubpass = utils::toUint(index); - }; - auto calculateLifeCycle = [&](GLES3GPURenderPass::AttachmentStatistics &statistics, uint32_t targetAttachment) { - for (size_t j = 0U; j < gpuRenderPass->subpasses.size(); ++j) { - auto &subpass = gpuRenderPass->subpasses[j]; - for (size_t k = 0U; k < subpass.colors.size(); ++k) { - if (subpass.colors[k] == targetAttachment) { - updateLifeCycle(statistics, j); - } - if (!subpass.resolves.empty() && subpass.resolves[k] == targetAttachment) { - updateLifeCycle(statistics, j); - } + auto &subPasses = gpuRenderPass->subpasses; + auto &attachments = gpuRenderPass->colorAttachments; + auto &drawBuffers = gpuRenderPass->drawBuffers; + + gpuRenderPass->drawBuffers.resize(subPasses.size()); + gpuRenderPass->indices.resize(attachments.size(), INVALID_BINDING); + + for (uint32_t i = 0; i < subPasses.size(); ++i) { + auto &sub = subPasses[i]; + auto &drawBuffer = drawBuffers[i]; + + std::vector visited(gpuRenderPass->colorAttachments.size()); + for (auto &input : sub.inputs) { + visited[input] = true; + drawBuffer.emplace_back(input); + } + + for (auto &color : sub.colors) { + auto &index = gpuRenderPass->indices[color]; + if (index == INVALID_BINDING) { + index = static_cast(gpuRenderPass->colors.size()); + gpuRenderPass->colors.emplace_back(color); } - for (unsigned int input : subpass.inputs) { - if (input == targetAttachment) { - updateLifeCycle(statistics, j); - } - } - if (subpass.depthStencil == targetAttachment) { - updateLifeCycle(statistics, j); - } - if (subpass.depthStencilResolve == targetAttachment) { - updateLifeCycle(statistics, j); + if (!visited[color]) { + drawBuffer.emplace_back(color); } } - }; - bool hasDepth = gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN; - gpuRenderPass->statistics.resize(gpuRenderPass->colorAttachments.size() + hasDepth); - for (size_t i = 0U; i < gpuRenderPass->statistics.size(); ++i) { - calculateLifeCycle(gpuRenderPass->statistics[i], static_cast(i)); - CC_ASSERT(gpuRenderPass->statistics[i].loadSubpass != SUBPASS_EXTERNAL && - gpuRenderPass->statistics[i].storeSubpass != SUBPASS_EXTERNAL); - } - - // if barrier deduce enabled: should deduce this from subpass & attachment access infos - if constexpr (ENABLE_GRAPH_AUTO_BARRIER) { - gpuRenderPass->subpassBarriers.resize(gpuRenderPass->dependencies.size()); - for (size_t i = 0; i < gpuRenderPass->subpassBarriers.size(); ++i) { - auto &barrier = gpuRenderPass->subpassBarriers[i]; - const auto &dependency = gpuRenderPass->dependencies[i]; - if (dependency.generalBarrier) { - barrier.prevAccesses = dependency.generalBarrier->getInfo().prevAccesses; - barrier.nextAccesses = dependency.generalBarrier->getInfo().nextAccesses; - completeBarrier(&barrier); - completeBarrier(&gpuRenderPass->blockBarrier); - } - - CC_ASSERT(dependency.prevAccesses.size() == dependency.nextAccesses.size()); - - for (size_t index = 0; index < dependency.prevAccesses.size(); ++index) { - barrier.prevAccesses = dependency.prevAccesses[i]; - barrier.nextAccesses = dependency.nextAccesses[i]; - completeBarrier(&barrier); - - gpuRenderPass->blockBarrier.glBarriers |= barrier.glBarriers; - gpuRenderPass->blockBarrier.glBarriersByRegion |= barrier.glBarriersByRegion; + for (auto &resolve : sub.resolves) { + auto &index = gpuRenderPass->indices[resolve]; + if (index == INVALID_BINDING) { + index = static_cast(gpuRenderPass->resolves.size()); + gpuRenderPass->resolves.emplace_back(resolve); } } - } else { - gpuRenderPass->subpassBarriers.resize(gpuRenderPass->subpasses.size() + 1); + + gpuRenderPass->depthStencil = sub.depthStencil; } } void cmdFuncGLES3DestroyRenderPass(GLES3Device * /*device*/, GLES3GPURenderPass *gpuRenderPass) { - gpuRenderPass->statistics.clear(); - gpuRenderPass->subpassBarriers.clear(); + } void cmdFuncGLES3CreateInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler) { @@ -1695,40 +1667,11 @@ static void doCreateFramebufferInstance(GLES3Device *device, GLES3GPUFramebuffer } void cmdFuncGLES3CreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO) { - if (gpuFBO->gpuRenderPass->subpasses.size() > 1) { - gpuFBO->usesFBF = device->constantRegistry()->mFBF != FBFSupportLevel::NONE; - } + const auto &colors = gpuFBO->gpuRenderPass->colors; + const auto &resolves = gpuFBO->gpuRenderPass->resolves; + const auto &depthStencil = gpuFBO->gpuRenderPass->depthStencil; - if (gpuFBO->usesFBF) { - for (auto &subpass : gpuFBO->gpuRenderPass->subpasses) { - if (subpass.inputs.size() == 4) { - gpuFBO->uberOnChipOutput = subpass.inputs.back(); - gpuFBO->uberFinalOutput = subpass.colors.back(); - break; - } - } - - gpuFBO->uberColorAttachmentIndices.clear(); - bool hasDepth{gpuFBO->gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN}; - gpuFBO->uberDepthStencil = hasDepth ? utils::toUint(gpuFBO->gpuColorViews.size()) : INVALID_BINDING; - for (uint32_t i = 0U; i < gpuFBO->gpuColorViews.size(); ++i) { - if (i == gpuFBO->uberFinalOutput) continue; - const auto *gpuTexture = gpuFBO->gpuColorViews[i]; - if (GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].hasDepth) { - gpuFBO->uberDepthStencil = i; - continue; - } - gpuFBO->uberColorAttachmentIndices.push_back(i); - } - doCreateFramebufferInstance(device, gpuFBO, gpuFBO->uberColorAttachmentIndices, gpuFBO->uberDepthStencil, &gpuFBO->uberInstance); - } else { - for (const auto &subpass : gpuFBO->gpuRenderPass->subpasses) { - gpuFBO->instances.emplace_back(); - auto &fboInst = gpuFBO->instances.back(); - doCreateFramebufferInstance(device, gpuFBO, subpass.colors, subpass.depthStencil, &fboInst, - subpass.resolves.empty() ? nullptr : subpass.resolves.data(), subpass.depthStencilResolve); - } - } + doCreateFramebufferInstance(device, gpuFBO, colors, depthStencil, &gpuFBO->frameBuffer, resolves.empty() ? nullptr : resolves.data()); } void GLES3GPUFramebuffer::GLFramebuffer::destroy(GLES3GPUStateCache *cache, GLES3GPUFramebufferCacheMap *framebufferCacheMap) { @@ -1749,14 +1692,8 @@ void cmdFuncGLES3DestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gp auto *cache = device->stateCache(); auto *framebufferCacheMap = device->framebufferCacheMap(); - for (auto &instance : gpuFBO->instances) { - instance.framebuffer.destroy(cache, framebufferCacheMap); - instance.resolveFramebuffer.destroy(cache, framebufferCacheMap); - } - gpuFBO->instances.clear(); - - gpuFBO->uberInstance.framebuffer.destroy(cache, framebufferCacheMap); - gpuFBO->uberInstance.resolveFramebuffer.destroy(cache, framebufferCacheMap); + gpuFBO->frameBuffer.framebuffer.destroy(cache, framebufferCacheMap); + gpuFBO->frameBuffer.resolveFramebuffer.destroy(cache, framebufferCacheMap); } void completeBarrier(GLES3GPUGeneralBarrier *barrier) { @@ -1846,11 +1783,11 @@ void cmdFuncGLES3CreateGeneralBarrier(GLES3Device * /*device*/, GLES3GPUGeneralB } void cmdFuncGLES3CreateQueryPool(GLES3Device * /*device*/, GLES3GPUQueryPool *gpuQueryPool) { - GL_CHECK(glGenQueries(gpuQueryPool->maxQueryObjects, &gpuQueryPool->glQueryIds[0])); + GL_CHECK(glGenQueries(gpuQueryPool->maxQueryObjects, gpuQueryPool->glQueryIds.data())); } void cmdFuncGLES3DestroyQueryPool(GLES3Device * /*device*/, GLES3GPUQueryPool *gpuQueryPool) { - GL_CHECK(glDeleteQueries(gpuQueryPool->maxQueryObjects, &gpuQueryPool->glQueryIds[0])); + GL_CHECK(glDeleteQueries(gpuQueryPool->maxQueryObjects, gpuQueryPool->glQueryIds.data())); } void cmdFuncGLES3Query(GLES3Device * /*device*/, GLES3QueryPool *queryPool, GLES3QueryType type, uint32_t id) { @@ -1916,32 +1853,21 @@ void cmdFuncGLES3Query(GLES3Device * /*device*/, GLES3QueryPool *queryPool, GLES } } -void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3GPURenderPass *gpuRenderPass, - GLES3GPUFramebuffer *gpuFramebuffer, const Rect *renderArea, - const Color *clearColors, float clearDepth, uint32_t clearStencil) { - static ccstd::vector invalidAttachments; - +void cmdFuncGLES3BeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFramebuffer, + const Rect *renderArea, const Color *clearColors, float clearDepth, uint32_t clearStencil) { + ccstd::vector invalidAttachments; GLES3GPUStateCache *cache = device->stateCache(); GLES3ObjectCache &gfxStateCache = cache->gfxStateCache; - gfxStateCache.subpassIdx = subpassIdx; - if (subpassIdx) { - gpuRenderPass = gfxStateCache.gpuRenderPass; - gpuFramebuffer = gfxStateCache.gpuFramebuffer; - renderArea = &gfxStateCache.renderArea; - clearColors = gfxStateCache.clearColors.data(); - clearDepth = gfxStateCache.clearDepth; - clearStencil = gfxStateCache.clearStencil; - } else { - gfxStateCache.gpuRenderPass = gpuRenderPass; - gfxStateCache.gpuFramebuffer = gpuFramebuffer; - gfxStateCache.renderArea = *renderArea; - gfxStateCache.clearColors.assign(clearColors, clearColors + gpuRenderPass->colorAttachments.size()); - gfxStateCache.clearDepth = clearDepth; - gfxStateCache.clearStencil = clearStencil; - } + gfxStateCache.subpassIdx = 0; + gfxStateCache.gpuRenderPass = gpuRenderPass; + gfxStateCache.gpuFramebuffer = gpuFramebuffer; + gfxStateCache.renderArea = *renderArea; + gfxStateCache.clearColors.assign(clearColors, clearColors + gpuRenderPass->colorAttachments.size()); + gfxStateCache.clearDepth = clearDepth; + gfxStateCache.clearStencil = clearStencil; if (gpuFramebuffer && gpuRenderPass) { - auto &instance = gpuFramebuffer->usesFBF ? gpuFramebuffer->uberInstance : gpuFramebuffer->instances[subpassIdx]; + auto &instance = gpuFramebuffer->frameBuffer; GLuint glFramebuffer = instance.framebuffer.getFramebuffer(); device->context()->makeCurrent(instance.framebuffer.swapchain, instance.framebuffer.swapchain); @@ -1951,22 +1877,20 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3 cache->glDrawFramebuffer = glFramebuffer; } - if (subpassIdx == 0) { - 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)); - cache->viewport.left = renderArea->x; - cache->viewport.top = renderArea->y; - cache->viewport.width = renderArea->width; - cache->viewport.height = renderArea->height; - } + 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)); + cache->viewport.left = renderArea->x; + cache->viewport.top = renderArea->y; + cache->viewport.width = renderArea->width; + cache->viewport.height = renderArea->height; + } - if (cache->scissor != *renderArea) { - GL_CHECK(glScissor(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); - cache->scissor = *renderArea; - } + if (cache->scissor != *renderArea) { + GL_CHECK(glScissor(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); + cache->scissor = *renderArea; } GLbitfield glClears = 0; @@ -1976,8 +1900,6 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3 bool maskSet = false; auto performLoadOp = [&](uint32_t attachmentIndex, uint32_t glAttachmentIndex) { - if (attachmentIndex == gpuFramebuffer->uberOnChipOutput) attachmentIndex = gpuFramebuffer->uberFinalOutput; - const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[attachmentIndex]; if (colorAttachment.format != Format::UNKNOWN) { switch (colorAttachment.loadOp) { @@ -2008,8 +1930,8 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3 } }; - auto performDepthStencilLoadOp = [&](uint32_t attachmentIndex, bool skipLoad) { - if (attachmentIndex != INVALID_BINDING && !skipLoad) { + auto performDepthStencilLoadOp = [&](uint32_t attachmentIndex) { + if (attachmentIndex != INVALID_BINDING) { LoadOp depthLoadOp = gpuRenderPass->depthStencilAttachment.depthLoadOp; LoadOp stencilLoadOp = gpuRenderPass->depthStencilAttachment.stencilLoadOp; bool hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->depthStencilAttachment.format)].hasStencil; @@ -2081,27 +2003,12 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3 } }; - uint32_t glAttachmentIndex = 0U; - if (gpuFramebuffer->usesFBF) { - if (subpassIdx == 0) { - cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->blockBarrier.glBarriers, gpuRenderPass->blockBarrier.glBarriersByRegion); - - for (const auto attachmentIndex : gpuFramebuffer->uberColorAttachmentIndices) { - performLoadOp(attachmentIndex, glAttachmentIndex++); - } - performDepthStencilLoadOp(gpuFramebuffer->uberDepthStencil, false); - } - } else { - cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->subpassBarriers[subpassIdx].glBarriers, gpuRenderPass->subpassBarriers[subpassIdx].glBarriersByRegion); - - for (const auto attachmentIndex : gpuRenderPass->subpasses[subpassIdx].colors) { - if (gpuRenderPass->statistics[attachmentIndex].loadSubpass != subpassIdx) continue; - performLoadOp(attachmentIndex, glAttachmentIndex++); - } - auto depthIndex = gpuRenderPass->subpasses[subpassIdx].depthStencil; - bool skipLoad = depthIndex == INVALID_BINDING || gpuRenderPass->statistics[depthIndex].loadSubpass != subpassIdx; - performDepthStencilLoadOp(depthIndex, skipLoad); + const auto &attachments = gpuRenderPass->colorAttachments; + const auto &indices = gpuRenderPass->indices; + for (uint32_t i = 0; i < attachments.size(); ++i) { + performLoadOp(i, indices[i]); } + performDepthStencilLoadOp(gpuRenderPass->depthStencil); } } @@ -2119,24 +2026,20 @@ static void ensureScissorRect(GLES3GPUStateCache *cache, int32_t x, int32_t y, u } void cmdFuncGLES3EndRenderPass(GLES3Device *device) { - static ccstd::vector invalidAttachments; + ccstd::vector invalidAttachments; GLES3GPUStateCache *cache = device->stateCache(); GLES3ObjectCache &gfxStateCache = cache->gfxStateCache; GLES3GPURenderPass *gpuRenderPass = gfxStateCache.gpuRenderPass; GLES3GPUFramebuffer *gpuFramebuffer = gfxStateCache.gpuFramebuffer; - const auto &instance = gpuFramebuffer->usesFBF ? gpuFramebuffer->uberInstance : gpuFramebuffer->instances[gfxStateCache.subpassIdx]; + const auto &instance = gpuFramebuffer->frameBuffer; const SubpassInfo &subpass = gpuRenderPass->subpasses[gfxStateCache.subpassIdx]; - bool isTheLastSubpass = gfxStateCache.subpassIdx == gpuRenderPass->subpasses.size() - 1; + GLuint glFramebuffer = instance.framebuffer.getFramebuffer(); GLuint glResolveFramebuffer = instance.resolveFramebuffer.getFramebuffer(); GLenum invalidateTarget = GL_DRAW_FRAMEBUFFER; - invalidAttachments.clear(); - auto performStoreOp = [&](uint32_t attachmentIndex, uint32_t glAttachmentIndex) { - if (attachmentIndex == gpuFramebuffer->uberOnChipOutput) attachmentIndex = gpuFramebuffer->uberFinalOutput; - const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[attachmentIndex]; if (colorAttachment.format != Format::UNKNOWN) { switch (colorAttachment.storeOp) { @@ -2149,8 +2052,8 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { } }; - auto performDepthStencilStoreOp = [&](uint32_t attachmentIndex, bool skipStore) { - if (attachmentIndex != INVALID_BINDING && !skipStore) { + auto performDepthStencilStoreOp = [&](uint32_t attachmentIndex) { + if (attachmentIndex != INVALID_BINDING) { StoreOp depthStoreOp = gpuRenderPass->depthStencilAttachment.depthStoreOp; StoreOp stencilStoreOp = gpuRenderPass->depthStencilAttachment.stencilStoreOp; bool hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->depthStencilAttachment.format)].hasStencil; @@ -2228,41 +2131,17 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { invalidateTarget = GL_READ_FRAMEBUFFER; } - uint32_t glAttachmentIndex = 0U; - if (gpuFramebuffer->usesFBF) { - if (isTheLastSubpass) { - for (const auto attachmentIndex : gpuFramebuffer->uberColorAttachmentIndices) { - performStoreOp(attachmentIndex, glAttachmentIndex++); - } - performDepthStencilStoreOp(gpuFramebuffer->uberDepthStencil, false); - - if (gpuFramebuffer->uberOnChipOutput != INVALID_BINDING) { - TextureBlit region; - auto *blitSrc = gpuFramebuffer->gpuColorViews[gpuFramebuffer->uberOnChipOutput]->gpuTexture; - auto *blitDst = gpuFramebuffer->gpuColorViews[gpuFramebuffer->uberFinalOutput]->gpuTexture; - region.srcExtent.width = region.dstExtent.width = blitSrc->width; - region.srcExtent.height = region.dstExtent.height = blitSrc->height; - cmdFuncGLES3BlitTexture(device, blitSrc, blitDst, ®ion, 1, Filter::POINT); - } - } else { - if (device->constantRegistry()->mFBF == FBFSupportLevel::NON_COHERENT_EXT) { - GL_CHECK(glFramebufferFetchBarrierEXT()); - } else if (device->constantRegistry()->mFBF == FBFSupportLevel::NON_COHERENT_QCOM) { - GL_CHECK(glFramebufferFetchBarrierQCOM()); - } - } - } else { - const auto &indices = subpass.resolves.empty() ? subpass.colors : subpass.resolves; - for (const auto attachmentIndex : indices) { - if (gpuRenderPass->statistics[attachmentIndex].storeSubpass != gfxStateCache.subpassIdx) continue; - performStoreOp(attachmentIndex, glAttachmentIndex++); - } - bool skipStore = subpass.depthStencil == INVALID_BINDING || - gpuRenderPass->statistics[subpass.depthStencil].storeSubpass != gfxStateCache.subpassIdx; - performDepthStencilStoreOp(subpass.depthStencil, skipStore); - - cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->subpassBarriers.back().glBarriers, gpuRenderPass->subpassBarriers.back().glBarriersByRegion); + const auto &attachments = gpuRenderPass->colorAttachments; + const auto &indices = gpuRenderPass->indices; + for (uint32_t i = 0; i < attachments.size(); ++i) { + performStoreOp(i, indices[i]); } + performDepthStencilStoreOp(gpuRenderPass->depthStencil); +// if (device->constantRegistry()->mFBF == FBFSupportLevel::NON_COHERENT_EXT) { +// GL_CHECK(glFramebufferFetchBarrierEXT()); +// } else if (device->constantRegistry()->mFBF == FBFSupportLevel::NON_COHERENT_QCOM) { +// GL_CHECK(glFramebufferFetchBarrierQCOM()); +// } } // NOLINTNEXTLINE(google-readability-function-size, readability-function-size) @@ -3022,7 +2901,7 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const destHeight = (region.texExtent.height + offset.y == (gpuTexture->height >> mipLevel)) ? region.texExtent.height : extent.height; for (uint32_t z = region.texSubres.baseArrayLayer; z < layerCount; ++z) { - offset.z = z; + offset.z = static_cast(z); const uint8_t *buff; if (stride.width == extent.width && stride.height == extent.height) { @@ -3248,7 +3127,7 @@ void cmdFuncGLES3ExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { switch (cmdType) { case GLESCmdType::BEGIN_RENDER_PASS: { GLES3CmdBeginRenderPass *cmd = cmdPackage->beginRenderPassCmds[cmdIdx]; - cmdFuncGLES3BeginRenderPass(device, cmd->subpassIdx, cmd->gpuRenderPass, cmd->gpuFBO, + cmdFuncGLES3BeginRenderPass(device, cmd->gpuRenderPass, cmd->gpuFBO, &cmd->renderArea, cmd->clearColors, cmd->clearDepth, cmd->clearStencil); break; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index 38f9a19815..7108e4ecee 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -263,7 +263,7 @@ void completeBarrier(GLES3GPUGeneralBarrier *barrier); void cmdFuncGLES3Query(GLES3Device *device, GLES3QueryPool *query, GLES3QueryType type, uint32_t id); -void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, +void cmdFuncGLES3BeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass = nullptr, GLES3GPUFramebuffer *gpuFramebuffer = nullptr, const Rect *renderArea = nullptr, diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index 65aeb6158e..ce0c29e14b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -120,8 +120,7 @@ bool GLES3Device::doInit(const DeviceInfo & /*info*/) { ccstd::string fbfLevelStr = "NONE"; // PVRVFrame has issues on their support -#if 0 // CC_PLATFORM != CC_PLATFORM_WINDOWS - // TODO: enable fbf in the future, it is not implemented yet in gles3 backend +//#if CC_PLATFORM != CC_PLATFORM_WINDOWS if (checkExtension("framebuffer_fetch")) { ccstd::string nonCoherent = "framebuffer_fetch_non"; @@ -141,11 +140,18 @@ bool GLES3Device::doInit(const DeviceInfo & /*info*/) { } else if (checkExtension(CC_TOSTR(GL_EXT_shader_framebuffer_fetch))) { // we only care about EXT_shader_framebuffer_fetch, the ARM version does not support MRT _gpuConstantRegistry->mFBF = FBFSupportLevel::COHERENT; + _features[toNumber(Feature::RASTERIZATION_ORDER_COHERENT)] = true; fbfLevelStr = "COHERENT"; } _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = _gpuConstantRegistry->mFBF != FBFSupportLevel::NONE; + _features[toNumber(Feature::SUBPASS_COLOR_INPUT)] = true; } -#endif + + if (checkExtension(CC_TOSTR(ARM_shader_framebuffer_fetch_depth_stencil))) { + _features[toNumber(Feature::SUBPASS_DEPTH_STENCIL_INPUT)] = true; + fbfLevelStr += "_DEPTH_STENCIL"; + } +//#endif #if CC_PLATFORM != CC_PLATFORM_WINDOWS || ALLOW_MULTISAMPLED_RENDER_TO_TEXTURE_ON_DESKTOP if (checkExtension("multisampled_render_to_texture")) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp b/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp index 5b1090ce4d..0e74d8081c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp @@ -160,7 +160,6 @@ bool GLES3GPUContext::initialize(GLES3GPUStateCache *stateCache, GLES3GPUConstan uint64_t lastScore = qualityPreferred ? std::numeric_limits::min() : std::numeric_limits::max(); for (int i = 0; i < numConfig; i++) { - int depthValue{0}; eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_RED_SIZE, ¶ms[0]); eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_GREEN_SIZE, ¶ms[1]); eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_BLUE_SIZE, ¶ms[2]); @@ -169,9 +168,7 @@ bool GLES3GPUContext::initialize(GLES3GPUStateCache *stateCache, GLES3GPUConstan eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_STENCIL_SIZE, ¶ms[5]); eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_SAMPLE_BUFFERS, ¶ms[6]); eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_SAMPLES, ¶ms[7]); - eglGetConfigAttrib(eglDisplay, eglConfigs[i], EGL_DEPTH_ENCODING_NV, &depthValue); - - int bNonLinearDepth = (depthValue == EGL_DEPTH_ENCODING_NONLINEAR_NV) ? 1 : 0; + int bNonLinearDepth = 0; /*------------------------------------------ANGLE's priority-----------------------------------------------*/ // Favor EGLConfigLists by RGB, then Depth, then Non-linear Depth, then Stencil, then Alpha diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h index 75cf6509ab..7c1317f284 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h @@ -320,21 +320,18 @@ struct GLES3GPUGeneralBarrier { GLbitfield glBarriersByRegion = 0U; }; +using DrawBuffer = std::vector; struct GLES3GPURenderPass { - struct AttachmentStatistics { - uint32_t loadSubpass{SUBPASS_EXTERNAL}; - uint32_t storeSubpass{SUBPASS_EXTERNAL}; - }; - ColorAttachmentList colorAttachments; DepthStencilAttachment depthStencilAttachment; SubpassInfoList subpasses; SubpassDependencyList dependencies; - ccstd::vector statistics; // per attachment - - ccstd::vector subpassBarriers; // per subpass - GLES3GPUGeneralBarrier blockBarrier; + std::vector colors; + std::vector resolves; + uint32_t depthStencil = INVALID_BINDING; + std::vector indices; // offsets to GL_COLOR_ATTACHMENT_0 + std::vector drawBuffers; }; class GLES3GPUFramebufferCacheMap; @@ -343,7 +340,6 @@ public: GLES3GPURenderPass *gpuRenderPass{nullptr}; GLES3GPUTextureViewList gpuColorViews; GLES3GPUTextureView *gpuDepthStencilView{nullptr}; - bool usesFBF{false}; struct GLFramebufferInfo { GLuint glFramebuffer{0U}; @@ -380,16 +376,7 @@ public: }; // one per subpass, if not using FBF - ccstd::vector instances; - - ccstd::vector uberColorAttachmentIndices; - uint32_t uberDepthStencil{INVALID_BINDING}; - Framebuffer uberInstance; - - // the assumed shader output, may differ from actual subpass output - // see Feature::INPUT_ATTACHMENT_BENEFIT for more details on this - uint32_t uberOnChipOutput{INVALID_BINDING}; - uint32_t uberFinalOutput{INVALID_BINDING}; + Framebuffer frameBuffer; }; struct GLES3GPUDescriptorSetLayout { diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp index 13847c96e3..067c503747 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp @@ -52,8 +52,46 @@ const GLenum GLE_S3_PRIMITIVES[] = { }; namespace { +void updateGPUShaderSourceByRenderPass(GLES3GPUShader *gpuShader, GLES3GPURenderPass *renderPass, uint32_t subpassIndex) { + auto iter = std::find_if(gpuShader->gpuStages.begin(), gpuShader->gpuStages.end(), [](const GLES3GPUShaderStage &stage) { + return stage.type == ShaderStageFlagBit::FRAGMENT; + }); + if (iter == gpuShader->gpuStages.end()) { + return; + } -void initGpuShader(GLES3GPUShader *gpuShader, GLES3GPUPipelineLayout *gpuPipelineLayout) { + CC_ASSERT(subpassIndex < renderPass->subpasses.size()); + if (renderPass->subpasses[subpassIndex].inputs.empty()) { + return; + } + auto &drawBuffers = renderPass->drawBuffers.at(subpassIndex); + + ccstd::string::size_type offset = 0; + for (uint32_t i = 0; i < drawBuffers.size(); ++i) { + const char* layoutPrefix = "layout(location = "; + + std::stringstream ss1; + ss1 << layoutPrefix << i << ") out"; + + std::stringstream ss2; + ss2 << layoutPrefix << i << ") inout"; + + auto &source = iter->source; + auto sIter = source.find(ss1.str(), offset); + if (sIter == std::string::npos) { + sIter = source.find(ss2.str(), offset); + } + + if (sIter != std::string::npos) { + auto loc = sIter + strlen(layoutPrefix); + source[loc] = drawBuffers[i] + '0'; + offset = loc; + } + } +} + +void initGpuShader(GLES3GPUShader *gpuShader, GLES3GPUPipelineLayout *gpuPipelineLayout, GLES3GPURenderPass *renderPass, uint32_t subpassIndex) { + updateGPUShaderSourceByRenderPass(gpuShader, renderPass, subpassIndex); cmdFuncGLES3CreateShader(GLES3Device::getInstance(), gpuShader, gpuPipelineLayout); CC_ASSERT(gpuShader->glProgram); @@ -82,8 +120,9 @@ void GLES3PipelineState::doInit(const PipelineStateInfo & /*info*/) { _gpuPipelineState->bs = _blendState; _gpuPipelineState->gpuPipelineLayout = static_cast(_pipelineLayout)->gpuPipelineLayout(); _gpuPipelineState->gpuShader = static_cast(_shader)->gpuShader(); + if (_renderPass) _gpuPipelineState->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); if (_gpuPipelineState->gpuShader->glProgram == 0) { - initGpuShader(_gpuPipelineState->gpuShader, _gpuPipelineState->gpuPipelineLayout); + initGpuShader(_gpuPipelineState->gpuShader, _gpuPipelineState->gpuPipelineLayout, _gpuPipelineState->gpuRenderPass, _subpass); } if (_renderPass) _gpuPipelineState->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp index 6617e0b81d..a489267092 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp @@ -64,12 +64,10 @@ void GLES3PrimaryCommandBuffer::end() { void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const * /*secondaryCBs*/, uint32_t /*secondaryCBCount*/) { _curSubpassIdx = 0U; - GLES3GPURenderPass *gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); + auto *gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); GLES3GPUFramebuffer *gpuFramebuffer = static_cast(fbo)->gpuFBO(); - cmdFuncGLES3BeginRenderPass(GLES3Device::getInstance(), _curSubpassIdx, gpuRenderPass, gpuFramebuffer, - &renderArea, colors, depth, stencil); - + cmdFuncGLES3BeginRenderPass(GLES3Device::getInstance(), gpuRenderPass, gpuFramebuffer, &renderArea, colors, depth, stencil); _curDynamicStates.viewport = {renderArea.x, renderArea.y, renderArea.width, renderArea.height}; _curDynamicStates.scissor = renderArea; } @@ -79,8 +77,7 @@ void GLES3PrimaryCommandBuffer::endRenderPass() { } void GLES3PrimaryCommandBuffer::nextSubpass() { - cmdFuncGLES3EndRenderPass(GLES3Device::getInstance()); - cmdFuncGLES3BeginRenderPass(GLES3Device::getInstance(), ++_curSubpassIdx); + ++_curSubpassIdx; } void GLES3PrimaryCommandBuffer::draw(const DrawInfo &info) { diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp index 651f1545a2..f44d42aee1 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp @@ -266,32 +266,12 @@ Sampler *DeviceValidator::getSampler(const SamplerInfo &info) { } GeneralBarrier *DeviceValidator::getGeneralBarrier(const GeneralBarrierInfo &info) { - if (info.prevAccesses > AccessFlagBit::PRESENT) { - // Write access should appear on its own. - CC_ASSERT(math::isPowerOfTwo(toNumber(info.prevAccesses))); - } - if (info.nextAccesses > AccessFlagBit::PRESENT) { - // Write access should appear on its own. - CC_ASSERT(math::isPowerOfTwo(toNumber(info.nextAccesses))); - } - /////////// execute /////////// - return _actor->getGeneralBarrier(info); } TextureBarrier *DeviceValidator::getTextureBarrier(const TextureBarrierInfo &info) { - if (info.prevAccesses > AccessFlagBit::PRESENT) { - // Write access should appear on its own. - CC_ASSERT(math::isPowerOfTwo(toNumber(info.prevAccesses))); - } - if (info.nextAccesses > AccessFlagBit::PRESENT) { - // Write access should appear on its own. - CC_ASSERT(math::isPowerOfTwo(toNumber(info.nextAccesses))); - } - /////////// execute /////////// - return _actor->getTextureBarrier(info); } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index c0a91e6822..acd0fa4a2e 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -506,7 +506,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende depthStencilResolves.resize(subpassCount, {VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE}); const VkPhysicalDeviceDepthStencilResolveProperties &prop{device->gpuContext()->physicalDeviceDepthStencilResolveProperties}; for (uint32_t i = 0U; i < gpuRenderPass->subpasses.size(); ++i) { - const SubpassInfo subpassInfo = gpuRenderPass->subpasses[i]; + const SubpassInfo& subpassInfo = gpuRenderPass->subpasses[i]; VkSubpassDescription2 &desc = subpassDescriptions[i]; desc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; @@ -634,7 +634,9 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende vkDependency.dstAccessMask |= dstAccessMask; dependencyManager.append(vkDependency); }; - + if (vkDependency.srcStageMask == 0) { + vkDependency.srcStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; + } addStageAccessMask(dependency); } diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index 5cb21fa57b..413a6a2496 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -61,7 +61,8 @@ CC_DISABLE_WARNINGS() #define VMA_IMPLEMENTATION #include "vk_mem_alloc.h" #define THSVS_ERROR_CHECK_MIXED_IMAGE_LAYOUT -#define THSVS_ERROR_CHECK_POTENTIAL_HAZARD +// remote potential hazard because of programmable blend +//#define THSVS_ERROR_CHECK_POTENTIAL_HAZARD #define THSVS_SIMPLER_VULKAN_SYNCHRONIZATION_IMPLEMENTATION #include "thsvs_simpler_vulkan_synchronization.h" CC_ENABLE_WARNINGS() @@ -272,13 +273,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { }; findPreferredDepthFormat(depthStencilFormatPriorityList, 3, &_gpuDevice->depthStencilFormat); - _features[toNumber(Feature::ELEMENT_INDEX_UINT)] = true; - _features[toNumber(Feature::INSTANCED_ARRAYS)] = true; - _features[toNumber(Feature::MULTIPLE_RENDER_TARGETS)] = true; - _features[toNumber(Feature::BLEND_MINMAX)] = true; - _features[toNumber(Feature::COMPUTE_SHADER)] = true; - _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = true; - + initDeviceFeature(); initFormatFeature(); ccstd::string compressedFmts; @@ -320,6 +315,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { _caps.maxShaderStorageBufferBindings = limits.maxDescriptorSetStorageBuffers; _caps.maxTextureUnits = limits.maxDescriptorSetSampledImages; _caps.maxVertexTextureUnits = limits.maxPerStageDescriptorSampledImages; + _caps.maxColorRenderTargets = limits.maxColorAttachments; _caps.maxTextureSize = limits.maxImageDimension2D; _caps.maxCubeMapTextureSize = limits.maxImageDimensionCube; _caps.maxArrayTextureLayers = limits.maxImageArrayLayers; @@ -762,6 +758,18 @@ void CCVKDevice::updateBackBufferCount(uint32_t backBufferCount) { _gpuDevice->backBufferCount = backBufferCount; } +void CCVKDevice::initDeviceFeature() { + _features[toNumber(Feature::ELEMENT_INDEX_UINT)] = true; + _features[toNumber(Feature::INSTANCED_ARRAYS)] = true; + _features[toNumber(Feature::MULTIPLE_RENDER_TARGETS)] = true; + _features[toNumber(Feature::BLEND_MINMAX)] = true; + _features[toNumber(Feature::COMPUTE_SHADER)] = true; + _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = true; + _features[toNumber(Feature::SUBPASS_COLOR_INPUT)] = true; + _features[toNumber(Feature::SUBPASS_DEPTH_STENCIL_INPUT)] = true; + _features[toNumber(Feature::RASTERIZATION_ORDER_COHERENT)] = _gpuContext->checkExtension("VK_EXT_rasterization_order_attachment_access"); +} + void CCVKDevice::initFormatFeature() { const auto formatLen = static_cast(Format::COUNT); VkFormatProperties properties = {}; @@ -940,7 +948,7 @@ void CCVKDevice::getQueryPoolResults(QueryPool *queryPool) { uint32_t width = bWait ? 1U : 2U; uint64_t stride = sizeof(uint64_t) * width; VkQueryResultFlagBits flag = bWait ? VK_QUERY_RESULT_WAIT_BIT : VK_QUERY_RESULT_WITH_AVAILABILITY_BIT; - ccstd::vector results(queryCount * width, 0ULL); + ccstd::vector results(queryCount * width, 0); if (queryCount > 0U) { VkResult result = vkGetQueryPoolResults( diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.h b/native/cocos/renderer/gfx-vulkan/VKDevice.h index a86af0bd69..c53f6cb20a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.h +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.h @@ -140,6 +140,7 @@ protected: void getQueryPoolResults(QueryPool *queryPool) override; void initFormatFeature(); + void initDeviceFeature(); void initExtensionCapability(); std::unique_ptr _gpuDevice; diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.cpp b/native/cocos/renderer/gfx-vulkan/VKUtils.cpp index 063074a322..0bd50ef3ab 100644 --- a/native/cocos/renderer/gfx-vulkan/VKUtils.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.cpp @@ -567,6 +567,14 @@ const ThsvsAccessType *getAccessType(AccessFlagBit flag) { return &THSVS_ACCESS_TYPES[utils::getBitPosition(toNumber(flag))]; } +ThsvsImageLayout getAccessLayout(AccessFlags flag) { + if (hasAnyFlags(flag, AccessFlagBit::FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT | AccessFlagBit::COLOR_ATTACHMENT_WRITE) || + hasAnyFlags(flag, AccessFlagBit::FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT | AccessFlagBit::DEPTH_STENCIL_ATTACHMENT_WRITE)) { + return THSVS_IMAGE_LAYOUT_GENERAL; + } + return THSVS_IMAGE_LAYOUT_OPTIMAL; +} + void getAccessTypes(AccessFlags flag, ccstd::vector &v) { for (uint32_t mask = toNumber(flag); mask; mask = utils::clearLowestBit(mask)) { v.push_back(THSVS_ACCESS_TYPES[utils::getBitPosition(utils::getLowestBit(mask))]); diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.h b/native/cocos/renderer/gfx-vulkan/VKUtils.h index a0dd3ec5cd..4b7ac04abe 100644 --- a/native/cocos/renderer/gfx-vulkan/VKUtils.h +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.h @@ -72,6 +72,7 @@ ccstd::string mapVendorName(uint32_t vendorID); void fullPipelineBarrier(VkCommandBuffer cmdBuff); const ThsvsAccessType *getAccessType(AccessFlagBit flag); +ThsvsImageLayout getAccessLayout(AccessFlags flag); void getAccessTypes(AccessFlags flag, ccstd::vector &v); VkDeviceSize roundUp(VkDeviceSize numToRound, uint32_t multiple); bool isLayerSupported(const char *required, const ccstd::vector &available); diff --git a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp index 9af81baddf..86199a46bc 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp @@ -41,7 +41,8 @@ CCVKTextureBarrier::CCVKTextureBarrier(const TextureBarrierInfo &info) : Texture _gpuBarrier->barrier.nextAccessCount = utils::toUint(_gpuBarrier->nextAccesses.size()); _gpuBarrier->barrier.pNextAccesses = _gpuBarrier->nextAccesses.data(); - _gpuBarrier->barrier.prevLayout = _gpuBarrier->barrier.nextLayout = THSVS_IMAGE_LAYOUT_OPTIMAL; + _gpuBarrier->barrier.prevLayout = getAccessLayout(info.prevAccesses); + _gpuBarrier->barrier.nextLayout = getAccessLayout(info.nextAccesses); _gpuBarrier->barrier.discardContents = !!info.discardContents; _gpuBarrier->barrier.subresourceRange.baseMipLevel = 0U; _gpuBarrier->barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; diff --git a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp index 12246a5678..9b59533ac2 100644 --- a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp +++ b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -188,6 +188,27 @@ bool isPassExecAdjecent(uint32_t passLID, uint32_t passRID) { return std::abs(static_cast(passLID) - static_cast(passRID)) <= 1; } +template +constexpr uint8_t highestBitPos() { + return highestBitPos<(N >> 1)>() + 1; +} + +template <> +constexpr uint8_t highestBitPos<0>() { + return 0; +} + +constexpr uint32_t filledShift(uint8_t pos) { + return 0xFFFFFFFF >> (32 - pos); +} + +constexpr uint8_t HIGHEST_READ_POS = highestBitPos(gfx::AccessFlagBit::PRESENT)>() - 1; +constexpr uint32_t READ_ACCESS = filledShift(HIGHEST_READ_POS) | static_cast(gfx::AccessFlagBit::SHADING_RATE); + +inline bool hasReadAccess(gfx::AccessFlagBit flag) { + return (static_cast(flag) & READ_ACCESS) != 0; +} + inline bool isReadOnlyAccess(gfx::AccessFlagBit flag) { return flag < gfx::AccessFlagBit::PRESENT || flag == gfx::AccessFlagBit::SHADING_RATE; } @@ -466,7 +487,7 @@ struct BarrierVisitor : public boost::bfs_visitor<> { const auto &desc = get(ResourceGraph::DescTag{}, resourceGraph, resID); if (desc.format == gfx::Format::DEPTH_STENCIL || desc.format == gfx::Format::DEPTH) { - if (g.access.at(u).attachmentStatus.size() > 1 && dependency.srcSubpass != INVALID_ID) { + if (g.access.at(u).attachmentStatus.size() > 1) { auto &dsDep = subpassDependencies.emplace_back(); dsDep.srcSubpass = dependency.srcSubpass; dsDep.dstSubpass = dependency.dstSubpass; @@ -474,20 +495,27 @@ struct BarrierVisitor : public boost::bfs_visitor<> { dsDep.nextAccesses.emplace_back(barrier.endStatus.accessFlag); } } else { - bool isWriteAccess = barrier.endStatus.accessFlag > gfx::AccessFlagBit::PRESENT; - if (isWriteAccess && dependency.srcSubpass != INVALID_ID) { + bool isWriteAccess = !isReadOnlyAccess(barrier.endStatus.accessFlag); + if (isWriteAccess) { auto &dep = subpassDependencies.emplace_back(); dep.srcSubpass = dependency.srcSubpass; dep.dstSubpass = dependency.dstSubpass; dep.prevAccesses.emplace_back(barrier.beginStatus.accessFlag); dep.nextAccesses.emplace_back(barrier.endStatus.accessFlag); + if (hasReadAccess(barrier.endStatus.accessFlag) && !cc::gfx::Device::getInstance()->hasFeature(gfx::Feature::RASTERIZATION_ORDER_COHERENT)) { + auto &selfDep = subpassDependencies.emplace_back(); + selfDep.srcSubpass = dependency.dstSubpass; + selfDep.dstSubpass = dependency.dstSubpass; + selfDep.prevAccesses.emplace_back(barrier.endStatus.accessFlag); + selfDep.nextAccesses.emplace_back(barrier.endStatus.accessFlag); + } } else { dependency.prevAccesses.emplace_back(barrier.beginStatus.accessFlag); dependency.nextAccesses.emplace_back(barrier.endStatus.accessFlag); } } } - if (!dependency.prevAccesses.empty() && dependency.srcSubpass != INVALID_ID) { + if (!dependency.prevAccesses.empty()) { subpassDependencies.emplace_back(dependency); } } @@ -513,13 +541,20 @@ struct BarrierVisitor : public boost::bfs_visitor<> { dsDep.nextAccesses.emplace_back(barrier.endStatus.accessFlag); } } else { - bool isWriteAccess = barrier.endStatus.accessFlag < gfx::AccessFlagBit::PRESENT; + bool isWriteAccess = !isReadOnlyAccess(barrier.endStatus.accessFlag); if (isWriteAccess) { auto &dep = subpassDependencies.emplace_back(); dep.srcSubpass = dependency.srcSubpass; dep.dstSubpass = dependency.dstSubpass; dep.prevAccesses.emplace_back(barrier.beginStatus.accessFlag); dep.nextAccesses.emplace_back(barrier.endStatus.accessFlag); + if (hasReadAccess(barrier.endStatus.accessFlag) && !cc::gfx::Device::getInstance()->hasFeature(gfx::Feature::RASTERIZATION_ORDER_COHERENT)) { + auto &selfDep = subpassDependencies.emplace_back(); + selfDep.srcSubpass = dependency.dstSubpass; + selfDep.dstSubpass = dependency.dstSubpass; + selfDep.prevAccesses.emplace_back(barrier.endStatus.accessFlag); + selfDep.nextAccesses.emplace_back(barrier.endStatus.accessFlag); + } } else { dependency.prevAccesses.emplace_back(barrier.beginStatus.accessFlag); dependency.nextAccesses.emplace_back(barrier.endStatus.accessFlag); @@ -529,6 +564,7 @@ struct BarrierVisitor : public boost::bfs_visitor<> { if (!dependency.prevAccesses.empty()) { subpassDependencies.emplace_back(dependency); } + } ++subpassIdx; } @@ -2082,7 +2118,6 @@ void processRasterPass(const Graphs &graphs, uint32_t passID, const RasterPass & tryAddEdge(EXPECT_START_ID, rlgVertID, relationGraph); } - uint32_t index = 0; // initial layout(accessrecord.laststatus) and final layout(accessrecord.currstatus) can be filled here for (const auto &[slotID, pair] : viewIndex) { const auto &name = pair.first; @@ -2103,38 +2138,28 @@ void processRasterPass(const Graphs &graphs, uint32_t passID, const RasterPass & auto &subpassInfo = rpInfo.subpasses.front(); if (view.attachmentType != AttachmentType::DEPTH_STENCIL) { if (view.attachmentType == AttachmentType::SHADING_RATE) { - subpassInfo.shadingRate = index; + subpassInfo.shadingRate = slotID; } else { if (view.accessType != AccessType::READ) { - subpassInfo.colors.emplace_back(index); + subpassInfo.colors.emplace_back(slotID); } if (view.accessType != AccessType::WRITE) { - subpassInfo.inputs.emplace_back(index); + subpassInfo.inputs.emplace_back(slotID); } } - fgRenderpassInfo.colorAccesses[index].prevAccess = prevAccess; - fgRenderpassInfo.colorAccesses[index].nextAccess = nextAccess; + fgRenderpassInfo.colorAccesses[slotID].prevAccess = prevAccess; + fgRenderpassInfo.colorAccesses[slotID].nextAccess = nextAccess; } else { subpassInfo.depthStencil = pass.rasterViews.size() - 1; fgRenderpassInfo.dsAccess.prevAccess = prevAccess; fgRenderpassInfo.dsAccess.nextAccess = nextAccess; } - fillRenderPassInfo(view, rpInfo, index, viewDesc); + fillRenderPassInfo(view, rpInfo, slotID, viewDesc); } } else { - PmrFlatSet viewSet(resourceAccessGraph.get_allocator()); - bool hasDS{false}; - for (const auto &subpass : pass.subpassGraph.subpasses) { - for (const auto &pair : subpass.rasterViews) { - if (pair.second.attachmentType != AttachmentType::DEPTH_STENCIL) { - viewSet.emplace(pair.first); - } else { - hasDS = true; - } - } - } - rpInfo.colorAttachments.resize(viewSet.size()); - fgRenderpassInfo.colorAccesses.resize(viewSet.size()); + auto colorSize = pass.attachmentIndexMap.size(); + rpInfo.colorAttachments.resize(colorSize); + fgRenderpassInfo.colorAccesses.resize(colorSize); } } @@ -2153,6 +2178,46 @@ void processComputePass(const Graphs &graphs, uint32_t passID, const ComputePass } } +uint32_t record(const ccstd::vector& indices) { + uint32_t res = 0; + for (auto attachmentIndex : indices) { + res |= 1 << attachmentIndex; + } + return res; +} + +void extract(uint32_t val, ccstd::vector& preserves) { + uint32_t index = 0; + while (val) { + if (val & 0x1) { + preserves.emplace_back(index); + } + val = val >> 1; + ++index; + } +} + +void getPreserves(gfx::RenderPassInfo& rpInfo) { + std::stack stack; + for (auto& info : rpInfo.subpasses) { + stack.push(&info); + } + + uint32_t laterRead{0}; + while (!stack.empty()) { + auto *tail = stack.top(); + stack.pop(); + + auto readRecord = record(tail->inputs); + auto writeRecord = record(tail->colors); + auto resolveRecord = record(tail->resolves); + auto shown = readRecord | writeRecord | resolveRecord; + auto needPreserve = (shown | laterRead) ^ shown; + extract(needPreserve, tail->preserves); + laterRead |= readRecord; + } +} + void processRasterSubpass(const Graphs &graphs, uint32_t passID, const RasterSubpass &pass) { const auto &[renderGraph, resourceGraph, layoutGraphData, resourceAccessGraph, relationGraph] = graphs; const auto &obj = renderGraph.objects.at(passID); @@ -2166,14 +2231,40 @@ void processRasterSubpass(const Graphs &graphs, uint32_t passID, const RasterSub resourceAccessGraph.passIndex[passID] = parentRagVert; - uint32_t dsIndex = INVALID_ID; - PmrFlatMap> viewIndex(rag.get_allocator()); + static const uint32_t ACCESS_TYPE_WEIGHT[] = {0, 1, 2}; + static const uint32_t ATTACHMENT_TYPE_WEIGHT[] = {0, 2, 1}; + + struct SubpassRasterViewSortKey { + uint32_t accessType; + uint32_t attachmentType; + std::string_view slotName; + }; + using RasterViewSortKey = std::tuple; + struct SubpassRasterViewData { + SubpassRasterViewSortKey sortKey; + std::string_view name; + gfx::AccessFlags access; + }; + + ccstd::vector viewIndex; for (const auto &[name, view] : pass.rasterViews) { auto resIter = rag.resourceIndex.find(name); gfx::AccessFlags prevAccess = resIter == rag.resourceIndex.end() ? gfx::AccessFlags::NONE : rag.accessRecord.at(resIter->second).currStatus.accessFlag; - viewIndex.emplace(std::piecewise_construct, std::forward_as_tuple(view.slotID), std::forward_as_tuple(name, prevAccess)); + viewIndex.emplace_back(SubpassRasterViewData { + {ACCESS_TYPE_WEIGHT[static_cast(view.accessType)], ATTACHMENT_TYPE_WEIGHT[static_cast(view.attachmentType)], view.slotName}, name, prevAccess + }); } + std::sort(viewIndex.begin(), viewIndex.end(), [](const SubpassRasterViewData &lhs, const SubpassRasterViewData &rhs) { + if (lhs.sortKey.accessType != rhs.sortKey.accessType) { + return lhs.sortKey.accessType < rhs.sortKey.accessType; + } + if (lhs.sortKey.attachmentType != rhs.sortKey.attachmentType) { + return lhs.sortKey.attachmentType < rhs.sortKey.attachmentType; + } + return lhs.sortKey.slotName < rhs.sortKey.slotName; + }); + auto &node = get(RAG::AccessNodeTag{}, resourceAccessGraph, parentRagVert); auto &fgRenderpassInfo = resourceAccessGraph.rpInfos.at(parentRagVert); auto &rpInfo = fgRenderpassInfo.rpInfo; @@ -2193,8 +2284,9 @@ void processRasterSubpass(const Graphs &graphs, uint32_t passID, const RasterSub tryAddEdge(EXPECT_START_ID, parentRagVert, relationGraph); } - for (const auto &[slotID, pair] : viewIndex) { - const auto &resName = pair.first; + uint32_t localSlot = 0; + for (const auto &[sortKey, name, access] : viewIndex) { + const auto *const resName = name.data(); auto findByResID = [&](const AccessStatus &status) { return status.vertID == rag.resourceIndex.at(resName); }; @@ -2202,7 +2294,14 @@ void processRasterSubpass(const Graphs &graphs, uint32_t passID, const RasterSub const auto &view = pass.rasterViews.at(resName); auto resID = rag.resourceIndex.at(resName); const auto &viewDesc = get(ResourceGraph::DescTag{}, resg, rag.resourceIndex.at(resName)); - auto slot = slotID > dsIndex ? slotID - 1 : slotID; + + uint32_t slot = uberPass.attachmentIndexMap.size(); + if (view.attachmentType != AttachmentType::DEPTH_STENCIL) { + CC_ASSERT(uberPass.attachmentIndexMap.count(resName)); + slot = uberPass.attachmentIndexMap.at(resName); + } + + // TD:remove find auto nodeIter = std::find_if(head->attachmentStatus.begin(), head->attachmentStatus.end(), [resID](const AccessStatus &status) { return status.vertID == resID; @@ -2221,7 +2320,6 @@ void processRasterSubpass(const Graphs &graphs, uint32_t passID, const RasterSub } fgRenderpassInfo.colorAccesses[slot].nextAccess = nextAccess; } else { - dsIndex = slotID; fgRenderpassInfo.dsAccess.nextAccess = nextAccess; subpassInfo.depthStencil = rpInfo.colorAttachments.size(); } @@ -2229,11 +2327,9 @@ void processRasterSubpass(const Graphs &graphs, uint32_t passID, const RasterSub if (iter == node.attachmentStatus.end()) { auto curIter = std::find_if(head->attachmentStatus.begin(), head->attachmentStatus.end(), findByResID); node.attachmentStatus.emplace_back(*curIter); - - auto colorIndex = dsIndex == INVALID_ID ? node.attachmentStatus.size() : node.attachmentStatus.size() - 1; - auto prevAccess = pair.second; - CC_ASSERT(head->attachmentStatus.size() > slotID); - auto nextAccess = head->attachmentStatus[slot].accessFlag; + auto prevAccess = access; + CC_ASSERT(head->attachmentStatus.size() > localSlot); + auto nextAccess = head->attachmentStatus[localSlot].accessFlag; if (view.attachmentType == AttachmentType::DEPTH_STENCIL) { fgRenderpassInfo.dsAccess.prevAccess = prevAccess; @@ -2242,6 +2338,11 @@ void processRasterSubpass(const Graphs &graphs, uint32_t passID, const RasterSub } fillRenderPassInfo(view, rpInfo, slot, viewDesc); } + ++localSlot; + } + + if (pass.subpassID == uberPass.subpassGraph.subpasses.size() - 1) { + getPreserves(rpInfo); } } diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp index 18a85fa247..5c46cd7455 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp @@ -1065,7 +1065,11 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> { resourceIndex.reserve(subpass.rasterViews.size() * 2); for (const auto& [resName, rasterView] : subpass.rasterViews) { const auto resID = vertex(resName, ctx.resourceGraph); - auto iter = ctx.lg.attributeIndex.find(rasterView.slotName); + auto slotName = rasterView.slotName; + if (rasterView.accessType == AccessType::READ || rasterView.accessType == AccessType::READ_WRITE) { + slotName.insert(0, "__in"); + } + auto iter = ctx.lg.attributeIndex.find(slotName); if (iter != ctx.lg.attributeIndex.end()) { resourceIndex.emplace(iter->second, resID); } @@ -1276,46 +1280,109 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { // TODO(zhenglong.zhou): resolve } } - void begin(const CopyPass& pass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static) + void copyTexture( + const CopyPair& copy, + ResourceGraph::vertex_descriptor srcID, + ResourceGraph::vertex_descriptor dstID) const { + auto& resg = ctx.resourceGraph; + std::vector copyInfos(copy.mipLevels, gfx::TextureCopy{}); + + gfx::Texture* srcTexture = resg.getTexture(srcID); + gfx::Texture* dstTexture = resg.getTexture(dstID); + CC_ENSURES(srcTexture); + CC_ENSURES(dstTexture); + if (!srcTexture || !dstTexture) { + return; + } + const auto& srcInfo = srcTexture->getInfo(); + const auto& dstInfo = dstTexture->getInfo(); + CC_ENSURES(srcInfo.width == dstInfo.width); + CC_ENSURES(srcInfo.height == dstInfo.height); + CC_ENSURES(srcInfo.depth == dstInfo.depth); + + for (uint32_t i = 0; i < copy.mipLevels; ++i) { + auto& copyInfo = copyInfos[i]; + copyInfo.srcSubres.mipLevel = copy.sourceMostDetailedMip + i; + copyInfo.srcSubres.baseArrayLayer = copy.sourceFirstSlice; + copyInfo.srcSubres.layerCount = copy.numSlices; + + copyInfo.dstSubres.mipLevel = copy.targetMostDetailedMip + i; + copyInfo.dstSubres.baseArrayLayer = copy.targetFirstSlice; + copyInfo.dstSubres.layerCount = copy.numSlices; + + copyInfo.srcOffset = {0, 0, 0}; + copyInfo.dstOffset = {0, 0, 0}; + copyInfo.extent = {srcInfo.width, srcInfo.height, srcInfo.depth}; + } + + ctx.cmdBuff->copyTexture(srcTexture, dstTexture, copyInfos.data(), static_cast(copyInfos.size())); + } + void copyBuffer( // NOLINT(readability-convert-member-functions-to-static) + const CopyPair& copy, + ResourceGraph::vertex_descriptor srcID, + ResourceGraph::vertex_descriptor dstID) const { + // TODO(zhouzhenglong): add impl + std::ignore = copy; + std::ignore = srcID; + std::ignore = dstID; + } + void uploadTexture( // NOLINT(readability-convert-member-functions-to-static) + const UploadPair& upload, + ResourceGraph::vertex_descriptor dstID) const { + // TODO(zhouzhenglong): add impl + std::ignore = upload; + std::ignore = dstID; + } + void uploadBuffer( + const UploadPair& upload, + ResourceGraph::vertex_descriptor dstID) const { + auto& resg = ctx.resourceGraph; + gfx::Buffer* dstBuffer = resg.getBuffer(dstID); + CC_ENSURES(dstBuffer); + if (!dstBuffer) { + return; + } + ctx.cmdBuff->updateBuffer(dstBuffer, upload.source.data(), static_cast(upload.source.size())); + } + void begin(const CopyPass& pass, RenderGraph::vertex_descriptor vertID) const { std::ignore = pass; std::ignore = vertID; - - auto getTexture = [this](const ccstd::pmr::string& name) { - auto resID = findVertex(name, ctx.resourceGraph); - return ctx.resourceGraph.getTexture(resID); - }; + auto& resg = ctx.resourceGraph; // currently, only texture to texture supported. for (const auto& copy : pass.copyPairs) { - std::vector copyInfos(copy.mipLevels, gfx::TextureCopy{}); - - gfx::Texture* srcTexture = getTexture(copy.source); - gfx::Texture* dstTexture = getTexture(copy.target); - CC_ENSURES(srcTexture); - CC_ENSURES(dstTexture); - - const auto& srcInfo = srcTexture->getInfo(); - const auto& dstInfo = dstTexture->getInfo(); - CC_ENSURES(srcInfo.width == dstInfo.width); - CC_ENSURES(srcInfo.height == dstInfo.height); - CC_ENSURES(srcInfo.depth == dstInfo.depth); - - for (uint32_t i = 0; i < copy.mipLevels; ++i) { - auto& copyInfo = copyInfos[i]; - copyInfo.srcSubres.mipLevel = copy.sourceMostDetailedMip + i; - copyInfo.srcSubres.baseArrayLayer = copy.sourceFirstSlice; - copyInfo.srcSubres.layerCount = copy.numSlices; - - copyInfo.dstSubres.mipLevel = copy.targetMostDetailedMip + i; - copyInfo.dstSubres.baseArrayLayer = copy.targetFirstSlice; - copyInfo.dstSubres.layerCount = copy.numSlices; - - copyInfo.srcOffset = {0, 0, 0}; - copyInfo.dstOffset = {0, 0, 0}; - copyInfo.extent = {srcInfo.width, srcInfo.height, srcInfo.depth}; + auto srcID = findVertex(copy.source, resg); + auto dstID = findVertex(copy.target, resg); + CC_ENSURES(srcID != RenderGraph::null_vertex()); + CC_ENSURES(dstID != RenderGraph::null_vertex()); + if (srcID == RenderGraph::null_vertex() || dstID == RenderGraph::null_vertex()) { + continue; + } + const bool sourceIsTexture = resg.isTexture(srcID); + const bool targetIsTexture = resg.isTexture(dstID); + CC_ENSURES(sourceIsTexture == targetIsTexture); + if (sourceIsTexture != targetIsTexture) { + continue; + } + if (targetIsTexture) { + copyTexture(copy, srcID, dstID); + } else { + copyBuffer(copy, srcID, dstID); + } + } + // copy from cpu + for (const auto& upload : pass.uploadPairs) { + auto dstID = findVertex(upload.target, resg); + CC_ENSURES(dstID != RenderGraph::null_vertex()); + if (dstID == RenderGraph::null_vertex()) { + continue; + } + const bool targetIsTexture = resg.isTexture(dstID); + if (targetIsTexture) { + uploadTexture(upload, dstID); + } else { + uploadBuffer(upload, dstID); } - - ctx.cmdBuff->copyTexture(srcTexture, dstTexture, copyInfos.data(), static_cast(copyInfos.size())); } } void begin(const MovePass& pass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static) @@ -1645,6 +1712,11 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { CC_EXPECTS(dstID != ResourceGraph::null_vertex()); resg.mount(ctx.device, dstID); } + for (const auto& pair : pass.uploadPairs) { + const auto& dstID = findVertex(pair.target, resg); + CC_EXPECTS(dstID != ResourceGraph::null_vertex()); + resg.mount(ctx.device, dstID); + } } void mountResources(const MovePass& pass) const { diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index 48cba14f7c..16c3da65bf 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -634,6 +634,24 @@ void NativePipeline::addCopyPass(const ccstd::vector ©Pairs) { renderGraph); } +void NativePipeline::addUploadPass(ccstd::vector& uploadPairs) { + CopyPass pass(renderGraph.get_allocator()); + pass.uploadPairs.reserve(uploadPairs.size()); + for (auto &&pair : uploadPairs) { + pass.uploadPairs.emplace_back(std::move(pair)); + } + uploadPairs.clear(); + std::string_view name("Copy"); + addVertex( + CopyTag{}, + std::forward_as_tuple(name), + std::forward_as_tuple(), + std::forward_as_tuple(), + std::forward_as_tuple(), + std::forward_as_tuple(std::move(pass)), + renderGraph); +} + gfx::DescriptorSetLayout *NativePipeline::getDescriptorSetLayout(const ccstd::string &shaderName, UpdateFrequency freq) { const auto &lg = programLibrary->layoutGraph; auto iter = lg.shaderLayoutIndex.find(std::string_view{shaderName}); diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h index 427d860b2a..d6b31fd020 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h +++ b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h @@ -105,8 +105,8 @@ public: void addRenderTarget(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, gfx::LoadOp loadOp, gfx::StoreOp storeOp, const gfx::Color &color) /*implements*/; void addDepthStencil(const ccstd::string &name, AccessType accessType, const ccstd::string &depthSlotName, const ccstd::string &stencilSlotName, gfx::LoadOp loadOp, gfx::StoreOp storeOp, float depth, uint8_t stencil, gfx::ClearFlagBit clearFlags) /*implements*/; void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) /*implements*/; - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) /*implements*/; - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) /*implements*/; + void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) /*implements*/; + void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) /*implements*/; void addComputeView(const ccstd::string &name, const ComputeView &view) /*implements*/; void setViewport(const gfx::Viewport &viewport) /*implements*/; RenderQueueBuilder *addQueue(QueueHint hint, const ccstd::string &layoutName) /*implements*/; @@ -243,11 +243,11 @@ public: void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) override { NativeRenderSubpassBuilderImpl::addTexture(name, slotName, sampler, plane); } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override { - NativeRenderSubpassBuilderImpl::addStorageBuffer(name, accessType, slotName, clearType, clearValue); + void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override { + NativeRenderSubpassBuilderImpl::addStorageBuffer(name, accessType, slotName); } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override { - NativeRenderSubpassBuilderImpl::addStorageImage(name, accessType, slotName, clearType, clearValue); + void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override { + NativeRenderSubpassBuilderImpl::addStorageImage(name, accessType, slotName); } void addComputeView(const ccstd::string &name, const ComputeView &view) override { NativeRenderSubpassBuilderImpl::addComputeView(name, view); @@ -333,11 +333,11 @@ public: void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) override { NativeRenderSubpassBuilderImpl::addTexture(name, slotName, sampler, plane); } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override { - NativeRenderSubpassBuilderImpl::addStorageBuffer(name, accessType, slotName, clearType, clearValue); + void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override { + NativeRenderSubpassBuilderImpl::addStorageBuffer(name, accessType, slotName); } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override { - NativeRenderSubpassBuilderImpl::addStorageImage(name, accessType, slotName, clearType, clearValue); + void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override { + NativeRenderSubpassBuilderImpl::addStorageImage(name, accessType, slotName); } void addComputeView(const ccstd::string &name, const ComputeView &view) override { NativeRenderSubpassBuilderImpl::addComputeView(name, view); @@ -419,8 +419,8 @@ public: void addRenderTarget(const ccstd::string &name, const ccstd::string &slotName) override; void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) override; - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override; - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override; + void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override; + void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override; void addComputeView(const ccstd::string &name, const ComputeView &view) override; ComputeQueueBuilder *addQueue(const ccstd::string &layoutName) override; void setCustomShaderStages(const ccstd::string &name, gfx::ShaderStageFlagBit stageFlags) override; @@ -492,8 +492,8 @@ public: bool getShowStatistics() const override; void setShowStatistics(bool enable) override; - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override; - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override; + void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override; + void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override; RenderSubpassBuilder *addRenderSubpass(const ccstd::string &layoutName) override; MultisampleRenderSubpassBuilder *addMultisampleRenderSubpass(uint32_t count, uint32_t quality, const ccstd::string &layoutName) override; ComputeSubpassBuilder *addComputeSubpass(const ccstd::string &layoutName) override; @@ -614,8 +614,8 @@ public: } void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) override; - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override; - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) override; + void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override; + void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) override; void addComputeView(const ccstd::string &name, const ComputeView &view) override; ComputeQueueBuilder *addQueue(const ccstd::string &layoutName) override; void setCustomShaderStages(const ccstd::string &name, gfx::ShaderStageFlagBit stageFlags) override; @@ -935,7 +935,7 @@ public: const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::string &programName) const override; ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) override; gfx::PipelineState *getComputePipelineState(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) override; - const ccstd::vector &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const override; + const ccstd::vector &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const override; const ccstd::unordered_map &getHandleMap(uint32_t phaseID, const ccstd::string &programName) const override; uint32_t getProgramID(uint32_t phaseID, const ccstd::pmr::string &programName) override; uint32_t getDescriptorNameID(const ccstd::pmr::string &name) override; @@ -1048,6 +1048,7 @@ public: void updateShadingRateTexture(const ccstd::string &name, uint32_t width, uint32_t height) override; RenderPassBuilder *addRenderPass(uint32_t width, uint32_t height, const ccstd::string &layoutName) override; ComputePassBuilder *addComputePass(const ccstd::string &layoutName) override; + void addUploadPass(ccstd::vector &uploadPairs) override; void addMovePass(const ccstd::vector &movePairs) override; uint32_t addCustomBuffer(const ccstd::string &name, const gfx::BufferInfo &info, const std::string &type) override; uint32_t addCustomTexture(const ccstd::string &name, const gfx::TextureInfo &info, const std::string &type) override; diff --git a/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp b/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp index 0cce9bb6ec..06e34e0763 100644 --- a/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp @@ -964,6 +964,9 @@ void overwriteShaderProgramBinding( overwriteShaderSourceBinding(shaderInfo, src->vert, scratch); overwriteShaderSourceBinding(shaderInfo, src->frag, scratch); + if (src->compute) { + overwriteShaderSourceBinding(shaderInfo, src->compute.value(), scratch); + } } // overwrite IProgramInfo using gfx.ShaderInfo @@ -1127,7 +1130,7 @@ void populatePipelineLayoutInfo( } template -static ccstd::hash_t getShaderHash(ccstd::hash_t src, const T &val) { +ccstd::hash_t getShaderHash(ccstd::hash_t src, const T &val) { if (src != gfx::INVALID_SHADER_HASH) { ccstd::hash_combine(src, val); } @@ -1545,7 +1548,7 @@ gfx::PipelineState *NativeProgramLibrary::getComputePipelineState( return native->pipelineState.get(); } -const ccstd::vector &NativeProgramLibrary::getBlockSizes( +const ccstd::vector &NativeProgramLibrary::getBlockSizes( uint32_t phaseID, const ccstd::string &programName) const { CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); const auto &group = phases.at(phaseID); diff --git a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp index 3362d8d071..8d9dfc2f30 100644 --- a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp @@ -403,31 +403,29 @@ void NativeRenderPassBuilder::addTexture( } void NativeRenderPassBuilder::addStorageBuffer( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } void NativeRenderPassBuilder::addStorageImage( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } @@ -491,6 +489,16 @@ void NativeRenderPassBuilder::setShowStatistics(bool enable) { namespace { +uint32_t getSlotID(RasterPass &pass, std::string_view name, AttachmentType type) { + if (type == AttachmentType::DEPTH_STENCIL) { + return 0xFF; + } + + const auto newID = static_cast(pass.attachmentIndexMap.size()); + auto iter = pass.attachmentIndexMap.find(name); + return iter != pass.attachmentIndexMap.end() ? iter->second : pass.attachmentIndexMap.emplace(name, newID).first->second; +} + template void addRasterViewImpl( std::string_view name, @@ -506,13 +514,13 @@ void addRasterViewImpl( RenderGraph &renderGraph) { CC_EXPECTS(!name.empty()); auto &subpass = get(Tag{}, subpassID, renderGraph); - const auto slotID = static_cast(subpass.rasterViews.size()); const auto passID = parent(subpassID, renderGraph); CC_EXPECTS(passID != RenderGraph::null_vertex()); CC_EXPECTS(holds(passID, renderGraph)); auto &pass = get(RasterPassTag{}, passID, renderGraph); CC_EXPECTS(subpass.subpassID < num_vertices(pass.subpassGraph)); auto &subpassData = get(SubpassGraph::SubpassTag{}, pass.subpassGraph, subpass.subpassID); + const auto slotID = getSlotID(pass, name, attachmentType); CC_EXPECTS(subpass.rasterViews.size() == subpassData.rasterViews.size()); { auto res = subpassData.rasterViews.emplace( @@ -658,31 +666,29 @@ void NativeRenderSubpassBuilderImpl::addTexture( } void NativeRenderSubpassBuilderImpl::addStorageBuffer( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } void NativeRenderSubpassBuilderImpl::addStorageImage( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } @@ -847,31 +853,29 @@ void NativeComputeSubpassBuilder::addTexture( } void NativeComputeSubpassBuilder::addStorageBuffer( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } void NativeComputeSubpassBuilder::addStorageImage( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } @@ -1539,31 +1543,29 @@ void NativeComputePassBuilder::addTexture( } void NativeComputePassBuilder::addStorageBuffer( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } void NativeComputePassBuilder::addStorageImage( - const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, - ClearValueType clearType, const ClearValue &clearValue) { + const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { addComputeView( name, ComputeView{ ccstd::pmr::string(slotName, renderGraph->get_allocator()), accessType, gfx::ClearFlagBit::NONE, - clearType, - clearValue, + ClearValueType::NONE, + ClearValue{}, gfx::ShaderStageFlagBit::NONE, renderGraph->get_allocator()}); } diff --git a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp index e3452f70e4..16686ad8e6 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -250,6 +250,23 @@ void ResourceGraph::unmount(uint64_t completedFenceValue) { } } +bool ResourceGraph::isTexture(vertex_descriptor resID) const noexcept { + return visitObject( + resID, *this, + [&](const ManagedBuffer& res) { + std::ignore = res; + return false; + }, + [&](const IntrusivePtr& res) { + std::ignore = res; + return false; + }, + [&](const auto& res) { + std::ignore = res; + return true; + }); +} + gfx::Buffer* ResourceGraph::getBuffer(vertex_descriptor resID) { gfx::Buffer* buffer = nullptr; visitObject( diff --git a/native/cocos/renderer/pipeline/custom/PrivateTypes.h b/native/cocos/renderer/pipeline/custom/PrivateTypes.h index abc34a85e1..e1f95c2d9d 100644 --- a/native/cocos/renderer/pipeline/custom/PrivateTypes.h +++ b/native/cocos/renderer/pipeline/custom/PrivateTypes.h @@ -70,7 +70,7 @@ public: virtual const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::string &programName) const = 0; virtual ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) = 0; virtual gfx::PipelineState *getComputePipelineState(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) = 0; - virtual const ccstd::vector &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const = 0; + virtual const ccstd::vector &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const = 0; virtual const ccstd::unordered_map &getHandleMap(uint32_t phaseID, const ccstd::string &programName) const = 0; virtual uint32_t getProgramID(uint32_t phaseID, const ccstd::pmr::string &programName) = 0; virtual uint32_t getDescriptorNameID(const ccstd::pmr::string &name) = 0; diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonFwd.h b/native/cocos/renderer/pipeline/custom/RenderCommonFwd.h index b688268c7f..0aff9daaf2 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonFwd.h +++ b/native/cocos/renderer/pipeline/custom/RenderCommonFwd.h @@ -82,6 +82,7 @@ enum class ResolveFlags : uint32_t; struct ResolvePair; struct CopyPair; +struct UploadPair; struct MovePair; struct PipelineStatistics; diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp b/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp index fec370ac34..e342b27250 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp +++ b/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp @@ -256,6 +256,35 @@ bool nativevalue_to_se(const cc::render::CopyPair &from, se::Value &to, se::Obje return true; } +bool nativevalue_to_se(const cc::render::UploadPair &from, se::Value &to, se::Object *ctx) { // NOLINT + se::HandleObject obj(se::Object::createPlainObject()); + se::Value tmp; + + nativevalue_to_se(from.source, tmp, ctx); + obj->setProperty("source", tmp); + + nativevalue_to_se(from.target, tmp, ctx); + obj->setProperty("target", tmp); + + nativevalue_to_se(from.mipLevels, tmp, ctx); + obj->setProperty("mipLevels", tmp); + + nativevalue_to_se(from.numSlices, tmp, ctx); + obj->setProperty("numSlices", tmp); + + nativevalue_to_se(from.targetMostDetailedMip, tmp, ctx); + obj->setProperty("targetMostDetailedMip", tmp); + + nativevalue_to_se(from.targetFirstSlice, tmp, ctx); + obj->setProperty("targetFirstSlice", tmp); + + nativevalue_to_se(from.targetPlaneSlice, tmp, ctx); + obj->setProperty("targetPlaneSlice", tmp); + + to.setObject(obj); + return true; +} + bool nativevalue_to_se(const cc::render::MovePair &from, se::Value &to, se::Object *ctx) { // NOLINT se::HandleObject obj(se::Object::createPlainObject()); se::Value tmp; @@ -575,6 +604,44 @@ bool sevalue_to_native(const se::Value &from, cc::render:: return ok; } +template <> +bool sevalue_to_native(const se::Value &from, cc::render::UploadPair *to, se::Object *ctx) { // NOLINT + SE_PRECONDITION2(from.isObject(), false, " Convert parameter to UploadPair failed !"); + + auto *obj = const_cast(from.toObject()); + bool ok = true; + se::Value field; + obj->getProperty("source", &field, true); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->source), ctx); + } + obj->getProperty("target", &field, true); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->target), ctx); + } + obj->getProperty("mipLevels", &field, true); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->mipLevels), ctx); + } + obj->getProperty("numSlices", &field, true); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->numSlices), ctx); + } + obj->getProperty("targetMostDetailedMip", &field, true); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->targetMostDetailedMip), ctx); + } + obj->getProperty("targetFirstSlice", &field, true); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->targetFirstSlice), ctx); + } + obj->getProperty("targetPlaneSlice", &field, true); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->targetPlaneSlice), ctx); + } + return ok; +} + template <> bool sevalue_to_native(const se::Value &from, cc::render::MovePair *to, se::Object *ctx) { // NOLINT SE_PRECONDITION2(from.isObject(), false, " Convert parameter to MovePair failed !"); diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonJsb.h b/native/cocos/renderer/pipeline/custom/RenderCommonJsb.h index 74652062b2..66c2aa3188 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonJsb.h +++ b/native/cocos/renderer/pipeline/custom/RenderCommonJsb.h @@ -50,6 +50,8 @@ bool nativevalue_to_se(const cc::render::ResolvePair &from, se::Value &to, se::O bool nativevalue_to_se(const cc::render::CopyPair &from, se::Value &to, se::Object *ctx); // NOLINT +bool nativevalue_to_se(const cc::render::UploadPair &from, se::Value &to, se::Object *ctx); // NOLINT + bool nativevalue_to_se(const cc::render::MovePair &from, se::Value &to, se::Object *ctx); // NOLINT // if function overload is used, android build fails @@ -80,6 +82,9 @@ bool sevalue_to_native(const se::Value &from, cc::render::ResolvePair *to, se::O template <> bool sevalue_to_native(const se::Value &from, cc::render::CopyPair *to, se::Object *ctx); // NOLINT +template <> +bool sevalue_to_native(const se::Value &from, cc::render::UploadPair *to, se::Object *ctx); // NOLINT + template <> bool sevalue_to_native(const se::Value &from, cc::render::MovePair *to, se::Object *ctx); // NOLINT diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonNames.h b/native/cocos/renderer/pipeline/custom/RenderCommonNames.h index 4ab84ff4be..d192cbd550 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonNames.h +++ b/native/cocos/renderer/pipeline/custom/RenderCommonNames.h @@ -157,6 +157,7 @@ inline const char* getName(const DescriptorBlockFlattened& /*v*/) noexcept { ret inline const char* getName(const DescriptorBlockIndex& /*v*/) noexcept { return "DescriptorBlockIndex"; } inline const char* getName(const ResolvePair& /*v*/) noexcept { return "ResolvePair"; } inline const char* getName(const CopyPair& /*v*/) noexcept { return "CopyPair"; } +inline const char* getName(const UploadPair& /*v*/) noexcept { return "UploadPair"; } inline const char* getName(const MovePair& /*v*/) noexcept { return "MovePair"; } inline const char* getName(const PipelineStatistics& /*v*/) noexcept { return "PipelineStatistics"; } diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonTypes.cpp b/native/cocos/renderer/pipeline/custom/RenderCommonTypes.cpp index 071c3b4f69..6246f7a86a 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonTypes.cpp +++ b/native/cocos/renderer/pipeline/custom/RenderCommonTypes.cpp @@ -187,6 +187,27 @@ CopyPair::CopyPair(CopyPair const& rhs, const allocator_type& alloc) targetFirstSlice(rhs.targetFirstSlice), targetPlaneSlice(rhs.targetPlaneSlice) {} +UploadPair::UploadPair(const allocator_type& alloc) noexcept +: target(alloc) {} + +UploadPair::UploadPair(ccstd::vector sourceIn, ccstd::pmr::string targetIn, uint32_t mipLevelsIn, uint32_t numSlicesIn, uint32_t targetMostDetailedMipIn, uint32_t targetFirstSliceIn, uint32_t targetPlaneSliceIn, const allocator_type& alloc) noexcept // NOLINT +: source(std::move(sourceIn)), + target(std::move(targetIn), alloc), + mipLevels(mipLevelsIn), + numSlices(numSlicesIn), + targetMostDetailedMip(targetMostDetailedMipIn), + targetFirstSlice(targetFirstSliceIn), + targetPlaneSlice(targetPlaneSliceIn) {} + +UploadPair::UploadPair(UploadPair&& rhs, const allocator_type& alloc) +: source(std::move(rhs.source)), + target(std::move(rhs.target), alloc), + mipLevels(rhs.mipLevels), + numSlices(rhs.numSlices), + targetMostDetailedMip(rhs.targetMostDetailedMip), + targetFirstSlice(rhs.targetFirstSlice), + targetPlaneSlice(rhs.targetPlaneSlice) {} + MovePair::MovePair(const allocator_type& alloc) noexcept : source(alloc), target(alloc) {} diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h b/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h index 92895ea3bd..01f666131f 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h @@ -451,6 +451,30 @@ struct CopyPair { uint32_t targetPlaneSlice{0}; }; +struct UploadPair { + using allocator_type = boost::container::pmr::polymorphic_allocator; + allocator_type get_allocator() const noexcept { // NOLINT + return {target.get_allocator().resource()}; + } + + UploadPair(const allocator_type& alloc = boost::container::pmr::get_default_resource()) noexcept; // NOLINT + UploadPair(ccstd::vector sourceIn, ccstd::pmr::string targetIn, uint32_t mipLevelsIn, uint32_t numSlicesIn, uint32_t targetMostDetailedMipIn, uint32_t targetFirstSliceIn, uint32_t targetPlaneSliceIn, const allocator_type& alloc = boost::container::pmr::get_default_resource()) noexcept; + UploadPair(UploadPair&& rhs, const allocator_type& alloc); + + UploadPair(UploadPair&& rhs) noexcept = default; + UploadPair(UploadPair const& rhs) = delete; + UploadPair& operator=(UploadPair&& rhs) = default; + UploadPair& operator=(UploadPair const& rhs) = delete; + + ccstd::vector source; + ccstd::pmr::string target; + uint32_t mipLevels{0xFFFFFFFF}; + uint32_t numSlices{0xFFFFFFFF}; + uint32_t targetMostDetailedMip{0}; + uint32_t targetFirstSlice{0}; + uint32_t targetPlaneSlice{0}; +}; + struct MovePair { using allocator_type = boost::container::pmr::polymorphic_allocator; allocator_type get_allocator() const noexcept { // NOLINT diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.cpp b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.cpp index 733552a021..e1d7c0b2b1 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.cpp +++ b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.cpp @@ -242,13 +242,12 @@ ResolvePass::ResolvePass(ResolvePass const& rhs, const allocator_type& alloc) : resolvePairs(rhs.resolvePairs, alloc) {} CopyPass::CopyPass(const allocator_type& alloc) noexcept -: copyPairs(alloc) {} +: copyPairs(alloc), + uploadPairs(alloc) {} CopyPass::CopyPass(CopyPass&& rhs, const allocator_type& alloc) -: copyPairs(std::move(rhs.copyPairs), alloc) {} - -CopyPass::CopyPass(CopyPass const& rhs, const allocator_type& alloc) -: copyPairs(rhs.copyPairs, alloc) {} +: copyPairs(std::move(rhs.copyPairs), alloc), + uploadPairs(std::move(rhs.uploadPairs), alloc) {} MovePass::MovePass(const allocator_type& alloc) noexcept : movePairs(alloc) {} diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h index eddc3ca095..73ff546f76 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h @@ -88,6 +88,7 @@ struct RenderSwapchain { : swapchain(swapchainIn) {} gfx::Swapchain* swapchain{nullptr}; + scene::RenderWindow* renderWindow{nullptr}; uint32_t currentID{0}; uint32_t numBackBuffers{0}; uint32_t generation{0xFFFFFFFF}; @@ -494,6 +495,7 @@ struct ResourceGraph { void validateSwapchains(); void mount(gfx::Device* device, vertex_descriptor vertID); void unmount(uint64_t completedFenceValue); + bool isTexture(vertex_descriptor resID) const noexcept; gfx::Texture* getTexture(vertex_descriptor resID); gfx::Buffer* getBuffer(vertex_descriptor resID); void invalidatePersistentRenderPassAndFramebuffer(gfx::Texture* pTexture); @@ -596,14 +598,14 @@ struct CopyPass { CopyPass(const allocator_type& alloc) noexcept; // NOLINT CopyPass(CopyPass&& rhs, const allocator_type& alloc); - CopyPass(CopyPass const& rhs, const allocator_type& alloc); CopyPass(CopyPass&& rhs) noexcept = default; CopyPass(CopyPass const& rhs) = delete; CopyPass& operator=(CopyPass&& rhs) = default; - CopyPass& operator=(CopyPass const& rhs) = default; + CopyPass& operator=(CopyPass const& rhs) = delete; ccstd::pmr::vector copyPairs; + ccstd::pmr::vector uploadPairs; }; struct MovePass { diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h index 36ace0ddd1..564eeb093d 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h @@ -328,8 +328,8 @@ public: virtual void addRenderTarget(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, gfx::LoadOp loadOp, gfx::StoreOp storeOp, const gfx::Color &color) = 0; virtual void addDepthStencil(const ccstd::string &name, AccessType accessType, const ccstd::string &depthSlotName, const ccstd::string &stencilSlotName, gfx::LoadOp loadOp, gfx::StoreOp storeOp, float depth, uint8_t stencil, gfx::ClearFlagBit clearFlags) = 0; virtual void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) = 0; - virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; - virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; + virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; + virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; /** * @deprecated method will be removed in 3.8.0 */ @@ -381,18 +381,6 @@ public: void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler) { addTexture(name, slotName, sampler, 0); } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageBuffer(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageBuffer(name, accessType, slotName, clearType, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageImage(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageImage(name, accessType, slotName, clearType, {}); - } RenderQueueBuilder *addQueue() { return addQueue(QueueHint::NONE, ""); } @@ -434,8 +422,8 @@ public: virtual void addRenderTarget(const ccstd::string &name, const ccstd::string &slotName) = 0; virtual void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) = 0; - virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; - virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; + virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; + virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; /** * @deprecated method will be removed in 3.8.0 */ @@ -451,18 +439,6 @@ public: void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler) { addTexture(name, slotName, sampler, 0); } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageBuffer(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageBuffer(name, accessType, slotName, clearType, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageImage(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageImage(name, accessType, slotName, clearType, {}); - } ComputeQueueBuilder *addQueue() { return addQueue(""); } @@ -472,8 +448,8 @@ class RenderPassBuilder : public BasicRenderPassBuilder { public: RenderPassBuilder() noexcept = default; - virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; - virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; + virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; + virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; virtual RenderSubpassBuilder *addRenderSubpass(const ccstd::string &layoutName) = 0; virtual MultisampleRenderSubpassBuilder *addMultisampleRenderSubpass(uint32_t count, uint32_t quality, const ccstd::string &layoutName) = 0; virtual ComputeSubpassBuilder *addComputeSubpass(const ccstd::string &layoutName) = 0; @@ -481,18 +457,6 @@ public: * @beta function signature might change */ virtual void setCustomShaderStages(const ccstd::string &name, gfx::ShaderStageFlagBit stageFlags) = 0; - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageBuffer(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageBuffer(name, accessType, slotName, clearType, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageImage(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageImage(name, accessType, slotName, clearType, {}); - } RenderSubpassBuilder *addRenderSubpass() { return addRenderSubpass(""); } @@ -509,8 +473,8 @@ public: ComputePassBuilder() noexcept = default; virtual void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) = 0; - virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; - virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType, const ClearValue &clearValue) = 0; + virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; + virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; /** * @deprecated method will be removed in 3.8.0 */ @@ -526,18 +490,6 @@ public: void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler) { addTexture(name, slotName, sampler, 0); } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageBuffer(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageBuffer(name, accessType, slotName, clearType, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) { - addStorageImage(name, accessType, slotName, ClearValueType::NONE, {}); - } - void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, ClearValueType clearType) { - addStorageImage(name, accessType, slotName, clearType, {}); - } ComputeQueueBuilder *addQueue() { return addQueue(""); } @@ -601,6 +553,7 @@ public: virtual void updateShadingRateTexture(const ccstd::string &name, uint32_t width, uint32_t height) = 0; RenderPassBuilder *addRenderPass(uint32_t width, uint32_t height, const ccstd::string &layoutName) override = 0 /* covariant */; virtual ComputePassBuilder *addComputePass(const ccstd::string &layoutName) = 0; + virtual void addUploadPass(ccstd::vector &uploadPairs) = 0; virtual void addMovePass(const ccstd::vector &movePairs) = 0; /** * @beta function signature might change diff --git a/native/cocos/renderer/pipeline/custom/test/test.h b/native/cocos/renderer/pipeline/custom/test/test.h index 2e4306f990..5138fd2000 100644 --- a/native/cocos/renderer/pipeline/custom/test/test.h +++ b/native/cocos/renderer/pipeline/custom/test/test.h @@ -118,6 +118,7 @@ static void fillTestGraph(const ViewInfo &rasterData, const ResourceInfo &rescIn bool isOutput = false; Subpass *subpass = nullptr; + RasterSubpass *subpassNode1 = nullptr; PmrTransparentMap *subpassViews = nullptr; if (hasSubpass) { const ccstd::string subpassName = "subpass" + std::to_string(passID); @@ -134,7 +135,7 @@ static void fillTestGraph(const ViewInfo &rasterData, const ResourceInfo &rescIn std::forward_as_tuple(std::move(subpassNode)), renderGraph, vertexID); - auto *subpassNode1 = get_if(subpassID, &renderGraph); + subpassNode1 = get_if(subpassID, &renderGraph); subpassViews = &subpassNode1->rasterViews; } @@ -163,6 +164,12 @@ static void fillTestGraph(const ViewInfo &rasterData, const ResourceInfo &rescIn rasterViews.emplace(viewName.c_str(), view); if (subpassViews) { subpassViews->emplace(viewName.c_str(), view); + + const auto newID = static_cast(raster.attachmentIndexMap.size()); + auto iter = raster.attachmentIndexMap.find(viewName); + if (iter == raster.attachmentIndexMap.end()) { + raster.attachmentIndexMap.emplace(viewName, newID); + } } ++slot; }