common.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. package wgpu
  2. import "strconv"
  3. // This file contains common types and constants
  4. const (
  5. ArrayLayerCountUndefined = 0xffffffff
  6. CopyStrideUndefined = 0xffffffff
  7. LimitU32Undefined uint32 = 0xffffffff
  8. LimitU64Undefined uint64 = 0xffffffffffffffff
  9. MipLevelCountUndefined = 0xffffffff
  10. WholeMapSize = ^uint(0)
  11. WholeSize = 0xffffffffffffffff
  12. )
  13. type Version uint32
  14. func (v Version) String() string {
  15. return "0x" + strconv.FormatUint(uint64(v), 8)
  16. }
  17. type Limits struct {
  18. MaxTextureDimension1D uint32
  19. MaxTextureDimension2D uint32
  20. MaxTextureDimension3D uint32
  21. MaxTextureArrayLayers uint32
  22. MaxBindGroups uint32
  23. MaxBindingsPerBindGroup uint32
  24. MaxDynamicUniformBuffersPerPipelineLayout uint32
  25. MaxDynamicStorageBuffersPerPipelineLayout uint32
  26. MaxSampledTexturesPerShaderStage uint32
  27. MaxSamplersPerShaderStage uint32
  28. MaxStorageBuffersPerShaderStage uint32
  29. MaxStorageTexturesPerShaderStage uint32
  30. MaxUniformBuffersPerShaderStage uint32
  31. MaxUniformBufferBindingSize uint64
  32. MaxStorageBufferBindingSize uint64
  33. MinUniformBufferOffsetAlignment uint32
  34. MinStorageBufferOffsetAlignment uint32
  35. MaxVertexBuffers uint32
  36. MaxBufferSize uint64
  37. MaxVertexAttributes uint32
  38. MaxVertexBufferArrayStride uint32
  39. MaxInterStageShaderComponents uint32
  40. MaxInterStageShaderVariables uint32
  41. MaxColorAttachments uint32
  42. MaxColorAttachmentBytesPerSample uint32
  43. MaxComputeWorkgroupStorageSize uint32
  44. MaxComputeInvocationsPerWorkgroup uint32
  45. MaxComputeWorkgroupSizeX uint32
  46. MaxComputeWorkgroupSizeY uint32
  47. MaxComputeWorkgroupSizeZ uint32
  48. MaxComputeWorkgroupsPerDimension uint32
  49. MaxPushConstantSize uint32
  50. }
  51. type SupportedLimits struct {
  52. Limits Limits
  53. }
  54. // Color as described:
  55. // https://gpuweb.github.io/gpuweb/#typedefdef-gpucolor
  56. type Color struct {
  57. R, G, B, A float64
  58. }
  59. type Origin3D struct {
  60. X, Y, Z uint32
  61. }
  62. // SurfaceConfiguration, corresponding to GPUCanvasConfiguration:
  63. // https://gpuweb.github.io/gpuweb/#dictdef-gpucanvasconfiguration
  64. type SurfaceConfiguration struct {
  65. Usage TextureUsage
  66. Format TextureFormat
  67. Width uint32
  68. Height uint32
  69. PresentMode PresentMode
  70. AlphaMode CompositeAlphaMode
  71. ViewFormats []TextureFormat
  72. }
  73. type ImageCopyTexture struct {
  74. Texture *Texture
  75. MipLevel uint32
  76. Origin Origin3D
  77. Aspect TextureAspect
  78. }
  79. type TextureDataLayout struct {
  80. Offset uint64
  81. BytesPerRow uint32
  82. RowsPerImage uint32
  83. }
  84. type Extent3D struct {
  85. Width uint32
  86. Height uint32
  87. DepthOrArrayLayers uint32
  88. }
  89. type InstanceDescriptor struct {
  90. Backends InstanceBackend
  91. Dx12ShaderCompiler Dx12Compiler
  92. DxilPath string
  93. DxcPath string
  94. }
  95. type InstanceEnumerateAdapterOptons struct {
  96. Backends InstanceBackend
  97. }
  98. // RequestAdapterOptions as described:
  99. // https://gpuweb.github.io/gpuweb/#dictdef-gpurequestadapteroptions
  100. type RequestAdapterOptions struct {
  101. CompatibleSurface *Surface
  102. PowerPreference PowerPreference
  103. ForceFallbackAdapter bool
  104. BackendType BackendType
  105. }
  106. type SurfaceCapabilities struct {
  107. Formats []TextureFormat
  108. PresentModes []PresentMode
  109. AlphaModes []CompositeAlphaMode
  110. }
  111. type ShaderModuleWGSLDescriptor struct {
  112. Code string
  113. }
  114. type RequiredLimits struct {
  115. Limits Limits
  116. }
  117. type DeviceDescriptor struct {
  118. Label string
  119. RequiredFeatures []FeatureName
  120. RequiredLimits *RequiredLimits
  121. DeviceLostCallback DeviceLostCallback
  122. TracePath string
  123. }
  124. type DeviceLostCallback func(reason DeviceLostReason, message string)
  125. // TextureDescriptor as described:
  126. // https://gpuweb.github.io/gpuweb/#gputexturedescriptor
  127. type TextureDescriptor struct {
  128. Label string
  129. Usage TextureUsage
  130. Dimension TextureDimension
  131. Size Extent3D
  132. Format TextureFormat
  133. MipLevelCount uint32
  134. SampleCount uint32
  135. }
  136. // BufferDescriptor as described:
  137. // https://gpuweb.github.io/gpuweb/#gpubufferdescriptor
  138. type BufferDescriptor struct {
  139. Label string
  140. Usage BufferUsage
  141. Size uint64
  142. MappedAtCreation bool
  143. }
  144. type BufferInitDescriptor struct {
  145. Label string
  146. Contents []byte
  147. Usage BufferUsage
  148. }
  149. type BufferMapCallback func(BufferMapAsyncStatus)
  150. type QueueWorkDoneCallback func(QueueWorkDoneStatus)
  151. // RenderPassDescriptor as described:
  152. // https://gpuweb.github.io/gpuweb/#dictdef-gpurenderpassdescriptor
  153. type RenderPassDescriptor struct {
  154. Label string
  155. ColorAttachments []RenderPassColorAttachment
  156. DepthStencilAttachment *RenderPassDepthStencilAttachment
  157. // unused in wgpu
  158. // OcclusionQuerySet QuerySet
  159. // TimestampWrites []RenderPassTimestampWrite
  160. }
  161. type RenderPassDepthStencilAttachment struct {
  162. View *TextureView
  163. DepthLoadOp LoadOp
  164. DepthStoreOp StoreOp
  165. DepthClearValue float32
  166. DepthReadOnly bool
  167. StencilLoadOp LoadOp
  168. StencilStoreOp StoreOp
  169. StencilClearValue uint32
  170. StencilReadOnly bool
  171. }
  172. // RenderPassColorAttachment as described:
  173. // https://gpuweb.github.io/gpuweb/#dictdef-gpurenderpasscolorattachment
  174. type RenderPassColorAttachment struct {
  175. View *TextureView
  176. ResolveTarget *TextureView
  177. LoadOp LoadOp
  178. StoreOp StoreOp
  179. ClearValue Color
  180. }
  181. // RenderPipelineDescriptor as described:
  182. // https://gpuweb.github.io/gpuweb/#dictdef-gpurenderpipelinedescriptor
  183. type RenderPipelineDescriptor struct {
  184. Label string
  185. Layout *PipelineLayout
  186. Vertex VertexState
  187. Primitive PrimitiveState
  188. DepthStencil *DepthStencilState
  189. Multisample MultisampleState
  190. Fragment *FragmentState
  191. }
  192. type CommandEncoderDescriptor struct {
  193. Label string
  194. }
  195. type TextureViewDescriptor struct {
  196. Label string
  197. Format TextureFormat
  198. Dimension TextureViewDimension
  199. BaseMipLevel uint32
  200. MipLevelCount uint32
  201. BaseArrayLayer uint32
  202. ArrayLayerCount uint32
  203. Aspect TextureAspect
  204. }
  205. type CommandBufferDescriptor struct {
  206. Label string
  207. }
  208. type WrappedSubmissionIndex struct {
  209. Queue *Queue
  210. SubmissionIndex SubmissionIndex
  211. }
  212. type SubmissionIndex uint64
  213. type ImageCopyBuffer struct {
  214. Layout TextureDataLayout
  215. Buffer *Buffer
  216. }
  217. type AdapterInfo struct {
  218. VendorId uint32
  219. VendorName string
  220. Architecture string
  221. DeviceId uint32
  222. Name string
  223. DriverDescription string
  224. AdapterType AdapterType
  225. BackendType BackendType
  226. }
  227. type SamplerDescriptor struct {
  228. Label string
  229. AddressModeU AddressMode
  230. AddressModeV AddressMode
  231. AddressModeW AddressMode
  232. MagFilter FilterMode
  233. MinFilter FilterMode
  234. MipmapFilter MipmapFilterMode
  235. LodMinClamp float32
  236. LodMaxClamp float32
  237. Compare CompareFunction
  238. MaxAnisotropy uint16
  239. }
  240. // BindGroupLayoutDescriptor as described:
  241. // https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutdescriptor
  242. type BindGroupLayoutDescriptor struct {
  243. Label string
  244. Entries []BindGroupLayoutEntry
  245. }
  246. // BindGroupDescriptor as described:
  247. // https://gpuweb.github.io/gpuweb/#dictdef-gpubindgroupdescriptor
  248. type BindGroupDescriptor struct {
  249. Label string
  250. Layout *BindGroupLayout
  251. Entries []BindGroupEntry
  252. }
  253. // BindGroupEntry as described:
  254. // https://gpuweb.github.io/gpuweb/#dictdef-gpubindgroupentry
  255. type BindGroupEntry struct {
  256. Binding uint32
  257. Buffer *Buffer
  258. Offset uint64
  259. Size uint64
  260. Sampler *Sampler
  261. TextureView *TextureView
  262. }
  263. // ProgrammableStageDescriptor as described:
  264. // https://gpuweb.github.io/gpuweb/#gpuprogrammablestage
  265. type ProgrammableStageDescriptor struct {
  266. Module *ShaderModule
  267. EntryPoint string
  268. }