Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPU: more changes and fixes for stencil support #12452

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ WebGPUEngine.prototype._createDepthStencilTexture = function (size: TextureSize,
comparisonFunction: 0,
generateStencil: false,
samples: 1,
depthTextureFormat: Constants.TEXTUREFORMAT_DEPTH32_FLOAT,
depthTextureFormat: options.generateStencil ? Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 : Constants.TEXTUREFORMAT_DEPTH32_FLOAT,
...options,
};

internalTexture.format = internalOptions.generateStencil ? Constants.TEXTUREFORMAT_DEPTH24_STENCIL8 : internalOptions.depthTextureFormat;
internalTexture.format = internalOptions.depthTextureFormat;

this._setupDepthStencilTexture(
internalTexture,
Expand Down
19 changes: 17 additions & 2 deletions packages/dev/core/src/Engines/WebGPU/webgpuTextureHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ export class WebGPUTextureHelper {
return WebGPUConstants.TextureFormat.Depth24PlusStencil8;
case Constants.TEXTUREFORMAT_DEPTH32_FLOAT:
return WebGPUConstants.TextureFormat.Depth32Float;
case Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8:
return WebGPUConstants.TextureFormat.Depth24UnormStencil8;
case Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8:
return WebGPUConstants.TextureFormat.Depth32FloatStencil8;

case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:
return useSRGBBuffer ? WebGPUConstants.TextureFormat.BC7RGBAUnormSRGB : WebGPUConstants.TextureFormat.BC7RGBAUnorm;
Expand Down Expand Up @@ -991,6 +995,17 @@ export class WebGPUTextureHelper {
return false;
}

public static HasDepthAndStencilAspects(format: GPUTextureFormat): boolean {
switch (format) {
case WebGPUConstants.TextureFormat.Depth24UnormStencil8:
case WebGPUConstants.TextureFormat.Depth32FloatStencil8:
case WebGPUConstants.TextureFormat.Depth24PlusStencil8:
return true;
}

return false;
}

public invertYPreMultiplyAlpha(
gpuOrHdwTexture: GPUTexture | WebGPUHardwareTexture,
width: number,
Expand Down Expand Up @@ -1478,7 +1493,7 @@ export class WebGPUTextureHelper {
baseArrayLayer: 0,
baseMipLevel: 0,
arrayLayerCount: 6,
aspect: WebGPUConstants.TextureAspect.All,
aspect: WebGPUTextureHelper.HasDepthAndStencilAspects(gpuTextureWrapper.format) ? WebGPUConstants.TextureAspect.DepthOnly : WebGPUConstants.TextureAspect.All,
},
isStorageTexture
);
Expand Down Expand Up @@ -1510,7 +1525,7 @@ export class WebGPUTextureHelper {
baseArrayLayer: 0,
baseMipLevel: 0,
arrayLayerCount: texture.is3D ? 1 : layerCount,
aspect: WebGPUConstants.TextureAspect.All,
aspect: WebGPUTextureHelper.HasDepthAndStencilAspects(gpuTextureWrapper.format) ? WebGPUConstants.TextureAspect.DepthOnly : WebGPUConstants.TextureAspect.All,
},
isStorageTexture
);
Expand Down
4 changes: 4 additions & 0 deletions packages/dev/core/src/Engines/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export class Constants {
public static readonly TEXTUREFORMAT_DEPTH16 = 15;
/** Depth 24 bits */
public static readonly TEXTUREFORMAT_DEPTH24 = 16;
/** Depth 24 bits unorm + Stencil 8 bits */
public static readonly TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 = 17;
/** Depth 32 bits float + Stencil 8 bits */
public static readonly TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8 = 18;

/** Compressed BC7 */
public static readonly TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM = 36492;
Expand Down
5 changes: 3 additions & 2 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,7 @@ export class WebGPUEngine extends Engine {

const depthTextureView = gpuDepthStencilTexture?.createView(this._rttRenderPassWrapper.depthAttachmentViewDescriptor!);
const depthMSAATextureView = gpuDepthStencilMSAATexture?.createView(this._rttRenderPassWrapper.depthAttachmentViewDescriptor!);
const depthTextureHasStencil = gpuDepthStencilWrapper ? WebGPUTextureHelper.HasStencilAspect(gpuDepthStencilWrapper.format) : false;

const colorAttachments: GPURenderPassColorAttachment[] = [];

Expand Down Expand Up @@ -2788,12 +2789,12 @@ export class WebGPUEngine extends Engine {
depthLoadOp: mustClearDepth ? WebGPUConstants.LoadOp.Clear : WebGPUConstants.LoadOp.Load,
depthStoreOp: WebGPUConstants.StoreOp.Store,
stencilClearValue: rtWrapper._depthStencilTextureWithStencil && mustClearStencil ? this._clearStencilValue : undefined,
stencilLoadOp: !this.isStencilEnable
stencilLoadOp: !depthTextureHasStencil
? undefined
: rtWrapper._depthStencilTextureWithStencil && mustClearStencil
? WebGPUConstants.LoadOp.Clear
: WebGPUConstants.LoadOp.Load,
stencilStoreOp: !this.isStencilEnable ? undefined : WebGPUConstants.StoreOp.Store,
stencilStoreOp: !depthTextureHasStencil ? undefined : WebGPUConstants.StoreOp.Store,
}
: undefined,
occlusionQuerySet: this._occlusionQuery?.hasQueries ? this._occlusionQuery.querySet : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const textureFormat = [
{ label: "Depth32 float", normalizable: 0, hideType: true, value: Constants.TEXTUREFORMAT_DEPTH32_FLOAT },
{ label: "Depth16", normalizable: 0, value: Constants.TEXTUREFORMAT_DEPTH16 },
{ label: "Depth24", normalizable: 0, value: Constants.TEXTUREFORMAT_DEPTH24 },
{ label: "Depth24Unorm/Stencil8", normalizable: 0, hideType: true, value: Constants.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8 },
{ label: "Depth32Float/Stencil8", normalizable: 0, hideType: true, value: Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8 },
{ label: "RGBA BPTC UNorm", normalizable: 0, compressed: true, value: Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM },
{ label: "RGB BPTC UFloat", normalizable: 0, compressed: true, value: Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT },
{ label: "RGB BPTC SFloat", normalizable: 0, compressed: true, value: Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT },
Expand Down