Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba8e49e

Browse files
authored
more adaptations (cocos#7205)
1 parent 048bb23 commit ba8e49e

21 files changed

+126
-76
lines changed

cocos/core/gfx/buffer.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
GFXMemoryUsageBit,
1212
GFXObject,
1313
GFXObjectType,
14-
GFXType,
1514
} from './define';
1615
import { GFXDevice } from './device';
1716

@@ -61,52 +60,60 @@ export abstract class GFXBuffer extends GFXObject {
6160
* @en Usage type of the buffer.
6261
* @zh 缓冲使用方式。
6362
*/
64-
public get usage (): GFXBufferUsage {
63+
get usage (): GFXBufferUsage {
6564
return this._usage;
6665
}
6766

6867
/**
6968
* @en Memory usage of the buffer.
7069
* @zh 缓冲的内存使用方式。
7170
*/
72-
public get memUsage (): GFXMemoryUsage {
71+
get memUsage (): GFXMemoryUsage {
7372
return this._memUsage;
7473
}
7574

7675
/**
7776
* @en Size of the buffer.
7877
* @zh 缓冲大小。
7978
*/
80-
public get size (): number {
79+
get size (): number {
8180
return this._size;
8281
}
8382

8483
/**
8584
* @en Stride of the buffer.
8685
* @zh 缓冲步长。
8786
*/
88-
public get stride (): number {
87+
get stride (): number {
8988
return this._stride;
9089
}
9190

9291
/**
9392
* @en Count of the buffer wrt. stride.
9493
* @zh 缓冲条目数量。
9594
*/
96-
public get count (): number {
95+
get count (): number {
9796
return this._count;
9897
}
9998

100-
public get flags (): GFXBufferFlags {
99+
get flags (): GFXBufferFlags {
101100
return this._flags;
102101
}
103102

104103
/**
105104
* @en View of the back-up buffer, if specified.
106105
* @zh 备份缓冲视图。
107106
*/
108-
public get bufferView (): Uint8Array | null {
109-
return this._bufferView;
107+
get backupBuffer (): Uint8Array | null {
108+
return this._bakcupBuffer;
109+
}
110+
111+
/**
112+
* @en Whether this buffer instance is only a view on top of another buffer.
113+
* @zh 此缓冲实例是否只是另一份缓冲的视图。
114+
*/
115+
get isBufferView () {
116+
return this._isBufferView;
110117
}
111118

112119
protected _device: GFXDevice;
@@ -116,8 +123,9 @@ export abstract class GFXBuffer extends GFXObject {
116123
protected _stride: number = 1;
117124
protected _count: number = 0;
118125
protected _flags: GFXBufferFlags = GFXBufferFlagBit.NONE;
119-
protected _bufferView: Uint8Array | null = null;
126+
protected _bakcupBuffer: Uint8Array | null = null;
120127
protected _indirectBuffer: IGFXIndirectBuffer | null = null;
128+
protected _isBufferView = false;
121129

122130
constructor (device: GFXDevice) {
123131
super(GFXObjectType.BUFFER);

cocos/core/gfx/define.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export enum GFXObjectType {
1111
UNKNOWN,
1212
BUFFER,
1313
TEXTURE,
14-
TEXTURE_VIEW,
1514
RENDER_PASS,
1615
FRAMEBUFFER,
1716
SAMPLER,

cocos/core/gfx/descriptor-set.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { GFXDescriptorType, GFXObject, GFXObjectType } from './define';
77
import { GFXDevice } from './device';
88
import { GFXSampler } from './sampler';
99
import { GFXTexture } from './texture';
10-
import { GFXDescriptorSetLayout } from '..';
10+
import { GFXDescriptorSetLayout } from './descriptor-set-layout';
1111

1212
export const DESCRIPTOR_BUFFER_TYPE =
1313
GFXDescriptorType.UNIFORM_BUFFER | GFXDescriptorType.DYNAMIC_UNIFORM_BUFFER |

cocos/core/gfx/webgl/webgl-buffer.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class WebGLBuffer extends GFXBuffer {
2727

2828
if ('buffer' in info) { // buffer view
2929

30+
this._isBufferView = true;
31+
3032
const buffer = info.buffer as WebGLBuffer;
3133

3234
this._usage = buffer.usage;
@@ -55,7 +57,7 @@ export class WebGLBuffer extends GFXBuffer {
5557
}
5658

5759
if (this._flags & GFXBufferFlagBit.BAKUP_BUFFER) {
58-
this._bufferView = new Uint8Array(this._size);
60+
this._bakcupBuffer = new Uint8Array(this._size);
5961
this._device.memoryStatus.bufferSize += this._size;
6062
}
6163

@@ -68,7 +70,7 @@ export class WebGLBuffer extends GFXBuffer {
6870
memUsage: this._memUsage,
6971
size: this._size,
7072
stride: this._stride,
71-
buffer: this._bufferView,
73+
buffer: this._bakcupBuffer,
7274
vf32: null,
7375
indirects: [],
7476
glTarget: 0,
@@ -102,11 +104,11 @@ export class WebGLBuffer extends GFXBuffer {
102104
this._gpuBufferView = null;
103105
}
104106

105-
this._bufferView = null;
107+
this._bakcupBuffer = null;
106108
}
107109

108110
public resize (size: number) {
109-
if (this._gpuBufferView) {
111+
if (this._isBufferView) {
110112
console.warn('cannot resize buffer views!');
111113
return;
112114
}
@@ -117,10 +119,10 @@ export class WebGLBuffer extends GFXBuffer {
117119
this._size = size;
118120
this._count = this._size / this._stride;
119121

120-
if (this._bufferView) {
121-
const oldView = this._bufferView;
122-
this._bufferView = new Uint8Array(this._size);
123-
this._bufferView.set(oldView);
122+
if (this._bakcupBuffer) {
123+
const oldView = this._bakcupBuffer;
124+
this._bakcupBuffer = new Uint8Array(this._size);
125+
this._bakcupBuffer.set(oldView);
124126
this._device.memoryStatus.bufferSize -= oldSize;
125127
this._device.memoryStatus.bufferSize += size;
126128
}
@@ -132,8 +134,8 @@ export class WebGLBuffer extends GFXBuffer {
132134
if (this._gpuBuffer) {
133135
if (this._uniformBuffer) {
134136
this._gpuBuffer.buffer = this._uniformBuffer;
135-
} else if (this._bufferView) {
136-
this._gpuBuffer.buffer = this._bufferView;
137+
} else if (this._bakcupBuffer) {
138+
this._gpuBuffer.buffer = this._bakcupBuffer;
137139
}
138140

139141
this._gpuBuffer.size = size;
@@ -146,7 +148,7 @@ export class WebGLBuffer extends GFXBuffer {
146148
}
147149

148150
public update (buffer: GFXBufferSource, offset?: number, size?: number) {
149-
if (this._gpuBufferView) {
151+
if (this._isBufferView) {
150152
console.warn('cannot update through buffer views!');
151153
return;
152154
}
@@ -159,9 +161,9 @@ export class WebGLBuffer extends GFXBuffer {
159161
} else {
160162
buffSize = (buffer as ArrayBuffer).byteLength;
161163
}
162-
if (this._bufferView && buffer !== this._bufferView.buffer) {
164+
if (this._bakcupBuffer && buffer !== this._bakcupBuffer.buffer) {
163165
const view = new Uint8Array(buffer as ArrayBuffer, 0, size);
164-
this._bufferView.set(view, offset);
166+
this._bakcupBuffer.set(view, offset);
165167
}
166168

167169
WebGLCmdFuncUpdateBuffer(

cocos/core/gfx/webgl/webgl-command-buffer.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export class WebGLCommandBuffer extends GFXCommandBuffer {
4949
protected _webGLAllocator: WebGLCommandAllocator | null = null;
5050
protected _isInRenderPass: boolean = false;
5151
protected _curGPUPipelineState: IWebGLGPUPipelineState | null = null;
52+
protected _curGPUInputAssembler: IWebGLGPUInputAssembler | null = null;
5253
protected _curGPUDescriptorSets: IWebGLGPUDescriptorSet[] = [];
5354
protected _curDynamicOffsets: number[][] = [];
54-
protected _curGPUInputAssembler: IWebGLGPUInputAssembler | null = null;
5555
protected _curViewport: GFXViewport | null = null;
5656
protected _curScissor: GFXRect | null = null;
5757
protected _curLineWidth: number | null = null;
@@ -69,6 +69,12 @@ export class WebGLCommandBuffer extends GFXCommandBuffer {
6969

7070
this._webGLAllocator = (this._device as WebGLDevice).cmdAllocator;
7171

72+
const setCount = (this._device as WebGLDevice).bindingMappingInfo.bufferOffsets.length;
73+
for (let i = 0; i < setCount; i++) {
74+
this._curGPUDescriptorSets.push(null!);
75+
this._curDynamicOffsets.push([]);
76+
}
77+
7278
return true;
7379
}
7480

@@ -82,8 +88,11 @@ export class WebGLCommandBuffer extends GFXCommandBuffer {
8288
public begin (renderPass?: GFXRenderPass, subpass = 0, frameBuffer?: GFXFramebuffer) {
8389
this._webGLAllocator!.clearCmds(this.cmdPackage);
8490
this._curGPUPipelineState = null;
85-
this._curGPUDescriptorSets.length = 0;
8691
this._curGPUInputAssembler = null;
92+
this._curGPUDescriptorSets.length = 0;
93+
for (let i = 0; i < this._curDynamicOffsets.length; i++) {
94+
this._curDynamicOffsets[i].length = 0;
95+
}
8796
this._curViewport = null;
8897
this._curScissor = null;
8998
this._curLineWidth = null;
@@ -95,9 +104,6 @@ export class WebGLCommandBuffer extends GFXCommandBuffer {
95104
this._numDrawCalls = 0;
96105
this._numInstances = 0;
97106
this._numTris = 0;
98-
for (let i = 0; i < this._curDynamicOffsets.length; i++) {
99-
if (this._curDynamicOffsets[i]) this._curDynamicOffsets[i].length = 0;
100-
}
101107
}
102108

103109
public end () {
@@ -151,8 +157,9 @@ export class WebGLCommandBuffer extends GFXCommandBuffer {
151157
this._isStateInvalied = true;
152158
}
153159
if (dynamicOffsets) {
154-
const offsets = this._curDynamicOffsets[set] || (this._curDynamicOffsets[set] = []);
160+
const offsets = this._curDynamicOffsets[set];
155161
for (let i = 0; i < dynamicOffsets.length; i++) offsets[i] = dynamicOffsets[i];
162+
offsets.length = dynamicOffsets.length;
156163
this._isStateInvalied = true;
157164
}
158165
}

cocos/core/gfx/webgl/webgl-device.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class WebGLDevice extends GFXDevice {
170170
private _useVAO: boolean = false;
171171
private _destroyShadersImmediately: boolean = true;
172172
private _noCompressedTexSubImage2D: boolean = false;
173-
private _bindingMappingInfo: GFXBindingMappingInfo | null = null;
173+
private _bindingMappingInfo: GFXBindingMappingInfo = new GFXBindingMappingInfo();
174174

175175
private _extensions: string[] | null = null;
176176
private _EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null = null;
@@ -214,6 +214,8 @@ export class WebGLDevice extends GFXDevice {
214214
if (info.bindingMappingInfo !== undefined) {
215215
this._bindingMappingInfo = info.bindingMappingInfo;
216216
}
217+
if (!this._bindingMappingInfo.bufferOffsets.length) this._bindingMappingInfo.bufferOffsets.push(0);
218+
if (!this._bindingMappingInfo.samplerOffsets.length) this._bindingMappingInfo.samplerOffsets.push(0);
217219

218220
try {
219221
const webGLCtxAttribs: WebGLContextAttributes = {

cocos/core/gfx/webgl/webgl-gpu-objects.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export interface IWebGLGPUDescriptorSetLayout {
167167

168168
export interface IWebGLGPUPipelineLayout {
169169
gpuSetLayouts: IWebGLGPUDescriptorSetLayout[];
170+
dynamicOffsetCount: number;
171+
dynamicOffsetOffsets: number[];
170172
dynamicOffsetIndices: number[][];
171173
}
172174

cocos/core/gfx/webgl/webgl-pipeline-layout.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export class WebGLPipelineLayout extends GFXPipelineLayout {
1313

1414
const dynamicOffsetIndices: number[][] = [];
1515

16-
const gpuSetLayouts: IWebGLGPUDescriptorSetLayout[] = []; let idx = 0;
16+
const gpuSetLayouts: IWebGLGPUDescriptorSetLayout[] = [];
17+
const dynamicOffsetOffsets: number[] = [];
18+
let dynamicOffsetCount = 0; let idx = 0;
1719
for (let i = 0; i < this._setLayouts.length; i++) {
1820
const setLayout = this._setLayouts[i] as WebGLDescriptorSetLayout;
1921
const dynamicBindings = setLayout.gpuDescriptorSetLayout.dynamicBindings;
@@ -30,10 +32,14 @@ export class WebGLPipelineLayout extends GFXPipelineLayout {
3032
}
3133

3234
dynamicOffsetIndices.push(indices);
35+
dynamicOffsetOffsets.push(dynamicOffsetCount);
36+
dynamicOffsetCount += dynamicBindings.length;
3337
}
3438

3539
this._gpuPipelineLayout = {
3640
gpuSetLayouts,
41+
dynamicOffsetCount,
42+
dynamicOffsetOffsets,
3743
dynamicOffsetIndices,
3844
};
3945

cocos/core/gfx/webgl2/webgl2-buffer.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export class WebGL2Buffer extends GFXBuffer {
1616
}
1717

1818
private _gpuBuffer: IWebGL2GPUBuffer | null = null;
19-
private _isBufferView: boolean = false;
2019

2120
public initialize (info: IGFXBufferInfo | IGFXBufferViewInfo): boolean {
2221

@@ -37,7 +36,7 @@ export class WebGL2Buffer extends GFXBuffer {
3736
memUsage: this._memUsage,
3837
size: this._size,
3938
stride: this._stride,
40-
buffer: this._bufferView,
39+
buffer: this._bakcupBuffer,
4140
indirects: buffer.gpuBuffer.indirects,
4241
glTarget: buffer.gpuBuffer.glTarget,
4342
glBuffer: buffer.gpuBuffer.glBuffer,
@@ -58,7 +57,7 @@ export class WebGL2Buffer extends GFXBuffer {
5857
}
5958

6059
if (this._flags & GFXBufferFlagBit.BAKUP_BUFFER) {
61-
this._bufferView = new Uint8Array(this._size);
60+
this._bakcupBuffer = new Uint8Array(this._size);
6261
this._device.memoryStatus.bufferSize += this._size;
6362
}
6463

@@ -67,7 +66,7 @@ export class WebGL2Buffer extends GFXBuffer {
6766
memUsage: this._memUsage,
6867
size: this._size,
6968
stride: this._stride,
70-
buffer: this._bufferView,
69+
buffer: this._bakcupBuffer,
7170
indirects: [],
7271
glTarget: 0,
7372
glBuffer: null,
@@ -95,7 +94,7 @@ export class WebGL2Buffer extends GFXBuffer {
9594
this._gpuBuffer = null;
9695
}
9796

98-
this._bufferView = null;
97+
this._bakcupBuffer = null;
9998
}
10099

101100
public resize (size: number) {
@@ -110,17 +109,17 @@ export class WebGL2Buffer extends GFXBuffer {
110109
this._size = size;
111110
this._count = this._size / this._stride;
112111

113-
if (this._bufferView) {
114-
const oldView = this._bufferView;
115-
this._bufferView = new Uint8Array(this._size);
116-
this._bufferView.set(oldView);
112+
if (this._bakcupBuffer) {
113+
const oldView = this._bakcupBuffer;
114+
this._bakcupBuffer = new Uint8Array(this._size);
115+
this._bakcupBuffer.set(oldView);
117116
this._device.memoryStatus.bufferSize -= oldSize;
118117
this._device.memoryStatus.bufferSize += size;
119118
}
120119

121120
if (this._gpuBuffer) {
122-
if (this._bufferView) {
123-
this._gpuBuffer.buffer = this._bufferView;
121+
if (this._bakcupBuffer) {
122+
this._gpuBuffer.buffer = this._bakcupBuffer;
124123
}
125124

126125
this._gpuBuffer.size = size;
@@ -146,9 +145,9 @@ export class WebGL2Buffer extends GFXBuffer {
146145
} else {
147146
buffSize = (buffer as ArrayBuffer).byteLength;
148147
}
149-
if (this._bufferView && buffer !== this._bufferView.buffer) {
148+
if (this._bakcupBuffer && buffer !== this._bakcupBuffer.buffer) {
150149
const view = new Uint8Array(buffer as ArrayBuffer, 0, size);
151-
this._bufferView.set(view, offset);
150+
this._bakcupBuffer.set(view, offset);
152151
}
153152

154153
WebGL2CmdFuncUpdateBuffer(

0 commit comments

Comments
 (0)