Skip to content

Initial clustered lights implementation (tiled clustering only) #16866

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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions packages/dev/core/src/Buffers/storageBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class StorageBuffer {
return this._buffer;
}

public clear(byteOffset?: number, byteLength?: number): void {
this._engine.clearStorageBuffer(this._buffer, byteOffset, byteLength);
}

/**
* Updates the storage buffer
* @param data the data used to update the storage buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ export class WebGPUShaderProcessorWGSL extends WebGPUShaderProcessor {
}

public finalizeShaders(vertexCode: string, fragmentCode: string): { vertexCode: string; fragmentCode: string } {
const enabledExtensions: string[] = [];
// TODO: conditionally enable if needed AND supported
const enabledExtensions: string[] = ["subgroups"];

const fragCoordCode =
fragmentCode.indexOf("fragmentInputs.position") >= 0 && !this.pureMode
Expand Down
4 changes: 4 additions & 0 deletions packages/dev/core/src/Engines/engineCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface EngineCapabilities {
maxVertexUniformVectors: number;
/** Maximum number of uniforms per fragment shader */
maxFragmentUniformVectors: number;
/** The number of bits that can be accurately represented in shader floats */
shaderFloatPrecision: number;
/** Defines if standard derivatives (dx/dy) are supported */
standardDerivatives: boolean;
/** Defines if s3tc texture compression is supported */
Expand Down Expand Up @@ -80,6 +82,8 @@ export interface EngineCapabilities {
depthTextureExtension: boolean;
/** Defines if float color buffer are supported */
colorBufferFloat: boolean;
/** Defines if float color blending is supported */
blendFloat: boolean;
/** Defines if half float color buffer are supported */
colorBufferHalfFloat?: boolean;
/** Gets disjoint timer query extension (null if not supported) */
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/Engines/nativeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export class NativeEngine extends Engine {
maxDrawBuffers: 8,
maxFragmentUniformVectors: 16,
maxVertexUniformVectors: 16,
shaderFloatPrecision: 23, // TODO: is this correct?
standardDerivatives: true,
astc: null,
pvrtc: null,
Expand All @@ -297,6 +298,7 @@ export class NativeEngine extends Engine {
fragmentDepthSupported: false,
highPrecisionShaderSupported: true,
colorBufferFloat: false,
blendFloat: false,
supportFloatTexturesResolve: false,
rg11b10ufColorRenderable: false,
textureFloat: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/Engines/nullEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class NullEngine extends Engine {
maxVaryingVectors: 16,
maxFragmentUniformVectors: 16,
maxVertexUniformVectors: 16,
shaderFloatPrecision: 10, // Minimum precision for mediump floats WebGL 1
standardDerivatives: false,
astc: null,
pvrtc: null,
Expand All @@ -144,6 +145,7 @@ export class NullEngine extends Engine {
fragmentDepthSupported: false,
highPrecisionShaderSupported: true,
colorBufferFloat: false,
blendFloat: false,
supportFloatTexturesResolve: false,
rg11b10ufColorRenderable: false,
textureFloat: false,
Expand Down
15 changes: 15 additions & 0 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export class ThinEngine extends AbstractEngine {
maxVaryingVectors: this._gl.getParameter(this._gl.MAX_VARYING_VECTORS),
maxFragmentUniformVectors: this._gl.getParameter(this._gl.MAX_FRAGMENT_UNIFORM_VECTORS),
maxVertexUniformVectors: this._gl.getParameter(this._gl.MAX_VERTEX_UNIFORM_VECTORS),
shaderFloatPrecision: 0,
parallelShaderCompile: this._gl.getExtension("KHR_parallel_shader_compile") || undefined,
standardDerivatives: this._webGLVersion > 1 || this._gl.getExtension("OES_standard_derivatives") !== null,
maxAnisotropy: 1,
Expand Down Expand Up @@ -533,6 +534,7 @@ export class ThinEngine extends AbstractEngine {
drawBuffersExtension: false,
maxMSAASamples: 1,
colorBufferFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_float")),
blendFloat: this._gl.getExtension("EXT_float_blend") !== null,
supportFloatTexturesResolve: false,
rg11b10ufColorRenderable: false,
colorBufferHalfFloat: !!(this._webGLVersion > 1 && this._gl.getExtension("EXT_color_buffer_half_float")),
Expand Down Expand Up @@ -734,6 +736,19 @@ export class ThinEngine extends AbstractEngine {

if (vertexhighp && fragmenthighp) {
this._caps.highPrecisionShaderSupported = vertexhighp.precision !== 0 && fragmenthighp.precision !== 0;
this._caps.shaderFloatPrecision = Math.min(vertexhighp.precision, fragmenthighp.precision);
}
// This will check both the capability and the `useHighPrecisionFloats` option
if (!this._shouldUseHighPrecisionShader) {
const vertexmedp = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.MEDIUM_FLOAT);
const fragmentmedp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.MEDIUM_FLOAT);
if (vertexmedp && fragmentmedp) {
this._caps.shaderFloatPrecision = Math.min(vertexmedp.precision, fragmentmedp.precision);
}
}
if (this._caps.shaderFloatPrecision < 10) {
// WebGL spec requires mediump precision to atleast be 10
this._caps.shaderFloatPrecision = 10;
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
maxVaryingVectors: this._deviceLimits.maxInterStageShaderVariables,
maxFragmentUniformVectors: Math.floor(this._deviceLimits.maxUniformBufferBindingSize / 4),
maxVertexUniformVectors: Math.floor(this._deviceLimits.maxUniformBufferBindingSize / 4),
shaderFloatPrecision: 23, // WGSL always uses IEEE-754 binary32 floats (which have 23 bits of significand)
standardDerivatives: true,
astc: (this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.TextureCompressionASTC) >= 0 ? true : undefined) as any,
s3tc: (this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.TextureCompressionBC) >= 0 ? true : undefined) as any,
Expand All @@ -869,6 +870,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
fragmentDepthSupported: true,
highPrecisionShaderSupported: true,
colorBufferFloat: true,
blendFloat: this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.Float32Blendable) >= 0,
supportFloatTexturesResolve: false, // See https://github.com/gpuweb/gpuweb/issues/3844
rg11b10ufColorRenderable: this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.RG11B10UFloatRenderable) >= 0,
textureFloat: true,
Expand Down Expand Up @@ -3901,6 +3903,10 @@ export class WebGPUEngine extends ThinWebGPUEngine {
return this._createBuffer(data, creationFlags | Constants.BUFFER_CREATIONFLAG_STORAGE, label);
}

public clearStorageBuffer(storageBuffer: DataBuffer, byteOffset?: number, byteLength?: number): void {
this._renderEncoder.clearBuffer(storageBuffer.underlyingResource, byteOffset, byteLength);
}

/**
* Updates a storage buffer
* @param buffer the storage buffer to update
Expand Down
Loading
Loading