WebGPU.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. let isAvailable = ( typeof navigator !== 'undefined' && navigator.gpu !== undefined );
  2. if ( typeof window !== 'undefined' && isAvailable ) {
  3. isAvailable = await navigator.gpu.requestAdapter();
  4. }
  5. /**
  6. * A utility module with basic WebGPU capability testing.
  7. *
  8. * @hideconstructor
  9. * @three_import import WebGPU from 'three/addons/capabilities/WebGPU.js';
  10. */
  11. class WebGPU {
  12. /**
  13. * Returns `true` if WebGPU is available.
  14. *
  15. * @return {boolean} Whether WebGPU is available or not.
  16. */
  17. static isAvailable() {
  18. return Boolean( isAvailable );
  19. }
  20. /**
  21. * Returns a `div` element representing a formatted error message that can be appended in
  22. * web sites if WebGPU isn't supported.
  23. *
  24. * @return {HTMLDivElement} A `div` element representing a formatted error message that WebGPU isn't supported.
  25. */
  26. static getErrorMessage() {
  27. const message = 'Your browser does not support <a href="https://gpuweb.github.io/gpuweb/" style="color:blue">WebGPU</a> yet';
  28. const element = document.createElement( 'div' );
  29. element.id = 'webgpumessage';
  30. element.style.fontFamily = 'monospace';
  31. element.style.fontSize = '13px';
  32. element.style.fontWeight = 'normal';
  33. element.style.textAlign = 'center';
  34. element.style.background = '#fff';
  35. element.style.color = '#000';
  36. element.style.padding = '1.5em';
  37. element.style.maxWidth = '400px';
  38. element.style.margin = '5em auto 0';
  39. element.innerHTML = message;
  40. return element;
  41. }
  42. }
  43. export default WebGPU;