Skip to content

Commit

Permalink
fix resize
Browse files Browse the repository at this point in the history
  • Loading branch information
hana-alice committed Sep 4, 2023
1 parent aff567f commit 12432e6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
76 changes: 50 additions & 26 deletions cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,51 @@ class ResourceVisitor implements ResourceGraphVisitor {
name: string;
constructor (resName = '') {
this.name = resName;
if (resName !== '') {
const ppl = context.pipeline as any;
ppl.resourceUses.push(resName);
}
}
set resName (value: string) {
this.name = value;
}
checkTexture (name: string): boolean {
const dTex = context.deviceTextures.get(name)!;
const resID = context.resourceGraph.vertex(this.name);
const desc = context.resourceGraph.getDesc(resID);
let res = false;
if (dTex.texture) {
res = dTex.texture.width === desc.width && dTex.texture.height === desc.height;
} else if (dTex.swapchain) {
res = dTex.swapchain.width === desc.width && dTex.swapchain.height === desc.height;
}
return res;
}
createDeviceTex (value: Texture | Framebuffer | ManagedResource | RenderSwapchain): void {
if (!context.deviceTextures.get(this.name)) {
const deviceTex = new DeviceTexture(this.name, value);
context.deviceTextures.set(this.name, deviceTex);
} else if (!this.checkTexture(this.name)) {
const dTex = context.deviceTextures.get(this.name)!;
dTex.texture?.destroy();
const deviceTex = new DeviceTexture(this.name, value);
context.deviceTextures.set(this.name, deviceTex);
}
}
checkBuffer (name: string): boolean {
const dBuf = context.deviceBuffers.get(name)!;
const resID = context.resourceGraph.vertex(this.name);
const desc = context.resourceGraph.getDesc(resID);
return dBuf.buffer?.size === desc.width;
return dBuf.buffer!.size >= desc.width;
}
createDeviceBuf (value: ManagedBuffer | PersistentBuffer): void {
if (!context.deviceBuffers.get(this.name) || !this.checkBuffer(this.name)) {
const mount: boolean = !!context.deviceBuffers.get(this.name);
if (!mount) {
const deviceBuf = new DeviceBuffer(this.name, value);
context.deviceBuffers.set(this.name, deviceBuf);
} else if (!this.checkBuffer(this.name)) {
const dBuf = context.deviceBuffers.get(this.name)!;
dBuf.buffer?.destroy();
const deviceBuf = new DeviceBuffer(this.name, value);
context.deviceBuffers.set(this.name, deviceBuf);
}
Expand Down Expand Up @@ -799,23 +826,21 @@ class DeviceRenderPass {
this.renderLayout.descriptorSet.update();
}
for (const [resName, rasterV] of passInfo.pass.rasterViews) {
let resTex = context.deviceTextures.get(resName);
if (!resTex) {
this.visitResource(resName);
resTex = context.deviceTextures.get(resName)!;
} else {
const resGraph = context.resourceGraph;
const resId = resGraph.vertex(resName);
const resFbo = resGraph._vertices[resId]._object;
if (resTex.framebuffer && resFbo instanceof Framebuffer && resTex.framebuffer !== resFbo) {
resTex.framebuffer = resFbo;
} else if (resTex.texture) {
const desc = resGraph.getDesc(resId);
if (resTex.texture.width !== desc.width || resTex.texture.height !== desc.height) {
resTex.texture.resize(desc.width, desc.height);
}
this.visitResource(resName);
const resTex = context.deviceTextures.get(resName)!;

const resGraph = context.resourceGraph;
const resId = resGraph.vertex(resName);
const resFbo = resGraph._vertices[resId]._object;
if (resTex.framebuffer && resFbo instanceof Framebuffer && resTex.framebuffer !== resFbo) {
resTex.framebuffer = resFbo;
} else if (resTex.texture) {
const desc = resGraph.getDesc(resId);
if (resTex.texture.width !== desc.width || resTex.texture.height !== desc.height) {
resTex.texture.resize(desc.width, desc.height);
}
}

if (!swapchain) swapchain = resTex.swapchain;
if (!framebuffer) framebuffer = resTex.framebuffer;
const clearFlag = rasterV.clearFlags & 0xffffffff;
Expand Down Expand Up @@ -1932,6 +1957,7 @@ export class Executor {
deviceBuffs.get(name)!.release();
deviceBuffs.delete(name);
}
resourceUses.length = 0;
}

execute (rg: RenderGraph): void {
Expand All @@ -1940,7 +1966,7 @@ export class Executor {
const cmdBuff = context.commandBuffer;
context.culling.buildRenderQueues(rg, context.layoutGraph, context.pipelineSceneData);
context.culling.uploadInstancing(cmdBuff);
// this._removeDeviceResource();
this._removeDeviceResource();
cmdBuff.begin();
if (!this._visitor) this._visitor = new RenderVisitor();
depthFirstSearch(this._visitor.graphView, this._visitor, this._visitor.colorMap);
Expand Down Expand Up @@ -2062,14 +2088,12 @@ class PreRenderVisitor extends BaseRenderVisitor implements RenderGraphVisitor {
if (value.uploadPairs.length) {
for (const upload of value.uploadPairs) {
const resBuffers = context.deviceBuffers;
let gfxBuffer = resBuffers.get(upload.target);
if (!gfxBuffer) {
const resourceGraph = context.resourceGraph;
const vertId = resourceGraph.vertex(upload.target);
resourceVisitor.resName = upload.target;
resourceGraph.visitVertex(resourceVisitor, vertId);
gfxBuffer = resBuffers.get(upload.target);
}
const resourceGraph = context.resourceGraph;
const vertId = resourceGraph.vertex(upload.target);
resourceVisitor.resName = upload.target;
resourceGraph.visitVertex(resourceVisitor, vertId);

const gfxBuffer = resBuffers.get(upload.target);
context.device.commandBuffer.updateBuffer(gfxBuffer!.buffer!, upload.source, upload.source.byteLength);
}
}
Expand Down
3 changes: 3 additions & 0 deletions cocos/rendering/custom/pipeline-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export function prepareResource (ppl: BasicPipeline, camera: Camera,
height = 1;
}
const windowID = prepareRenderWindow(camera);
info.width = width;
info.height = height;
info.windowID = windowID;
updateResourceFunc(ppl, info);
return info;
}
Expand Down
4 changes: 2 additions & 2 deletions cocos/rendering/render-additive-light-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Model } from '../render-scene/scene/model';
import { PipelineStateManager } from './pipeline-state-manager';
import { Vec3, nextPow2, Mat4, Color, Pool, geometry, cclegacy } from '../core';
import { Device, RenderPass, Buffer, BufferUsageBit, MemoryUsageBit,
BufferInfo, BufferViewInfo, CommandBuffer } from '../gfx';
BufferInfo, BufferViewInfo, CommandBuffer, deviceManager } from '../gfx';
import { RenderInstancedQueue } from './render-instanced-queue';
import { SphereLight } from '../render-scene/scene/sphere-light';
import { SpotLight } from '../render-scene/scene/spot-light';
Expand Down Expand Up @@ -490,7 +490,7 @@ export class RenderAdditiveLightQueue {
this._lightBuffer.resize(this._lightBufferStride * this._lightBufferCount);
this._lightBufferData = new Float32Array(this._lightBufferElementCount * this._lightBufferCount);

this._firstLightBufferView.initialize(new BufferViewInfo(this._lightBuffer, 0, UBOForwardLight.SIZE));
this._firstLightBufferView = deviceManager.gfxDevice.createBuffer(new BufferViewInfo(this._lightBuffer, 0, UBOForwardLight.SIZE));
}

for (let l = 0, offset = 0; l < validPunctualLights.length; l++, offset += this._lightBufferElementCount) {
Expand Down

0 comments on commit 12432e6

Please sign in to comment.