mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
shader stores attribute info (#6866)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import { GFXObject, GFXObjectType, GFXShaderType, GFXType } from './define';
|
||||
import { GFXDevice } from './device';
|
||||
import { IGFXAttribute } from './input-assembler';
|
||||
|
||||
export interface IGFXShaderMacro {
|
||||
macro: string;
|
||||
@@ -34,7 +35,6 @@ export class GFXUniformBlock {
|
||||
public shaderStages: GFXShaderType = GFXShaderType.NONE;
|
||||
public binding: number = -1;
|
||||
public name: string = '';
|
||||
// instance : string;
|
||||
public members: GFXUniform[] = [];
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ export class GFXUniformSampler {
|
||||
export interface IGFXShaderInfo {
|
||||
name: string;
|
||||
stages: IGFXShaderStage[];
|
||||
// bindings: GFXBinding[];
|
||||
|
||||
blocks?: GFXUniformBlock[];
|
||||
samplers?: GFXUniformSampler[];
|
||||
attributes: IGFXAttribute[];
|
||||
blocks: GFXUniformBlock[];
|
||||
samplers: GFXUniformSampler[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +81,18 @@ export abstract class GFXShader extends GFXObject {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get attributes () {
|
||||
return this._attributes;
|
||||
}
|
||||
|
||||
public get blocks () {
|
||||
return this._blocks;
|
||||
}
|
||||
|
||||
public get samplers () {
|
||||
return this._samplers;
|
||||
}
|
||||
|
||||
protected _device: GFXDevice;
|
||||
|
||||
protected _id: number;
|
||||
@@ -89,9 +101,9 @@ export abstract class GFXShader extends GFXObject {
|
||||
|
||||
protected _stages: IGFXShaderStage[] = [];
|
||||
|
||||
// protected _bindings: GFXBinding[] = [];
|
||||
protected _attributes: IGFXAttribute[] = [];
|
||||
|
||||
protected _blocks: GFXUniformBlock[] = []; // blocks are used for being compatible with single uniforms
|
||||
protected _blocks: GFXUniformBlock[] = [];
|
||||
|
||||
protected _samplers: GFXUniformSampler[] = [];
|
||||
|
||||
|
||||
@@ -16,14 +16,9 @@ export class WebGLGFXShader extends GFXShader {
|
||||
|
||||
this._name = info.name;
|
||||
this._stages = info.stages;
|
||||
|
||||
if (info.blocks !== undefined) {
|
||||
this._blocks = info.blocks;
|
||||
}
|
||||
|
||||
if (info.samplers !== undefined) {
|
||||
this._samplers = info.samplers;
|
||||
}
|
||||
this._attributes = info.attributes;
|
||||
this._blocks = info.blocks;
|
||||
this._samplers = info.samplers;
|
||||
|
||||
this._gpuShader = {
|
||||
name: info.name ? info.name : '',
|
||||
|
||||
@@ -16,14 +16,9 @@ export class WebGL2GFXShader extends GFXShader {
|
||||
|
||||
this._name = info.name;
|
||||
this._stages = info.stages;
|
||||
|
||||
if (info.blocks !== undefined) {
|
||||
this._blocks = info.blocks;
|
||||
}
|
||||
|
||||
if (info.samplers !== undefined) {
|
||||
this._samplers = info.samplers;
|
||||
}
|
||||
this._attributes = info.attributes;
|
||||
this._blocks = info.blocks;
|
||||
this._samplers = info.samplers;
|
||||
|
||||
this._gpuShader = {
|
||||
name: info.name ? info.name : '',
|
||||
|
||||
@@ -29,18 +29,7 @@ export class PipelineStateManager {
|
||||
const pipelineLayout = device.createPipelineLayout({
|
||||
layouts: [psoCreateInfo.bindingLayout]
|
||||
});
|
||||
const iaAttrs = this._inputState.attributes = ia.attributes;
|
||||
const shaderAttrs = psoCreateInfo.shaderInput.attributes;
|
||||
for (let i = 0; i < iaAttrs.length; i++) {
|
||||
const attr = iaAttrs[i]; let j = 0;
|
||||
for (; j < shaderAttrs.length; j++) {
|
||||
const shaderAttr = shaderAttrs[j];
|
||||
if (shaderAttr.name === attr.name) {
|
||||
attr.location = shaderAttr.location;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._inputState.attributes = ia.attributes;
|
||||
pso = device.createPipelineState({
|
||||
primitive: psoCreateInfo.primitive,
|
||||
shader: psoCreateInfo.shader,
|
||||
|
||||
@@ -190,7 +190,6 @@ export class Pass {
|
||||
protected _device: GFXDevice;
|
||||
protected _shader: GFXShader | null = null;
|
||||
protected _bindings: IGFXBinding[] = [];
|
||||
protected _shaderInput: GFXInputState | null = null;
|
||||
// for dynamic batching
|
||||
protected _batchedBuffer: BatchedBuffer | null = null;
|
||||
protected _instancedBuffer: InstancedBuffer | null = null;
|
||||
@@ -497,7 +496,7 @@ export class Pass {
|
||||
this._dynamicBatchingSync();
|
||||
const res = programLib.getGFXShader(this._device, this._programName, this._defines, pipeline);
|
||||
if (!res.shader) { console.warn(`create shader ${this._programName} failed`); return false; }
|
||||
this._shader = res.shader; this._bindings = res.bindings; this._shaderInput = res.input;
|
||||
this._shader = res.shader; this._bindings = res.bindings;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -509,7 +508,7 @@ export class Pass {
|
||||
* @param patches the marcos to be used in shader.
|
||||
*/
|
||||
public createPipelineStateCI (patches?: IMacroPatch[]): IPSOCreateInfo | null {
|
||||
if ((!this._shader || !this._bindings.length || !this._shaderInput) && !this.tryCompile()) {
|
||||
if ((!this._shader || !this._bindings.length) && !this.tryCompile()) {
|
||||
console.warn(`pass resources not complete, create PSO hash info failed`);
|
||||
return null;
|
||||
}
|
||||
@@ -552,7 +551,6 @@ export class Pass {
|
||||
dynamicStates: this._dynamicStates,
|
||||
bindingLayout,
|
||||
hash: this._hash,
|
||||
shaderInput: res && res.input || this._shaderInput!,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -679,7 +677,6 @@ export class Pass {
|
||||
// resources
|
||||
get shader () { return this._shader!; }
|
||||
get bindings () { return this._bindings; }
|
||||
get shaderInput () { return this._shaderInput!; }
|
||||
get dynamics () { return this._dynamics; }
|
||||
get batchedBuffer () { return this._batchedBuffer; }
|
||||
get instancedBuffer () { return this._instancedBuffer; }
|
||||
|
||||
@@ -177,7 +177,6 @@ function getShaderBindings (
|
||||
export interface IShaderResources {
|
||||
shader: GFXShader;
|
||||
bindings: IGFXBinding[];
|
||||
input: GFXInputState;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,18 +337,18 @@ class ProgramLib {
|
||||
const blocks: IBlockInfoRT[] = [];
|
||||
const samplers: ISamplerInfoRT[] = [];
|
||||
const bindings: IGFXBinding[] = [];
|
||||
const inputState = new GFXInputState();
|
||||
getShaderBindings(tmpl, defines, blocks, samplers, bindings, inputState.attributes);
|
||||
const attributes: IGFXAttribute[] = [];
|
||||
getShaderBindings(tmpl, defines, blocks, samplers, bindings, attributes);
|
||||
|
||||
const shader = device.createShader({
|
||||
name: getShaderInstanceName(name, macroArray),
|
||||
blocks, samplers,
|
||||
blocks, samplers, attributes,
|
||||
stages: [
|
||||
{ type: GFXShaderType.VERTEX, source: prefix + src.vert },
|
||||
{ type: GFXShaderType.FRAGMENT, source: prefix + src.frag },
|
||||
],
|
||||
});
|
||||
return this._cache[key] = { shader, bindings, input: inputState };
|
||||
return this._cache[key] = { shader, bindings };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ export class Model {
|
||||
this.updateLocalBindings(psoCreateInfos[i], subModelIndex);
|
||||
}
|
||||
|
||||
this.updateInstancedAttributeList(psoCreateInfos[0].shaderInput.attributes, subModel.passes[0]);
|
||||
this.updateInstancedAttributeList(psoCreateInfos[0].shader.attributes, subModel.passes[0]);
|
||||
}
|
||||
|
||||
public getMacroPatches (subModelIndex: number) : IMacroPatch[] | undefined {
|
||||
|
||||
@@ -8,9 +8,8 @@ import { RenderPriority } from '../../pipeline/define';
|
||||
import { IMacroPatch } from '../core/pass';
|
||||
import { GFXShader } from '../../gfx/shader';
|
||||
import { GFXDynamicState, GFXPrimitiveMode } from '../../gfx/define';
|
||||
import { GFXBlendState, GFXDepthStencilState, GFXRasterizerState, GFXInputState } from '../../gfx/pipeline-state';
|
||||
import { GFXPipelineLayout } from '../../gfx/pipeline-layout';
|
||||
import { GFXBindingLayout } from '../../gfx';
|
||||
import { GFXBlendState, GFXDepthStencilState, GFXRasterizerState } from '../../gfx/pipeline-state';
|
||||
import { GFXBindingLayout } from '../../gfx/binding-layout';
|
||||
import { legacyCC } from '../../global-exports';
|
||||
|
||||
export interface IPSOCreateInfo {
|
||||
@@ -21,7 +20,6 @@ export interface IPSOCreateInfo {
|
||||
blendState: GFXBlendState;
|
||||
dynamicStates: GFXDynamicState[];
|
||||
bindingLayout: GFXBindingLayout;
|
||||
shaderInput: GFXInputState;
|
||||
hash: number;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user