engine.computeShader.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from "../../Compute/computeEffect";
  2. import type { IComputeContext } from "../../Compute/IComputeContext";
  3. import type { IComputePipelineContext } from "../../Compute/IComputePipelineContext";
  4. import type { Nullable } from "../../types";
  5. import type { WebGPUPerfCounter } from "../WebGPU/webgpuPerfCounter";
  6. import type { DataBuffer } from "../../Buffers/dataBuffer";
  7. /**
  8. * Type used to locate a resource in a compute shader.
  9. * TODO: remove this when browsers support reflection for wgsl shaders
  10. */
  11. export type ComputeBindingLocation = {
  12. group: number;
  13. binding: number;
  14. };
  15. /**
  16. * Type used to lookup a resource and retrieve its binding location
  17. * TODO: remove this when browsers support reflection for wgsl shaders
  18. */
  19. export type ComputeBindingMapping = {
  20. [key: string]: ComputeBindingLocation;
  21. };
  22. /**
  23. * Types of messages that can be generated during compilation
  24. */
  25. export type ComputeCompilationMessageType = "error" | "warning" | "info";
  26. /**
  27. * Messages generated during compilation
  28. */
  29. export interface ComputeCompilationMessages {
  30. /**
  31. * Number of errors generated during compilation
  32. */
  33. numErrors: number;
  34. /**
  35. * List of messages generated during compilation
  36. */
  37. messages: {
  38. type: ComputeCompilationMessageType;
  39. text: string;
  40. line?: number;
  41. column?: number;
  42. length?: number;
  43. offset?: number;
  44. }[];
  45. }
  46. /** @internal */
  47. export declare enum ComputeBindingType {
  48. Texture = 0,
  49. StorageTexture = 1,
  50. UniformBuffer = 2,
  51. StorageBuffer = 3,
  52. TextureWithoutSampler = 4,
  53. Sampler = 5,
  54. ExternalTexture = 6,
  55. DataBuffer = 7
  56. }
  57. /** @internal */
  58. export type ComputeBindingList = {
  59. [key: string]: {
  60. type: ComputeBindingType;
  61. object: any;
  62. indexInGroupEntries?: number;
  63. };
  64. };
  65. declare module "../../Engines/abstractEngine" {
  66. interface AbstractEngine {
  67. /**
  68. * Creates a new compute effect
  69. * @param baseName Name of the effect
  70. * @param options Options used to create the effect
  71. * @returns The new compute effect
  72. */
  73. createComputeEffect(baseName: string | (IComputeShaderPath & {
  74. /**
  75. * @internal
  76. */
  77. computeToken?: string;
  78. }), options: IComputeEffectCreationOptions): ComputeEffect;
  79. /**
  80. * Creates a new compute pipeline context
  81. * @returns the new pipeline
  82. */
  83. createComputePipelineContext(): IComputePipelineContext;
  84. /**
  85. * Creates a new compute context
  86. * @returns the new context
  87. */
  88. createComputeContext(): IComputeContext | undefined;
  89. /**
  90. * Dispatches a compute shader
  91. * @param effect The compute effect
  92. * @param context The compute context
  93. * @param bindings The list of resources to bind to the shader
  94. * @param x The number of workgroups to execute on the X dimension
  95. * @param y The number of workgroups to execute on the Y dimension
  96. * @param z The number of workgroups to execute on the Z dimension
  97. * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)
  98. * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object
  99. */
  100. computeDispatch(effect: ComputeEffect, context: IComputeContext, bindings: ComputeBindingList, x: number, y?: number, z?: number, bindingsMapping?: ComputeBindingMapping, gpuPerfCounter?: WebGPUPerfCounter): void;
  101. /**
  102. * Dispatches a compute shader
  103. * @param effect The compute effect
  104. * @param context The compute context
  105. * @param bindings The list of resources to bind to the shader
  106. * @param x The number of workgroups to execute on the X dimension
  107. * @param y The number of workgroups to execute on the Y dimension
  108. * @param z The number of workgroups to execute on the Z dimension
  109. * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)
  110. * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object
  111. */
  112. computeDispatchIndirect(effect: ComputeEffect, context: IComputeContext, bindings: ComputeBindingList, buffer: DataBuffer, offset?: number, bindingsMapping?: ComputeBindingMapping, gpuPerfCounter?: WebGPUPerfCounter): void;
  113. /**
  114. * Gets a boolean indicating if all created compute effects are ready
  115. * @returns true if all effects are ready
  116. */
  117. areAllComputeEffectsReady(): boolean;
  118. /**
  119. * Forces the engine to release all cached compute effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled
  120. */
  121. releaseComputeEffects(): void;
  122. /** @internal */
  123. _prepareComputePipelineContext(pipelineContext: IComputePipelineContext, computeSourceCode: string, rawComputeSourceCode: string, defines: Nullable<string>, entryPoint: string): void;
  124. /** @internal */
  125. _rebuildComputeEffects(): void;
  126. /** @internal */
  127. _executeWhenComputeStateIsCompiled(pipelineContext: IComputePipelineContext, action: (messages: Nullable<ComputeCompilationMessages>) => void): void;
  128. /** @internal */
  129. _releaseComputeEffect(effect: ComputeEffect): void;
  130. /** @internal */
  131. _deleteComputePipelineContext(pipelineContext: IComputePipelineContext): void;
  132. }
  133. }