Skip to content

Commit

Permalink
V3.8.2 pipeline simplify (cocos#16578)
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e authored Dec 8, 2023
1 parent b71e598 commit 477047f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 4 deletions.
45 changes: 45 additions & 0 deletions cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,11 @@ export class WebPipeline implements BasicPipeline {
throw new Error('Method not implemented.');
}
addRenderWindow (name: string, format: Format, width: number, height: number, renderWindow: RenderWindow): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateRenderWindow(name, renderWindow);
return resID;
}
// Objects need to be held for a long time, so there is no need to use pool management
const desc = new ResourceDesc();
desc.dimension = ResourceDimension.TEXTURE2D;
Expand Down Expand Up @@ -1978,6 +1983,11 @@ export class WebPipeline implements BasicPipeline {
}

public addBuffer (name: string, size: number, flags: ResourceFlags, residency: ResourceResidency): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateBuffer(name, size);
return resID;
}
const desc = new ResourceDesc();
desc.dimension = ResourceDimension.BUFFER;
desc.width = size;
Expand Down Expand Up @@ -2007,6 +2017,11 @@ export class WebPipeline implements BasicPipeline {
}

public addTexture (name: string, textureType: TextureType, format: Format, width: number, height: number, depth: number, arraySize: number, mipLevels: number, sampleCount: SampleCount, flags: ResourceFlags, residency: ResourceResidency): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateTexture(name, format, width, height, depth, arraySize, mipLevels, sampleCount);
return resID;
}
const desc = new ResourceDesc();
desc.dimension = getResourceDimension(textureType);
desc.width = width;
Expand Down Expand Up @@ -2034,6 +2049,11 @@ export class WebPipeline implements BasicPipeline {
}

public addResource (name: string, dimension: ResourceDimension, format: Format, width: number, height: number, depth: number, arraySize: number, mipLevels: number, sampleCount: SampleCount, flags: ResourceFlags, residency: ResourceResidency): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateResource(name, format, width, height, depth, arraySize, mipLevels, sampleCount);
return resID;
}
if (dimension === ResourceDimension.BUFFER) {
return this.addBuffer(name, width, flags, residency);
} else {
Expand Down Expand Up @@ -2334,6 +2354,11 @@ export class WebPipeline implements BasicPipeline {
this.compile();
}
addStorageBuffer (name: string, format: Format, size: number, residency = ResourceResidency.MANAGED): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateStorageBuffer(name, size, format);
return resID;
}
const desc = new ResourceDesc();
desc.dimension = ResourceDimension.BUFFER;
desc.width = size;
Expand Down Expand Up @@ -2366,6 +2391,11 @@ export class WebPipeline implements BasicPipeline {
);
}
addRenderTarget (name: string, format: Format, width: number, height: number, residency = ResourceResidency.MANAGED): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateRenderTarget(name, width, height, format);
return resID;
}
const desc = new ResourceDesc();
desc.dimension = ResourceDimension.TEXTURE2D;
desc.width = width;
Expand All @@ -2388,6 +2418,11 @@ export class WebPipeline implements BasicPipeline {
);
}
addDepthStencil (name: string, format: Format, width: number, height: number, residency = ResourceResidency.MANAGED): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateDepthStencil(name, width, height, format);
return resID;
}
const desc = new ResourceDesc();
desc.dimension = ResourceDimension.TEXTURE2D;
desc.width = width;
Expand All @@ -2409,6 +2444,11 @@ export class WebPipeline implements BasicPipeline {
);
}
addStorageTexture (name: string, format: Format, width: number, height: number, residency = ResourceResidency.MANAGED): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.updateStorageTexture(name, width, height, format);
return resID;
}
const desc = new ResourceDesc();
desc.dimension = ResourceDimension.TEXTURE2D;
desc.width = width;
Expand All @@ -2429,6 +2469,11 @@ export class WebPipeline implements BasicPipeline {
);
}
addShadingRateTexture (name: string, width: number, height: number, residency = ResourceResidency.MANAGED): number {
const resID = this._resourceGraph.find(name);
if (resID !== 0xFFFFFFFF) {
this.addShadingRateTexture(name, width, height);
return resID;
}
const desc = new ResourceDesc();
desc.dimension = ResourceDimension.TEXTURE2D;
desc.width = width;
Expand Down
79 changes: 75 additions & 4 deletions native/cocos/renderer/pipeline/custom/NativePipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ bool NativePipeline::containsResource(const ccstd::string &name) const {
}

uint32_t NativePipeline::addExternalTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateExternalTexture(name, texture);
return resID;
}

const auto &texInfo = texture->getInfo();
ResourceDesc desc{};
desc.dimension = getResourceDimension(texInfo.type);
Expand Down Expand Up @@ -185,6 +191,12 @@ void NativePipeline::updateExternalTexture(const ccstd::string &name, gfx::Textu

// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
uint32_t NativePipeline::addRenderWindow(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, scene::RenderWindow *renderWindow) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateRenderWindow(name, renderWindow);
return resID;
}

ResourceDesc desc{};
desc.dimension = ResourceDimension::TEXTURE2D;
desc.width = width;
Expand Down Expand Up @@ -234,6 +246,11 @@ uint32_t NativePipeline::addRenderWindow(const ccstd::string &name, gfx::Format

// NOLINTNEXTLINE
uint32_t NativePipeline::addStorageBuffer(const ccstd::string &name, gfx::Format format, uint32_t size, ResourceResidency residency) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateStorageBuffer(name, size, format);
return resID;
}
ResourceDesc desc{};
desc.dimension = ResourceDimension::BUFFER;
desc.width = size;
Expand All @@ -258,6 +275,11 @@ uint32_t NativePipeline::addStorageBuffer(const ccstd::string &name, gfx::Format

// NOLINTNEXTLINE
uint32_t NativePipeline::addRenderTarget(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateRenderTarget(name, width, height, format);
return resID;
}
ResourceDesc desc{};
desc.dimension = ResourceDimension::TEXTURE2D;
desc.width = width;
Expand All @@ -283,6 +305,11 @@ uint32_t NativePipeline::addRenderTarget(const ccstd::string &name, gfx::Format

// NOLINTNEXTLINE
uint32_t NativePipeline::addDepthStencil(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateDepthStencil(name, width, height, format);
return resID;
}
ResourceDesc desc{};
desc.dimension = ResourceDimension::TEXTURE2D;
desc.width = width;
Expand All @@ -302,7 +329,7 @@ uint32_t NativePipeline::addDepthStencil(const ccstd::string &name, gfx::Format
samplerInfo.minFilter = gfx::Filter::POINT;
samplerInfo.mipFilter = gfx::Filter::NONE;

auto resID = addVertex(
resID = addVertex(
ManagedTextureTag{},
std::forward_as_tuple(name.c_str()),
std::forward_as_tuple(desc),
Expand All @@ -317,6 +344,11 @@ uint32_t NativePipeline::addDepthStencil(const ccstd::string &name, gfx::Format
}

uint32_t NativePipeline::addTexture(const ccstd::string &name, gfx::TextureType type, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateTexture(name, format, width, height, depth, arraySize, mipLevels, sampleCount);
return resID;
}
const auto dimension = getResourceDimension(type);
ResourceDesc desc{
dimension,
Expand Down Expand Up @@ -347,6 +379,11 @@ void NativePipeline::updateTexture(const ccstd::string &name, gfx::Format format
}

uint32_t NativePipeline::addBuffer(const ccstd::string &name, uint32_t size, ResourceFlags flags, ResourceResidency residency) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateBuffer(name, size);
return resID;
}
ResourceDesc desc = {};
desc.dimension = ResourceDimension::BUFFER;
desc.width = size;
Expand All @@ -371,7 +408,19 @@ uint32_t NativePipeline::addResource(
gfx::Format format,
uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels,
gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) {
return dimension == ResourceDimension::BUFFER ? addBuffer(name, width, flags, residency) : addTexture(name, getTextureType(dimension, arraySize), format, width, height, depth, arraySize, mipLevels, sampleCount, flags, residency);
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateResource(name, format, width, height, depth, arraySize, mipLevels, sampleCount);
return resID;
}
return dimension == ResourceDimension::BUFFER
? addBuffer(name, width, flags, residency)
: addTexture(
name,
getTextureType(dimension, arraySize),
format, width, height, depth,
arraySize, mipLevels, sampleCount,
flags, residency);
}

void NativePipeline::updateResource(
Expand Down Expand Up @@ -414,6 +463,11 @@ void NativePipeline::updateResource(

// NOLINTNEXTLINE
uint32_t NativePipeline::addStorageTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateStorageTexture(name, width, height, format);
return resID;
}
ResourceDesc desc{};
desc.dimension = ResourceDimension::TEXTURE2D;
desc.width = width;
Expand Down Expand Up @@ -443,6 +497,11 @@ uint32_t NativePipeline::addStorageTexture(const ccstd::string &name, gfx::Forma
}
// NOLINTNEXTLINE
uint32_t NativePipeline::addShadingRateTexture(const ccstd::string &name, uint32_t width, uint32_t height, ResourceResidency residency) {
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateShadingRateTexture(name, width, height);
return resID;
}
ResourceDesc desc{};
desc.dimension = ResourceDimension::TEXTURE2D;
desc.width = width;
Expand Down Expand Up @@ -477,6 +536,11 @@ uint32_t NativePipeline::addCustomBuffer(
if (!custom.currentContext) {
return ResourceGraph::null_vertex();
}
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateBuffer(name, info.size);
return resID;
}
auto &ctx = *custom.currentContext;

ResourceDesc desc{};
Expand Down Expand Up @@ -509,6 +573,13 @@ uint32_t NativePipeline::addCustomTexture(
if (!custom.currentContext) {
return ResourceGraph::null_vertex();
}
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
if (resID != ResourceGraph::null_vertex()) {
updateTexture(name,
info.format, info.width, info.height, info.depth,
info.layerCount, info.levelCount, info.samples);
return resID;
}
auto &ctx = *custom.currentContext;

ResourceDesc desc{};
Expand Down Expand Up @@ -553,7 +624,7 @@ void NativePipeline::updateRenderWindow(const ccstd::string &name, scene::Render
},
[&](RenderSwapchain &sc) {
auto *newSwapchain = renderWindow->getSwapchain();
const auto& oldTexture = resourceGraph.getTexture(resID);
const auto &oldTexture = resourceGraph.getTexture(resID);
resourceGraph.invalidatePersistentRenderPassAndFramebuffer(oldTexture);
if (newSwapchain) {
desc.width = newSwapchain->getWidth();
Expand All @@ -567,7 +638,7 @@ void NativePipeline::updateRenderWindow(const ccstd::string &name, scene::Render
CC_EXPECTS(renderWindow->getFramebuffer()->getColorTextures().size() == 1);
CC_EXPECTS(renderWindow->getFramebuffer()->getColorTextures().front());

const auto& texture = renderWindow->getFramebuffer()->getColorTextures().front();
const auto &texture = renderWindow->getFramebuffer()->getColorTextures().front();
desc.width = texture->getWidth();
desc.height = texture->getHeight();

Expand Down

0 comments on commit 477047f

Please sign in to comment.