@luma.gl/webgpu 9.0.0-alpha.50 → 9.0.0-alpha.52

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.
@@ -14,8 +14,8 @@ export declare class WebGPUShader extends Shader {
14
14
  constructor(device: WebGPUDevice, props: WebGPUShaderProps);
15
15
  _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void>;
16
16
  destroy(): void;
17
- protected createHandle(): GPUShaderModule;
18
17
  /** Returns compilation info for this shader */
19
- compilationInfo(): Promise<readonly CompilerMessage[]>;
18
+ getCompilationInfo(): Promise<readonly CompilerMessage[]>;
19
+ protected createHandle(): GPUShaderModule;
20
20
  }
21
21
  //# sourceMappingURL=webgpu-shader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAC,MAAM,EAAM,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACtC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,iBAAiB;IAYpD,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxE,OAAO,IAAI,IAAI;IAIxB,SAAS,CAAC,YAAY,IAAI,eAAe;IAwBzC,+CAA+C;IACzC,eAAe,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;CAI7D"}
1
+ {"version":3,"file":"webgpu-shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-shader.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAC,MAAM,EAAM,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACtC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,iBAAiB;IAYpD,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxE,OAAO,IAAI,IAAI;IAKxB,+CAA+C;IACzC,kBAAkB,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IAO/D,SAAS,CAAC,YAAY,IAAI,eAAe;CAuB1C"}
@@ -13,12 +13,16 @@ export class WebGPUShader extends Shader {
13
13
  async _checkCompilationError(errorScope) {
14
14
  const error = await errorScope;
15
15
  if (error) {
16
- const shaderLog = await this.compilationInfo();
16
+ const shaderLog = await this.getCompilationInfo();
17
17
  log.error(`Shader compilation error: ${error.message}`, shaderLog)();
18
18
  throw new Error(`Shader compilation error: ${error.message}`);
19
19
  }
20
20
  }
21
21
  destroy() {}
22
+ async getCompilationInfo() {
23
+ const compilationInfo = await this.handle.getCompilationInfo();
24
+ return compilationInfo.messages;
25
+ }
22
26
  createHandle() {
23
27
  const {
24
28
  source,
@@ -42,9 +46,5 @@ export class WebGPUShader extends Shader {
42
46
  throw new Error(language);
43
47
  }
44
48
  }
45
- async compilationInfo() {
46
- const compilationInfo = await this.handle.getCompilationInfo();
47
- return compilationInfo.messages;
48
- }
49
49
  }
50
50
  //# sourceMappingURL=webgpu-shader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webgpu-shader.js","names":["Shader","log","WebGPUShader","constructor","device","props","handle","pushErrorScope","createHandle","label","id","_checkCompilationError","popErrorScope","errorScope","error","shaderLog","compilationInfo","message","Error","destroy","source","stage","language","includes","createShaderModule","code","transform","glsl","glslang","compileGLSL","getCompilationInfo","messages"],"sources":["../../../src/adapter/resources/webgpu-shader.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {ShaderProps, CompilerMessage} from '@luma.gl/core';\nimport {Shader, log} from '@luma.gl/core';\nimport type {WebGPUDevice} from '../webgpu-device';\n\nexport type WebGPUShaderProps = ShaderProps & {\n handle?: GPUShaderModule;\n};\n\n/**\n * Immutable shader\n */\nexport class WebGPUShader extends Shader {\n readonly device: WebGPUDevice;\n readonly handle: GPUShaderModule;\n\n constructor(device: WebGPUDevice, props: WebGPUShaderProps) {\n super(device, props);\n this.device = device;\n\n this.device.handle.pushErrorScope('validation');\n\n this.handle = this.props.handle || this.createHandle();\n this.handle.label = this.props.id;\n\n this._checkCompilationError(this.device.handle.popErrorScope());\n }\n\n async _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void> {\n const error = await errorScope as GPUValidationError;\n if (error) {\n const shaderLog = await this.compilationInfo();\n log.error(`Shader compilation error: ${error.message}`, shaderLog)();\n // Note: Even though this error is asynchronous and thrown after the constructor completes,\n // it will result in a useful stack trace leading back to the constructor\n throw new Error(`Shader compilation error: ${error.message}`);\n }\n }\n\n override destroy(): void {\n // this.handle.destroy();\n }\n\n protected createHandle(): GPUShaderModule {\n const {source, stage} = this.props;\n\n let language = this.props.language;\n // Compile from src\n if (language === 'auto') {\n // wgsl uses C++ \"auto\" style arrow notation\n language = source.includes('->') ? 'wgsl' : 'glsl';\n }\n\n switch(language) {\n case 'wgsl':\n return this.device.handle.createShaderModule({code: source});\n case 'glsl':\n return this.device.handle.createShaderModule({\n code: source,\n // @ts-expect-error\n transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)\n });\n default:\n throw new Error(language);\n }\n }\n\n /** Returns compilation info for this shader */\n async compilationInfo(): Promise<readonly CompilerMessage[]> {\n const compilationInfo = await this.handle.getCompilationInfo();\n return compilationInfo.messages;\n }\n}\n"],"mappings":"AAIA,SAAQA,MAAM,EAAEC,GAAG,QAAO,eAAe;AAUzC,OAAO,MAAMC,YAAY,SAASF,MAAM,CAAC;EAIvCG,WAAWA,CAACC,MAAoB,EAAEC,KAAwB,EAAE;IAC1D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KAJdD,MAAM;IAAA,KACNE,MAAM;IAIb,IAAI,CAACF,MAAM,GAAGA,MAAM;IAEpB,IAAI,CAACA,MAAM,CAACE,MAAM,CAACC,cAAc,CAAC,YAAY,CAAC;IAE/C,IAAI,CAACD,MAAM,GAAG,IAAI,CAACD,KAAK,CAACC,MAAM,IAAI,IAAI,CAACE,YAAY,CAAC,CAAC;IACtD,IAAI,CAACF,MAAM,CAACG,KAAK,GAAG,IAAI,CAACJ,KAAK,CAACK,EAAE;IAEjC,IAAI,CAACC,sBAAsB,CAAC,IAAI,CAACP,MAAM,CAACE,MAAM,CAACM,aAAa,CAAC,CAAC,CAAC;EACjE;EAEA,MAAMD,sBAAsBA,CAACE,UAAoC,EAAiB;IAChF,MAAMC,KAAK,GAAG,MAAMD,UAAgC;IACpD,IAAIC,KAAK,EAAE;MACT,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACC,eAAe,CAAC,CAAC;MAC9Cf,GAAG,CAACa,KAAK,CAAE,6BAA4BA,KAAK,CAACG,OAAQ,EAAC,EAAEF,SAAS,CAAC,CAAC,CAAC;MAGpE,MAAM,IAAIG,KAAK,CAAE,6BAA4BJ,KAAK,CAACG,OAAQ,EAAC,CAAC;IAC/D;EACF;EAESE,OAAOA,CAAA,EAAS,CAEzB;EAEUX,YAAYA,CAAA,EAAoB;IACxC,MAAM;MAACY,MAAM;MAAEC;IAAK,CAAC,GAAG,IAAI,CAAChB,KAAK;IAElC,IAAIiB,QAAQ,GAAG,IAAI,CAACjB,KAAK,CAACiB,QAAQ;IAElC,IAAIA,QAAQ,KAAK,MAAM,EAAE;MAEvBA,QAAQ,GAAGF,MAAM,CAACG,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM;IACpD;IAEA,QAAOD,QAAQ;MACb,KAAK,MAAM;QACT,OAAO,IAAI,CAAClB,MAAM,CAACE,MAAM,CAACkB,kBAAkB,CAAC;UAACC,IAAI,EAAEL;QAAM,CAAC,CAAC;MAC9D,KAAK,MAAM;QACT,OAAO,IAAI,CAAChB,MAAM,CAACE,MAAM,CAACkB,kBAAkB,CAAC;UAC3CC,IAAI,EAAEL,MAAM;UAEZM,SAAS,EAAGC,IAAI,IAAK,IAAI,CAACvB,MAAM,CAACwB,OAAO,CAACC,WAAW,CAACF,IAAI,EAAEN,KAAK;QAClE,CAAC,CAAC;MACJ;QACE,MAAM,IAAIH,KAAK,CAACI,QAAQ,CAAC;IAC7B;EACF;EAGA,MAAMN,eAAeA,CAAA,EAAwC;IAC3D,MAAMA,eAAe,GAAG,MAAM,IAAI,CAACV,MAAM,CAACwB,kBAAkB,CAAC,CAAC;IAC9D,OAAOd,eAAe,CAACe,QAAQ;EACjC;AACF"}
1
+ {"version":3,"file":"webgpu-shader.js","names":["Shader","log","WebGPUShader","constructor","device","props","handle","pushErrorScope","createHandle","label","id","_checkCompilationError","popErrorScope","errorScope","error","shaderLog","getCompilationInfo","message","Error","destroy","compilationInfo","messages","source","stage","language","includes","createShaderModule","code","transform","glsl","glslang","compileGLSL"],"sources":["../../../src/adapter/resources/webgpu-shader.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {ShaderProps, CompilerMessage} from '@luma.gl/core';\nimport {Shader, log} from '@luma.gl/core';\nimport type {WebGPUDevice} from '../webgpu-device';\n\nexport type WebGPUShaderProps = ShaderProps & {\n handle?: GPUShaderModule;\n};\n\n/**\n * Immutable shader\n */\nexport class WebGPUShader extends Shader {\n readonly device: WebGPUDevice;\n readonly handle: GPUShaderModule;\n\n constructor(device: WebGPUDevice, props: WebGPUShaderProps) {\n super(device, props);\n this.device = device;\n\n this.device.handle.pushErrorScope('validation');\n\n this.handle = this.props.handle || this.createHandle();\n this.handle.label = this.props.id;\n\n this._checkCompilationError(this.device.handle.popErrorScope());\n }\n\n async _checkCompilationError(errorScope: Promise<GPUError | null>): Promise<void> {\n const error = await errorScope as GPUValidationError;\n if (error) {\n const shaderLog = await this.getCompilationInfo();\n log.error(`Shader compilation error: ${error.message}`, shaderLog)();\n // Note: Even though this error is asynchronous and thrown after the constructor completes,\n // it will result in a useful stack trace leading back to the constructor\n throw new Error(`Shader compilation error: ${error.message}`);\n }\n }\n\n override destroy(): void {\n // Note: WebGPU does not offer a method to destroy shaders\n // this.handle.destroy();\n }\n\n /** Returns compilation info for this shader */\n async getCompilationInfo(): Promise<readonly CompilerMessage[]> {\n const compilationInfo = await this.handle.getCompilationInfo();\n return compilationInfo.messages;\n }\n\n // PRIVATE METHODS\n\n protected createHandle(): GPUShaderModule {\n const {source, stage} = this.props;\n\n let language = this.props.language;\n // Compile from src\n if (language === 'auto') {\n // wgsl uses C++ \"auto\" style arrow notation\n language = source.includes('->') ? 'wgsl' : 'glsl';\n }\n\n switch(language) {\n case 'wgsl':\n return this.device.handle.createShaderModule({code: source});\n case 'glsl':\n return this.device.handle.createShaderModule({\n code: source,\n // @ts-expect-error\n transform: (glsl) => this.device.glslang.compileGLSL(glsl, stage)\n });\n default:\n throw new Error(language);\n }\n }\n}\n"],"mappings":"AAIA,SAAQA,MAAM,EAAEC,GAAG,QAAO,eAAe;AAUzC,OAAO,MAAMC,YAAY,SAASF,MAAM,CAAC;EAIvCG,WAAWA,CAACC,MAAoB,EAAEC,KAAwB,EAAE;IAC1D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KAJdD,MAAM;IAAA,KACNE,MAAM;IAIb,IAAI,CAACF,MAAM,GAAGA,MAAM;IAEpB,IAAI,CAACA,MAAM,CAACE,MAAM,CAACC,cAAc,CAAC,YAAY,CAAC;IAE/C,IAAI,CAACD,MAAM,GAAG,IAAI,CAACD,KAAK,CAACC,MAAM,IAAI,IAAI,CAACE,YAAY,CAAC,CAAC;IACtD,IAAI,CAACF,MAAM,CAACG,KAAK,GAAG,IAAI,CAACJ,KAAK,CAACK,EAAE;IAEjC,IAAI,CAACC,sBAAsB,CAAC,IAAI,CAACP,MAAM,CAACE,MAAM,CAACM,aAAa,CAAC,CAAC,CAAC;EACjE;EAEA,MAAMD,sBAAsBA,CAACE,UAAoC,EAAiB;IAChF,MAAMC,KAAK,GAAG,MAAMD,UAAgC;IACpD,IAAIC,KAAK,EAAE;MACT,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACC,kBAAkB,CAAC,CAAC;MACjDf,GAAG,CAACa,KAAK,CAAE,6BAA4BA,KAAK,CAACG,OAAQ,EAAC,EAAEF,SAAS,CAAC,CAAC,CAAC;MAGpE,MAAM,IAAIG,KAAK,CAAE,6BAA4BJ,KAAK,CAACG,OAAQ,EAAC,CAAC;IAC/D;EACF;EAESE,OAAOA,CAAA,EAAS,CAGzB;EAGA,MAAMH,kBAAkBA,CAAA,EAAwC;IAC9D,MAAMI,eAAe,GAAG,MAAM,IAAI,CAACd,MAAM,CAACU,kBAAkB,CAAC,CAAC;IAC9D,OAAOI,eAAe,CAACC,QAAQ;EACjC;EAIUb,YAAYA,CAAA,EAAoB;IACxC,MAAM;MAACc,MAAM;MAAEC;IAAK,CAAC,GAAG,IAAI,CAAClB,KAAK;IAElC,IAAImB,QAAQ,GAAG,IAAI,CAACnB,KAAK,CAACmB,QAAQ;IAElC,IAAIA,QAAQ,KAAK,MAAM,EAAE;MAEvBA,QAAQ,GAAGF,MAAM,CAACG,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM;IACpD;IAEA,QAAOD,QAAQ;MACb,KAAK,MAAM;QACT,OAAO,IAAI,CAACpB,MAAM,CAACE,MAAM,CAACoB,kBAAkB,CAAC;UAACC,IAAI,EAAEL;QAAM,CAAC,CAAC;MAC9D,KAAK,MAAM;QACT,OAAO,IAAI,CAAClB,MAAM,CAACE,MAAM,CAACoB,kBAAkB,CAAC;UAC3CC,IAAI,EAAEL,MAAM;UAEZM,SAAS,EAAGC,IAAI,IAAK,IAAI,CAACzB,MAAM,CAAC0B,OAAO,CAACC,WAAW,CAACF,IAAI,EAAEN,KAAK;QAClE,CAAC,CAAC;MACJ;QACE,MAAM,IAAIL,KAAK,CAACM,QAAQ,CAAC;IAC7B;EACF;AACF"}
package/dist/dist.dev.js CHANGED
@@ -1360,26 +1360,175 @@ var __exports__ = (() => {
1360
1360
  colorSpace: "srgb"
1361
1361
  });
1362
1362
 
1363
+ // ../core/src/lib/compiler-log/format-compiler-log.ts
1364
+ function formatCompilerLog(shaderLog, source, options) {
1365
+ let formattedLog = "";
1366
+ const lines = source.split(/\r?\n/);
1367
+ const log2 = shaderLog.slice().sort((a, b) => a.lineNum - b.lineNum);
1368
+ switch (options?.showSourceCode || "no") {
1369
+ case "all":
1370
+ let currentMessage = 0;
1371
+ for (let lineNum = 1; lineNum <= lines.length; lineNum++) {
1372
+ formattedLog += getNumberedLine(lines[lineNum - 1], lineNum, options);
1373
+ while (log2.length > currentMessage && log2[currentMessage].lineNum === lineNum) {
1374
+ const message = log2[currentMessage++];
1375
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
1376
+ ...options,
1377
+ inlineSource: false
1378
+ });
1379
+ }
1380
+ }
1381
+ return formattedLog;
1382
+ case "issues":
1383
+ case "no":
1384
+ for (const message of shaderLog) {
1385
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
1386
+ inlineSource: options?.showSourceCode !== "no"
1387
+ });
1388
+ }
1389
+ return formattedLog;
1390
+ }
1391
+ }
1392
+ function formatCompilerMessage(message, lines, lineNum, options) {
1393
+ if (options?.inlineSource) {
1394
+ const numberedLines = getNumberedLines(lines, lineNum);
1395
+ const positionIndicator = message.linePos > 0 ? `${" ".repeat(message.linePos + 5)}^^^
1396
+ ` : "";
1397
+ return `
1398
+ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.message}
1399
+
1400
+ `;
1401
+ }
1402
+ return options?.html ? `<div class='luma-compiler-log-error' style="color:red;"><b> ${message.type.toUpperCase()}: ${message.message}</b></div>` : `${message.type.toUpperCase()}: ${message.message}`;
1403
+ }
1404
+ function getNumberedLines(lines, lineNum, options) {
1405
+ let numberedLines = "";
1406
+ for (let lineIndex = lineNum - 2; lineIndex <= lineNum; lineIndex++) {
1407
+ const sourceLine = lines[lineIndex - 1];
1408
+ if (sourceLine !== void 0) {
1409
+ numberedLines += getNumberedLine(sourceLine, lineNum, options);
1410
+ }
1411
+ }
1412
+ return numberedLines;
1413
+ }
1414
+ function getNumberedLine(line, lineNum, options) {
1415
+ return `${padLeft(String(lineNum), 4)}: ${line}${options?.html ? "<br/>" : "\n"}`;
1416
+ }
1417
+ function padLeft(string, paddedLength) {
1418
+ let result = "";
1419
+ for (let i = string.length; i < paddedLength; ++i) {
1420
+ result += " ";
1421
+ }
1422
+ return result + string;
1423
+ }
1424
+
1425
+ // ../core/src/lib/compiler-log/get-shader-info.ts
1426
+ function getShaderInfo(source, defaultName) {
1427
+ return {
1428
+ name: getShaderName(source, defaultName),
1429
+ language: "glsl",
1430
+ version: getShaderVersion(source)
1431
+ };
1432
+ }
1433
+ function getShaderName(shader, defaultName = "unnamed") {
1434
+ const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
1435
+ const match = SHADER_NAME_REGEXP.exec(shader);
1436
+ return match ? match[1] : defaultName;
1437
+ }
1438
+ function getShaderVersion(source) {
1439
+ let version = 100;
1440
+ const words = source.match(/[^\s]+/g);
1441
+ if (words && words.length >= 2 && words[0] === "#version") {
1442
+ const v = parseInt(words[1], 10);
1443
+ if (Number.isFinite(v)) {
1444
+ version = v;
1445
+ }
1446
+ }
1447
+ return version;
1448
+ }
1449
+
1363
1450
  // ../core/src/adapter/resources/shader.ts
1364
1451
  var _Shader = class extends Resource {
1365
1452
  get [Symbol.toStringTag]() {
1366
1453
  return "Shader";
1367
1454
  }
1455
+ compilationStatus = "pending";
1368
1456
  constructor(device, props) {
1369
- super(device, props, _Shader.defaultProps);
1457
+ super(device, {
1458
+ id: getShaderIdFromProps(props),
1459
+ ...props
1460
+ }, _Shader.defaultProps);
1370
1461
  this.stage = this.props.stage;
1371
1462
  this.source = this.props.source;
1372
1463
  }
1464
+ getCompilationInfoSync() {
1465
+ return null;
1466
+ }
1467
+ async debugShader() {
1468
+ switch (this.props.debug) {
1469
+ case "never":
1470
+ return;
1471
+ case "errors":
1472
+ if (this.compilationStatus === "success") {
1473
+ return;
1474
+ }
1475
+ break;
1476
+ case "warnings":
1477
+ case "always":
1478
+ break;
1479
+ }
1480
+ const messages = await this.getCompilationInfo();
1481
+ if (this.props.debug === "warnings" && messages?.length === 0) {
1482
+ return;
1483
+ }
1484
+ this._displayShaderLog(messages);
1485
+ }
1486
+ _displayShaderLog(messages) {
1487
+ if (typeof document === "undefined" || !document?.createElement) {
1488
+ return;
1489
+ }
1490
+ const shaderName = getShaderInfo(this.source).name;
1491
+ const shaderTitle = `${this.stage} ${shaderName}`;
1492
+ const htmlLog = formatCompilerLog(messages, this.source, {
1493
+ showSourceCode: "all",
1494
+ html: true
1495
+ });
1496
+ const button = document.createElement("Button");
1497
+ button.innerHTML = `
1498
+ <h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
1499
+ <code style="user-select:text;"><pre>
1500
+ ${htmlLog}
1501
+ </pre></code>`;
1502
+ button.style.top = "10px";
1503
+ button.style.left = "10px";
1504
+ button.style.position = "absolute";
1505
+ button.style.zIndex = "9999";
1506
+ button.style.width = "100%";
1507
+ button.style.textAlign = "left";
1508
+ document.body.appendChild(button);
1509
+ const errors = document.getElementsByClassName("luma-compiler-log-error");
1510
+ if (errors[0]?.scrollIntoView) {
1511
+ errors[0].scrollIntoView();
1512
+ }
1513
+ button.onclick = () => {
1514
+ const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
1515
+ navigator.clipboard.writeText(dataURI);
1516
+ };
1517
+ }
1373
1518
  };
1374
1519
  var Shader = _Shader;
1375
1520
  __publicField(Shader, "defaultProps", {
1376
1521
  ...Resource.defaultProps,
1522
+ language: "auto",
1377
1523
  stage: "vertex",
1378
1524
  source: "",
1379
1525
  sourceMap: null,
1380
- language: "auto",
1381
- shaderType: 0
1526
+ entryPoint: "main",
1527
+ debug: "errors"
1382
1528
  });
1529
+ function getShaderIdFromProps(props) {
1530
+ return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
1531
+ }
1383
1532
 
1384
1533
  // ../core/src/adapter/resources/sampler.ts
1385
1534
  var _Sampler = class extends Resource {
@@ -2060,13 +2209,17 @@ var __exports__ = (() => {
2060
2209
  async _checkCompilationError(errorScope) {
2061
2210
  const error = await errorScope;
2062
2211
  if (error) {
2063
- const shaderLog = await this.compilationInfo();
2212
+ const shaderLog = await this.getCompilationInfo();
2064
2213
  log.error(`Shader compilation error: ${error.message}`, shaderLog)();
2065
2214
  throw new Error(`Shader compilation error: ${error.message}`);
2066
2215
  }
2067
2216
  }
2068
2217
  destroy() {
2069
2218
  }
2219
+ async getCompilationInfo() {
2220
+ const compilationInfo = await this.handle.getCompilationInfo();
2221
+ return compilationInfo.messages;
2222
+ }
2070
2223
  createHandle() {
2071
2224
  const {
2072
2225
  source,
@@ -2090,10 +2243,6 @@ var __exports__ = (() => {
2090
2243
  throw new Error(language);
2091
2244
  }
2092
2245
  }
2093
- async compilationInfo() {
2094
- const compilationInfo = await this.handle.getCompilationInfo();
2095
- return compilationInfo.messages;
2096
- }
2097
2246
  };
2098
2247
 
2099
2248
  // src/adapter/helpers/webgpu-parameters.ts
package/dist/index.cjs CHANGED
@@ -378,13 +378,19 @@ var WebGPUShader = class extends import_core5.Shader {
378
378
  async _checkCompilationError(errorScope) {
379
379
  const error = await errorScope;
380
380
  if (error) {
381
- const shaderLog = await this.compilationInfo();
381
+ const shaderLog = await this.getCompilationInfo();
382
382
  import_core5.log.error(`Shader compilation error: ${error.message}`, shaderLog)();
383
383
  throw new Error(`Shader compilation error: ${error.message}`);
384
384
  }
385
385
  }
386
386
  destroy() {
387
387
  }
388
+ /** Returns compilation info for this shader */
389
+ async getCompilationInfo() {
390
+ const compilationInfo = await this.handle.getCompilationInfo();
391
+ return compilationInfo.messages;
392
+ }
393
+ // PRIVATE METHODS
388
394
  createHandle() {
389
395
  const { source, stage } = this.props;
390
396
  let language = this.props.language;
@@ -404,11 +410,6 @@ var WebGPUShader = class extends import_core5.Shader {
404
410
  throw new Error(language);
405
411
  }
406
412
  }
407
- /** Returns compilation info for this shader */
408
- async compilationInfo() {
409
- const compilationInfo = await this.handle.getCompilationInfo();
410
- return compilationInfo.messages;
411
- }
412
413
  };
413
414
 
414
415
  // src/adapter/resources/webgpu-render-pipeline.ts