webgpuPipelineContext.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import type { IPipelineContext } from "../IPipelineContext";
  2. import type { Nullable } from "../../types";
  3. import type { WebGPUEngine } from "../webgpuEngine";
  4. import type { Effect } from "../../Materials/effect";
  5. import type { WebGPUShaderProcessingContext } from "./webgpuShaderProcessingContext";
  6. import { UniformBuffer } from "../../Materials/uniformBuffer";
  7. import type { IMatrixLike, IVector2Like, IVector3Like, IVector4Like, IColor3Like, IColor4Like, IQuaternionLike } from "../../Maths/math.like";
  8. /** @internal */
  9. export interface IWebGPURenderPipelineStageDescriptor {
  10. vertexStage: GPUProgrammableStage;
  11. fragmentStage?: GPUProgrammableStage;
  12. }
  13. /** @internal */
  14. export declare class WebGPUPipelineContext implements IPipelineContext {
  15. engine: WebGPUEngine;
  16. shaderProcessingContext: WebGPUShaderProcessingContext;
  17. protected _leftOverUniformsByName: {
  18. [name: string]: string;
  19. };
  20. vertexBufferKindToType: {
  21. [kind: string]: number;
  22. };
  23. sources: {
  24. vertex: string;
  25. fragment: string;
  26. rawVertex: string;
  27. rawFragment: string;
  28. };
  29. stages: Nullable<IWebGPURenderPipelineStageDescriptor>;
  30. bindGroupLayouts: {
  31. [textureState: number]: GPUBindGroupLayout[];
  32. };
  33. /**
  34. * Stores the left-over uniform buffer
  35. */
  36. uniformBuffer: Nullable<UniformBuffer>;
  37. onCompiled?: () => void;
  38. get isAsync(): boolean;
  39. get isReady(): boolean;
  40. /** @internal */
  41. _name: string;
  42. constructor(shaderProcessingContext: WebGPUShaderProcessingContext, engine: WebGPUEngine);
  43. _handlesSpectorRebuildCallback(): void;
  44. _fillEffectInformation(effect: Effect, uniformBuffersNames: {
  45. [key: string]: number;
  46. }, uniformsNames: string[], uniforms: {
  47. [key: string]: Nullable<WebGLUniformLocation>;
  48. }, samplerList: string[], samplers: {
  49. [key: string]: number;
  50. }, attributesNames: string[], attributes: number[]): void;
  51. /** @internal */
  52. /**
  53. * Build the uniform buffer used in the material.
  54. */
  55. buildUniformLayout(): void;
  56. /**
  57. * Release all associated resources.
  58. **/
  59. dispose(): void;
  60. /**
  61. * Sets an integer value on a uniform variable.
  62. * @param uniformName Name of the variable.
  63. * @param value Value to be set.
  64. */
  65. setInt(uniformName: string, value: number): void;
  66. /**
  67. * Sets an int2 value on a uniform variable.
  68. * @param uniformName Name of the variable.
  69. * @param x First int in int2.
  70. * @param y Second int in int2.
  71. */
  72. setInt2(uniformName: string, x: number, y: number): void;
  73. /**
  74. * Sets an int3 value on a uniform variable.
  75. * @param uniformName Name of the variable.
  76. * @param x First int in int3.
  77. * @param y Second int in int3.
  78. * @param z Third int in int3.
  79. */
  80. setInt3(uniformName: string, x: number, y: number, z: number): void;
  81. /**
  82. * Sets an int4 value on a uniform variable.
  83. * @param uniformName Name of the variable.
  84. * @param x First int in int4.
  85. * @param y Second int in int4.
  86. * @param z Third int in int4.
  87. * @param w Fourth int in int4.
  88. */
  89. setInt4(uniformName: string, x: number, y: number, z: number, w: number): void;
  90. /**
  91. * Sets an int array on a uniform variable.
  92. * @param uniformName Name of the variable.
  93. * @param array array to be set.
  94. */
  95. setIntArray(uniformName: string, array: Int32Array): void;
  96. /**
  97. * Sets an int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  98. * @param uniformName Name of the variable.
  99. * @param array array to be set.
  100. */
  101. setIntArray2(uniformName: string, array: Int32Array): void;
  102. /**
  103. * Sets an int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  104. * @param uniformName Name of the variable.
  105. * @param array array to be set.
  106. */
  107. setIntArray3(uniformName: string, array: Int32Array): void;
  108. /**
  109. * Sets an int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  110. * @param uniformName Name of the variable.
  111. * @param array array to be set.
  112. */
  113. setIntArray4(uniformName: string, array: Int32Array): void;
  114. /**
  115. * Sets an unsigned integer value on a uniform variable.
  116. * @param uniformName Name of the variable.
  117. * @param value Value to be set.
  118. */
  119. setUInt(uniformName: string, value: number): void;
  120. /**
  121. * Sets an unsigned int2 value on a uniform variable.
  122. * @param uniformName Name of the variable.
  123. * @param x First unsigned int in uint2.
  124. * @param y Second unsigned int in uint2.
  125. */
  126. setUInt2(uniformName: string, x: number, y: number): void;
  127. /**
  128. * Sets an unsigned int3 value on a uniform variable.
  129. * @param uniformName Name of the variable.
  130. * @param x First unsigned int in uint3.
  131. * @param y Second unsigned int in uint3.
  132. * @param z Third unsigned int in uint3.
  133. */
  134. setUInt3(uniformName: string, x: number, y: number, z: number): void;
  135. /**
  136. * Sets an unsigned int4 value on a uniform variable.
  137. * @param uniformName Name of the variable.
  138. * @param x First unsigned int in uint4.
  139. * @param y Second unsigned int in uint4.
  140. * @param z Third unsigned int in uint4.
  141. * @param w Fourth unsigned int in uint4.
  142. */
  143. setUInt4(uniformName: string, x: number, y: number, z: number, w: number): void;
  144. /**
  145. * Sets an unsigned int array on a uniform variable.
  146. * @param uniformName Name of the variable.
  147. * @param array array to be set.
  148. */
  149. setUIntArray(uniformName: string, array: Uint32Array): void;
  150. /**
  151. * Sets an unsigned int array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  152. * @param uniformName Name of the variable.
  153. * @param array array to be set.
  154. */
  155. setUIntArray2(uniformName: string, array: Uint32Array): void;
  156. /**
  157. * Sets an unsigned int array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  158. * @param uniformName Name of the variable.
  159. * @param array array to be set.
  160. */
  161. setUIntArray3(uniformName: string, array: Uint32Array): void;
  162. /**
  163. * Sets an unsigned int array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  164. * @param uniformName Name of the variable.
  165. * @param array array to be set.
  166. */
  167. setUIntArray4(uniformName: string, array: Uint32Array): void;
  168. /**
  169. * Sets an array on a uniform variable.
  170. * @param uniformName Name of the variable.
  171. * @param array array to be set.
  172. */
  173. setArray(uniformName: string, array: number[]): void;
  174. /**
  175. * Sets an array 2 on a uniform variable. (Array is specified as single array eg. [1,2,3,4] will result in [[1,2],[3,4]] in the shader)
  176. * @param uniformName Name of the variable.
  177. * @param array array to be set.
  178. */
  179. setArray2(uniformName: string, array: number[]): void;
  180. /**
  181. * Sets an array 3 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6] will result in [[1,2,3],[4,5,6]] in the shader)
  182. * @param uniformName Name of the variable.
  183. * @param array array to be set.
  184. */
  185. setArray3(uniformName: string, array: number[]): void;
  186. /**
  187. * Sets an array 4 on a uniform variable. (Array is specified as single array eg. [1,2,3,4,5,6,7,8] will result in [[1,2,3,4],[5,6,7,8]] in the shader)
  188. * @param uniformName Name of the variable.
  189. * @param array array to be set.
  190. */
  191. setArray4(uniformName: string, array: number[]): void;
  192. /**
  193. * Sets matrices on a uniform variable.
  194. * @param uniformName Name of the variable.
  195. * @param matrices matrices to be set.
  196. */
  197. setMatrices(uniformName: string, matrices: Float32Array): void;
  198. /**
  199. * Sets matrix on a uniform variable.
  200. * @param uniformName Name of the variable.
  201. * @param matrix matrix to be set.
  202. */
  203. setMatrix(uniformName: string, matrix: IMatrixLike): void;
  204. /**
  205. * Sets a 3x3 matrix on a uniform variable. (Specified as [1,2,3,4,5,6,7,8,9] will result in [1,2,3][4,5,6][7,8,9] matrix)
  206. * @param uniformName Name of the variable.
  207. * @param matrix matrix to be set.
  208. */
  209. setMatrix3x3(uniformName: string, matrix: Float32Array): void;
  210. /**
  211. * Sets a 2x2 matrix on a uniform variable. (Specified as [1,2,3,4] will result in [1,2][3,4] matrix)
  212. * @param uniformName Name of the variable.
  213. * @param matrix matrix to be set.
  214. */
  215. setMatrix2x2(uniformName: string, matrix: Float32Array): void;
  216. /**
  217. * Sets a float on a uniform variable.
  218. * @param uniformName Name of the variable.
  219. * @param value value to be set.
  220. */
  221. setFloat(uniformName: string, value: number): void;
  222. /**
  223. * Sets a Vector2 on a uniform variable.
  224. * @param uniformName Name of the variable.
  225. * @param vector2 vector2 to be set.
  226. */
  227. setVector2(uniformName: string, vector2: IVector2Like): void;
  228. /**
  229. * Sets a float2 on a uniform variable.
  230. * @param uniformName Name of the variable.
  231. * @param x First float in float2.
  232. * @param y Second float in float2.
  233. */
  234. setFloat2(uniformName: string, x: number, y: number): void;
  235. /**
  236. * Sets a Vector3 on a uniform variable.
  237. * @param uniformName Name of the variable.
  238. * @param vector3 Value to be set.
  239. */
  240. setVector3(uniformName: string, vector3: IVector3Like): void;
  241. /**
  242. * Sets a float3 on a uniform variable.
  243. * @param uniformName Name of the variable.
  244. * @param x First float in float3.
  245. * @param y Second float in float3.
  246. * @param z Third float in float3.
  247. */
  248. setFloat3(uniformName: string, x: number, y: number, z: number): void;
  249. /**
  250. * Sets a Vector4 on a uniform variable.
  251. * @param uniformName Name of the variable.
  252. * @param vector4 Value to be set.
  253. */
  254. setVector4(uniformName: string, vector4: IVector4Like): void;
  255. /**
  256. * Sets a Quaternion on a uniform variable.
  257. * @param uniformName Name of the variable.
  258. * @param quaternion Value to be set.
  259. */
  260. setQuaternion(uniformName: string, quaternion: IQuaternionLike): void;
  261. /**
  262. * Sets a float4 on a uniform variable.
  263. * @param uniformName Name of the variable.
  264. * @param x First float in float4.
  265. * @param y Second float in float4.
  266. * @param z Third float in float4.
  267. * @param w Fourth float in float4.
  268. */
  269. setFloat4(uniformName: string, x: number, y: number, z: number, w: number): void;
  270. /**
  271. * Sets a Color3 on a uniform variable.
  272. * @param uniformName Name of the variable.
  273. * @param color3 Value to be set.
  274. */
  275. setColor3(uniformName: string, color3: IColor3Like): void;
  276. /**
  277. * Sets a Color4 on a uniform variable.
  278. * @param uniformName Name of the variable.
  279. * @param color3 Value to be set.
  280. * @param alpha Alpha value to be set.
  281. */
  282. setColor4(uniformName: string, color3: IColor3Like, alpha: number): void;
  283. /**
  284. * Sets a Color4 on a uniform variable
  285. * @param uniformName defines the name of the variable
  286. * @param color4 defines the value to be set
  287. */
  288. setDirectColor4(uniformName: string, color4: IColor4Like): void;
  289. _getVertexShaderCode(): string | null;
  290. _getFragmentShaderCode(): string | null;
  291. }