Skip to content

Commit

Permalink
Merge branch 'v3.8.5' of https://github.com/cocos/cocos-engine into 3…
Browse files Browse the repository at this point in the history
…85-gfx-copyTextureToTexture

# Conflicts:
#	cocos/gfx/webgl/webgl-commands.ts
  • Loading branch information
dumganhar committed Jul 2, 2024
2 parents e2909ca + 2a805dd commit 8a512f9
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 50 deletions.
9 changes: 1 addition & 8 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,7 @@ rules:
'@typescript-eslint/unbound-method': off # we exploit prototype methods sometimes to acheive better performace
'@typescript-eslint/no-explicit-any': off # still relevant for some heavily templated usages

'@typescript-eslint/no-empty-function': [error, {
allow: [
private-constructors,
protected-constructors,
decoratedFunctions,
overrideMethods,
]
}]
'@typescript-eslint/no-empty-function': off # may become useful in some parent classes

'@typescript-eslint/no-unused-vars': off # may become useful in some parent classes
'@typescript-eslint/no-non-null-assertion': off # sometimes we just know better than the compiler
Expand Down
4 changes: 2 additions & 2 deletions cocos/gfx/base/descriptor-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Buffer } from './buffer';
import { DescriptorSetLayout } from './descriptor-set-layout';
import { Sampler } from './states/sampler';
import { Texture } from './texture';
import { GFXObject, ObjectType, DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE, AccessFlags } from './define';
import { GFXObject, ObjectType, DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE, AccessFlags, AccessFlagBit } from './define';

/**
* @en GFX descriptor sets.
Expand Down Expand Up @@ -96,7 +96,7 @@ export abstract class DescriptorSet extends GFXObject {
* @param binding The target binding.
* @param texture The texture to be bound.
*/
public bindTexture (binding: number, texture: Texture, index = 0, flags?: AccessFlags): void {
public bindTexture (binding: number, texture: Texture, index = 0, flags = AccessFlagBit.NONE): void {
const bindingIndex = this._layout!.bindingIndices[binding];
const info = this._layout!.bindings[bindingIndex]; if (!info) { return; }
if (info.descriptorType & DESCRIPTOR_SAMPLER_TYPE) {
Expand Down
9 changes: 0 additions & 9 deletions cocos/gfx/base/pipeline-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@ import { PipelineLayout } from './pipeline-layout';
import { RenderPass } from './render-pass';
import { Shader } from './shader';
import {
BlendFactor,
BlendOp,
ColorMask,
ComparisonFunc,
CullMode,
DynamicStateFlagBit,
DynamicStateFlags,
GFXObject,
ObjectType,
PolygonMode,
PrimitiveMode,
ShadeModel,
StencilOp,
InputState,
Color,
PipelineBindPoint,
} from './define';
import { BlendState, BlendTarget, RasterizerState, DepthStencilState } from './pipeline-sub-state';
Expand Down
12 changes: 6 additions & 6 deletions cocos/gfx/base/states/sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export class Sampler extends GFXObject {

static computeHash (info: Readonly<SamplerInfo>): Filter {
let hash = info.minFilter;
hash |= (info.magFilter << 2);
hash |= (info.mipFilter << 4);
hash |= (info.addressU << 6);
hash |= (info.addressV << 8);
hash |= (info.addressW << 10);
hash |= ((info.magFilter as number) << 2);
hash |= ((info.mipFilter as number) << 4);
hash |= ((info.addressU as number) << 6);
hash |= ((info.addressV as number) << 8);
hash |= ((info.addressW as number) << 10);
hash |= (info.maxAnisotropy << 12);
hash |= (info.cmpFunc << 16);
hash |= ((info.cmpFunc as number) << 16);
return hash;
}

Expand Down
19 changes: 14 additions & 5 deletions cocos/gfx/empty/empty-command-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ export class EmptyCommandBuffer extends CommandBuffer {
this._queue = info.queue;
}
public destroy (): void {}
public begin (renderPass?: RenderPass, subpass = 0, frameBuffer?: Framebuffer): void {}
public begin (renderPass?: RenderPass, subpass?: number, frameBuffer?: Framebuffer): void {}
public end (): void {}
public beginRenderPass (renderPass: RenderPass, framebuffer: Framebuffer, renderArea: Readonly<Rect>,
clearColors: Readonly<Color[]>, clearDepth: number, clearStencil: number): void {}
public beginRenderPass (
renderPass: RenderPass,
framebuffer: Framebuffer,
renderArea: Readonly<Rect>,
clearColors: Readonly<Color[]>,
clearDepth: number,
clearStencil: number,
): void {}
public endRenderPass (): void {}
public bindPipelineState (pipelineState: PipelineState): void {}
public bindDescriptorSet (set: number, descriptorSet: DescriptorSet, dynamicOffsets?: Readonly<number[]>): void {}
Expand All @@ -63,9 +69,12 @@ export class EmptyCommandBuffer extends CommandBuffer {
public updateBuffer (buffer: Buffer, data: Readonly<BufferSource>, size?: number): void {}
public copyBuffersToTexture (buffers: Readonly<ArrayBufferView[]>, texture: Texture, regions: Readonly<BufferTextureCopy[]>): void {}
public execute (cmdBuffs: Readonly<CommandBuffer[]>, count: number): void {}
public pipelineBarrier (GeneralBarrier: Readonly<GeneralBarrier>, bufferBarriers?: Readonly<BufferBarrier[]>,
public pipelineBarrier (
GeneralBarrier: Readonly<GeneralBarrier>,
bufferBarriers?: Readonly<BufferBarrier[]>,
buffers?: Readonly<Buffer[]>,
textureBarriers?: Readonly<TextureBarrier[]>,
textures?: Readonly<Texture[]>): void {}
textures?: Readonly<Texture[]>,
): void {}
public blitTexture (srcTexture: Readonly<Texture>, dstTexture: Texture, regions: Readonly<TextureBlit []>, filter: Filter): void {}
}
5 changes: 3 additions & 2 deletions cocos/gfx/webgl/webgl-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from './webgl-commands';
import { IWebGLGPUBuffer, IWebGLGPUBufferView, WebGLIndirectDrawInfos } from './webgl-gpu-objects';
import { WebGLDeviceManager } from './webgl-define';
import { warn } from '../../core';

export class WebGLBuffer extends Buffer {
get gpuBuffer (): IWebGLGPUBuffer {
Expand Down Expand Up @@ -112,7 +113,7 @@ export class WebGLBuffer extends Buffer {

public resize (size: number): void {
if (this._isBufferView) {
console.warn('cannot resize buffer views!');
warn('cannot resize buffer views!');
return;
}

Expand Down Expand Up @@ -142,7 +143,7 @@ export class WebGLBuffer extends Buffer {

public update (buffer: Readonly<BufferSource>, size?: number): void {
if (this._isBufferView) {
console.warn('cannot update through buffer views!');
warn('cannot update through buffer views!');
return;
}

Expand Down
9 changes: 5 additions & 4 deletions cocos/gfx/webgl/webgl-command-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { GeneralBarrier } from '../base/states/general-barrier';
import { TextureBarrier } from '../base/states/texture-barrier';
import { BufferBarrier } from '../base/states/buffer-barrier';
import { WebGLDeviceManager } from './webgl-define';
import { error } from '../../core';

export class WebGLCommandBuffer extends CommandBuffer {
public cmdPackage: WebGLCmdPackage = new WebGLCmdPackage();
Expand Down Expand Up @@ -74,7 +75,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
this._cmdAllocator.clearCmds(this.cmdPackage);
}

public begin (renderPass?: RenderPass, subpass = 0, frameBuffer?: Framebuffer): void {
public begin (renderPass?: RenderPass, subpass?: number, frameBuffer?: Framebuffer): void {
this._cmdAllocator.clearCmds(this.cmdPackage);
this._curGPUPipelineState = null;
this._curGPUInputAssembler = null;
Expand Down Expand Up @@ -295,7 +296,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
}
}
} else {
console.error('Command \'draw\' must be recorded inside a render pass.');
error('Command \'draw\' must be recorded inside a render pass.');
}
}

Expand Down Expand Up @@ -331,7 +332,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
this.cmdPackage.cmds.push(WebGLCmd.UPDATE_BUFFER);
}
} else {
console.error('Command \'updateBuffer\' must be recorded outside a render pass.');
error('Command \'updateBuffer\' must be recorded outside a render pass.');
}
}

Expand All @@ -353,7 +354,7 @@ export class WebGLCommandBuffer extends CommandBuffer {
}
}
} else {
console.error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
}
}

Expand Down
4 changes: 1 addition & 3 deletions cocos/gfx/webgl/webgl-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ export class WebGLCmdDraw extends WebGLCmdObject {
super(WebGLCmd.DRAW);
}

public clear (): void {
//
}
public clear (): void {}
}

export class WebGLCmdUpdateBuffer extends WebGLCmdObject {
Expand Down
19 changes: 14 additions & 5 deletions cocos/gfx/webgl/webgl-gpu-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,16 @@ export class IWebGLBlitManager {
this._gpuShader = {
name: 'Blit Pass',
blocks: [
new UniformBlock(0, 0, `BlitParams`,
new UniformBlock(
0,
0,
`BlitParams`,
[
new Uniform(`tilingOffsetSrc`, Type.FLOAT4, 1),
new Uniform(`tilingOffsetDst`, Type.FLOAT4, 1),
],
1),
1,
),
],
samplerTextures: [new UniformSamplerTexture(0, samplerOffset, 'textureSrc', Type.SAMPLER2D, 1)],
subpassInputs: [],
Expand Down Expand Up @@ -538,7 +542,7 @@ export class IWebGLBlitManager {
descriptor.gpuSampler = filter === Filter.POINT ? this._gpuPointSampler : this._gpuLinearSampler;

const formatInfo = FormatInfos[gpuTextureDst.format];
let attachment = gl.COLOR_ATTACHMENT0;
let attachment: number = gl.COLOR_ATTACHMENT0;
if (formatInfo.hasStencil) {
attachment = gl.DEPTH_STENCIL_ATTACHMENT;
} else if (formatInfo.hasDepth) {
Expand Down Expand Up @@ -582,8 +586,13 @@ export class IWebGLBlitManager {
this._uniformBuffer[6] = region.dstOffset.x / dstWidth;
this._uniformBuffer[7] = region.dstOffset.y / dstHeight;

WebGLCmdFuncUpdateBuffer(device, this._gpuUniformBuffer, this._uniformBuffer, 0,
this._uniformBuffer.length * Float32Array.BYTES_PER_ELEMENT);
WebGLCmdFuncUpdateBuffer(
device,
this._gpuUniformBuffer,
this._uniformBuffer,
0,
this._uniformBuffer.length * Float32Array.BYTES_PER_ELEMENT,
);
WebGLCmdFuncBindStates(device, this._gpuPipelineState, this._gpuInputAssembler, [this._gpuDescriptorSet], [], null!);
WebGLCmdFuncDraw(device, this._drawInfo);
}
Expand Down
5 changes: 3 additions & 2 deletions cocos/gfx/webgl2/webgl2-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
THE SOFTWARE.
*/

import { warn } from '../../core';
import { Buffer } from '../base/buffer';
import { BufferUsageBit, BufferSource, BufferInfo, BufferViewInfo } from '../base/define';
import {
Expand Down Expand Up @@ -101,7 +102,7 @@ export class WebGL2Buffer extends Buffer {

public resize (size: number): void {
if (this._isBufferView) {
console.warn('cannot resize buffer views!');
warn('cannot resize buffer views!');
return;
}

Expand All @@ -123,7 +124,7 @@ export class WebGL2Buffer extends Buffer {

public update (buffer: Readonly<BufferSource>, size?: number): void {
if (this._isBufferView) {
console.warn('cannot update through buffer views!');
warn('cannot update through buffer views!');
return;
}

Expand Down
9 changes: 5 additions & 4 deletions cocos/gfx/webgl2/webgl2-command-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { GeneralBarrier } from '../base/states/general-barrier';
import { TextureBarrier } from '../base/states/texture-barrier';
import { BufferBarrier } from '../base/states/buffer-barrier';
import { WebGL2DeviceManager } from './webgl2-define';
import { error } from '../../core';

export class WebGL2CommandBuffer extends CommandBuffer {
public cmdPackage: WebGL2CmdPackage = new WebGL2CmdPackage();
Expand Down Expand Up @@ -87,7 +88,7 @@ export class WebGL2CommandBuffer extends CommandBuffer {
this._cmdAllocator.clearCmds(this.cmdPackage);
}

public begin (renderPass?: RenderPass, subpass = 0, frameBuffer?: Framebuffer): void {
public begin (renderPass?: RenderPass, subpass?: number, frameBuffer?: Framebuffer): void {
this._cmdAllocator.clearCmds(this.cmdPackage);
this._curGPUPipelineState = null;
this._curGPUInputAssembler = null;
Expand Down Expand Up @@ -307,7 +308,7 @@ export class WebGL2CommandBuffer extends CommandBuffer {
}
}
} else {
console.error('Command \'draw\' must be recorded inside a render pass.');
error('Command \'draw\' must be recorded inside a render pass.');
}
}

Expand Down Expand Up @@ -342,7 +343,7 @@ export class WebGL2CommandBuffer extends CommandBuffer {
this.cmdPackage.cmds.push(WebGL2Cmd.UPDATE_BUFFER);
}
} else {
console.error('Command \'updateBuffer\' must be recorded outside a render pass.');
error('Command \'updateBuffer\' must be recorded outside a render pass.');
}
}

Expand All @@ -362,7 +363,7 @@ export class WebGL2CommandBuffer extends CommandBuffer {
this.cmdPackage.cmds.push(WebGL2Cmd.COPY_BUFFER_TO_TEXTURE);
}
} else {
console.error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
error('Command \'copyBufferToTexture\' must be recorded outside a render pass.');
}
}

Expand Down

0 comments on commit 8a512f9

Please sign in to comment.