WebGPU.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. */
  10. class WebGPU {
  11. /**
  12. * Returns `true` if WebGPU is available.
  13. *
  14. * @return {boolean} Whether WebGPU is available or not.
  15. */
  16. static isAvailable() {
  17. return Boolean( isAvailable );
  18. }
  19. /**
  20. * Returns a `div` element representing a formatted error message that can be appended in
  21. * web sites if WebGPU isn't supported.
  22. *
  23. * @return {HTMLDivElement} A `div` element representing a formatted error message that WebGPU isn't supported.
  24. */
  25. static getErrorMessage() {
  26. const message = 'Your browser does not support <a href="https://gpuweb.github.io/gpuweb/" style="color:blue">WebGPU</a> yet';
  27. const element = document.createElement( 'div' );
  28. element.id = 'webgpumessage';
  29. element.style.fontFamily = 'monospace';
  30. element.style.fontSize = '13px';
  31. element.style.fontWeight = 'normal';
  32. element.style.textAlign = 'center';
  33. element.style.background = '#fff';
  34. element.style.color = '#000';
  35. element.style.padding = '1.5em';
  36. element.style.maxWidth = '400px';
  37. element.style.margin = '5em auto 0';
  38. element.innerHTML = message;
  39. return element;
  40. }
  41. }
  42. export default WebGPU;
粤ICP备19079148号