misc fixes for vulkan (#6883)

* misc fixes for vulkan

* render window accepts external renderpass
This commit is contained in:
Yun Hsiao Wu
2020-06-17 11:10:44 +08:00
committed by GitHub
parent fc73e6312c
commit dafb0ef102
15 changed files with 119 additions and 79 deletions
File diff suppressed because one or more lines are too long
+1 -7
View File
@@ -42,14 +42,8 @@ export function createMesh (geometry: IGeometry, out?: Mesh, options?: createMes
attr = _defAttrs[0];
}
// device NDC correction
const info = GFXFormatInfos[attr.format];
const ySign = legacyCC.director.root.device.projectionSignY;
for (let i = 1; i < positions.length; i += info.count) {
positions[i] *= ySign;
}
attributes.push(attr);
const info = GFXFormatInfos[attr.format];
vertCount = Math.max(vertCount, Math.floor(positions.length / info.count));
channels.push({ offset: stride, data: positions, attribute: attr });
stride += info.size;
+1 -1
View File
@@ -365,7 +365,7 @@ export class Material extends Asset {
const defs = passInfo.defines = this._defines.length > k ? this._defines[k] : {};
if (passInfo.switch && !defs[passInfo.switch]) { continue; }
passInfo.stateOverrides = this._states.length > k ? this._states[k] : {};
passInfo.idxInTech = k;
passInfo.idxInTech = passInfo.phase === 'forward-add' ? 0 : k;
const pass = new Pass(legacyCC.director.root);
pass.initialize(passInfo);
passes.push(pass);
+6
View File
@@ -41,12 +41,18 @@ export enum GFXFeature {
TEXTURE_FLOAT_LINEAR,
TEXTURE_HALF_FLOAT_LINEAR,
FORMAT_R11G11B10F,
FORMAT_D16,
FORMAT_D16S8,
FORMAT_D24,
FORMAT_D24S8,
FORMAT_D32F,
FORMAT_D32FS8,
FORMAT_ETC1,
FORMAT_ETC2,
FORMAT_DXT,
FORMAT_PVRTC,
FORMAT_ASTC,
FORMAT_RGB8,
MSAA,
ELEMENT_INDEX_UINT,
INSTANCED_ARRAYS,
+1
View File
@@ -27,6 +27,7 @@ export * from './framebuffer';
export * from './input-assembler';
export * from './pipeline-layout';
export * from './pipeline-state';
export * from './fence';
export * from './queue';
export * from './render-pass';
export * from './sampler';
+8 -3
View File
@@ -53,7 +53,7 @@ export interface IGFXSubPassInfo {
export interface IGFXRenderPassInfo {
colorAttachments: GFXColorAttachment[];
depthStencilAttachment: GFXDepthStencilAttachment;
depthStencilAttachment: GFXDepthStencilAttachment | null;
subPasses?: IGFXSubPassInfo[];
}
@@ -68,9 +68,15 @@ export abstract class GFXRenderPass extends GFXObject {
protected _colorInfos: GFXColorAttachment[] = [];
protected _depthStencilInfo: GFXDepthStencilAttachment | null = null;
protected _subPasses : IGFXSubPassInfo[] = [];
protected _hash: number = 0;
// protected _subPasses : GFXSubPassInfo[] = [];
get colorAttachments () { return this._colorInfos; }
get depthStencilAttachment () { return this._depthStencilInfo; }
get subPasses () { return this._subPasses; }
get hash () { return this._hash; }
constructor (device: GFXDevice) {
super(GFXObjectType.RENDER_PASS);
@@ -80,7 +86,6 @@ export abstract class GFXRenderPass extends GFXObject {
public abstract initialize (info: IGFXRenderPassInfo): boolean;
public abstract destroy (): void;
public get hash (): number { return this._hash; }
protected computeHash (): number {
let res = 'ca';
+4 -4
View File
@@ -103,11 +103,11 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGLRenderingConte
case GFXFormat.RGB9E5: return gl.UNSIGNED_BYTE;
case GFXFormat.D16: return gl.UNSIGNED_SHORT;
case GFXFormat.D16S8: return gl.UNSIGNED_SHORT;
case GFXFormat.D16S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; // not supported, fallback
case GFXFormat.D24: return gl.UNSIGNED_INT;
case GFXFormat.D24S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL;
case GFXFormat.D32F: return gl.FLOAT;
case GFXFormat.D32F_S8: return gl.FLOAT;
case GFXFormat.D32F: return gl.UNSIGNED_INT; // not supported, fallback
case GFXFormat.D32F_S8: return WebGLEXT.UNSIGNED_INT_24_8_WEBGL; // not supported, fallback
case GFXFormat.BC1: return gl.UNSIGNED_BYTE;
case GFXFormat.BC1_SRGB: return gl.UNSIGNED_BYTE;
@@ -810,7 +810,7 @@ export function WebGLCmdFuncCreateTexture (device: WebGLGFXDevice, gpuTexture: W
gl.bindRenderbuffer(gl.RENDERBUFFER, gpuTexture.glRenderbuffer);
device.stateCache.glRenderbuffer = gpuTexture.glRenderbuffer;
}
// Special treatment, refer to https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/renderbufferStorage
// The internal format here differs from texImage2D convension
if (gpuTexture.glInternelFmt === gl.DEPTH_COMPONENT) {
gpuTexture.glInternelFmt = gl.DEPTH_COMPONENT16;
}
+4 -2
View File
@@ -354,7 +354,11 @@ export class WebGLGFXDevice extends GFXDevice {
this._features[GFXFeature.TEXTURE_HALF_FLOAT_LINEAR] = true;
}
this._features[GFXFeature.FORMAT_RGB8] = true;
if (this._WEBGL_depth_texture) {
this._features[GFXFeature.FORMAT_D16] = true;
this._features[GFXFeature.FORMAT_D24] = true;
this._features[GFXFeature.FORMAT_D24S8] = true;
}
@@ -393,8 +397,6 @@ export class WebGLGFXDevice extends GFXDevice {
compressedFormat += 'astc ';
}
this._features[GFXFeature.MSAA] = false;
if (this._OES_vertex_array_object) {
if (RUNTIME_BASED) {
// @ts-ignore
@@ -14,6 +14,9 @@ export class WebGLGFXRenderPass extends GFXRenderPass {
this._colorInfos = info.colorAttachments;
this._depthStencilInfo = info.depthStencilAttachment;
if (info.subPasses) {
this._subPasses = info.subPasses;
}
this._gpuRenderPass = {
colorAttachments: this._colorInfos,
+1 -1
View File
@@ -136,7 +136,7 @@ export function GFXFormatToWebGLType (format: GFXFormat, gl: WebGL2RenderingCont
case GFXFormat.RGB9E5: return gl.FLOAT;
case GFXFormat.D16: return gl.UNSIGNED_SHORT;
case GFXFormat.D16S8: return gl.UNSIGNED_SHORT;
case GFXFormat.D16S8: return gl.UNSIGNED_INT_24_8; // not supported, fallback
case GFXFormat.D24: return gl.UNSIGNED_INT;
case GFXFormat.D24S8: return gl.UNSIGNED_INT_24_8;
case GFXFormat.D32F: return gl.FLOAT;
+5
View File
@@ -251,7 +251,12 @@ export class WebGL2GFXDevice extends GFXDevice {
this._features[GFXFeature.TEXTURE_FLOAT] = true;
this._features[GFXFeature.TEXTURE_HALF_FLOAT] = true;
this._features[GFXFeature.FORMAT_R11G11B10F] = true;
this._features[GFXFeature.FORMAT_RGB8] = true;
this._features[GFXFeature.FORMAT_D16] = true;
this._features[GFXFeature.FORMAT_D24] = true;
this._features[GFXFeature.FORMAT_D32F] = true;
this._features[GFXFeature.FORMAT_D24S8] = true;
this._features[GFXFeature.FORMAT_D32FS8] = true;
this._features[GFXFeature.MSAA] = true;
this._features[GFXFeature.ELEMENT_INDEX_UINT] = true;
this._features[GFXFeature.INSTANCED_ARRAYS] = true;
@@ -14,6 +14,9 @@ export class WebGL2GFXRenderPass extends GFXRenderPass {
this._colorInfos = info.colorAttachments;
this._depthStencilInfo = info.depthStencilAttachment;
if (info.subPasses) {
this._subPasses = info.subPasses;
}
this._gpuRenderPass = {
colorAttachments: this._colorInfos,
+27 -17
View File
@@ -15,6 +15,7 @@ export interface IRenderWindowInfo {
height: number;
renderPassInfo: IGFXRenderPassInfo;
isOffscreen?: boolean;
renderPass?: GFXRenderPass; // will use this reference instead if specified
}
export class RenderWindow {
@@ -120,24 +121,33 @@ export class RenderWindow {
this._nativeWidth = this._width;
this._nativeHeight = this._height;
for (let i = 0; i < info.renderPassInfo.colorAttachments.length; i++) {
const attachment = info.renderPassInfo.colorAttachments[i];
if (attachment.format === GFXFormat.UNKNOWN) {
attachment.format = this._root.device.colorFormat;
}
}
if (info.renderPassInfo.depthStencilAttachment) {
const attachment = info.renderPassInfo.depthStencilAttachment;
if (attachment.format === GFXFormat.UNKNOWN) {
attachment.format = this._root.device.depthStencilFormat;
}
}
this._renderPass = this._root.device.createRenderPass(info.renderPassInfo);
let colorAttachments = info.renderPassInfo.colorAttachments;
let depthStencilAttachment = info.renderPassInfo.depthStencilAttachment;
let colorTexturesToCreate = info.renderPassInfo.colorAttachments.length;
if (info.renderPass) {
this._renderPass = info.renderPass;
colorAttachments = info.renderPass.colorAttachments;
depthStencilAttachment = info.renderPass.depthStencilAttachment;
} else {
for (let i = 0; i < colorAttachments.length; i++) {
const attachment = colorAttachments[i];
if (attachment.format === GFXFormat.UNKNOWN) {
attachment.format = this._root.device.colorFormat;
}
}
if (depthStencilAttachment) {
const attachment = depthStencilAttachment;
if (attachment.format === GFXFormat.UNKNOWN) {
attachment.format = this._root.device.depthStencilFormat;
}
}
this._renderPass = this._root.device.createRenderPass(info.renderPassInfo);
}
let colorTexturesToCreate = colorAttachments.length;
if (!this._isOffscreen) { colorTexturesToCreate--; } // -1 for swapchain image
for (let i = 0; i < colorTexturesToCreate; i++) {
const format = info.renderPassInfo.colorAttachments[i].format;
const format = colorAttachments[i].format;
const colorTex = this._root.device.createTexture({
type: GFXTextureType.TEX2D,
usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED,
@@ -151,8 +161,8 @@ export class RenderWindow {
});
this._colorTexs.push(colorTex);
}
if (this._isOffscreen && info.renderPassInfo.depthStencilAttachment) {
const format = info.renderPassInfo.depthStencilAttachment.format;
if (this._isOffscreen && depthStencilAttachment) {
const format = depthStencilAttachment.format;
this._depthStencilTex = this._root.device.createTexture({
type: GFXTextureType.TEX2D,
usage: GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT,
+12 -3
View File
@@ -36,9 +36,7 @@ import { GFXBuffer, IGFXBufferInfo } from '../../gfx/buffer';
import { GFXBindingType, GFXBufferUsageBit, GFXDynamicState,
GFXGetTypeSize, GFXMemoryUsageBit, GFXPrimitiveMode, GFXType } from '../../gfx/define';
import { GFXFeature, GFXDevice } from '../../gfx/device';
import { GFXBlendState, GFXBlendTarget, GFXDepthStencilState,
GFXRasterizerState,
GFXInputState} from '../../gfx/pipeline-state';
import { GFXBlendState, GFXBlendTarget, GFXDepthStencilState, GFXRasterizerState } from '../../gfx/pipeline-state';
import { GFXSampler } from '../../gfx/sampler';
import { GFXShader } from '../../gfx/shader';
import { GFXTexture } from '../../gfx/texture';
@@ -99,6 +97,17 @@ const _blInfo: IGFXBindingLayoutInfo = {
bindings: null!,
};
// tslint:disable: no-shadowed-variable
export namespace Pass {
export type getBindingTypeFromHandle = typeof getBindingTypeFromHandle;
export type getTypeFromHandle = typeof getTypeFromHandle;
export type getBindingFromHandle = typeof getBindingFromHandle;
export type fillinPipelineInfo = typeof Pass.fillinPipelineInfo;
export type getPassHash = typeof Pass.getPassHash;
export type getOffsetFromHandle = typeof getOffsetFromHandle;
}
// tslint:enable: no-shadowed-variable
/**
* @zh
* 渲染 pass,储存实际描述绘制过程的各项资源。
+6 -1
View File
@@ -300,6 +300,12 @@ export class Profiler {
}
}
// device NDC correction
const ySign = this._device!.projectionSignY;
for (let i = 1; i < vertexPos.length; i += 3) {
vertexPos[i] *= ySign;
}
const modelCom = managerNode.addComponent('cc.ModelComponent') as ModelComponent;
modelCom.mesh = createMesh({
positions: vertexPos,
@@ -307,7 +313,6 @@ export class Profiler {
colors: vertexUV, // pack all the necessary info in a_color: { x: u, y: v, z: id.x, w: id.y }
});
const ySign = this._device!.projectionSignY;
const _material = new Material();
_material.initialize({ effectName: 'util/profiler' });
_material.setProperty('offset', new Vec4(-0.9, -0.9 * ySign, this._eachNumWidth, 0));