@null3d/engine 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wasm/single/null3d.js +4 -4
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +4 -4
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/reference/engine.md +2 -1
- package/docs/cli/null3d.md +60 -4
- package/docs/concepts/backends.md +4 -0
- package/docs/concepts/quality-presets.md +2 -0
- package/docs/errors/E1308.md +31 -0
- package/docs/errors/E1404.md +5 -1
- package/docs/errors/index.md +1 -0
- package/docs/getting-started/cdn.md +1 -1
- package/docs/getting-started/first-scene.md +3 -1
- package/docs/getting-started/hosting.md +13 -3
- package/docs/getting-started/install.md +21 -1
- package/docs/getting-started/project-structure.md +1 -1
- package/docs/guides/agents.md +12 -9
- package/docs/guides/assets-pipeline.md +77 -6
- package/docs/guides/content-pages.md +33 -0
- package/docs/guides/debugging.md +2 -0
- package/docs/guides/deploying.md +5 -1
- package/docs/guides/deterministic-simulation.md +5 -2
- package/docs/guides/loading-screens.md +4 -0
- package/docs/guides/performance.md +2 -0
- package/docs/guides/start-time.md +8 -0
- package/docs/guides/testing.md +20 -0
- package/docs/pages.md +1 -1
- package/docs/porting/verification.md +1 -1
- package/lib/errors/codes.js +11 -0
- package/lib/errors/engine-error.js +1 -1
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +2 -1
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +6 -0
- package/lib/gpu/device-shaders.d.ts +5 -0
- package/lib/gpu/device-shaders.js +10 -1
- package/lib/gpu/variants.d.ts +25 -0
- package/lib/gpu/variants.js +75 -5
- package/lib/gpu/webgl2/backend.d.ts +22 -3
- package/lib/gpu/webgl2/backend.js +108 -22
- package/lib/gpu/webgl2/programs.d.ts +5 -0
- package/lib/gpu/webgl2/programs.js +25 -2
- package/lib/gpu/webgpu/backend.d.ts +34 -1
- package/lib/gpu/webgpu/backend.js +173 -27
- package/lib/gpu/webgpu/pipelines.d.ts +2 -2
- package/lib/gpu/webgpu/pipelines.js +15 -15
- package/lib/page/engine.d.ts +15 -2
- package/lib/page/engine.js +124 -9
- package/lib/page/permutation-recording.d.ts +5 -3
- package/lib/page/permutation-recording.js +13 -7
- package/lib/quality/chooser.d.ts +2 -0
- package/lib/quality/chooser.js +4 -0
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/permutation-words.d.ts +6 -0
- package/lib/shared/permutation-words.js +6 -0
- package/lib/shared/tier.d.ts +9 -0
- package/lib/shared/tier.js +4 -1
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/workers/protocol.d.ts +29 -0
- package/lib/workers/render-worker.js +6 -3
- package/lib/workers/sketch-worker.js +6 -3
- package/package.json +1 -1
|
@@ -21,16 +21,17 @@
|
|
|
21
21
|
import * as G from '../../generated/gpu.js';
|
|
22
22
|
import { DEV } from '../../shared/dev.js';
|
|
23
23
|
import { ImageTable } from '../../shared/images.js';
|
|
24
|
+
import { ShaderLoadError } from '../device-shaders.js';
|
|
24
25
|
import { EarlyBuilds, PipelineListing } from '../early-builds.js';
|
|
25
26
|
import { JoinedBuilds, joinedReady } from '../effect-join.js';
|
|
26
27
|
import { CLOUD_FIELD_WORD, CLOUD_STEPS_WORD, LAYER_WORD, LIGHT_BUFFER_WORD, } from '../environment-words.js';
|
|
27
28
|
import { floatOfBits } from '../float-bits.js';
|
|
28
29
|
import { GpuMemory, textureBytes } from '../memory.js';
|
|
29
30
|
import { pipelineName } from '../pipeline-name.js';
|
|
30
|
-
import { variantFor } from '../variants.js';
|
|
31
|
+
import { MissingVariantError, reportMissingVariant, reportUnavailableShader, variantFor, } from '../variants.js';
|
|
31
32
|
import { forEachFallbackAttribute, forEachVertexAttribute, isNormalized, vertexStride, } from '../vertex-format.js';
|
|
32
33
|
import { setDepthMode } from './depth.js';
|
|
33
|
-
import { buildPermutation, createProgram, customTemplate, engineTemplates, LinkFailure, linkLogs, metalFault, mipmapTemplate, prepareProgram, programHost, relink, slotOf, UPLOAD_UNIT, } from './programs.js';
|
|
34
|
+
import { buildPermutation, createProgram, customTemplate, engineTemplates, LinkFailure, linkLogs, metalFault, mipmapTemplate, prepareProgram, programHost, refusedProgram, relink, slotOf, UPLOAD_UNIT, } from './programs.js';
|
|
34
35
|
/** The unit that the mip level shader samples: its source texture's group 0, binding 0. */
|
|
35
36
|
const MIP_UNIT = 0;
|
|
36
37
|
/** The key of the mip level program among the programs of pipelines. */
|
|
@@ -303,6 +304,8 @@ export class WebGL2Backend {
|
|
|
303
304
|
pipelines = [];
|
|
304
305
|
/** The programs of the templates and permutations in use, which their pipelines share. */
|
|
305
306
|
programs = new Map();
|
|
307
|
+
/** The spare programs whose shader variant the loaded set lacks, by key. */
|
|
308
|
+
spareMissing = new Set();
|
|
306
309
|
templates;
|
|
307
310
|
/** The template of the program that draws mip levels. */
|
|
308
311
|
mipTemplate;
|
|
@@ -804,10 +807,28 @@ export class WebGL2Backend {
|
|
|
804
807
|
this.early = undefined;
|
|
805
808
|
return this.listing.take();
|
|
806
809
|
}
|
|
807
|
-
/**
|
|
810
|
+
/**
|
|
811
|
+
* Creates each parked pipeline whose custom material's shader has arrived. A pipeline whose
|
|
812
|
+
* shader file failed to load is dropped, with a drawer that draws nothing, so no frame waits
|
|
813
|
+
* for it.
|
|
814
|
+
*/
|
|
808
815
|
unpark() {
|
|
809
816
|
for (const [id, operands] of this.parked) {
|
|
810
|
-
|
|
817
|
+
const template = operands[1];
|
|
818
|
+
const permutation = operands[2];
|
|
819
|
+
let ready;
|
|
820
|
+
try {
|
|
821
|
+
ready = this.templateReady(template, permutation);
|
|
822
|
+
}
|
|
823
|
+
catch (error) {
|
|
824
|
+
if (!(error instanceof ShaderLoadError))
|
|
825
|
+
throw error;
|
|
826
|
+
this.parked.delete(id);
|
|
827
|
+
this.counts.pipelines--;
|
|
828
|
+
this.installPipeline(operands, 0, this.unavailableProgram(template, permutation, error));
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if (!ready)
|
|
811
832
|
continue;
|
|
812
833
|
this.parked.delete(id);
|
|
813
834
|
this.counts.pipelines--;
|
|
@@ -832,19 +853,32 @@ export class WebGL2Backend {
|
|
|
832
853
|
*/
|
|
833
854
|
createPipeline(words, a, background) {
|
|
834
855
|
const template = words[a + 1];
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
856
|
+
const permutation = words[a + 2];
|
|
857
|
+
try {
|
|
858
|
+
if (!this.templateReady(template, permutation)) {
|
|
859
|
+
// The command's header, before its operands, gives its length in words.
|
|
860
|
+
this.parked.set(words[a], words.slice(a, a - 1 + (words[a - 1] >>> 8)));
|
|
861
|
+
this.counts.pipelines++;
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
this.installPipeline(words, a, this.programOf(template, permutation, background));
|
|
841
865
|
}
|
|
866
|
+
catch (error) {
|
|
867
|
+
if (!(error instanceof ShaderLoadError))
|
|
868
|
+
throw error;
|
|
869
|
+
this.installPipeline(words, a, this.unavailableProgram(template, permutation, error));
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
/** Stores the pipeline of a create command that draws with `program`. */
|
|
873
|
+
installPipeline(words, a, program) {
|
|
874
|
+
const template = words[a + 1];
|
|
875
|
+
const flags = words[a + 6];
|
|
842
876
|
const depth = words[a + 4] !== G.FORMAT_NONE;
|
|
843
877
|
// The list's bias is in reversed depth. Standard depth stores the near plane as 0, so a bias
|
|
844
878
|
// toward the camera turns negative there.
|
|
845
879
|
const sign = this.depth.standard ? -1 : 1;
|
|
846
880
|
this.pipelines[words[a]] = {
|
|
847
|
-
program
|
|
881
|
+
program,
|
|
848
882
|
cull: this.cullOf(flags),
|
|
849
883
|
depth,
|
|
850
884
|
depthWrite: depth && (flags & (G.STATE_NO_DEPTH_WRITE | G.STATE_NO_DEPTH_TEST)) === 0,
|
|
@@ -856,10 +890,20 @@ export class WebGL2Backend {
|
|
|
856
890
|
offsetFactor: sign * floatOfBits(words[a + 9]),
|
|
857
891
|
vertexFormat: words[a + 7],
|
|
858
892
|
mode: flags & G.STATE_LINE_LIST ? this.gl.LINES : this.gl.TRIANGLES,
|
|
859
|
-
vertices: this.
|
|
893
|
+
vertices: this.templates[template]?.vertices,
|
|
860
894
|
};
|
|
861
895
|
this.counts.pipelines++;
|
|
862
896
|
}
|
|
897
|
+
/**
|
|
898
|
+
* A stand-in for a pipeline whose shader file did not load. Its draws draw nothing, as a
|
|
899
|
+
* pipeline that the driver refused twice does, and the engine warns once.
|
|
900
|
+
*/
|
|
901
|
+
unavailableProgram(template, permutation, error) {
|
|
902
|
+
reportUnavailableShader(pipelineName(template, permutation), error.message);
|
|
903
|
+
if (this.joins.joined(template))
|
|
904
|
+
this.joins.failed(template, error);
|
|
905
|
+
return refusedProgram(this.gl, template, permutation);
|
|
906
|
+
}
|
|
863
907
|
resetCounts() {
|
|
864
908
|
this.counts.uploadBytes = 0;
|
|
865
909
|
this.counts.drawCalls = 0;
|
|
@@ -1157,13 +1201,33 @@ export class WebGL2Backend {
|
|
|
1157
1201
|
}
|
|
1158
1202
|
/**
|
|
1159
1203
|
* The program that draws mip levels, or the one that copies a layer, in use. Its first use
|
|
1160
|
-
* waits for its link when the driver has not finished it.
|
|
1204
|
+
* waits for its link when the driver has not finished it. Undefined when the loaded set lacks
|
|
1205
|
+
* its shader, which skips the pass.
|
|
1161
1206
|
*/
|
|
1162
1207
|
spareProgram(key) {
|
|
1163
|
-
const program = this.
|
|
1164
|
-
|
|
1208
|
+
const program = this.spareProgramFor(key);
|
|
1209
|
+
if (program)
|
|
1210
|
+
this.useProgram(program);
|
|
1165
1211
|
return program;
|
|
1166
1212
|
}
|
|
1213
|
+
/**
|
|
1214
|
+
* The program that draws mip levels, copies a layer or scales a texture, or undefined when the
|
|
1215
|
+
* loaded set lacks its variant, which the engine reports once.
|
|
1216
|
+
*/
|
|
1217
|
+
spareProgramFor(key) {
|
|
1218
|
+
if (this.spareMissing.has(key))
|
|
1219
|
+
return undefined;
|
|
1220
|
+
try {
|
|
1221
|
+
return this.spareProgramOf(key);
|
|
1222
|
+
}
|
|
1223
|
+
catch (error) {
|
|
1224
|
+
if (!(error instanceof MissingVariantError))
|
|
1225
|
+
throw error;
|
|
1226
|
+
this.spareMissing.add(key);
|
|
1227
|
+
reportMissingVariant(`the ${key} shader`, error.word);
|
|
1228
|
+
return undefined;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1167
1231
|
/**
|
|
1168
1232
|
* Puts a program of the scene's objects in use, as `useProgram` does, and returns true. A link
|
|
1169
1233
|
* that the driver refused links once more, from new shaders: a driver can run short of memory
|
|
@@ -1239,7 +1303,21 @@ export class WebGL2Backend {
|
|
|
1239
1303
|
let program = this.programs.get(key);
|
|
1240
1304
|
if (!program) {
|
|
1241
1305
|
const glsl = this.need(this.templates, template, 'render pipeline template');
|
|
1242
|
-
|
|
1306
|
+
try {
|
|
1307
|
+
program = createProgram(this.gl, glsl, permutation);
|
|
1308
|
+
}
|
|
1309
|
+
catch (error) {
|
|
1310
|
+
// A pipeline whose word the loaded set lacks skips its draws, as one the driver
|
|
1311
|
+
// refused twice does. A joined shader's effects fall back to a pass each.
|
|
1312
|
+
if (!(error instanceof MissingVariantError))
|
|
1313
|
+
throw error;
|
|
1314
|
+
program = refusedProgram(this.gl, template, permutation);
|
|
1315
|
+
reportMissingVariant(pipelineName(template, permutation), error.word);
|
|
1316
|
+
if (this.joins.joined(template))
|
|
1317
|
+
this.joins.failed(template, error);
|
|
1318
|
+
this.programs.set(key, program);
|
|
1319
|
+
return program;
|
|
1320
|
+
}
|
|
1243
1321
|
this.programs.set(key, program);
|
|
1244
1322
|
const joined = this.joins.joined(template)
|
|
1245
1323
|
? { template, start: performance.now(), failed: false }
|
|
@@ -1763,6 +1841,8 @@ export class WebGL2Backend {
|
|
|
1763
1841
|
return;
|
|
1764
1842
|
}
|
|
1765
1843
|
const program = this.beginSpareDraws(MIP_PROGRAM, texture, texture.format, texture.width, texture.height);
|
|
1844
|
+
if (!program)
|
|
1845
|
+
return;
|
|
1766
1846
|
const count = levels === 0 ? texture.mips : Math.min(levels, texture.mips);
|
|
1767
1847
|
for (let level = 1; level < count; level++) {
|
|
1768
1848
|
const width = Math.max(1, texture.width >> level);
|
|
@@ -1788,6 +1868,8 @@ export class WebGL2Backend {
|
|
|
1788
1868
|
const source = this.textureOf(sourceId);
|
|
1789
1869
|
const dest = this.textureOf(destId);
|
|
1790
1870
|
const program = this.beginSpareDraws(SCALE_PROGRAM, source, dest.format, size, size);
|
|
1871
|
+
if (!program)
|
|
1872
|
+
return;
|
|
1791
1873
|
this.drawScaleIntoSpare(program, source, size | (sourceLayer << SCALE_SIZE_BITS), size, size);
|
|
1792
1874
|
this.copyFromSpare(dest, 0, 0, 0, destLayer, 0, 0, size, size);
|
|
1793
1875
|
this.endSpareDraws(source, dest.format);
|
|
@@ -1888,9 +1970,11 @@ export class WebGL2Backend {
|
|
|
1888
1970
|
* takes the format of what the draws go into, which a scale draw writes into another texture.
|
|
1889
1971
|
*/
|
|
1890
1972
|
beginSpareDraws(key, source, format, width, height) {
|
|
1973
|
+
const program = this.spareProgram(key);
|
|
1974
|
+
if (!program)
|
|
1975
|
+
return undefined;
|
|
1891
1976
|
const gl = this.gl;
|
|
1892
1977
|
const spare = this.spareOf(format, width, height);
|
|
1893
|
-
const program = this.spareProgram(key);
|
|
1894
1978
|
if (!this.mipFramebuffer)
|
|
1895
1979
|
this.mipFramebuffer = gl.createFramebuffer();
|
|
1896
1980
|
if (!this.mipSampler) {
|
|
@@ -2028,12 +2112,14 @@ export class WebGL2Backend {
|
|
|
2028
2112
|
const right = sourceX + width;
|
|
2029
2113
|
const top = sourceY + height;
|
|
2030
2114
|
const program = this.beginSpareDraws(COPY_PROGRAM, source, source.format, right, top);
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2115
|
+
if (program) {
|
|
2116
|
+
for (let k = 0; k < layers; k++) {
|
|
2117
|
+
this.drawIntoSpare(program, source, sourceLevel, sourceLayer + k, right, top);
|
|
2118
|
+
this.copyFromSpare(destination, level, x, y, layer + k, sourceX, sourceY, width, height);
|
|
2119
|
+
}
|
|
2120
|
+
this.endSpareDraws(source, source.format);
|
|
2121
|
+
return;
|
|
2034
2122
|
}
|
|
2035
|
-
this.endSpareDraws(source, source.format);
|
|
2036
|
-
return;
|
|
2037
2123
|
}
|
|
2038
2124
|
if (!this.copyFramebuffer)
|
|
2039
2125
|
this.copyFramebuffer = gl.createFramebuffer();
|
|
@@ -157,6 +157,11 @@ export declare function mipmapTemplate(shaders: DeviceShaders, pipeline: 'main'
|
|
|
157
157
|
* shader of its build with the prepass's fragment shader.
|
|
158
158
|
*/
|
|
159
159
|
export declare function createProgram(gl: WebGL2RenderingContext, template: GlslTemplate, permutation: number): Program;
|
|
160
|
+
/**
|
|
161
|
+
* A stand-in for a program of a mesh template whose shader variant the loaded set lacks. Its draws
|
|
162
|
+
* draw nothing, as a program that the driver refused twice does, so the rest of the scene draws.
|
|
163
|
+
*/
|
|
164
|
+
export declare function refusedProgram(gl: WebGL2RenderingContext, template: number, permutation: number): Program;
|
|
160
165
|
/**
|
|
161
166
|
* The names that a GLSL source declares as uniforms or uniform blocks. One walk of the source
|
|
162
167
|
* answers every name, so a check over a program's whole reflection costs a scan beside a scan
|
|
@@ -16,7 +16,7 @@ import { PERMUTATION_PREPASS, TEMPLATE_ACCUMULATE, TEMPLATE_AO, TEMPLATE_AO_DENO
|
|
|
16
16
|
import { DEBUG_LINES_SHADER, DEBUG_VIEW_SHADER, DEPTH_MAPPING_UNIFORM, MOTION_VIEW_SHADER, } from '../../generated/shaders.js';
|
|
17
17
|
import { LINE_VERTICES } from '../line-vertices.js';
|
|
18
18
|
import { PARTICLE_RECORDS } from '../particle-records.js';
|
|
19
|
-
import { missingVariant, variantFor } from '../variants.js';
|
|
19
|
+
import { listedWord, MissingVariantError, missingVariant, variantFor } from '../variants.js';
|
|
20
20
|
/**
|
|
21
21
|
* True in development builds, which add the debug views' templates. This file reads the constant
|
|
22
22
|
* itself, as the files that load on first use do. It loads with its GPU path's renderers, apart from
|
|
@@ -289,7 +289,7 @@ export function createProgram(gl, template, permutation) {
|
|
|
289
289
|
const shading = variantFor(template.shader, build, 'glsl')?.glsl?.[template.pipeline];
|
|
290
290
|
const source = shading && build !== permutation ? { ...shading, fragment: PREPASS_FRAGMENT } : shading;
|
|
291
291
|
if (!source)
|
|
292
|
-
throw new
|
|
292
|
+
throw new MissingVariantError(listedWord(build), `a render pipeline template: ${missingVariant(build)}`);
|
|
293
293
|
const { program, shaders } = link(gl, source, '');
|
|
294
294
|
return {
|
|
295
295
|
program,
|
|
@@ -302,6 +302,29 @@ export function createProgram(gl, template, permutation) {
|
|
|
302
302
|
background: false,
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* A stand-in for a program of a mesh template whose shader variant the loaded set lacks. Its draws
|
|
307
|
+
* draw nothing, as a program that the driver refused twice does, so the rest of the scene draws.
|
|
308
|
+
*/
|
|
309
|
+
export function refusedProgram(gl, template, permutation) {
|
|
310
|
+
const program = gl.createProgram();
|
|
311
|
+
if (!program)
|
|
312
|
+
throw new Error('WebGL2 could not create a program');
|
|
313
|
+
return {
|
|
314
|
+
program,
|
|
315
|
+
source: {
|
|
316
|
+
vertex: { source: '', uniformBlocks: [], textures: [] },
|
|
317
|
+
fragment: { source: '', uniformBlocks: [], textures: [] },
|
|
318
|
+
},
|
|
319
|
+
shaders: [],
|
|
320
|
+
firstInstance: null,
|
|
321
|
+
firstInstanceValue: 0,
|
|
322
|
+
textureUnits: [],
|
|
323
|
+
ready: true,
|
|
324
|
+
background: false,
|
|
325
|
+
objects: { template, permutation, refused: true },
|
|
326
|
+
};
|
|
327
|
+
}
|
|
305
328
|
/** The head of a uniform declaration, with the text between it and the declaration's end. */
|
|
306
329
|
const DECLARATION = /^\s*(?:layout\([^)]*\)\s*)?uniform\b([^;{]*)/gm;
|
|
307
330
|
/** A word of a declaration, which is a name that the source declares. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DeviceShaders, FirstUseShaders } from '../../generated/shaders.js';
|
|
2
2
|
import { ImageTable } from '../../shared/images.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type DeviceShaderSet } from '../device-shaders.js';
|
|
4
4
|
import { JoinedBuilds } from '../effect-join.js';
|
|
5
5
|
import { GpuMemory } from '../memory.js';
|
|
6
6
|
import type { ReadSink } from '../readback.js';
|
|
@@ -40,6 +40,10 @@ export declare class WebGPUBackend {
|
|
|
40
40
|
private readonly ownsImages;
|
|
41
41
|
/** The sampler that mip levels read the level before them with. */
|
|
42
42
|
private mipSampler;
|
|
43
|
+
/** True once the loaded set showed that it lacks the shader that makes mip levels. */
|
|
44
|
+
private mipMissing;
|
|
45
|
+
/** True once the loaded set showed that it lacks the shader that scales a texture into another. */
|
|
46
|
+
private scaleMissing;
|
|
43
47
|
/** What making each texture's mip levels draws with, by texture id, once it made them. */
|
|
44
48
|
private readonly mipChains;
|
|
45
49
|
/**
|
|
@@ -254,6 +258,16 @@ export declare class WebGPUBackend {
|
|
|
254
258
|
private copyTexture;
|
|
255
259
|
/** Bytes of one block of texels of a texture: one texel unless its format is compressed. */
|
|
256
260
|
private blockBytes;
|
|
261
|
+
/**
|
|
262
|
+
* The pipeline that makes mip levels of textures of `format`, or undefined when its shader is
|
|
263
|
+
* absent, which leaves the levels as they are. The engine reports the cause once.
|
|
264
|
+
*/
|
|
265
|
+
private mipPipeline;
|
|
266
|
+
/**
|
|
267
|
+
* The pipeline that draws a texture into the corner of another, or undefined when its shader is
|
|
268
|
+
* absent, which leaves the image as it is. The engine reports the cause once.
|
|
269
|
+
*/
|
|
270
|
+
private scalePipeline;
|
|
257
271
|
/**
|
|
258
272
|
* Makes mip levels 1 and up of one layer of a texture array, a render pass per level. Each pass
|
|
259
273
|
* draws into its level of the layer, and reads the level before it through a view of every
|
|
@@ -402,6 +416,25 @@ export declare class WebGPUBackend {
|
|
|
402
416
|
* operands at `a`: in the background when `background` is set, else at once.
|
|
403
417
|
*/
|
|
404
418
|
private createPipeline;
|
|
419
|
+
/**
|
|
420
|
+
* The render pipeline's descriptor, or null when the loaded shader set lacks its variant, for a
|
|
421
|
+
* template that draws the scene's meshes or a full-screen pass. Its draws then draw nothing, as
|
|
422
|
+
* a pipeline that the driver refused twice does. A joined shader's effects fall back to a pass
|
|
423
|
+
* each.
|
|
424
|
+
*/
|
|
425
|
+
private describedRender;
|
|
426
|
+
/**
|
|
427
|
+
* Reports a shader that is absent or that failed to load, and returns true for either. A word
|
|
428
|
+
* that the loaded set lacks goes to the page's report, and a file that did not load goes to its
|
|
429
|
+
* warning. Any other error returns false, and the caller rethrows it as the engine fault it is.
|
|
430
|
+
*/
|
|
431
|
+
private reportUnavailable;
|
|
432
|
+
/**
|
|
433
|
+
* Marks the pipeline of a create command as unavailable when its shader is absent or did not
|
|
434
|
+
* load: its draws or dispatches do nothing, and the engine reports the cause once. A joined
|
|
435
|
+
* shader's effects fall back to a pass each. Returns false for any other error.
|
|
436
|
+
*/
|
|
437
|
+
private unavailable;
|
|
405
438
|
/**
|
|
406
439
|
* Hears that a render pipeline did not build. A pipeline of the scene's objects that the GPU's
|
|
407
440
|
* driver refused waits for its retry, and still counts as building. Any other failure, such as
|
|
@@ -7,12 +7,13 @@ import * as G from '../../generated/gpu.js';
|
|
|
7
7
|
import { DEV } from '../../shared/dev.js';
|
|
8
8
|
import { ImageTable } from '../../shared/images.js';
|
|
9
9
|
import { DROP_COUNTED_LABEL } from '../../shared/metrics.js';
|
|
10
|
+
import { ShaderLoadError } from '../device-shaders.js';
|
|
10
11
|
import { EarlyBuilds, keyOf, PipelineListing } from '../early-builds.js';
|
|
11
12
|
import { JoinedBuilds, joinedReady } from '../effect-join.js';
|
|
12
13
|
import { CLOUD_FIELD_WORD, CLOUD_STEPS_WORD, LAYER_WORD, LIGHT_BUFFER_WORD, } from '../environment-words.js';
|
|
13
14
|
import { floatOfBits } from '../float-bits.js';
|
|
14
15
|
import { GpuMemory, textureBytes } from '../memory.js';
|
|
15
|
-
import { variantFor } from '../variants.js';
|
|
16
|
+
import { MissingShaderError, MissingVariantError, reportMissingVariant, reportUnavailableShader, variantFor, } from '../variants.js';
|
|
16
17
|
import { BufferReads } from './buffer-reads.js';
|
|
17
18
|
import { IndirectArguments } from './indirect-arguments.js';
|
|
18
19
|
import { Pipelines, SKIN_BUILDS } from './pipelines.js';
|
|
@@ -151,6 +152,10 @@ export class WebGPUBackend {
|
|
|
151
152
|
ownsImages;
|
|
152
153
|
/** The sampler that mip levels read the level before them with. */
|
|
153
154
|
mipSampler;
|
|
155
|
+
/** True once the loaded set showed that it lacks the shader that makes mip levels. */
|
|
156
|
+
mipMissing = false;
|
|
157
|
+
/** True once the loaded set showed that it lacks the shader that scales a texture into another. */
|
|
158
|
+
scaleMissing = false;
|
|
154
159
|
/** What making each texture's mip levels draws with, by texture id, once it made them. */
|
|
155
160
|
mipChains = [];
|
|
156
161
|
/**
|
|
@@ -585,6 +590,40 @@ export class WebGPUBackend {
|
|
|
585
590
|
blockBytes(id) {
|
|
586
591
|
return G.FORMAT_BLOCK_BYTES[this.formats[id]] ?? 0;
|
|
587
592
|
}
|
|
593
|
+
/**
|
|
594
|
+
* The pipeline that makes mip levels of textures of `format`, or undefined when its shader is
|
|
595
|
+
* absent, which leaves the levels as they are. The engine reports the cause once.
|
|
596
|
+
*/
|
|
597
|
+
mipPipeline(format) {
|
|
598
|
+
if (this.mipMissing)
|
|
599
|
+
return undefined;
|
|
600
|
+
try {
|
|
601
|
+
return this.pipelines.mipmaps(format);
|
|
602
|
+
}
|
|
603
|
+
catch (error) {
|
|
604
|
+
if (!this.reportUnavailable(error, 'the mip level shader'))
|
|
605
|
+
throw error;
|
|
606
|
+
this.mipMissing = true;
|
|
607
|
+
return undefined;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* The pipeline that draws a texture into the corner of another, or undefined when its shader is
|
|
612
|
+
* absent, which leaves the image as it is. The engine reports the cause once.
|
|
613
|
+
*/
|
|
614
|
+
scalePipeline(format) {
|
|
615
|
+
if (this.scaleMissing)
|
|
616
|
+
return undefined;
|
|
617
|
+
try {
|
|
618
|
+
return this.pipelines.mipScale(format);
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
if (!this.reportUnavailable(error, 'the mip scale shader'))
|
|
622
|
+
throw error;
|
|
623
|
+
this.scaleMissing = true;
|
|
624
|
+
return undefined;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
588
627
|
/**
|
|
589
628
|
* Makes mip levels 1 and up of one layer of a texture array, a render pass per level. Each pass
|
|
590
629
|
* draws into its level of the layer, and reads the level before it through a view of every
|
|
@@ -595,7 +634,9 @@ export class WebGPUBackend {
|
|
|
595
634
|
*/
|
|
596
635
|
generateMipmaps(id, layer, levels = 0) {
|
|
597
636
|
const texture = this.need(this.textures, id, 'texture');
|
|
598
|
-
const pipeline = this.
|
|
637
|
+
const pipeline = this.mipPipeline(texture.format);
|
|
638
|
+
if (!pipeline)
|
|
639
|
+
return;
|
|
599
640
|
let chain = this.mipChains[id];
|
|
600
641
|
if (!chain || chain.layer !== layer || chain.pipeline !== pipeline)
|
|
601
642
|
chain = this.mipChains[id] = this.mipChain(texture, pipeline, layer);
|
|
@@ -625,7 +666,9 @@ export class WebGPUBackend {
|
|
|
625
666
|
const levels = words[a + 5];
|
|
626
667
|
const source = this.need(this.textures, sourceId, 'texture');
|
|
627
668
|
const dest = this.need(this.textures, destId, 'texture');
|
|
628
|
-
const pipeline = this.
|
|
669
|
+
const pipeline = this.scalePipeline(dest.format);
|
|
670
|
+
if (!pipeline)
|
|
671
|
+
return;
|
|
629
672
|
this.mipSampler ??= this.device.createSampler({ magFilter: 'linear', minFilter: 'linear' });
|
|
630
673
|
const sourceView = source.createView({
|
|
631
674
|
dimension: '2d-array',
|
|
@@ -1054,10 +1097,17 @@ export class WebGPUBackend {
|
|
|
1054
1097
|
for (const build of Object.values(builds))
|
|
1055
1098
|
if (build.wgsl)
|
|
1056
1099
|
this.pipelines.prepareModule(name, build.wgsl);
|
|
1057
|
-
for (const [template, bits] of compute ?? [])
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1100
|
+
for (const [template, bits] of compute ?? []) {
|
|
1101
|
+
try {
|
|
1102
|
+
this.device
|
|
1103
|
+
.createComputePipelineAsync(this.pipelines.compute(template, bits))
|
|
1104
|
+
.catch(() => undefined);
|
|
1105
|
+
}
|
|
1106
|
+
catch (error) {
|
|
1107
|
+
if (!this.reportUnavailable(error, `compute pass ${template}`))
|
|
1108
|
+
throw error;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1061
1111
|
}
|
|
1062
1112
|
/**
|
|
1063
1113
|
* Starts to build the pipelines of `list`, a pipeline list of the pipelines that the first frame
|
|
@@ -1140,7 +1190,19 @@ export class WebGPUBackend {
|
|
|
1140
1190
|
unparkEach(parked, op, ready) {
|
|
1141
1191
|
for (let k = parked.length - 1; k >= 0; k--) {
|
|
1142
1192
|
const operands = parked[k];
|
|
1143
|
-
|
|
1193
|
+
let isReady;
|
|
1194
|
+
try {
|
|
1195
|
+
isReady = ready(operands);
|
|
1196
|
+
}
|
|
1197
|
+
catch (error) {
|
|
1198
|
+
if (!this.unavailable(error, op, operands))
|
|
1199
|
+
throw error;
|
|
1200
|
+
parked.splice(k, 1);
|
|
1201
|
+
this.builds--;
|
|
1202
|
+
this.counts.pipelines--;
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
if (!isReady)
|
|
1144
1206
|
continue;
|
|
1145
1207
|
parked.splice(k, 1);
|
|
1146
1208
|
this.builds--;
|
|
@@ -1156,12 +1218,23 @@ export class WebGPUBackend {
|
|
|
1156
1218
|
this.counts.pipelines++;
|
|
1157
1219
|
const id = words[a];
|
|
1158
1220
|
const device = this.device;
|
|
1221
|
+
const template = words[a + 1];
|
|
1222
|
+
const permutation = words[a + 2];
|
|
1159
1223
|
if (op === G.OP_CREATE_COMPUTE_PIPELINE) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
this.
|
|
1163
|
-
|
|
1164
|
-
|
|
1224
|
+
let descriptor;
|
|
1225
|
+
try {
|
|
1226
|
+
if (!this.computeReady(template, permutation)) {
|
|
1227
|
+
// Its dispatches do nothing until its shader file arrives and the pipeline builds.
|
|
1228
|
+
this.computePipelines[id] = null;
|
|
1229
|
+
this.builds++;
|
|
1230
|
+
this.parkedCompute.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
descriptor = this.pipelines.compute(template, permutation);
|
|
1234
|
+
}
|
|
1235
|
+
catch (error) {
|
|
1236
|
+
if (!this.unavailable(error, op, words.subarray(a)))
|
|
1237
|
+
throw error;
|
|
1165
1238
|
return;
|
|
1166
1239
|
}
|
|
1167
1240
|
const early = background ? this.early?.take(op, words, a) : undefined;
|
|
@@ -1172,10 +1245,9 @@ export class WebGPUBackend {
|
|
|
1172
1245
|
if (!background) {
|
|
1173
1246
|
this.computePipelines[id] =
|
|
1174
1247
|
this.takeAhead(op, words, a) ??
|
|
1175
|
-
device.createComputePipeline(
|
|
1248
|
+
device.createComputePipeline(descriptor);
|
|
1176
1249
|
return;
|
|
1177
1250
|
}
|
|
1178
|
-
const descriptor = this.pipelines.compute(words[a + 1], words[a + 2]);
|
|
1179
1251
|
this.computePipelines[id] = null;
|
|
1180
1252
|
this.builds++;
|
|
1181
1253
|
this.running++;
|
|
@@ -1189,17 +1261,23 @@ export class WebGPUBackend {
|
|
|
1189
1261
|
return;
|
|
1190
1262
|
}
|
|
1191
1263
|
this.lineLists[id] = (words[a + 6] & G.STATE_LINE_LIST) !== 0;
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1264
|
+
try {
|
|
1265
|
+
if (!this.templateReady(template, permutation)) {
|
|
1266
|
+
// Its draws draw nothing until the shader arrives and the pipeline builds.
|
|
1267
|
+
this.renderPipelines[id] = null;
|
|
1268
|
+
this.builds++;
|
|
1269
|
+
// The command's header, before its operands, gives its length in words.
|
|
1270
|
+
this.parked.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
catch (error) {
|
|
1275
|
+
if (!this.unavailable(error, op, words.subarray(a)))
|
|
1276
|
+
throw error;
|
|
1198
1277
|
return;
|
|
1199
1278
|
}
|
|
1200
1279
|
// A joined shader always builds in the background, so a frame never waits for it and its
|
|
1201
1280
|
// failure only sends its effects back to a pass each.
|
|
1202
|
-
const template = words[a + 1];
|
|
1203
1281
|
const joined = this.joins.joined(template);
|
|
1204
1282
|
if (DEV && !joined && this.images.shaders.has(template))
|
|
1205
1283
|
this.customOperands.set(id, words.slice(a, a + RENDER_PIPELINE_OPERANDS));
|
|
@@ -1209,17 +1287,24 @@ export class WebGPUBackend {
|
|
|
1209
1287
|
return;
|
|
1210
1288
|
}
|
|
1211
1289
|
if (!background && !joined) {
|
|
1212
|
-
this.
|
|
1213
|
-
|
|
1214
|
-
|
|
1290
|
+
const ahead = this.takeAhead(op, words, a);
|
|
1291
|
+
if (ahead) {
|
|
1292
|
+
this.renderPipelines[id] = ahead;
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
const descriptor = this.describedRender(words, a);
|
|
1296
|
+
if (descriptor === null)
|
|
1297
|
+
return;
|
|
1298
|
+
this.renderPipelines[id] = device.createRenderPipeline(descriptor);
|
|
1215
1299
|
return;
|
|
1216
1300
|
}
|
|
1217
|
-
const descriptor = this.
|
|
1301
|
+
const descriptor = this.describedRender(words, a);
|
|
1302
|
+
if (descriptor === null)
|
|
1303
|
+
return;
|
|
1218
1304
|
this.renderPipelines[id] = null;
|
|
1219
1305
|
this.builds++;
|
|
1220
1306
|
this.running++;
|
|
1221
1307
|
const start = performance.now();
|
|
1222
|
-
const permutation = words[a + 2];
|
|
1223
1308
|
device.createRenderPipelineAsync(descriptor).then((pipeline) => {
|
|
1224
1309
|
this.running--;
|
|
1225
1310
|
if (joined)
|
|
@@ -1233,6 +1318,67 @@ export class WebGPUBackend {
|
|
|
1233
1318
|
this.joins.failed(template, error);
|
|
1234
1319
|
});
|
|
1235
1320
|
}
|
|
1321
|
+
/**
|
|
1322
|
+
* The render pipeline's descriptor, or null when the loaded shader set lacks its variant, for a
|
|
1323
|
+
* template that draws the scene's meshes or a full-screen pass. Its draws then draw nothing, as
|
|
1324
|
+
* a pipeline that the driver refused twice does. A joined shader's effects fall back to a pass
|
|
1325
|
+
* each.
|
|
1326
|
+
*/
|
|
1327
|
+
describedRender(words, a) {
|
|
1328
|
+
const template = words[a + 1];
|
|
1329
|
+
try {
|
|
1330
|
+
return this.renderDescriptor(words, a);
|
|
1331
|
+
}
|
|
1332
|
+
catch (error) {
|
|
1333
|
+
if (!(error instanceof MissingVariantError))
|
|
1334
|
+
throw error;
|
|
1335
|
+
this.renderPipelines[words[a]] = null;
|
|
1336
|
+
reportMissingVariant(this.pipelines.describe(template, words[a + 2]), error.word);
|
|
1337
|
+
if (this.joins.joined(template))
|
|
1338
|
+
this.joins.failed(template, error);
|
|
1339
|
+
return null;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Reports a shader that is absent or that failed to load, and returns true for either. A word
|
|
1344
|
+
* that the loaded set lacks goes to the page's report, and a file that did not load goes to its
|
|
1345
|
+
* warning. Any other error returns false, and the caller rethrows it as the engine fault it is.
|
|
1346
|
+
*/
|
|
1347
|
+
reportUnavailable(error, name) {
|
|
1348
|
+
if (error instanceof MissingShaderError) {
|
|
1349
|
+
reportMissingVariant(`the ${error.shader} shader`, error.word);
|
|
1350
|
+
return true;
|
|
1351
|
+
}
|
|
1352
|
+
if (error instanceof ShaderLoadError) {
|
|
1353
|
+
reportUnavailableShader(name, error.message);
|
|
1354
|
+
return true;
|
|
1355
|
+
}
|
|
1356
|
+
return false;
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Marks the pipeline of a create command as unavailable when its shader is absent or did not
|
|
1360
|
+
* load: its draws or dispatches do nothing, and the engine reports the cause once. A joined
|
|
1361
|
+
* shader's effects fall back to a pass each. Returns false for any other error.
|
|
1362
|
+
*/
|
|
1363
|
+
unavailable(error, op, operands) {
|
|
1364
|
+
const compute = op === G.OP_CREATE_COMPUTE_PIPELINE;
|
|
1365
|
+
const id = operands[0];
|
|
1366
|
+
const template = operands[1];
|
|
1367
|
+
const permutation = operands[2];
|
|
1368
|
+
const name = compute
|
|
1369
|
+
? `compute pass ${template}`
|
|
1370
|
+
: this.pipelines.describe(template, permutation);
|
|
1371
|
+
if (!this.reportUnavailable(error, name))
|
|
1372
|
+
return false;
|
|
1373
|
+
if (compute)
|
|
1374
|
+
this.computePipelines[id] = null;
|
|
1375
|
+
else {
|
|
1376
|
+
this.renderPipelines[id] = null;
|
|
1377
|
+
if (this.joins.joined(template))
|
|
1378
|
+
this.joins.failed(template, error);
|
|
1379
|
+
}
|
|
1380
|
+
return true;
|
|
1381
|
+
}
|
|
1236
1382
|
/**
|
|
1237
1383
|
* Hears that a render pipeline did not build. A pipeline of the scene's objects that the GPU's
|
|
1238
1384
|
* driver refused waits for its retry, and still counts as building. Any other failure, such as
|
|
@@ -198,8 +198,8 @@ export declare class Pipelines {
|
|
|
198
198
|
has(id: number): boolean;
|
|
199
199
|
/**
|
|
200
200
|
* True when the pipelines of a template draw objects of the scene: meshes, or a custom material's
|
|
201
|
-
* draw shader. A
|
|
202
|
-
*
|
|
201
|
+
* draw shader. A driver's refusal of such a pipeline is retried, and then its draws skip. A
|
|
202
|
+
* missing shader or a failed load skips any pipeline or pass (D-405).
|
|
203
203
|
*/
|
|
204
204
|
drawsObjects(id: number): boolean;
|
|
205
205
|
/** The name of a render pipeline of a template, for a message (`pipelineName`). */
|