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

Fix a number of bugs in WebGPU #9788

Merged
merged 5 commits into from Jan 13, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Engines/WebGPU/webgpuTextureHelper.ts
Expand Up @@ -733,6 +733,11 @@ export class WebGPUTextureHelper {
public createTexture(imageBitmap: ImageBitmap | { width: number, height: number, layers: number }, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, is3D = false, format: GPUTextureFormat = WebGPUConstants.TextureFormat.RGBA8Unorm,
sampleCount = 1, commandEncoder?: GPUCommandEncoder, usage = -1): GPUTexture
{
if (sampleCount > 1) {
// TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
sampleCount = 4;
}

const layerCount = (imageBitmap as any).layers || 1;
let textureSize = {
width: imageBitmap.width,
Expand Down Expand Up @@ -767,6 +772,11 @@ export class WebGPUTextureHelper {
public createCubeTexture(imageBitmaps: ImageBitmap[] | { width: number, height: number }, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, format: GPUTextureFormat = WebGPUConstants.TextureFormat.RGBA8Unorm,
sampleCount = 1, commandEncoder?: GPUCommandEncoder, usage = -1): GPUTexture
{
if (sampleCount > 1) {
// TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
sampleCount = 4;
}

const width = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].width : imageBitmaps.width;
const height = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].height : imageBitmaps.height;

Expand Down
3 changes: 3 additions & 0 deletions src/Engines/engineFeatures.ts
Expand Up @@ -48,6 +48,9 @@ export interface EngineFeatures {
/** Indicates that synchronous texture reading is supported */
supportSyncTextureRead: boolean;

/** Indicates that y should be inverted when dealing with bitmaps (notably in environment tools) */
needsInvertingBitmap: boolean;

/** @hidden */
_collectUbosUpdatedInFrame: boolean;
}
1 change: 1 addition & 0 deletions src/Engines/nativeEngine.ts
Expand Up @@ -816,6 +816,7 @@ export class NativeEngine extends Engine {
supportExtendedTextureFormats: false,
supportSwitchCaseInShader: false,
supportSyncTextureRead: false,
needsInvertingBitmap: true,
_collectUbosUpdatedInFrame: false,
};

Expand Down
1 change: 1 addition & 0 deletions src/Engines/nullEngine.ts
Expand Up @@ -162,6 +162,7 @@ export class NullEngine extends Engine {
supportExtendedTextureFormats: false,
supportSwitchCaseInShader: false,
supportSyncTextureRead: false,
needsInvertingBitmap: false,
_collectUbosUpdatedInFrame: false,
};

Expand Down
1 change: 1 addition & 0 deletions src/Engines/thinEngine.ts
Expand Up @@ -1078,6 +1078,7 @@ export class ThinEngine {
supportExtendedTextureFormats: this._webGLVersion !== 1,
supportSwitchCaseInShader: this._webGLVersion !== 1,
supportSyncTextureRead: true,
needsInvertingBitmap: true,
_collectUbosUpdatedInFrame: false,
};
}
Expand Down
11 changes: 11 additions & 0 deletions src/Engines/webgpuEngine.ts
Expand Up @@ -562,6 +562,7 @@ export class WebGPUEngine extends Engine {
supportExtendedTextureFormats: true,
supportSwitchCaseInShader: true,
supportSyncTextureRead: false,
needsInvertingBitmap: false,
_collectUbosUpdatedInFrame: true,
};
}
Expand Down Expand Up @@ -2632,6 +2633,11 @@ export class WebGPUEngine extends Engine {

samples = Math.min(samples, this.getCaps().maxMSAASamples);

if (samples > 1) {
// TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
samples = 4;
}

this._textureHelper.createMSAATexture(texture, samples);

if (texture._depthStencilTexture) {
Expand All @@ -2657,6 +2663,11 @@ export class WebGPUEngine extends Engine {

samples = Math.min(samples, this.getCaps().maxMSAASamples);

if (samples > 1) {
// TODO WEBGPU for the time being, Chrome only accepts values of 1 or 4
samples = 4;
}

// Note that the last texture of textures is the depth texture (if the depth texture has been generated by the MRT class) and so the MSAA texture
// will be recreated for this texture too. As a consequence, there's no need to explicitly recreate the MSAA texture for textures[0]._depthStencilTexture
for (let i = 0; i < textures.length; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/Misc/environmentTextureTools.ts
Expand Up @@ -375,7 +375,7 @@ export class EnvironmentTextureTools {
// Uncompress the data to a RTT
rgbdPostProcess!.onApply = (effect) => {
effect._bindTexture("textureSampler", tempTexture);
effect.setFloat2("scale", 1, (image instanceof ImageBitmap) ? -1 : 1);
effect.setFloat2("scale", 1, engine._features.needsInvertingBitmap && (image instanceof ImageBitmap) ? -1 : 1);
};

if (!engine.scenes.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/Shaders/background.vertex.fx
Expand Up @@ -40,7 +40,7 @@ varying vec2 vDiffuseUV;
#include<clipPlaneVertexDeclaration>

#include<fogVertexDeclaration>
#include<__decl__lightFragment>[0..maxSimultaneousLights]
#include<__decl__lightVxFragment>[0..maxSimultaneousLights]

#ifdef REFLECTIONMAP_SKYBOX
varying vec3 vPositionUVW;
Expand Down