├── .gitattributes ├── src └── Web │ └── GPU │ ├── GPUExternalTexture.js │ ├── GPUCommandBuffer.purs │ ├── GPUSampler.purs │ ├── GPUBindGroup.purs │ ├── GPUShaderModule.js │ ├── GPUTextureView.purs │ ├── GPURenderBundle.purs │ ├── GPUPipelineLayout.purs │ ├── GPURenderPipeline.purs │ ├── Navigator.js │ ├── GPUBindGroupLayout.purs │ ├── GPUComputePipeline.purs │ ├── GPUPipelineBase.js │ ├── Internal │ ├── RequiredAndOptional.js │ ├── Bitwise.purs │ ├── Types.purs │ └── RequiredAndOptional.purs │ ├── GPUMapMode.js │ ├── HTMLCanvasElement.js │ ├── GPUQuerySet.js │ ├── GPU.js │ ├── GPUCanvasContext.js │ ├── GPUShaderStage.js │ ├── GPURenderBundleDescriptor.purs │ ├── GPUCommandEncoderDescriptor.purs │ ├── GPUExternalTextureBindingLayout.purs │ ├── GPULoadOp.purs │ ├── GPUFragmentState.purs │ ├── GPUVertexState.purs │ ├── GPUColorWrite.js │ ├── GPUFrontFace.purs │ ├── GPUBlendState.purs │ ├── GPUStorageTextureAccess.purs │ ├── GPUStoreOp.purs │ ├── GPUSamplerBindingLayout.purs │ ├── GPUExternalTexture.purs │ ├── GPUBufferMapState.purs │ ├── GPUVertexStepMode.purs │ ├── GPUCullMode.purs │ ├── Navigator.purs │ ├── GPUFilterMode.purs │ ├── GPUIndexFormat.purs │ ├── GPUQueryType.purs │ ├── GPUColor.purs │ ├── GPUMapMode.purs │ ├── GPUShaderModuleCompilationHint.purs │ ├── GPUPipelineLayoutDescriptor.purs │ ├── GPUQuerySetDescriptor.purs │ ├── GPUImageDataLayout.purs │ ├── GPUBindGroupLayoutDescriptor.purs │ ├── GPURequestAdapterOptions.purs │ ├── GPUComputePassDescriptor.purs │ ├── GPUImageCopyTextureTagged.purs │ ├── GPUMultisampleState.purs │ ├── GPUBufferDescriptor.purs │ ├── GPUMipmapFilterMode.purs │ ├── GPUCanvasAlphaMode.purs │ ├── PredefinedColorSpace.purs │ ├── UnmaskHint.purs │ ├── GPURenderPassTimestampLocation.purs │ ├── GPUBindGroupDescriptor.purs │ ├── GPUBlendComponent.purs │ ├── GPUExternalTextureDescriptor.purs │ ├── GPUPowerPreference.purs │ ├── GPUVertexAttribute.purs │ ├── GPUBufferBindingLayout.purs │ ├── GPUImageCopyBuffer.purs │ ├── GPUComputePipelineDescriptor.purs │ ├── GPUTextureUsage.js │ ├── HTMLCanvasElement.purs │ ├── GPUAddressMode.purs │ ├── GPUImageCopyExternalImage.purs │ ├── GPUSamplerBindingType.purs │ ├── GPUTextureAspect.purs │ ├── GPUTextureDimension.purs │ ├── GPUVertexBufferLayout.purs │ ├── GPUColorTargetState.purs │ ├── GPUTextureBindingLayout.purs │ ├── GPUStencilFaceState.purs │ ├── GPUAdapter.js │ ├── GPUProgrammableStage.purs │ ├── GPUShaderModuleDescriptor.purs │ ├── GPUComputePassTimestampLocation.purs │ ├── GPUBlendOperation.purs │ ├── GPUBufferBindingType.purs │ ├── GPUShaderStage.purs │ ├── GPURenderPassTimestampWrite.purs │ ├── GPUComputePassTimestampWrite.purs │ ├── GPUImageCopyTexture.purs │ ├── GPUStorageTextureBindingLayout.purs │ ├── GPUPrimitiveState.purs │ ├── GPUTexture.js │ ├── GPURenderPassColorAttachment.purs │ ├── GPUColorWrite.purs │ ├── GPUOrigin2D.purs │ ├── GPURenderBundleEncoderDescriptor.purs │ ├── GPUPrimitiveTopology.purs │ ├── GPUCompareFunction.purs │ ├── GPUPipelineBase.purs │ ├── GPUTextureViewDimension.purs │ ├── GPUTextureSampleType.purs │ ├── GPUTextureUsage.purs │ ├── GPUCanvasConfiguration.purs │ ├── GPUQuerySet.purs │ ├── GPUDeviceDescriptor.purs │ ├── GPUExtent3D.purs │ ├── GPUTextureDescriptor.purs │ ├── GPUTextureViewDescriptor.purs │ ├── GPUImageCopyExternalImageSource.purs │ ├── GPURenderPipelineDescriptor.purs │ ├── GPURenderPassDepthStencilAttachment.purs │ ├── GPUDepthStencilState.purs │ ├── GPURenderPassDescriptor.purs │ ├── GPUOrigin3D.purs │ ├── GPUSamplerDescriptor.purs │ ├── GPUBufferUsage.js │ ├── GPUBuffer.js │ ├── GPUBufferUsage.purs │ ├── GPUStencilOperation.purs │ ├── GPUQueue.js │ ├── GPU.purs │ ├── GPUBlendFactor.purs │ ├── GPUFeatureName.purs │ ├── GPUCanvasContext.purs │ ├── GPUBindGroupEntry.purs │ ├── GPUShaderModule.purs │ ├── GPUBindGroupLayoutEntry.purs │ ├── GPUSupportedLimits.purs │ ├── GPUComputePassEncoder.js │ ├── BufferSource.purs │ ├── GPUCommandEncoder.js │ ├── GPUAdapter.purs │ ├── GPUVertexFormat.purs │ ├── GPUDevice.js │ ├── GPUTexture.purs │ ├── GPUQueue.purs │ ├── GPUBuffer.purs │ ├── GPUComputePassEncoder.purs │ ├── GPUCommandEncoder.purs │ ├── GPUTextureFormat.purs │ ├── GPUDevice.purs │ ├── GPURenderBundleEncoder.js │ ├── GPURenderPassEncoder.js │ └── GPURenderBundleEncoder.purs ├── sandbox.dhall ├── sandbox ├── index.js └── index.html ├── .gitignore ├── .tidyrc.json ├── sandbox-dev.dhall ├── spago.dhall ├── test └── Types │ └── RequiredAndOptional.purs ├── README.md ├── package.json ├── apply-backend-es-annotations.py └── packages.dhall /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUExternalTexture.js: -------------------------------------------------------------------------------- 1 | export const expiredImpl = texture => texture.expired; 2 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUCommandBuffer.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.Internal.GPUCommandBuffer where 2 | 3 | data GPUCommandBuffer -------------------------------------------------------------------------------- /src/Web/GPU/GPUSampler.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUSampler 2 | ( GPUSampler 3 | ) where 4 | 5 | data GPUSampler -------------------------------------------------------------------------------- /src/Web/GPU/GPUBindGroup.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBindGroup 2 | ( GPUBindGroup 3 | ) where 4 | 5 | data GPUBindGroup -------------------------------------------------------------------------------- /src/Web/GPU/GPUShaderModule.js: -------------------------------------------------------------------------------- 1 | export const compilationInfoImpl = shaderModule => 2 | shaderModule.compilationInfo(); 3 | -------------------------------------------------------------------------------- /sandbox.dhall: -------------------------------------------------------------------------------- 1 | let conf = ./sandbox-dev.dhall 2 | 3 | in conf 4 | // { backend = "purs-backend-es build" 5 | } -------------------------------------------------------------------------------- /sandbox/index.js: -------------------------------------------------------------------------------- 1 | import { main } from "../output/Sandbox" // find way to do vite alias on windows, seems broken... 2 | main(); -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureView.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureView 2 | ( GPUTextureView 3 | ) where 4 | 5 | data GPUTextureView -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderBundle.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderBundle 2 | ( GPURenderBundle 3 | ) where 4 | 5 | data GPURenderBundle -------------------------------------------------------------------------------- /src/Web/GPU/GPUPipelineLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUPipelineLayout 2 | ( GPUPipelineLayout 3 | ) where 4 | 5 | data GPUPipelineLayout -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPipeline.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderPipeline 2 | ( GPURenderPipeline 3 | ) where 4 | 5 | data GPURenderPipeline -------------------------------------------------------------------------------- /src/Web/GPU/Navigator.js: -------------------------------------------------------------------------------- 1 | export const gpuImpl = (just, nothing, navigator) => 2 | navigator.gpu ? just(navigator.gpu) : nothing; 3 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBindGroupLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBindGroupLayout 2 | ( GPUBindGroupLayout 3 | ) where 4 | 5 | data GPUBindGroupLayout -------------------------------------------------------------------------------- /src/Web/GPU/GPUComputePipeline.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUComputePipeline 2 | ( GPUComputePipeline 3 | ) where 4 | 5 | data GPUComputePipeline -------------------------------------------------------------------------------- /src/Web/GPU/GPUPipelineBase.js: -------------------------------------------------------------------------------- 1 | export const unsafeGetBindGroupLayoutImpl = (pipeline, index) => 2 | pipeline.getBindGroupLayout(index); 3 | -------------------------------------------------------------------------------- /src/Web/GPU/Internal/RequiredAndOptional.js: -------------------------------------------------------------------------------- 1 | export const requiredAndOptionalImpl = (required, optional) => ({ 2 | ...required, 3 | ...optional, 4 | }); 5 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUMapMode.js: -------------------------------------------------------------------------------- 1 | export const read = window.GPUMapMode ? window.GPUMapMode.READ : 0x0000; 2 | export const write = window.GPUMapMode ? window.GPUMapMode.WRITE : 0x0000; 3 | -------------------------------------------------------------------------------- /src/Web/GPU/HTMLCanvasElement.js: -------------------------------------------------------------------------------- 1 | export const getContextImpl = (just, nothing, canvas) => { 2 | const o = canvas.getContext("webgpu"); 3 | return o ? just(o) : nothing; 4 | }; 5 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUQuerySet.js: -------------------------------------------------------------------------------- 1 | export const destroyImpl = querySet => querySet.destroy(); 2 | export const typeImpl = querySet => querySet.type; 3 | export const countImpl = querySet => querySet.count; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc-package/ 7 | /.psc* 8 | /.purs* 9 | /.psa* 10 | /.spago 11 | /sandbox/dist 12 | /output-es -------------------------------------------------------------------------------- /.tidyrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "importSort": "source", 3 | "importWrap": "source", 4 | "indent": 2, 5 | "operatorsFile": null, 6 | "ribbon": 1, 7 | "typeArrowPlacement": "first", 8 | "unicode": "source", 9 | "width": 80 10 | } -------------------------------------------------------------------------------- /src/Web/GPU/GPU.js: -------------------------------------------------------------------------------- 1 | export const requestAdapterImpl = (just, nothing, gpu, options) => 2 | gpu.requestAdapter(options).then(o => (o ? just(o) : nothing)); 3 | 4 | export const getPreferredCanvasFormatImpl = gpu => 5 | gpu.getPreferredCanvasFormat(); 6 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUCanvasContext.js: -------------------------------------------------------------------------------- 1 | export const canvasImpl = context => context.canvas; 2 | export const configureImpl = (context, descriptor) => 3 | context.configure(descriptor); 4 | export const unconfigureImpl = context => context.unconfigure(); 5 | export const getCurrentTextureImpl = context => context.getCurrentTexture(); 6 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUShaderStage.js: -------------------------------------------------------------------------------- 1 | export const vertex = window.GPUShaderStage 2 | ? window.GPUShaderStage.VERTEX 3 | : 0x0000; 4 | export const fragment = window.GPUShaderStage 5 | ? window.GPUShaderStage.FRAGMENT 6 | : 0x0000; 7 | export const compute = window.GPUShaderStage 8 | ? window.GPUShaderStage.COMPUTE 9 | : 0x0000; 10 | -------------------------------------------------------------------------------- /sandbox-dev.dhall: -------------------------------------------------------------------------------- 1 | let conf = ./spago.dhall 2 | 3 | in conf 4 | // { sources = conf.sources # [ "sandbox/**/*.purs" ] 5 | , dependencies = conf.dependencies # [ "aff", "arrays", "refs", "st", "console", "js-date", "gl-matrix", "numbers", "aff-promise", "arraybuffer", "control", "float32", "foldable-traversable", "uint", "web-dom" ] 6 | } -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderBundleDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderBundleDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 5 | 6 | newtype GPURenderBundleDescriptor = GPURenderBundleDescriptor 7 | (RequiredAndOptional () (label :: String)) 8 | 9 | derive instance Newtype GPURenderBundleDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUCommandEncoderDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUCommandEncoderDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 5 | 6 | newtype GPUCommandEncoderDescriptor = GPUCommandEncoderDescriptor 7 | (RequiredAndOptional () (label :: String)) 8 | 9 | derive instance Newtype GPUCommandEncoderDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUExternalTextureBindingLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUExternalTextureBindingLayout where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 5 | 6 | newtype GPUExternalTextureBindingLayout = GPUExternalTextureBindingLayout 7 | (RequiredAndOptional () ()) 8 | 9 | derive instance Newtype GPUExternalTextureBindingLayout _ -------------------------------------------------------------------------------- /src/Web/GPU/Internal/Bitwise.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.Internal.Bitwise (class Bitwise, or, (.|.)) where 2 | 3 | import Data.Int.Bits as IntBits 4 | import Data.UInt (UInt) 5 | import Data.UInt as UIntBits 6 | 7 | class Bitwise a where 8 | or :: a -> a -> a 9 | 10 | instance Bitwise Int where 11 | or = IntBits.or 12 | 13 | instance Bitwise UInt where 14 | or = UIntBits.or 15 | 16 | infixl 10 or as .|. -------------------------------------------------------------------------------- /src/Web/GPU/GPULoadOp.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPULoadOp 2 | ( GPULoadOp 3 | , clear 4 | , load 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPULoadOp = GPULoadOp String 10 | 11 | derive instance Eq GPULoadOp 12 | derive instance Ord GPULoadOp 13 | derive newtype instance Show GPULoadOp 14 | 15 | load :: GPULoadOp 16 | load = GPULoadOp "load" 17 | 18 | clear :: GPULoadOp 19 | clear = GPULoadOp "clear" -------------------------------------------------------------------------------- /src/Web/GPU/GPUFragmentState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUFragmentState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUColorTargetState (GPUColorTargetState) 5 | import Web.GPU.GPUProgrammableStage (MakeGPUProgrammableStage) 6 | 7 | newtype GPUFragmentState = GPUFragmentState 8 | (MakeGPUProgrammableStage (targets :: Array GPUColorTargetState) ()) 9 | 10 | derive instance Newtype GPUFragmentState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUVertexState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUVertexState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUProgrammableStage (MakeGPUProgrammableStage) 5 | import Web.GPU.GPUVertexBufferLayout (GPUVertexBufferLayout) 6 | 7 | newtype GPUVertexState = GPUVertexState 8 | (MakeGPUProgrammableStage () (buffers :: Array GPUVertexBufferLayout)) 9 | 10 | derive instance Newtype GPUVertexState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUColorWrite.js: -------------------------------------------------------------------------------- 1 | export const red = window.GPUColorWrite ? window.GPUColorWrite.RED : 0x0000; 2 | export const green = window.GPUColorWrite ? window.GPUColorWrite.GREEN : 0x0000; 3 | export const blue = window.GPUColorWrite ? window.GPUColorWrite.BLUE : 0x0000; 4 | export const alpha = window.GPUColorWrite ? window.GPUColorWrite.ALPHA : 0x0000; 5 | export const all = window.GPUColorWrite ? window.GPUColorWrite.ALL : 0x0000; 6 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUFrontFace.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUFrontFace 2 | ( GPUFrontFace 3 | , cw 4 | , ccw 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUFrontFace = GPUFrontFace String 10 | 11 | derive instance Eq GPUFrontFace 12 | derive instance Ord GPUFrontFace 13 | derive newtype instance Show GPUFrontFace 14 | 15 | ccw :: GPUFrontFace 16 | ccw = GPUFrontFace "ccw" 17 | 18 | cw :: GPUFrontFace 19 | cw = GPUFrontFace "cw" -------------------------------------------------------------------------------- /src/Web/GPU/GPUBlendState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBlendState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBlendComponent (GPUBlendComponent) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | 7 | newtype GPUBlendState = GPUBlendState 8 | ( RequiredAndOptional (color :: GPUBlendComponent, alpha :: GPUBlendComponent) 9 | () 10 | ) 11 | 12 | derive instance Newtype GPUBlendState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUStorageTextureAccess.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUStorageTextureAccess where 2 | 3 | import Prelude 4 | 5 | newtype GPUStorageTextureAccess = GPUStorageTextureAccess String 6 | 7 | derive instance Eq GPUStorageTextureAccess 8 | derive instance Ord GPUStorageTextureAccess 9 | derive newtype instance Show GPUStorageTextureAccess 10 | 11 | writeOnly :: GPUStorageTextureAccess 12 | writeOnly = GPUStorageTextureAccess "write-only" -------------------------------------------------------------------------------- /src/Web/GPU/GPUStoreOp.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUStoreOp 2 | ( GPUStoreOp 3 | , discard 4 | , store 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUStoreOp = GPUStoreOp String 10 | 11 | derive instance Eq GPUStoreOp 12 | derive instance Ord GPUStoreOp 13 | derive newtype instance Show GPUStoreOp 14 | 15 | store :: GPUStoreOp 16 | store = GPUStoreOp "store" 17 | 18 | discard :: GPUStoreOp 19 | discard = GPUStoreOp "discard" -------------------------------------------------------------------------------- /src/Web/GPU/GPUSamplerBindingLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUSamplerBindingLayout where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUSamplerBindingType (GPUSamplerBindingType) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | 7 | newtype GPUSamplerBindingLayout = GPUSamplerBindingLayout 8 | (RequiredAndOptional () (type :: GPUSamplerBindingType)) 9 | 10 | derive instance Newtype GPUSamplerBindingLayout _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUExternalTexture.purs: -------------------------------------------------------------------------------- 1 | -- @inline export expired arity=1 2 | module Web.GPU.GPUExternalTexture 3 | ( GPUExternalTexture 4 | , expired 5 | ) where 6 | 7 | import Effect (Effect) 8 | import Effect.Uncurried(EffectFn1, runEffectFn1) 9 | 10 | data GPUExternalTexture 11 | 12 | foreign import expiredImpl :: EffectFn1 GPUExternalTexture Boolean 13 | expired :: GPUExternalTexture -> Effect Boolean 14 | expired a = runEffectFn1 expiredImpl a -------------------------------------------------------------------------------- /spago.dhall: -------------------------------------------------------------------------------- 1 | { name = "webgpu" 2 | , dependencies = 3 | [ "arraybuffer-types" 4 | , "effect" 5 | , "foreign" 6 | , "foreign-object" 7 | , "functions" 8 | , "integers" 9 | , "js-promise" 10 | , "maybe" 11 | , "newtype" 12 | , "ordered-collections" 13 | , "prelude" 14 | , "uint" 15 | , "unsafe-coerce" 16 | , "web-events" 17 | , "web-html" 18 | ] 19 | , packages = ./packages.dhall 20 | , sources = [ "src/**/*.purs" ] 21 | } 22 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBufferMapState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBufferMapState 2 | ( GPUBufferMapState 3 | , mapped 4 | , pending 5 | , unmapped 6 | ) where 7 | 8 | newtype GPUBufferMapState = GPUBufferMapState String 9 | 10 | unmapped :: GPUBufferMapState 11 | unmapped = GPUBufferMapState "unmapped" 12 | 13 | pending :: GPUBufferMapState 14 | pending = GPUBufferMapState "pending" 15 | 16 | mapped :: GPUBufferMapState 17 | mapped = GPUBufferMapState "mapped" -------------------------------------------------------------------------------- /src/Web/GPU/GPUVertexStepMode.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUVertexStepMode where 2 | 3 | import Prelude 4 | 5 | newtype GPUVertexStepMode = GPUVertexStepMode String 6 | 7 | derive instance Eq GPUVertexStepMode 8 | derive instance Ord GPUVertexStepMode 9 | derive newtype instance Show GPUVertexStepMode 10 | 11 | vertex :: GPUVertexStepMode 12 | vertex = GPUVertexStepMode "vertex" 13 | 14 | instance' :: GPUVertexStepMode 15 | instance' = GPUVertexStepMode "instance" -------------------------------------------------------------------------------- /src/Web/GPU/GPUCullMode.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUCullMode 2 | ( GPUCullMode 3 | , back 4 | , front 5 | , none 6 | ) where 7 | 8 | import Prelude 9 | 10 | newtype GPUCullMode = GPUCullMode String 11 | 12 | derive instance Eq GPUCullMode 13 | derive instance Ord GPUCullMode 14 | derive newtype instance Show GPUCullMode 15 | 16 | none = GPUCullMode "none" :: GPUCullMode 17 | front = GPUCullMode "front" :: GPUCullMode 18 | back = GPUCullMode "back" :: GPUCullMode -------------------------------------------------------------------------------- /src/Web/GPU/Navigator.purs: -------------------------------------------------------------------------------- 1 | -- @inline export gpu arity=4 2 | module Web.GPU.Navigator (gpu) where 3 | 4 | import Data.Maybe (Maybe(..)) 5 | import Effect.Uncurried(EffectFn3, runEffectFn3) 6 | import Effect (Effect) 7 | import Web.GPU.GPU (GPU) 8 | import Web.HTML.Navigator (Navigator) 9 | 10 | foreign import gpuImpl :: EffectFn3 (GPU -> Maybe GPU) (Maybe GPU) Navigator (Maybe GPU) 11 | gpu :: Navigator -> Effect (Maybe GPU) 12 | gpu a = runEffectFn3 gpuImpl Just Nothing a -------------------------------------------------------------------------------- /src/Web/GPU/GPUFilterMode.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUFilterMode 2 | ( GPUFilterMode 3 | , linear 4 | , nearest 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUFilterMode = GPUFilterMode String 10 | 11 | derive instance Eq GPUFilterMode 12 | derive instance Ord GPUFilterMode 13 | derive newtype instance Show GPUFilterMode 14 | 15 | nearest :: GPUFilterMode 16 | nearest = GPUFilterMode "nearest" 17 | 18 | linear :: GPUFilterMode 19 | linear = GPUFilterMode "linear" -------------------------------------------------------------------------------- /src/Web/GPU/GPUIndexFormat.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUIndexFormat 2 | ( GPUIndexFormat 3 | , uint16 4 | , uint32 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUIndexFormat = GPUIndexFormat String 10 | 11 | derive instance Eq GPUIndexFormat 12 | derive instance Ord GPUIndexFormat 13 | derive newtype instance Show GPUIndexFormat 14 | 15 | uint16 :: GPUIndexFormat 16 | uint16 = GPUIndexFormat "uint16" 17 | 18 | uint32 :: GPUIndexFormat 19 | uint32 = GPUIndexFormat "uint32" -------------------------------------------------------------------------------- /src/Web/GPU/GPUQueryType.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUQueryType 2 | ( GPUQueryType 3 | , occlusion 4 | , timestamp 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUQueryType = GPUQueryType String 10 | 11 | derive instance Eq GPUQueryType 12 | derive instance Ord GPUQueryType 13 | derive newtype instance Show GPUQueryType 14 | 15 | occlusion :: GPUQueryType 16 | occlusion = GPUQueryType "occlusion" 17 | 18 | timestamp :: GPUQueryType 19 | timestamp = GPUQueryType "timestamp" -------------------------------------------------------------------------------- /src/Web/GPU/GPUColor.purs: -------------------------------------------------------------------------------- 1 | -- @inline export gpuColorRGBA arity=4 2 | module Web.GPU.GPUColor 3 | ( GPUColor 4 | , gpuColorDict 5 | , gpuColorRGBA 6 | ) where 7 | 8 | import Unsafe.Coerce (unsafeCoerce) 9 | 10 | data GPUColor 11 | 12 | gpuColorRGBA :: Number -> Number -> Number -> Number -> GPUColor 13 | gpuColorRGBA r g b a = unsafeCoerce [ r, g, b, a ] 14 | 15 | gpuColorDict 16 | :: { r :: Number, g :: Number, b :: Number, a :: Number } -> GPUColor 17 | gpuColorDict rgba = unsafeCoerce rgba -------------------------------------------------------------------------------- /src/Web/GPU/GPUMapMode.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUMapMode 2 | ( GPUMapMode 3 | , read 4 | , write 5 | ) where 6 | 7 | import Data.Int.Bits as Bits 8 | import Web.GPU.Internal.Bitwise (class Bitwise) 9 | import Web.GPU.Internal.Types (UnsignedLong) 10 | 11 | newtype GPUMapMode = GPUMapMode UnsignedLong 12 | 13 | foreign import read :: GPUMapMode 14 | foreign import write :: GPUMapMode 15 | 16 | instance Bitwise GPUMapMode where 17 | or (GPUMapMode a) (GPUMapMode b) = GPUMapMode (a `Bits.or` b) -------------------------------------------------------------------------------- /src/Web/GPU/GPUShaderModuleCompilationHint.purs: -------------------------------------------------------------------------------- 1 | -- @inline export hintFromPipelineLayout arity=1 2 | module Web.GPU.GPUShaderModuleCompilationHint where 3 | 4 | import Unsafe.Coerce (unsafeCoerce) 5 | import Web.GPU.GPUPipelineLayout (GPUPipelineLayout) 6 | 7 | data GPUShaderModuleCompilationHint 8 | 9 | auto :: GPUShaderModuleCompilationHint 10 | auto = unsafeCoerce "auto" 11 | 12 | hintFromPipelineLayout :: GPUPipelineLayout -> GPUShaderModuleCompilationHint 13 | hintFromPipelineLayout = unsafeCoerce -------------------------------------------------------------------------------- /src/Web/GPU/GPUPipelineLayoutDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUPipelineLayoutDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBindGroupLayout (GPUBindGroupLayout) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | 7 | newtype GPUPipelineLayoutDescriptor = GPUPipelineLayoutDescriptor 8 | ( RequiredAndOptional (bindGroupLayouts :: Array GPUBindGroupLayout) 9 | (label :: String) 10 | ) 11 | 12 | derive instance Newtype GPUPipelineLayoutDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUQuerySetDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUQuerySetDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUQueryType (GPUQueryType) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | import Web.GPU.Internal.Types (GPUSize32) 7 | 8 | newtype GPUQuerySetDescriptor = GPUQuerySetDescriptor 9 | ( RequiredAndOptional (type :: GPUQueryType, count :: GPUSize32) 10 | (label :: String) 11 | ) 12 | 13 | derive instance Newtype GPUQuerySetDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUImageDataLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUImageDataLayout where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 5 | import Web.GPU.Internal.Types (GPUSize64, GPUSize32) 6 | 7 | newtype GPUImageDataLayout = GPUImageDataLayout 8 | ( RequiredAndOptional () 9 | ( offset :: GPUSize64 10 | , bytesPerRow :: GPUSize32 11 | , rowsPerImage :: GPUSize32 12 | ) 13 | ) 14 | 15 | derive instance Newtype GPUImageDataLayout _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUBindGroupLayoutDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBindGroupLayoutDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBindGroupLayoutEntry (GPUBindGroupLayoutEntry) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | 7 | newtype GPUBindGroupLayoutDescriptor = GPUBindGroupLayoutDescriptor 8 | ( RequiredAndOptional (entries :: Array GPUBindGroupLayoutEntry) 9 | (label :: String) 10 | ) 11 | 12 | derive instance Newtype GPUBindGroupLayoutDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPURequestAdapterOptions.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURequestAdapterOptions where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUPowerPreference (GPUPowerPreference) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | 7 | newtype GPURequestAdapterOptions = 8 | GPURequestAdapterOptions 9 | ( RequiredAndOptional () 10 | (powerPreference :: GPUPowerPreference, forceFallbackAdapter :: Boolean) 11 | ) 12 | 13 | derive instance Newtype GPURequestAdapterOptions _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUComputePassDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUComputePassDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUComputePassTimestampWrite (GPUComputePassTimestampWrite) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | 7 | newtype GPUComputePassDescriptor = GPUComputePassDescriptor 8 | ( RequiredAndOptional () 9 | (timestampWrites :: Array GPUComputePassTimestampWrite, label :: String) 10 | ) 11 | 12 | derive instance Newtype GPUComputePassDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUImageCopyTextureTagged.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUImageCopyTextureTagged where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 5 | import Web.GPU.PredefinedColorSpace (PredefinedColorSpace) 6 | 7 | newtype GPUImageCopyTextureTagged = GPUImageCopyTextureTagged 8 | ( RequiredAndOptional () 9 | ( colorSpace :: PredefinedColorSpace 10 | , premultipliedAlpha :: Boolean 11 | ) 12 | ) 13 | 14 | derive instance Newtype GPUImageCopyTextureTagged _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUMultisampleState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUMultisampleState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 5 | import Web.GPU.Internal.Types (GPUSize32, GPUSampleMask) 6 | 7 | newtype GPUMultisampleState = GPUMultisampleState 8 | ( RequiredAndOptional 9 | () 10 | ( count :: GPUSize32 11 | , mask :: GPUSampleMask 12 | , alphaToCoverageEnabled :: Boolean 13 | ) 14 | ) 15 | 16 | derive instance Newtype GPUMultisampleState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUBufferDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBufferDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBufferUsage (GPUBufferUsageFlags) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | import Web.GPU.Internal.Types (GPUSize64) 7 | 8 | newtype GPUBufferDescriptor = GPUBufferDescriptor 9 | ( RequiredAndOptional (size :: GPUSize64, usage :: GPUBufferUsageFlags) 10 | (mappedAtCreation :: Boolean, label :: String) 11 | ) 12 | 13 | derive instance Newtype GPUBufferDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUMipmapFilterMode.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUMipmapFilterMode 2 | ( GPUMipmapFilterMode 3 | , linear 4 | , nearest 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUMipmapFilterMode = GPUMipmapFilterMode String 10 | 11 | derive instance Eq GPUMipmapFilterMode 12 | derive instance Ord GPUMipmapFilterMode 13 | derive newtype instance Show GPUMipmapFilterMode 14 | 15 | nearest :: GPUMipmapFilterMode 16 | nearest = GPUMipmapFilterMode "nearest" 17 | 18 | linear :: GPUMipmapFilterMode 19 | linear = GPUMipmapFilterMode "linear" -------------------------------------------------------------------------------- /src/Web/GPU/GPUCanvasAlphaMode.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUCanvasAlphaMode 2 | ( GPUCanvasAlphaMode 3 | , opaque 4 | , premultiplied 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUCanvasAlphaMode = GPUCanvasAlphaMode String 10 | 11 | derive instance Eq GPUCanvasAlphaMode 12 | derive instance Ord GPUCanvasAlphaMode 13 | derive newtype instance Show GPUCanvasAlphaMode 14 | 15 | opaque :: GPUCanvasAlphaMode 16 | opaque = GPUCanvasAlphaMode "opaque" 17 | 18 | premultiplied :: GPUCanvasAlphaMode 19 | premultiplied = GPUCanvasAlphaMode "premultiplied" -------------------------------------------------------------------------------- /src/Web/GPU/PredefinedColorSpace.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.PredefinedColorSpace 2 | ( PredefinedColorSpace 3 | , displayP3 4 | , srgb 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype PredefinedColorSpace = PredefinedColorSpace String 10 | 11 | derive instance Eq PredefinedColorSpace 12 | derive instance Ord PredefinedColorSpace 13 | derive newtype instance Show PredefinedColorSpace 14 | 15 | srgb :: PredefinedColorSpace 16 | srgb = PredefinedColorSpace "srgb" 17 | 18 | displayP3 :: PredefinedColorSpace 19 | displayP3 = PredefinedColorSpace "display-p3" -------------------------------------------------------------------------------- /src/Web/GPU/UnmaskHint.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.UnmaskHint 2 | ( UnmaskHint 3 | , architecture 4 | , description 5 | , device 6 | , vendor 7 | ) where 8 | 9 | import Prelude 10 | 11 | newtype UnmaskHint = UnmaskHint String 12 | vendor = UnmaskHint "vendor" :: UnmaskHint 13 | architecture = UnmaskHint "architecture" :: UnmaskHint 14 | device = UnmaskHint "device" :: UnmaskHint 15 | description = UnmaskHint "description" :: UnmaskHint 16 | 17 | derive instance Eq UnmaskHint 18 | derive instance Ord UnmaskHint 19 | derive newtype instance Show UnmaskHint -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPassTimestampLocation.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderPassTimestampLocation 2 | ( GPURenderPassTimestampLocation 3 | , beginning 4 | , end 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPURenderPassTimestampLocation = GPURenderPassTimestampLocation String 10 | 11 | derive instance Eq GPURenderPassTimestampLocation 12 | derive instance Ord GPURenderPassTimestampLocation 13 | derive newtype instance Show GPURenderPassTimestampLocation 14 | 15 | beginning :: String 16 | beginning = "beginning" 17 | 18 | end :: String 19 | end = "end" -------------------------------------------------------------------------------- /test/Types/RequiredAndOptional.purs: -------------------------------------------------------------------------------- 1 | module Test.Types.RequiredAndOptiona where 2 | 3 | import Prelude 4 | 5 | import Data.Foldable (for_) 6 | import Effect (Effect) 7 | import Web.GPU.GPU (requestAdapter) 8 | 9 | import Web.GPU.Internal.RequiredAndOptional ((~)) 10 | import Web.GPU.Navigator (gpu) 11 | import Web.HTML (window) 12 | import Web.HTML.Window (navigator) 13 | 14 | test1 :: Effect Unit 15 | test1 = do 16 | w <- window 17 | n <- navigator w 18 | g' <- gpu n 19 | for_ g' \g -> do 20 | _ <- requestAdapter g ({} ~ {}) 21 | pure unit 22 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBindGroupDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBindGroupDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBindGroupEntry (GPUBindGroupEntry) 5 | import Web.GPU.GPUBindGroupLayout (GPUBindGroupLayout) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | newtype GPUBindGroupDescriptor = GPUBindGroupDescriptor 9 | ( RequiredAndOptional 10 | (layout :: GPUBindGroupLayout, entries :: Array GPUBindGroupEntry) 11 | (label :: String) 12 | ) 13 | 14 | derive instance Newtype GPUBindGroupDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUBlendComponent.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBlendComponent where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBlendFactor (GPUBlendFactor) 5 | import Web.GPU.GPUBlendOperation (GPUBlendOperation) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | newtype GPUBlendComponent = GPUBlendComponent 9 | ( RequiredAndOptional () 10 | ( operation :: GPUBlendOperation 11 | , srcFactor :: GPUBlendFactor 12 | , dstFactor :: GPUBlendFactor 13 | ) 14 | ) 15 | 16 | derive instance Newtype GPUBlendComponent _ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # purescript-webgpu 2 | 3 | No-frills bindings to the WebGPU API. 4 | 5 | ## Goals 6 | 7 | 1. As close to the [WebGPU spec](https://gpuweb.github.io/gpuweb/) as possible. 8 | 1. Very limited type-level machinery. 9 | 1. Clickable docs. 10 | 1. Small, single-purpose files. 11 | 1. Tests as much of the surface area as possible. 12 | 13 | ## Non-goals 14 | 15 | 1. Fancy abstractions. 16 | 17 | ## For example 18 | 19 | [An early test](https://waggish-quartz.surge.sh/). Make sure to use Chrome. If this stops working, it's because my origin trial stopped working. Sorry. -------------------------------------------------------------------------------- /src/Web/GPU/GPUExternalTextureDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUExternalTextureDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 5 | import Web.GPU.PredefinedColorSpace (PredefinedColorSpace) 6 | import Web.HTML (HTMLVideoElement) 7 | 8 | newtype GPUExternalTextureDescriptor = GPUExternalTextureDescriptor 9 | ( RequiredAndOptional (source :: HTMLVideoElement) 10 | (colorSpace :: PredefinedColorSpace, label :: String) 11 | ) 12 | 13 | derive instance Newtype GPUExternalTextureDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUPowerPreference.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUPowerPreference 2 | ( GPUPowerPreference(..) 3 | , highPerformance 4 | , lowPower 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUPowerPreference = GPUPowerPreference String 10 | 11 | derive instance Eq GPUPowerPreference 12 | derive instance Ord GPUPowerPreference 13 | derive newtype instance Show GPUPowerPreference 14 | 15 | lowPower ∷ GPUPowerPreference 16 | lowPower = GPUPowerPreference "low-power" 17 | 18 | highPerformance ∷ GPUPowerPreference 19 | highPerformance = GPUPowerPreference "high-performance" -------------------------------------------------------------------------------- /src/Web/GPU/GPUVertexAttribute.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUVertexAttribute where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUVertexFormat (GPUVertexFormat) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | import Web.GPU.Internal.Types (GPUSize64, GPUIndex32) 7 | 8 | newtype GPUVertexAttribute = GPUVertexAttribute 9 | ( RequiredAndOptional 10 | ( format :: GPUVertexFormat 11 | , offset :: GPUSize64 12 | , shaderLocation :: GPUIndex32 13 | ) 14 | () 15 | ) 16 | 17 | derive instance Newtype GPUVertexAttribute _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUBufferBindingLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBufferBindingLayout where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBufferBindingType (GPUBufferBindingType) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | import Web.GPU.Internal.Types (GPUSize64) 7 | 8 | newtype GPUBufferBindingLayout = GPUBufferBindingLayout 9 | ( RequiredAndOptional () 10 | ( type :: GPUBufferBindingType 11 | , hasDynamicOffset :: Boolean 12 | , minBindingSize :: GPUSize64 13 | ) 14 | ) 15 | 16 | derive instance Newtype GPUBufferBindingLayout _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUImageCopyBuffer.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUImageCopyBuffer where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBuffer (GPUBuffer) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | import Web.GPU.Internal.Types (GPUSize64, GPUSize32) 7 | 8 | newtype GPUImageCopyBuffer = GPUImageCopyBuffer 9 | ( RequiredAndOptional 10 | ( buffer :: GPUBuffer 11 | ) 12 | ( offset :: GPUSize64 13 | , bytesPerRow :: GPUSize32 14 | , rowsPerImage :: GPUSize32 15 | ) 16 | ) 17 | 18 | derive instance Newtype GPUImageCopyBuffer _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUComputePipelineDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUComputePipelineDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUPipelineLayout (GPUPipelineLayout) 5 | import Web.GPU.GPUProgrammableStage (GPUProgrammableStage) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | newtype GPUComputePipelineDescriptor = GPUComputePipelineDescriptor 9 | ( RequiredAndOptional 10 | (compute :: GPUProgrammableStage, layout :: GPUPipelineLayout) 11 | (label :: String) 12 | ) 13 | 14 | derive instance Newtype GPUComputePipelineDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureUsage.js: -------------------------------------------------------------------------------- 1 | export const copySrc = window.GPUTextureUsage 2 | ? window.GPUTextureUsage.COPY_SRC 3 | : 0x0000; 4 | export const copyDst = window.GPUTextureUsage 5 | ? window.GPUTextureUsage.COPY_DST 6 | : 0x0000; 7 | export const textureBinding = window.GPUTextureUsage 8 | ? window.GPUTextureUsage.TEXTURE_BINDING 9 | : 0x0000; 10 | export const storageBinding = window.GPUTextureUsage 11 | ? window.GPUTextureUsage.STORAGE_BINDING 12 | : 0x0000; 13 | export const renderAttachment = window.GPUTextureUsage 14 | ? window.GPUTextureUsage.RENDER_ATTACHMENT 15 | : 0x0000; 16 | -------------------------------------------------------------------------------- /src/Web/GPU/HTMLCanvasElement.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.HTMLCanvasElement 2 | ( getContext 3 | ) where 4 | 5 | import Data.Maybe (Maybe(..)) 6 | import Effect.Uncurried(EffectFn3, runEffectFn3) 7 | import Effect (Effect) 8 | import Web.GPU.GPUCanvasContext (GPUCanvasContext) 9 | import Web.HTML (HTMLCanvasElement) 10 | 11 | foreign import getContextImpl :: EffectFn3 (GPUCanvasContext -> Maybe GPUCanvasContext) (Maybe GPUCanvasContext) HTMLCanvasElement (Maybe GPUCanvasContext) 12 | getContext ∷ HTMLCanvasElement → Effect (Maybe GPUCanvasContext) 13 | getContext a = runEffectFn3 getContextImpl Just Nothing a -------------------------------------------------------------------------------- /src/Web/GPU/GPUAddressMode.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUAddressMode 2 | ( GPUAddressMode 3 | , clampToEdge 4 | , mirrorRepeat 5 | , repeat 6 | ) where 7 | 8 | import Prelude 9 | 10 | newtype GPUAddressMode = GPUAddressMode String 11 | 12 | derive instance Eq GPUAddressMode 13 | derive instance Ord GPUAddressMode 14 | derive newtype instance Show GPUAddressMode 15 | 16 | clampToEdge :: GPUAddressMode 17 | clampToEdge = GPUAddressMode "clamp-to-edge" 18 | 19 | repeat :: GPUAddressMode 20 | repeat = GPUAddressMode "repeat" 21 | 22 | mirrorRepeat :: GPUAddressMode 23 | mirrorRepeat = GPUAddressMode "mirror-repeat" -------------------------------------------------------------------------------- /src/Web/GPU/GPUImageCopyExternalImage.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUImageCopyExternalImage where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUImageCopyExternalImageSource (GPUImageCopyExternalImageSource) 5 | import Web.GPU.GPUOrigin2D (GPUOrigin2D) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | newtype GPUImageCopyExternalImage = GPUImageCopyExternalImage 9 | ( RequiredAndOptional (source :: GPUImageCopyExternalImageSource) 10 | ( origin :: GPUOrigin2D 11 | , flipY :: Boolean 12 | ) 13 | ) 14 | 15 | derive instance Newtype GPUImageCopyExternalImage _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUSamplerBindingType.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUSamplerBindingType where 2 | 3 | import Prelude 4 | 5 | newtype GPUSamplerBindingType = GPUSamplerBindingType String 6 | 7 | derive instance Eq GPUSamplerBindingType 8 | derive instance Ord GPUSamplerBindingType 9 | derive newtype instance Show GPUSamplerBindingType 10 | 11 | filtering :: GPUSamplerBindingType 12 | filtering = GPUSamplerBindingType "filtering" 13 | 14 | nonFiltering :: GPUSamplerBindingType 15 | nonFiltering = GPUSamplerBindingType "non-filtering" 16 | 17 | comparison :: GPUSamplerBindingType 18 | comparison = GPUSamplerBindingType "comparison" -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureAspect.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureAspect 2 | ( GPUTextureAspect 3 | , all 4 | , depthOnly 5 | , stencilOnly 6 | ) where 7 | 8 | import Prelude 9 | 10 | newtype GPUTextureAspect = GPUTextureAspect String 11 | 12 | derive instance Eq GPUTextureAspect 13 | derive instance Ord GPUTextureAspect 14 | derive newtype instance Show GPUTextureAspect 15 | 16 | all :: GPUTextureAspect 17 | all = GPUTextureAspect "all" 18 | 19 | stencilOnly :: GPUTextureAspect 20 | stencilOnly = GPUTextureAspect "stencil-only" 21 | 22 | depthOnly :: GPUTextureAspect 23 | depthOnly = GPUTextureAspect "depth-only" -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureDimension.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureDimension 2 | ( GPUTextureDimension 3 | , oneD 4 | , threeD 5 | , twoD 6 | ) where 7 | 8 | import Prelude 9 | 10 | newtype GPUTextureDimension = GPUTextureDimension String 11 | 12 | derive instance Eq GPUTextureDimension 13 | derive instance Ord GPUTextureDimension 14 | derive newtype instance Show GPUTextureDimension 15 | 16 | oneD :: GPUTextureDimension 17 | oneD = GPUTextureDimension "1d" 18 | 19 | twoD :: GPUTextureDimension 20 | twoD = GPUTextureDimension "2d" 21 | 22 | threeD :: GPUTextureDimension 23 | threeD = GPUTextureDimension "3d" -------------------------------------------------------------------------------- /src/Web/GPU/GPUVertexBufferLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUVertexBufferLayout where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUVertexAttribute (GPUVertexAttribute) 5 | import Web.GPU.GPUVertexStepMode (GPUVertexStepMode) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | import Web.GPU.Internal.Types (GPUSize64) 8 | 9 | newtype GPUVertexBufferLayout = GPUVertexBufferLayout 10 | ( RequiredAndOptional 11 | (arrayStride :: GPUSize64, attributes :: Array GPUVertexAttribute) 12 | (stepMode :: GPUVertexStepMode) 13 | ) 14 | 15 | derive instance Newtype GPUVertexBufferLayout _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUColorTargetState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUColorTargetState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUBlendState (GPUBlendState) 5 | import Web.GPU.GPUColorWrite (GPUColorWriteFlags) 6 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | 9 | newtype GPUColorTargetState = GPUColorTargetState 10 | ( RequiredAndOptional 11 | ( format :: GPUTextureFormat 12 | ) 13 | ( blend :: GPUBlendState 14 | , writeMask :: GPUColorWriteFlags 15 | ) 16 | ) 17 | 18 | derive instance Newtype GPUColorTargetState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureBindingLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureBindingLayout where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUTextureSampleType (GPUTextureSampleType) 5 | import Web.GPU.GPUTextureViewDimension (GPUTextureViewDimension) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | newtype GPUTextureBindingLayout = GPUTextureBindingLayout 9 | ( RequiredAndOptional () 10 | ( sampleType :: GPUTextureSampleType 11 | , viewDimension :: GPUTextureViewDimension 12 | , multisampled :: Boolean 13 | ) 14 | ) 15 | 16 | derive instance Newtype GPUTextureBindingLayout _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUStencilFaceState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUStencilFaceState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUCompareFunction (GPUCompareFunction) 5 | import Web.GPU.GPUStencilOperation (GPUStencilOperation) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | newtype GPUStencilFaceState = GPUStencilFaceState 9 | ( RequiredAndOptional () 10 | ( compare :: GPUCompareFunction 11 | , failOp :: GPUStencilOperation 12 | , depthFailOp :: GPUStencilOperation 13 | , passOp :: GPUStencilOperation 14 | ) 15 | ) 16 | 17 | derive instance Newtype GPUStencilFaceState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUAdapter.js: -------------------------------------------------------------------------------- 1 | export const featuresImpl = (insert, empty, adapter) => { 2 | const iterator1 = adapter.features.entries(); 3 | let out = empty; 4 | for (const entry of iterator1) { 5 | out = insert(entry)(out); 6 | } 7 | return out; 8 | }; 9 | export const limitsImpl = adapter => adapter.limits; 10 | export const isFallbackAdapterImpl = adapter => adapter.isFallbackAdapter; 11 | export const requestDeviceImpl = (just, nothing, adapter, options) => 12 | adapter.requestDevice(options).then(o => (o ? just(o) : nothing)); 13 | export const requestAdapterInfoImpl = (adapter, unmaskHints) => 14 | adapter.requestAdapterInfo(unmaskHints); 15 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUProgrammableStage.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUProgrammableStage where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Foreign.Object (Object) 5 | import Web.GPU.GPUShaderModule (GPUShaderModule) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | type MakeGPUProgrammableStage r o = RequiredAndOptional 9 | (module :: GPUShaderModule, entryPoint :: String | r) 10 | (constants :: Object GPUPipelineConstantValue | o) 11 | 12 | newtype GPUProgrammableStage = GPUProgrammableStage 13 | (MakeGPUProgrammableStage () ()) 14 | 15 | type GPUPipelineConstantValue = Number 16 | 17 | derive instance Newtype GPUProgrammableStage _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUShaderModuleDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUShaderModuleDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Foreign (Foreign) 5 | import Foreign.Object (Object) 6 | import Web.GPU.GPUShaderModuleCompilationHint (GPUShaderModuleCompilationHint) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | 9 | newtype GPUShaderModuleDescriptor = GPUShaderModuleDescriptor 10 | ( RequiredAndOptional (code :: String) 11 | ( sourceMap :: Foreign 12 | , hints :: Object GPUShaderModuleCompilationHint 13 | , label :: String 14 | ) 15 | ) 16 | 17 | derive instance Newtype GPUShaderModuleDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUComputePassTimestampLocation.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUComputePassTimestampLocation 2 | ( GPUComputePassTimestampLocation 3 | , beginning 4 | , end 5 | ) where 6 | 7 | import Prelude 8 | 9 | newtype GPUComputePassTimestampLocation = GPUComputePassTimestampLocation String 10 | 11 | derive instance Eq GPUComputePassTimestampLocation 12 | derive instance Ord GPUComputePassTimestampLocation 13 | derive newtype instance Show GPUComputePassTimestampLocation 14 | 15 | beginning :: GPUComputePassTimestampLocation 16 | beginning = GPUComputePassTimestampLocation "beginning" 17 | 18 | end :: GPUComputePassTimestampLocation 19 | end = GPUComputePassTimestampLocation "end" -------------------------------------------------------------------------------- /src/Web/GPU/GPUBlendOperation.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBlendOperation where 2 | 3 | import Prelude 4 | 5 | newtype GPUBlendOperation = GPUBlendOperation String 6 | 7 | derive instance Eq GPUBlendOperation 8 | derive instance Ord GPUBlendOperation 9 | derive newtype instance Show GPUBlendOperation 10 | 11 | add :: GPUBlendOperation 12 | add = GPUBlendOperation "add" 13 | 14 | subtract :: GPUBlendOperation 15 | subtract = GPUBlendOperation "subtract" 16 | 17 | reverseSubtract :: GPUBlendOperation 18 | reverseSubtract = GPUBlendOperation "reverse-subtract" 19 | 20 | min :: GPUBlendOperation 21 | min = GPUBlendOperation "min" 22 | 23 | max :: GPUBlendOperation 24 | max = GPUBlendOperation "max" -------------------------------------------------------------------------------- /src/Web/GPU/GPUBufferBindingType.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBufferBindingType 2 | ( GPUBufferBindingType 3 | , readOnlyStorage 4 | , storage 5 | , uniform 6 | ) where 7 | 8 | import Prelude 9 | 10 | newtype GPUBufferBindingType = GPUBufferBindingType String 11 | 12 | derive instance Eq GPUBufferBindingType 13 | derive instance Ord GPUBufferBindingType 14 | derive newtype instance Show GPUBufferBindingType 15 | 16 | uniform :: GPUBufferBindingType 17 | uniform = GPUBufferBindingType "uniform" 18 | 19 | storage :: GPUBufferBindingType 20 | storage = GPUBufferBindingType "storage" 21 | 22 | readOnlyStorage :: GPUBufferBindingType 23 | readOnlyStorage = GPUBufferBindingType "read-only-storage" -------------------------------------------------------------------------------- /src/Web/GPU/GPUShaderStage.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUShaderStage 2 | ( GPUShaderStage 3 | , GPUShaderStageFlags 4 | , vertex 5 | , fragment 6 | , compute 7 | ) where 8 | 9 | import Data.Int.Bits as Bits 10 | import Web.GPU.Internal.Bitwise (class Bitwise) 11 | import Web.GPU.Internal.Types (UnsignedLong) 12 | 13 | newtype GPUShaderStage = GPUShaderStage UnsignedLong 14 | 15 | foreign import vertex :: GPUShaderStage 16 | foreign import fragment :: GPUShaderStage 17 | foreign import compute :: GPUShaderStage 18 | 19 | instance Bitwise GPUShaderStage where 20 | or (GPUShaderStage a) (GPUShaderStage b) = GPUShaderStage (a `Bits.or` b) 21 | 22 | type GPUShaderStageFlags = GPUShaderStage -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPassTimestampWrite.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderPassTimestampWrite where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUQuerySet (GPUQuerySet) 5 | import Web.GPU.GPURenderPassTimestampLocation (GPURenderPassTimestampLocation) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | import Web.GPU.Internal.Types (GPUSize32) 8 | 9 | newtype GPURenderPassTimestampWrite = GPURenderPassTimestampWrite 10 | ( RequiredAndOptional 11 | ( querySet :: GPUQuerySet 12 | , queryIndex :: GPUSize32 13 | , location :: GPURenderPassTimestampLocation 14 | ) 15 | () 16 | ) 17 | 18 | derive instance Newtype GPURenderPassTimestampWrite _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUComputePassTimestampWrite.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUComputePassTimestampWrite where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUComputePassTimestampLocation (GPUComputePassTimestampLocation) 5 | import Web.GPU.GPUQuerySet (GPUQuerySet) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | import Web.GPU.Internal.Types (GPUSize32) 8 | 9 | newtype GPUComputePassTimestampWrite = GPUComputePassTimestampWrite 10 | ( RequiredAndOptional 11 | ( querySet :: GPUQuerySet 12 | , queryIndex :: GPUSize32 13 | , location :: GPUComputePassTimestampLocation 14 | ) 15 | () 16 | ) 17 | 18 | derive instance Newtype GPUComputePassTimestampWrite _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUImageCopyTexture.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUImageCopyTexture where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUOrigin3D (GPUOrigin3D) 5 | import Web.GPU.GPUTexture (GPUTexture) 6 | import Web.GPU.GPUTextureAspect (GPUTextureAspect) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | import Web.GPU.Internal.Types (GPUIntegerCoordinate) 9 | 10 | newtype GPUImageCopyTexture = GPUImageCopyTexture 11 | ( RequiredAndOptional 12 | ( texture :: GPUTexture 13 | ) 14 | ( mipLevel :: GPUIntegerCoordinate 15 | , origin :: GPUOrigin3D 16 | , aspect :: GPUTextureAspect 17 | ) 18 | ) 19 | 20 | derive instance Newtype GPUImageCopyTexture _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUStorageTextureBindingLayout.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUStorageTextureBindingLayout where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUStorageTextureAccess (GPUStorageTextureAccess) 5 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 6 | import Web.GPU.GPUTextureViewDimension (GPUTextureViewDimension) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | 9 | newtype GPUStorageTextureBindingLayout = GPUStorageTextureBindingLayout 10 | ( RequiredAndOptional (format :: GPUTextureFormat) 11 | ( viewDimension :: GPUTextureViewDimension 12 | , access :: GPUStorageTextureAccess 13 | ) 14 | ) 15 | 16 | derive instance Newtype GPUStorageTextureBindingLayout _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUPrimitiveState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUPrimitiveState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUCullMode (GPUCullMode) 5 | import Web.GPU.GPUFrontFace (GPUFrontFace) 6 | import Web.GPU.GPUIndexFormat (GPUIndexFormat) 7 | import Web.GPU.GPUPrimitiveTopology (GPUPrimitiveTopology) 8 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 9 | 10 | newtype GPUPrimitiveState = GPUPrimitiveState 11 | ( RequiredAndOptional () 12 | ( topology :: GPUPrimitiveTopology 13 | , stripIndexFormat :: GPUIndexFormat 14 | , frontFace :: GPUFrontFace 15 | , cullMode :: GPUCullMode 16 | , unclippedDepth :: Boolean 17 | ) 18 | ) 19 | 20 | derive instance Newtype GPUPrimitiveState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUTexture.js: -------------------------------------------------------------------------------- 1 | export const createViewImpl = texture => texture.createView(); 2 | export const createViewWithDescriptorImpl = (texture, descriptor) => 3 | texture.createView(descriptor); 4 | export const destroyImpl = texture => texture.destroy(); 5 | export const widthImpl = texture => texture.width; 6 | export const heightImpl = texture => texture.height; 7 | export const depthOrArrayLayersImpl = texture => texture.depthOrArrayLayers; 8 | export const mipLevelCountImpl = texture => texture.mipLevelCount; 9 | export const sampleCountImpl = texture => texture.sampleCount; 10 | export const dimensionImpl = texture => texture.dimension; 11 | export const formatImpl = texture => texture.format; 12 | export const usageImpl = texture => texture.usage; 13 | -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPassColorAttachment.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderPassColorAttachment where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUColor (GPUColor) 5 | import Web.GPU.GPULoadOp (GPULoadOp) 6 | import Web.GPU.GPUStoreOp (GPUStoreOp) 7 | import Web.GPU.GPUTextureView (GPUTextureView) 8 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 9 | 10 | newtype GPURenderPassColorAttachment = GPURenderPassColorAttachment 11 | ( RequiredAndOptional 12 | ( view :: GPUTextureView 13 | , loadOp :: GPULoadOp 14 | , storeOp :: GPUStoreOp 15 | ) 16 | ( resolveTarget :: GPUTextureView 17 | , clearValue :: GPUColor 18 | ) 19 | ) 20 | 21 | derive instance Newtype GPURenderPassColorAttachment _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUColorWrite.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUColorWrite 2 | ( GPUColorWrite 3 | , GPUColorWriteFlags 4 | , red 5 | , green 6 | , blue 7 | , alpha 8 | , all 9 | ) where 10 | 11 | import Data.Int.Bits as Bits 12 | import Web.GPU.Internal.Bitwise (class Bitwise) 13 | import Web.GPU.Internal.Types (UnsignedLong) 14 | 15 | newtype GPUColorWrite = GPUColorWrite UnsignedLong 16 | 17 | foreign import red :: GPUColorWrite 18 | foreign import green :: GPUColorWrite 19 | foreign import blue :: GPUColorWrite 20 | foreign import alpha :: GPUColorWrite 21 | foreign import all :: GPUColorWrite 22 | 23 | instance Bitwise GPUColorWrite where 24 | or (GPUColorWrite a) (GPUColorWrite b) = GPUColorWrite (a `Bits.or` b) 25 | 26 | type GPUColorWriteFlags = GPUColorWrite -------------------------------------------------------------------------------- /src/Web/GPU/GPUOrigin2D.purs: -------------------------------------------------------------------------------- 1 | -- @inline export gpuOrigin2DX arity=1 2 | -- @inline export gpuOrigin2DXY arity=2 3 | module Web.GPU.GPUOrigin2D 4 | ( GPUOrigin2D 5 | , gpuOrigin2DX 6 | , gpuOrigin2DXY 7 | , gpuOrigin2DDict 8 | ) where 9 | 10 | import Unsafe.Coerce (unsafeCoerce) 11 | import Web.GPU.Internal.Types (GPUIntegerCoordinate) 12 | 13 | data GPUOrigin2D 14 | 15 | gpuOrigin2DX :: GPUIntegerCoordinate -> GPUOrigin2D 16 | gpuOrigin2DX x = unsafeCoerce [ x ] 17 | 18 | gpuOrigin2DXY :: GPUIntegerCoordinate -> GPUIntegerCoordinate -> GPUOrigin2D 19 | gpuOrigin2DXY x y = unsafeCoerce [ x, y ] 20 | 21 | gpuOrigin2DDict 22 | :: { x :: GPUIntegerCoordinate 23 | , y :: GPUIntegerCoordinate 24 | } 25 | -> GPUOrigin2D 26 | gpuOrigin2DDict = unsafeCoerce -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderBundleEncoderDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderBundleEncoderDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 5 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 6 | import Web.GPU.Internal.Types (GPUSize32) 7 | 8 | newtype GPURenderBundleEncoderDescriptor = GPURenderBundleEncoderDescriptor 9 | ( RequiredAndOptional 10 | ( colorFormats :: Array GPUTextureFormat 11 | ) 12 | ( depthReadOnly :: Boolean 13 | , stencilReadOnly :: Boolean 14 | , depthStencilFormat :: GPUTextureFormat 15 | , sampleCount :: GPUSize32 16 | , label :: String 17 | ) 18 | ) 19 | 20 | derive instance Newtype GPURenderBundleEncoderDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUPrimitiveTopology.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUPrimitiveTopology where 2 | 3 | import Prelude 4 | 5 | newtype GPUPrimitiveTopology = GPUPrimitiveTopology String 6 | 7 | derive instance Eq GPUPrimitiveTopology 8 | derive instance Ord GPUPrimitiveTopology 9 | derive newtype instance Show GPUPrimitiveTopology 10 | 11 | pointList :: GPUPrimitiveTopology 12 | pointList = GPUPrimitiveTopology "point-list" 13 | 14 | lineList :: GPUPrimitiveTopology 15 | lineList = GPUPrimitiveTopology "line-list" 16 | 17 | lineStrip :: GPUPrimitiveTopology 18 | lineStrip = GPUPrimitiveTopology "line-strip" 19 | 20 | triangleList :: GPUPrimitiveTopology 21 | triangleList = GPUPrimitiveTopology "triangle-list" 22 | 23 | triangleStrip :: GPUPrimitiveTopology 24 | triangleStrip = GPUPrimitiveTopology "triangle-strip" -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purescript-webgpu", 3 | "version": "0.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "sandbox": "spago -x sandbox.dhall build && vite build sandbox/", 8 | "sandbox-dev": "spago -x sandbox-dev.dhall build && vite dev sandbox/", 9 | "format": "purs-tidy format-in-place \"src/**/*.purs sandbox/**/*.purs\" && prettier --arrow-parens avoid --write \"src/**/*.js\"" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "prettier": "^2.8.1", 16 | "purescript": "^0.15.7", 17 | "purs-backend-es": "^1.3.1", 18 | "purs-tidy": "^0.9.2", 19 | "spago": "^0.20.9", 20 | "vite": "^4.0.4" 21 | }, 22 | "dependencies": { 23 | "gl-matrix": "^3.4.3" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUCompareFunction.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUCompareFunction where 2 | 3 | import Prelude 4 | 5 | newtype GPUCompareFunction = GPUCompareFunction String 6 | 7 | derive instance Eq GPUCompareFunction 8 | derive instance Ord GPUCompareFunction 9 | derive newtype instance Show GPUCompareFunction 10 | never = GPUCompareFunction "never" :: GPUCompareFunction 11 | less = GPUCompareFunction "less" :: GPUCompareFunction 12 | equal = GPUCompareFunction "equal" :: GPUCompareFunction 13 | lessEqual = GPUCompareFunction "less-equal" :: GPUCompareFunction 14 | greater = GPUCompareFunction "greater" :: GPUCompareFunction 15 | notEqual = GPUCompareFunction "not-equal" :: GPUCompareFunction 16 | greaterEqual = GPUCompareFunction "greater-equal" :: GPUCompareFunction 17 | always = GPUCompareFunction "always" :: GPUCompareFunction -------------------------------------------------------------------------------- /src/Web/GPU/GPUPipelineBase.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUPipelineBase where 2 | 3 | import Effect (Effect) 4 | import Effect.Uncurried (EffectFn2, runEffectFn2) 5 | import Web.GPU.GPUBindGroupLayout (GPUBindGroupLayout) 6 | import Web.GPU.GPUComputePipeline (GPUComputePipeline) 7 | import Web.GPU.GPURenderPipeline (GPURenderPipeline) 8 | import Web.GPU.Internal.Types (UnsignedLong) 9 | 10 | foreign import unsafeGetBindGroupLayoutImpl :: forall a. EffectFn2 a UnsignedLong GPUBindGroupLayout 11 | class GPUPipelineBase a where 12 | getBindGroupLayout :: a -> UnsignedLong -> Effect GPUBindGroupLayout 13 | 14 | instance GPUPipelineBase GPUComputePipeline where 15 | getBindGroupLayout a b = runEffectFn2 unsafeGetBindGroupLayoutImpl a b 16 | 17 | instance GPUPipelineBase GPURenderPipeline where 18 | getBindGroupLayout a b = runEffectFn2 unsafeGetBindGroupLayoutImpl a b -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureViewDimension.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureViewDimension where 2 | 3 | import Prelude 4 | 5 | newtype GPUTextureViewDimension = GPUTextureViewDimension String 6 | 7 | derive instance Eq GPUTextureViewDimension 8 | derive instance Ord GPUTextureViewDimension 9 | derive newtype instance Show GPUTextureViewDimension 10 | 11 | oneD :: GPUTextureViewDimension 12 | oneD = GPUTextureViewDimension "1d" 13 | 14 | twoD :: GPUTextureViewDimension 15 | twoD = GPUTextureViewDimension "2d" 16 | 17 | twoDArray :: GPUTextureViewDimension 18 | twoDArray = GPUTextureViewDimension "2d-array" 19 | 20 | cube :: GPUTextureViewDimension 21 | cube = GPUTextureViewDimension "cube" 22 | 23 | cubeArray :: GPUTextureViewDimension 24 | cubeArray = GPUTextureViewDimension "cube-array" 25 | 26 | threeD :: GPUTextureViewDimension 27 | threeD = GPUTextureViewDimension "3d" -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureSampleType.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureSampleType 2 | ( GPUTextureSampleType 3 | , depth 4 | , float 5 | , sint 6 | , uint 7 | , unfilterableFloat 8 | ) where 9 | 10 | import Prelude 11 | 12 | newtype GPUTextureSampleType = GPUTextureSampleType String 13 | 14 | derive instance Eq GPUTextureSampleType 15 | derive instance Ord GPUTextureSampleType 16 | derive newtype instance Show GPUTextureSampleType 17 | 18 | float :: GPUTextureSampleType 19 | float = GPUTextureSampleType "float" 20 | 21 | unfilterableFloat :: GPUTextureSampleType 22 | unfilterableFloat = GPUTextureSampleType "unfilterable-float" 23 | 24 | depth :: GPUTextureSampleType 25 | depth = GPUTextureSampleType "depth" 26 | 27 | sint :: GPUTextureSampleType 28 | sint = GPUTextureSampleType "sint" 29 | 30 | uint :: GPUTextureSampleType 31 | uint = GPUTextureSampleType "uint" -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureUsage.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureUsage 2 | ( GPUTextureUsage 3 | , GPUTextureUsageFlags 4 | , copyDst 5 | , copySrc 6 | , renderAttachment 7 | , storageBinding 8 | , textureBinding 9 | ) where 10 | 11 | import Data.Int.Bits as Bits 12 | import Web.GPU.Internal.Bitwise (class Bitwise) 13 | import Web.GPU.Internal.Types (UnsignedLong) 14 | 15 | newtype GPUTextureUsage = GPUTextureUsage UnsignedLong 16 | 17 | foreign import copySrc :: GPUTextureUsage 18 | foreign import copyDst :: GPUTextureUsage 19 | foreign import textureBinding :: GPUTextureUsage 20 | foreign import storageBinding :: GPUTextureUsage 21 | foreign import renderAttachment :: GPUTextureUsage 22 | 23 | instance Bitwise GPUTextureUsage where 24 | or (GPUTextureUsage a) (GPUTextureUsage b) = GPUTextureUsage (a `Bits.or` b) 25 | 26 | type GPUTextureUsageFlags = GPUTextureUsage -------------------------------------------------------------------------------- /src/Web/GPU/GPUCanvasConfiguration.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUCanvasConfiguration where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUCanvasAlphaMode (GPUCanvasAlphaMode) 5 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 6 | import Web.GPU.GPUTextureUsage (GPUTextureUsageFlags) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | import Web.GPU.PredefinedColorSpace (PredefinedColorSpace) 9 | import Web.GPU.GPUDevice (GPUDevice) 10 | 11 | newtype GPUCanvasConfiguration = GPUCanvasConfiguration 12 | ( RequiredAndOptional 13 | ( device :: GPUDevice 14 | , format :: GPUTextureFormat 15 | 16 | ) 17 | ( usage :: GPUTextureUsageFlags 18 | , viewFormats :: Array GPUTextureFormat 19 | , colorSpace :: PredefinedColorSpace 20 | , alphaMode :: GPUCanvasAlphaMode 21 | 22 | ) 23 | ) 24 | 25 | derive instance Newtype GPUCanvasConfiguration _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUQuerySet.purs: -------------------------------------------------------------------------------- 1 | -- @inline export destroy arity=1 2 | -- @inline export type' arity=1 3 | -- @inline export count arity=1 4 | module Web.GPU.GPUQuerySet 5 | ( GPUQuerySet 6 | , count 7 | , destroy 8 | , type' 9 | ) where 10 | 11 | import Prelude 12 | 13 | import Effect (Effect) 14 | import Effect.Uncurried (EffectFn1, runEffectFn1) 15 | import Web.GPU.GPUQueryType (GPUQueryType) 16 | import Web.GPU.Internal.Types (GPUSize32) 17 | 18 | data GPUQuerySet 19 | 20 | foreign import destroyImpl :: EffectFn1 GPUQuerySet Unit 21 | destroy :: GPUQuerySet -> Effect Unit 22 | destroy a = runEffectFn1 destroyImpl a 23 | 24 | foreign import typeImpl :: EffectFn1 GPUQuerySet GPUQueryType 25 | type' :: GPUQuerySet -> Effect GPUQueryType 26 | type' a = runEffectFn1 typeImpl a 27 | 28 | foreign import countImpl :: EffectFn1 GPUQuerySet GPUSize32 29 | count :: GPUQuerySet -> Effect Int 30 | count a = runEffectFn1 countImpl a -------------------------------------------------------------------------------- /src/Web/GPU/GPUDeviceDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUDeviceDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUFeatureName (GPUFeatureName) 5 | import Web.GPU.GPUSupportedLimits (GPUSupportedLimits) 6 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 7 | 8 | newtype GPUQueueDescriptor = GPUQueueDescriptor 9 | (RequiredAndOptional () (label :: String)) 10 | 11 | derive instance Newtype GPUQueueDescriptor _ 12 | 13 | newtype GPURequiredLimits = GPURequiredLimits 14 | (RequiredAndOptional () GPUSupportedLimits) 15 | 16 | derive instance Newtype GPURequiredLimits _ 17 | newtype GPUDeviceDescriptor = GPUDeviceDescriptor 18 | ( RequiredAndOptional () 19 | ( requiredFeatures :: Array GPUFeatureName 20 | , requiredLimits :: GPURequiredLimits 21 | , defaultQueue :: GPUQueueDescriptor 22 | , label :: String 23 | ) 24 | ) 25 | 26 | derive instance Newtype GPUDeviceDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUExtent3D.purs: -------------------------------------------------------------------------------- 1 | -- @inline export gpuExtent3DW arity=1 2 | -- @inline export gpuExtent3DWH arity=2 3 | -- @inline export gpuExtent3DWHD arity=3 4 | module Web.GPU.GPUExtent3D where 5 | 6 | import Unsafe.Coerce (unsafeCoerce) 7 | import Web.GPU.Internal.Types (GPUIntegerCoordinate) 8 | 9 | data GPUExtent3D 10 | 11 | gpuExtent3DW :: GPUIntegerCoordinate -> GPUExtent3D 12 | gpuExtent3DW w = unsafeCoerce [ w ] 13 | 14 | gpuExtent3DWH :: GPUIntegerCoordinate -> GPUIntegerCoordinate -> GPUExtent3D 15 | gpuExtent3DWH w h = unsafeCoerce [ w, h ] 16 | 17 | gpuExtent3DWHD 18 | :: GPUIntegerCoordinate 19 | -> GPUIntegerCoordinate 20 | -> GPUIntegerCoordinate 21 | -> GPUExtent3D 22 | gpuExtent3DWHD w h d = unsafeCoerce [ w, h, d ] 23 | 24 | gpuExtent3DDict 25 | :: { width :: GPUIntegerCoordinate 26 | , height :: GPUIntegerCoordinate 27 | , depthOrArrayLayers :: GPUIntegerCoordinate 28 | } 29 | -> GPUExtent3D 30 | gpuExtent3DDict = unsafeCoerce -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUExtent3D (GPUExtent3D) 5 | import Web.GPU.GPUTextureDimension (GPUTextureDimension) 6 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 7 | import Web.GPU.GPUTextureUsage (GPUTextureUsageFlags) 8 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 9 | import Web.GPU.Internal.Types (GPUIntegerCoordinate, GPUSize32) 10 | 11 | newtype GPUTextureDescriptor = GPUTextureDescriptor 12 | ( RequiredAndOptional 13 | ( size :: GPUExtent3D 14 | , format :: GPUTextureFormat 15 | , usage :: GPUTextureUsageFlags 16 | ) 17 | ( dimension :: GPUTextureDimension 18 | , sampleCount :: GPUSize32 19 | , viewFormats :: Array GPUTextureFormat 20 | , mipLevelCount :: GPUIntegerCoordinate 21 | , label :: String 22 | ) 23 | ) 24 | 25 | derive instance Newtype GPUTextureDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureViewDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureViewDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUTextureAspect (GPUTextureAspect) 5 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 6 | import Web.GPU.GPUTextureViewDimension (GPUTextureViewDimension) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | import Web.GPU.Internal.Types (GPUIntegerCoordinate) 9 | 10 | newtype GPUTextureViewDescriptor = GPUTextureViewDescriptor 11 | ( RequiredAndOptional 12 | () 13 | ( format :: GPUTextureFormat 14 | , dimension :: GPUTextureViewDimension 15 | , aspect :: GPUTextureAspect 16 | , baseMipLevel :: GPUIntegerCoordinate 17 | , mipLevelCount :: GPUIntegerCoordinate 18 | , baseArrayLayer :: GPUIntegerCoordinate 19 | , arrayLayerCount :: GPUIntegerCoordinate 20 | , label :: String 21 | ) 22 | ) 23 | 24 | derive instance Newtype GPUTextureViewDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUImageCopyExternalImageSource.purs: -------------------------------------------------------------------------------- 1 | -- @inline export fromImageBitmap arity=1 2 | -- @inline export fromHTMLVideoElement arity=1 3 | -- @inline export fromHTMLCanvasElement arity=1 4 | -- @inline export fromOffscreenCanvas arity=1 5 | module Web.GPU.GPUImageCopyExternalImageSource where 6 | 7 | import Unsafe.Coerce (unsafeCoerce) 8 | import Web.GPU.Internal.Types (ImageBitmap, OffscreenCanvas) 9 | import Web.HTML (HTMLCanvasElement, HTMLVideoElement) 10 | 11 | data GPUImageCopyExternalImageSource 12 | 13 | fromImageBitmap :: ImageBitmap -> GPUImageCopyExternalImageSource 14 | fromImageBitmap = unsafeCoerce 15 | 16 | fromHTMLVideoElement :: HTMLVideoElement -> GPUImageCopyExternalImageSource 17 | fromHTMLVideoElement = unsafeCoerce 18 | 19 | fromHTMLCanvasElement :: HTMLCanvasElement -> GPUImageCopyExternalImageSource 20 | fromHTMLCanvasElement = unsafeCoerce 21 | 22 | fromOffscreenCanvas :: OffscreenCanvas -> GPUImageCopyExternalImageSource 23 | fromOffscreenCanvas = unsafeCoerce -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPipelineDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderPipelineDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUDepthStencilState (GPUDepthStencilState) 5 | import Web.GPU.GPUFragmentState (GPUFragmentState) 6 | import Web.GPU.GPUMultisampleState (GPUMultisampleState) 7 | import Web.GPU.GPUPipelineLayout (GPUPipelineLayout) 8 | import Web.GPU.GPUPrimitiveState (GPUPrimitiveState) 9 | import Web.GPU.GPUVertexState (GPUVertexState) 10 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 11 | 12 | newtype GPURenderPipelineDescriptor = GPURenderPipelineDescriptor 13 | ( RequiredAndOptional (vertex :: GPUVertexState, layout :: GPUPipelineLayout) 14 | ( primitive :: GPUPrimitiveState 15 | , depthStencil :: GPUDepthStencilState 16 | , multisample :: GPUMultisampleState 17 | , fragment :: GPUFragmentState 18 | , label :: String 19 | ) 20 | ) 21 | 22 | derive instance Newtype GPURenderPipelineDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/Internal/Types.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.Internal.Types 2 | ( GPUBufferDynamicOffset 3 | , GPUDepthBias 4 | , GPUIndex32 5 | , GPUIntegerCoordinate 6 | , GPUSampleMask 7 | , GPUSignedOffset32 8 | , GPUSize32 9 | , GPUSize64 10 | , GPUStencilValue 11 | , ImageBitmap 12 | , Long 13 | , OffscreenCanvas 14 | , UnsignedLong 15 | , UnsignedLongLong 16 | , UnsignedShort 17 | ) where 18 | 19 | -- todo: add this to the PS ecosystem 20 | data ImageBitmap 21 | -- todo: add this to the PS ecosystem 22 | data OffscreenCanvas 23 | type Long = Int 24 | type UnsignedShort = Int 25 | type UnsignedLong = Int 26 | type UnsignedLongLong = Int 27 | type GPUSize64 = UnsignedLongLong 28 | type GPUIntegerCoordinate = UnsignedLong 29 | type GPUSize32 = UnsignedLong 30 | type GPUIndex32 = UnsignedLong 31 | type GPUStencilValue = UnsignedLong 32 | type GPUSampleMask = UnsignedLong 33 | type GPUDepthBias = Long 34 | type GPUBufferDynamicOffset = UnsignedLong 35 | type GPUSignedOffset32 = Long -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPassDepthStencilAttachment.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderPassDepthStencilAttachment where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPULoadOp (GPULoadOp) 5 | import Web.GPU.GPUStoreOp (GPUStoreOp) 6 | import Web.GPU.GPUTextureView (GPUTextureView) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | import Web.GPU.Internal.Types (GPUStencilValue) 9 | 10 | newtype GPURenderPassDepthStencilAttachment = 11 | GPURenderPassDepthStencilAttachment 12 | ( RequiredAndOptional 13 | ( view :: GPUTextureView 14 | ) 15 | ( depthClearValue :: Number 16 | , depthLoadOp :: GPULoadOp 17 | , depthStoreOp :: GPUStoreOp 18 | , depthReadOnly :: Boolean 19 | , stencilClearValue :: GPUStencilValue 20 | , stencilLoadOp :: GPULoadOp 21 | , stencilStoreOp :: GPUStoreOp 22 | , stencilReadOnly :: Boolean 23 | ) 24 | ) 25 | 26 | derive instance Newtype GPURenderPassDepthStencilAttachment _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUDepthStencilState.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUDepthStencilState where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUCompareFunction (GPUCompareFunction) 5 | import Web.GPU.GPUStencilFaceState (GPUStencilFaceState) 6 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 7 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 8 | import Web.GPU.Internal.Types (GPUStencilValue, GPUDepthBias) 9 | 10 | newtype GPUDepthStencilState = GPUDepthStencilState 11 | ( RequiredAndOptional 12 | (format :: GPUTextureFormat) 13 | ( depthWriteEnabled :: Boolean 14 | , depthCompare :: GPUCompareFunction 15 | , stencilFront :: GPUStencilFaceState 16 | , stencilBack :: GPUStencilFaceState 17 | , stencilReadMask :: GPUStencilValue 18 | , stencilWriteMask :: GPUStencilValue 19 | , depthBias :: GPUDepthBias 20 | , depthBiasSlopeScale :: Number 21 | , depthBiasClamp :: Number 22 | ) 23 | ) 24 | 25 | derive instance Newtype GPUDepthStencilState _ -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPassDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPURenderPassDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUQuerySet (GPUQuerySet) 5 | import Web.GPU.GPURenderPassColorAttachment (GPURenderPassColorAttachment) 6 | import Web.GPU.GPURenderPassDepthStencilAttachment (GPURenderPassDepthStencilAttachment) 7 | import Web.GPU.GPURenderPassTimestampWrite (GPURenderPassTimestampWrite) 8 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 9 | import Web.GPU.Internal.Types (GPUSize64) 10 | 11 | newtype GPURenderPassDescriptor = GPURenderPassDescriptor 12 | ( RequiredAndOptional 13 | ( colorAttachments :: Array GPURenderPassColorAttachment 14 | ) 15 | ( depthStencilAttachment :: GPURenderPassDepthStencilAttachment 16 | , occlusionQuerySet :: GPUQuerySet 17 | , timestampWrites :: Array GPURenderPassTimestampWrite 18 | , maxDrawCount :: GPUSize64 19 | , label :: String 20 | ) 21 | ) 22 | 23 | derive instance Newtype GPURenderPassDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUOrigin3D.purs: -------------------------------------------------------------------------------- 1 | -- @inline export gpuOrigin3DX arity=1 2 | -- @inline export gpuOrigin3DXY arity=2 3 | -- @inline export gpuOrigin3DXYZ arity=3 4 | module Web.GPU.GPUOrigin3D 5 | ( gpuOrigin3DX 6 | , gpuOrigin3DXY 7 | , gpuOrigin3DXYZ 8 | , gpuOrigin3DDict 9 | , GPUOrigin3D 10 | ) where 11 | 12 | import Unsafe.Coerce (unsafeCoerce) 13 | import Web.GPU.Internal.Types (GPUIntegerCoordinate) 14 | 15 | data GPUOrigin3D 16 | 17 | gpuOrigin3DX :: GPUIntegerCoordinate -> GPUOrigin3D 18 | gpuOrigin3DX x = unsafeCoerce [ x ] 19 | 20 | gpuOrigin3DXY :: GPUIntegerCoordinate -> GPUIntegerCoordinate -> GPUOrigin3D 21 | gpuOrigin3DXY x y = unsafeCoerce [ x, y ] 22 | 23 | gpuOrigin3DXYZ 24 | :: GPUIntegerCoordinate 25 | -> GPUIntegerCoordinate 26 | -> GPUIntegerCoordinate 27 | -> GPUOrigin3D 28 | gpuOrigin3DXYZ x y z = unsafeCoerce [ x, y, z ] 29 | 30 | gpuOrigin3DDict 31 | :: { x :: GPUIntegerCoordinate 32 | , y :: GPUIntegerCoordinate 33 | , z :: GPUIntegerCoordinate 34 | } 35 | -> GPUOrigin3D 36 | gpuOrigin3DDict = unsafeCoerce -------------------------------------------------------------------------------- /src/Web/GPU/GPUSamplerDescriptor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUSamplerDescriptor where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Web.GPU.GPUAddressMode (GPUAddressMode) 5 | import Web.GPU.GPUCompareFunction (GPUCompareFunction) 6 | import Web.GPU.GPUFilterMode (GPUFilterMode) 7 | import Web.GPU.GPUMipmapFilterMode (GPUMipmapFilterMode) 8 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 9 | import Web.GPU.Internal.Types (UnsignedShort) 10 | 11 | newtype GPUSamplerDescriptor = GPUSamplerDescriptor 12 | ( RequiredAndOptional () 13 | ( addressModeU :: GPUAddressMode 14 | , addressModeV :: GPUAddressMode 15 | , addressModeW :: GPUAddressMode 16 | , magFilter :: GPUFilterMode 17 | , minFilter :: GPUFilterMode 18 | , mipmapFilter :: GPUMipmapFilterMode 19 | , lodMinClamp :: Number 20 | , lodMaxClamp :: Number 21 | , compare :: GPUCompareFunction 22 | , maxAnisotropy :: UnsignedShort 23 | , label :: String 24 | ) 25 | ) 26 | 27 | derive instance Newtype GPUSamplerDescriptor _ -------------------------------------------------------------------------------- /src/Web/GPU/GPUBufferUsage.js: -------------------------------------------------------------------------------- 1 | export const mapRead = window.GPUBufferUsage 2 | ? window.GPUBufferUsage.MAP_READ 3 | : 0x0000; 4 | export const mapWrite = window.GPUBufferUsage 5 | ? window.GPUBufferUsage.MAP_WRITE 6 | : 0x0000; 7 | export const copySrc = window.GPUBufferUsage 8 | ? window.GPUBufferUsage.COPY_SRC 9 | : 0x0000; 10 | export const copyDst = window.GPUBufferUsage 11 | ? window.GPUBufferUsage.COPY_DST 12 | : 0x0000; 13 | export const index = window.GPUBufferUsage 14 | ? window.GPUBufferUsage.INDEX 15 | : 0x0000; 16 | export const vertex = window.GPUBufferUsage 17 | ? window.GPUBufferUsage.VERTEX 18 | : 0x0000; 19 | export const uniform = window.GPUBufferUsage 20 | ? window.GPUBufferUsage.UNIFORM 21 | : 0x0000; 22 | export const storage = window.GPUBufferUsage 23 | ? window.GPUBufferUsage.STORAGE 24 | : 0x0000; 25 | export const indirect = window.GPUBufferUsage 26 | ? window.GPUBufferUsage.INDIRECT 27 | : 0x0000; 28 | export const queryResolve = window.GPUBufferUsage 29 | ? window.GPUBufferUsage.QUERY_RESOLVE 30 | : 0x0000; 31 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBuffer.js: -------------------------------------------------------------------------------- 1 | export const sizeImpl = buffer => buffer.size; 2 | export const usageImpl = buffer => buffer.usage; 3 | export const mapStateImpl = buffer => buffer.mapState; 4 | export const mapAsyncImpl = (buffer, mode) => buffer.mapAsync(mode); 5 | export const mapAsyncWithOffsetImpl = (buffer, mode, offset) => 6 | buffer.mapAsync(mode, offset); 7 | export const mapAsyncWithSizeImpl = (buffer, mode, size) => 8 | buffer.mapAsync(mode, undefined, size); 9 | export const mapAsyncWithOffsetAndSizeImpl = (buffer, mode, offset, size) => 10 | buffer.mapAsync(mode, offset, size); 11 | export const getMappedRangeImpl = buffer => buffer.getMappedRange(); 12 | export const getMappedRangeWithOffsetImpl = (buffer, offset) => 13 | buffer.getMappedRange(offset); 14 | export const getMappedRangeWithSizeImpl = (buffer, size) => 15 | buffer.getMappedRange(undefined, size); 16 | export const getMappedRangeWithOffsetAndSizeImpl = (buffer, offset, size) => 17 | buffer.getMappedRange(offset, size); 18 | export const unmapImpl = buffer => buffer.unmap(); 19 | export const destroyImpl = buffer => buffer.destroy(); 20 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBufferUsage.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBufferUsage 2 | ( GPUBufferUsage 3 | , GPUBufferUsageFlags 4 | , copyDst 5 | , copySrc 6 | , index 7 | , indirect 8 | , mapRead 9 | , mapWrite 10 | , queryResolve 11 | , storage 12 | , uniform 13 | , vertex 14 | ) where 15 | 16 | import Data.Int.Bits as Bits 17 | import Web.GPU.Internal.Bitwise (class Bitwise) 18 | import Web.GPU.Internal.Types (UnsignedLong) 19 | 20 | newtype GPUBufferUsage = GPUBufferUsage UnsignedLong 21 | 22 | foreign import mapRead :: GPUBufferUsage 23 | foreign import mapWrite :: GPUBufferUsage 24 | foreign import copySrc :: GPUBufferUsage 25 | foreign import copyDst :: GPUBufferUsage 26 | foreign import index :: GPUBufferUsage 27 | foreign import vertex :: GPUBufferUsage 28 | foreign import uniform :: GPUBufferUsage 29 | foreign import storage :: GPUBufferUsage 30 | foreign import indirect :: GPUBufferUsage 31 | foreign import queryResolve :: GPUBufferUsage 32 | 33 | instance Bitwise GPUBufferUsage where 34 | or (GPUBufferUsage a) (GPUBufferUsage b) = GPUBufferUsage (a `Bits.or` b) 35 | 36 | type GPUBufferUsageFlags = GPUBufferUsage -------------------------------------------------------------------------------- /sandbox/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | WebGPU Hello Triangle 7 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUStencilOperation.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUStencilOperation 2 | ( GPUStencilOperation 3 | , decrementClamp 4 | , decrementWrap 5 | , incrementClamp 6 | , incrementWrap 7 | , invert 8 | , keep 9 | , replace 10 | , zero 11 | ) where 12 | 13 | import Prelude 14 | 15 | newtype GPUStencilOperation = GPUStencilOperation String 16 | 17 | derive instance Eq GPUStencilOperation 18 | derive instance Ord GPUStencilOperation 19 | derive newtype instance Show GPUStencilOperation 20 | 21 | keep :: GPUStencilOperation 22 | keep = GPUStencilOperation "keep" 23 | 24 | zero :: GPUStencilOperation 25 | zero = GPUStencilOperation "zero" 26 | 27 | replace :: GPUStencilOperation 28 | replace = GPUStencilOperation "replace" 29 | 30 | invert :: GPUStencilOperation 31 | invert = GPUStencilOperation "invert" 32 | 33 | incrementClamp :: GPUStencilOperation 34 | incrementClamp = GPUStencilOperation "increment-clamp" 35 | 36 | decrementClamp :: GPUStencilOperation 37 | decrementClamp = GPUStencilOperation "decrement-clamp" 38 | 39 | incrementWrap :: GPUStencilOperation 40 | incrementWrap = GPUStencilOperation "increment-wrap" 41 | 42 | decrementWrap :: GPUStencilOperation 43 | decrementWrap = GPUStencilOperation "decrement-wrap" -------------------------------------------------------------------------------- /src/Web/GPU/GPUQueue.js: -------------------------------------------------------------------------------- 1 | export const submitImpl = (queue, commandBuffers) => 2 | queue.submit(commandBuffers); 3 | export const onSubmittedWorkDoneImpl = queue => queue.onSubmittedWorkDone(); 4 | export const writeBufferImpl = (queue, buffer, bufferOffset, data) => 5 | queue.writeBuffer(buffer, bufferOffset, data); 6 | export const writeBufferWithOffsetImpl = ( 7 | queue, 8 | buffer, 9 | bufferOffset, 10 | data, 11 | dataOffset 12 | ) => queue.writeBuffer(buffer, bufferOffset, data, dataOffset); 13 | export const writeBufferWithSizeImpl = ( 14 | queue, 15 | buffer, 16 | bufferOffset, 17 | data, 18 | size 19 | ) => queue.writeBuffer(buffer, bufferOffset, data, undefined, size); 20 | export const writeBufferWithOffsetAndSizeImpl = ( 21 | queue, 22 | buffer, 23 | bufferOffset, 24 | data, 25 | dataOffset, 26 | size 27 | ) => queue.writeBuffer(buffer, bufferOffset, data, dataOffset, size); 28 | export const writeTextureImpl = (queue, destination, data, dataLayout, size) => 29 | queue.writeTexture(destination, data, dataLayout, size); 30 | export const copyExternalImageToTextureImpl = ( 31 | queue, 32 | source, 33 | destination, 34 | copySize 35 | ) => queue.copyExternalImageToTexture(source, destination, copySize); 36 | -------------------------------------------------------------------------------- /src/Web/GPU/GPU.purs: -------------------------------------------------------------------------------- 1 | -- @inline export requestAdapter arity=1 2 | -- @inline export getPreferredCanvasFormat arity=1 3 | module Web.GPU.GPU 4 | ( GPU 5 | , requestAdapter 6 | , getPreferredCanvasFormat 7 | ) where 8 | 9 | import Data.Maybe (Maybe(..)) 10 | import Effect.Uncurried (EffectFn1, runEffectFn1, EffectFn4, runEffectFn4) 11 | import Effect (Effect) 12 | import Web.GPU.GPURequestAdapterOptions (GPURequestAdapterOptions) 13 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 14 | import Promise (Promise) 15 | import Web.GPU.GPUAdapter (GPUAdapter) 16 | 17 | data GPU 18 | 19 | -- requestAdapter 20 | 21 | foreign import requestAdapterImpl 22 | :: EffectFn4 (GPUAdapter -> Maybe GPUAdapter) (Maybe GPUAdapter) GPU 23 | GPURequestAdapterOptions 24 | (Promise (Maybe GPUAdapter)) 25 | 26 | requestAdapter 27 | :: GPU 28 | -> GPURequestAdapterOptions 29 | -> Effect (Promise (Maybe GPUAdapter)) 30 | requestAdapter a b = runEffectFn4 requestAdapterImpl Just Nothing a b 31 | 32 | -- getPreferredCanvasFormat 33 | 34 | foreign import getPreferredCanvasFormatImpl :: EffectFn1 GPU GPUTextureFormat 35 | 36 | getPreferredCanvasFormat :: GPU -> Effect GPUTextureFormat 37 | getPreferredCanvasFormat a = runEffectFn1 getPreferredCanvasFormatImpl a 38 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBlendFactor.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBlendFactor 2 | ( GPUBlendFactor 3 | , constant 4 | , dst 5 | , dstAlpha 6 | , one 7 | , oneMinusConstant 8 | , oneMinusDst 9 | , oneMinusDstAlpha 10 | , oneMinusSrc 11 | , oneMinusSrcAlpha 12 | , src 13 | , srcAlpha 14 | , srcAlphaSaturated 15 | , zero 16 | ) where 17 | 18 | import Prelude 19 | 20 | newtype GPUBlendFactor = GPUBlendFactor String 21 | 22 | derive instance Eq GPUBlendFactor 23 | derive instance Ord GPUBlendFactor 24 | derive newtype instance Show GPUBlendFactor 25 | zero = GPUBlendFactor "zero" :: GPUBlendFactor 26 | one = GPUBlendFactor "one" :: GPUBlendFactor 27 | src = GPUBlendFactor "src" :: GPUBlendFactor 28 | oneMinusSrc = GPUBlendFactor "one-minus-src" :: GPUBlendFactor 29 | srcAlpha = GPUBlendFactor "src-alpha" :: GPUBlendFactor 30 | oneMinusSrcAlpha = GPUBlendFactor "one-minus-src-alpha" :: GPUBlendFactor 31 | dst = GPUBlendFactor "dst" :: GPUBlendFactor 32 | oneMinusDst = GPUBlendFactor "one-minus-dst" :: GPUBlendFactor 33 | dstAlpha = GPUBlendFactor "dst-alpha" :: GPUBlendFactor 34 | oneMinusDstAlpha = GPUBlendFactor "one-minus-dst-alpha" :: GPUBlendFactor 35 | srcAlphaSaturated = GPUBlendFactor "src-alpha-saturated" :: GPUBlendFactor 36 | constant = GPUBlendFactor "constant" :: GPUBlendFactor 37 | oneMinusConstant = GPUBlendFactor "one-minus-constant" :: GPUBlendFactor -------------------------------------------------------------------------------- /src/Web/GPU/GPUFeatureName.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUFeatureName 2 | ( GPUFeatureName 3 | , bgra8unormStorage 4 | , depth32floatStencil8 5 | , depthClipControl 6 | , indirectFirstInstance 7 | , rg11b10ufloatRenderable 8 | , shaderF16 9 | , textureCompressionAstc 10 | , textureCompressionBc 11 | , textureCompressionEtc2 12 | , timestampQuery 13 | ) where 14 | 15 | import Prelude 16 | 17 | newtype GPUFeatureName = GPUFeatureName String 18 | 19 | derive instance Eq GPUFeatureName 20 | derive instance Ord GPUFeatureName 21 | derive newtype instance Show GPUFeatureName 22 | depthClipControl = GPUFeatureName "depth-clip-control" :: GPUFeatureName 23 | depth32floatStencil8 = GPUFeatureName "depth32float-stencil8" :: GPUFeatureName 24 | textureCompressionBc = GPUFeatureName "texture-compression-bc" :: GPUFeatureName 25 | textureCompressionEtc2 = 26 | GPUFeatureName "texture-compression-etc2" :: GPUFeatureName 27 | 28 | textureCompressionAstc = 29 | GPUFeatureName "texture-compression-astc" :: GPUFeatureName 30 | 31 | timestampQuery = GPUFeatureName "timestamp-query" :: GPUFeatureName 32 | indirectFirstInstance = 33 | GPUFeatureName "indirect-first-instance" :: GPUFeatureName 34 | 35 | shaderF16 = GPUFeatureName "shader-f16" :: GPUFeatureName 36 | bgra8unormStorage = GPUFeatureName "bgra8unorm-storage" :: GPUFeatureName 37 | rg11b10ufloatRenderable = 38 | GPUFeatureName "rg11b10ufloat-renderable" :: GPUFeatureName -------------------------------------------------------------------------------- /src/Web/GPU/GPUCanvasContext.purs: -------------------------------------------------------------------------------- 1 | -- @inline export canvas arity=1 2 | -- @inline export configure arity=2 3 | -- @inline export unconfigure arity=1 4 | -- @inline export getCurrentTexture arity=1 5 | module Web.GPU.GPUCanvasContext 6 | ( GPUCanvasContext 7 | , canvas 8 | , configure 9 | , getCurrentTexture 10 | , unconfigure 11 | ) where 12 | 13 | import Prelude 14 | import Effect.Uncurried(EffectFn1, runEffectFn1,EffectFn2, runEffectFn2) 15 | 16 | import Effect (Effect) 17 | import Web.GPU.GPUCanvasConfiguration (GPUCanvasConfiguration) 18 | import Web.GPU.GPUTexture (GPUTexture) 19 | import Web.HTML (HTMLCanvasElement) 20 | 21 | data GPUCanvasContext 22 | 23 | foreign import canvasImpl :: EffectFn1 GPUCanvasContext HTMLCanvasElement 24 | canvas :: GPUCanvasContext -> Effect HTMLCanvasElement 25 | canvas a = runEffectFn1 canvasImpl a 26 | 27 | foreign import configureImpl :: EffectFn2 GPUCanvasContext GPUCanvasConfiguration Unit 28 | configure :: GPUCanvasContext -> GPUCanvasConfiguration -> Effect Unit 29 | configure a b = runEffectFn2 configureImpl a b 30 | 31 | foreign import unconfigureImpl :: EffectFn1 GPUCanvasContext Unit 32 | unconfigure :: GPUCanvasContext -> Effect Unit 33 | unconfigure a = runEffectFn1 unconfigureImpl a 34 | 35 | foreign import getCurrentTextureImpl :: EffectFn1 GPUCanvasContext GPUTexture 36 | getCurrentTexture :: GPUCanvasContext -> Effect GPUTexture 37 | getCurrentTexture a = runEffectFn1 getCurrentTextureImpl a -------------------------------------------------------------------------------- /src/Web/GPU/GPUBindGroupEntry.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBindGroupEntry where 2 | 3 | import Data.Newtype (class Newtype) 4 | import Unsafe.Coerce (unsafeCoerce) 5 | import Web.GPU.GPUBuffer (GPUBuffer) 6 | import Web.GPU.GPUExternalTexture (GPUExternalTexture) 7 | import Web.GPU.GPUSampler (GPUSampler) 8 | import Web.GPU.GPUTextureView (GPUTextureView) 9 | import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional) 10 | import Web.GPU.Internal.Types (GPUIndex32, GPUSize64) 11 | 12 | data GPUBindGroupEntry 13 | 14 | class AsGPUBindGroupEntry e where 15 | gpuBindGroupEntry :: GPUIndex32 -> e -> GPUBindGroupEntry 16 | 17 | instance AsGPUBindGroupEntry GPUSampler where 18 | gpuBindGroupEntry binding resource = unsafeCoerce 19 | { binding, resource: unsafeCoerce resource } 20 | 21 | instance AsGPUBindGroupEntry GPUTextureView where 22 | gpuBindGroupEntry binding resource = unsafeCoerce 23 | { binding, resource: unsafeCoerce resource } 24 | 25 | newtype GPUBufferBinding = GPUBufferBinding 26 | ( RequiredAndOptional (buffer :: GPUBuffer) 27 | (offset :: GPUSize64, size :: GPUSize64) 28 | ) 29 | 30 | derive instance Newtype GPUBufferBinding _ 31 | 32 | instance AsGPUBindGroupEntry GPUBufferBinding where 33 | gpuBindGroupEntry binding resource = unsafeCoerce 34 | { binding, resource: unsafeCoerce resource } 35 | 36 | instance AsGPUBindGroupEntry GPUExternalTexture where 37 | gpuBindGroupEntry binding resource = unsafeCoerce 38 | { binding, resource: unsafeCoerce resource } -------------------------------------------------------------------------------- /src/Web/GPU/GPUShaderModule.purs: -------------------------------------------------------------------------------- 1 | -- @inline export compilationInfo arity=1 2 | module Web.GPU.GPUShaderModule 3 | ( GPUShaderModule 4 | , compilationInfo 5 | , GPUCompilationMessageType 6 | , error 7 | , warning 8 | , info 9 | ) where 10 | 11 | import Prelude 12 | import Effect.Uncurried (EffectFn1, runEffectFn1) 13 | 14 | import Effect (Effect) 15 | import Web.GPU.Internal.Types (UnsignedLongLong) 16 | import Promise (Promise) 17 | 18 | data GPUShaderModule 19 | newtype GPUCompilationMessageType = GPUCompilationMessageType String 20 | 21 | derive instance Eq GPUCompilationMessageType 22 | derive instance Ord GPUCompilationMessageType 23 | derive newtype instance Show GPUCompilationMessageType 24 | 25 | error :: GPUCompilationMessageType 26 | error = GPUCompilationMessageType "error" 27 | 28 | warning :: GPUCompilationMessageType 29 | warning = GPUCompilationMessageType "warning" 30 | 31 | info :: GPUCompilationMessageType 32 | info = GPUCompilationMessageType "info" 33 | 34 | type GPUCompilationMessage = 35 | { message :: String 36 | , type :: GPUCompilationMessageType 37 | , lineNum :: UnsignedLongLong 38 | , linePos :: UnsignedLongLong 39 | , offset :: UnsignedLongLong 40 | , length :: UnsignedLongLong 41 | } 42 | 43 | type GPUCompilationInfo = 44 | { messages :: Array GPUCompilationMessage 45 | } 46 | 47 | foreign import compilationInfoImpl 48 | :: EffectFn1 GPUShaderModule (Promise GPUCompilationInfo) 49 | 50 | compilationInfo :: GPUShaderModule -> Effect (Promise GPUCompilationInfo) 51 | compilationInfo a = runEffectFn1 compilationInfoImpl a 52 | -------------------------------------------------------------------------------- /src/Web/GPU/Internal/RequiredAndOptional.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.Internal.RequiredAndOptional 2 | ( (~) 3 | , RequiredAndOptional 4 | , e 5 | , o 6 | , r 7 | , x 8 | , requiredAndOptional 9 | ) where 10 | 11 | import Data.Function.Uncurried (Fn2, runFn2) 12 | import Data.Newtype (class Newtype) 13 | import Prim.Row (class Union) 14 | import Unsafe.Coerce (unsafeCoerce) 15 | 16 | data RequiredAndOptional (required :: Row Type) (optional :: Row Type) 17 | 18 | foreign import requiredAndOptionalImpl :: forall a b c. Fn2 a b c 19 | 20 | requiredAndOptional 21 | :: forall nt required optionalL optionalR optional 22 | . Union optionalL optionalR optional 23 | => Newtype nt (RequiredAndOptional required optional) 24 | => { | required } 25 | -> { | optionalL } 26 | -> nt 27 | requiredAndOptional a b = runFn2 requiredAndOptionalImpl a b 28 | 29 | infixl 4 requiredAndOptional as ~ 30 | 31 | r 32 | :: forall nt required optional 33 | . Newtype nt (RequiredAndOptional required optional) 34 | => { | required } 35 | -> nt 36 | r = unsafeCoerce 37 | 38 | x 39 | :: forall nt incoming required optional optionalL optionalR 40 | . Newtype nt (RequiredAndOptional required optional) 41 | => Union required optionalL incoming 42 | => Union optionalL optionalR optional 43 | => { | incoming } 44 | -> nt 45 | x = unsafeCoerce 46 | 47 | o 48 | :: forall nt optionalL optionalR optional 49 | . Union optionalL optionalR optional 50 | => Newtype nt (RequiredAndOptional () optional) 51 | => { | optionalL } 52 | -> nt 53 | o = unsafeCoerce 54 | 55 | e 56 | :: forall nt optional 57 | . Newtype nt (RequiredAndOptional () optional) 58 | => nt 59 | e = unsafeCoerce {} 60 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBindGroupLayoutEntry.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUBindGroupLayoutEntry where 2 | 3 | import Unsafe.Coerce (unsafeCoerce) 4 | import Web.GPU.GPUBufferBindingLayout (GPUBufferBindingLayout) 5 | import Web.GPU.GPUExternalTextureBindingLayout (GPUExternalTextureBindingLayout) 6 | import Web.GPU.GPUSamplerBindingLayout (GPUSamplerBindingLayout) 7 | import Web.GPU.GPUShaderStage (GPUShaderStageFlags) 8 | import Web.GPU.GPUStorageTextureBindingLayout (GPUStorageTextureBindingLayout) 9 | import Web.GPU.GPUTextureBindingLayout (GPUTextureBindingLayout) 10 | import Web.GPU.Internal.Types (GPUIndex32) 11 | 12 | data GPUBindGroupLayoutEntry 13 | 14 | class AsGPUBindGroupLayoutEntry e where 15 | gpuBindGroupLayoutEntry 16 | :: GPUIndex32 -> GPUShaderStageFlags -> e -> GPUBindGroupLayoutEntry 17 | 18 | instance AsGPUBindGroupLayoutEntry GPUBufferBindingLayout where 19 | gpuBindGroupLayoutEntry binding visibility buffer = unsafeCoerce 20 | { binding, visibility, buffer } 21 | 22 | instance AsGPUBindGroupLayoutEntry GPUSamplerBindingLayout where 23 | gpuBindGroupLayoutEntry binding visibility sampler = unsafeCoerce 24 | { binding, visibility, sampler } 25 | 26 | instance AsGPUBindGroupLayoutEntry GPUTextureBindingLayout where 27 | gpuBindGroupLayoutEntry binding visibility texture = unsafeCoerce 28 | { binding, visibility, texture } 29 | 30 | instance AsGPUBindGroupLayoutEntry GPUStorageTextureBindingLayout where 31 | gpuBindGroupLayoutEntry binding visibility storageTexture = unsafeCoerce 32 | { binding, visibility, storageTexture } 33 | 34 | instance AsGPUBindGroupLayoutEntry GPUExternalTextureBindingLayout where 35 | gpuBindGroupLayoutEntry binding visibility externalTexture = 36 | unsafeCoerce { binding, visibility, externalTexture } -------------------------------------------------------------------------------- /src/Web/GPU/GPUSupportedLimits.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUSupportedLimits 2 | ( GPUSupportedLimits 3 | ) where 4 | 5 | import Web.GPU.Internal.Types (UnsignedLong, UnsignedLongLong) 6 | 7 | type GPUSupportedLimits = 8 | ( maxTextureDimension1D :: UnsignedLong 9 | , maxTextureDimension2D :: UnsignedLong 10 | , maxTextureDimension3D :: UnsignedLong 11 | , maxTextureArrayLayers :: UnsignedLong 12 | , maxBindGroups :: UnsignedLong 13 | , maxBindingsPerBindGroup :: UnsignedLong 14 | , maxDynamicUniformBuffersPerPipelineLayout :: UnsignedLong 15 | , maxDynamicStorageBuffersPerPipelineLayout :: UnsignedLong 16 | , maxSampledTexturesPerShaderStage :: UnsignedLong 17 | , maxSamplersPerShaderStage :: UnsignedLong 18 | , maxStorageBuffersPerShaderStage :: UnsignedLong 19 | , maxStorageTexturesPerShaderStage :: UnsignedLong 20 | , maxUniformBuffersPerShaderStage :: UnsignedLong 21 | , maxUniformBufferBindingSize :: UnsignedLongLong 22 | , maxStorageBufferBindingSize :: UnsignedLongLong 23 | , minUniformBufferOffsetAlignment :: UnsignedLong 24 | , minStorageBufferOffsetAlignment :: UnsignedLong 25 | , maxVertexBuffers :: UnsignedLong 26 | , maxBufferSize :: UnsignedLongLong 27 | , maxVertexAttributes :: UnsignedLong 28 | , maxVertexBufferArrayStride :: UnsignedLong 29 | , maxInterStageShaderComponents :: UnsignedLong 30 | , maxInterStageShaderVariables :: UnsignedLong 31 | , maxColorAttachments :: UnsignedLong 32 | , maxColorAttachmentBytesPerSample :: UnsignedLong 33 | , maxComputeWorkgroupStorageSize :: UnsignedLong 34 | , maxComputeInvocationsPerWorkgroup :: UnsignedLong 35 | , maxComputeWorkgroupSizeX :: UnsignedLong 36 | , maxComputeWorkgroupSizeY :: UnsignedLong 37 | , maxComputeWorkgroupSizeZ :: UnsignedLong 38 | , maxComputeWorkgroupsPerDimension :: UnsignedLong 39 | ) -------------------------------------------------------------------------------- /src/Web/GPU/GPUComputePassEncoder.js: -------------------------------------------------------------------------------- 1 | export const setPipelineImpl = (computePassEncoder, pipeline) => 2 | computePassEncoder.setPipeline(pipeline); 3 | export const dispatchWorkgroupsImpl = (computePassEncoder, size) => 4 | computePassEncoder.dispatchWorkgroups(size); 5 | export const dispatchWorkgroupsXImpl = (computePassEncoder, size) => 6 | computePassEncoder.dispatchWorkgroups(size); 7 | export const dispatchWorkgroupsXYImpl = (computePassEncoder, x, y) => 8 | computePassEncoder.dispatchWorkgroups(x, y); 9 | export const dispatchWorkgroupsXYZImpl = (computePassEncoder, x, y, z) => 10 | computePassEncoder.dispatchWorkgroups(x, y, z); 11 | export const dispatchWorkgroupsIndirectImpl = ( 12 | computePassEncoder, 13 | indirectBuffer, 14 | indirectOffset 15 | ) => 16 | computePassEncoder.dispatchWorkgroupsIndirect(indirectBuffer, indirectOffset); 17 | export const endImpl = computePassEncoder => computePassEncoder.end(); 18 | export const setBindGroupImpl = (computePassEncoder, index, bindGroup) => 19 | computePassEncoder.setBindGroup(index, bindGroup); 20 | export const setBindGroupWithDynamicOffsetsImpl = ( 21 | computePassEncoder, 22 | index, 23 | bindGroup, 24 | dynamicOffsets 25 | ) => computePassEncoder.setBindGroup(index, bindGroup, dynamicOffsets); 26 | export const setBindGroupWithDyanmicOffsetBoundsImpl = ( 27 | computePassEncoder, 28 | index, 29 | bindGroup, 30 | data, 31 | dynamicOffsetsDataStart, 32 | dynamicOffsetsDataLength 33 | ) => 34 | computePassEncoder.setBindGroup( 35 | index, 36 | bindGroup, 37 | data, 38 | dynamicOffsetsDataStart, 39 | dynamicOffsetsDataLength 40 | ); 41 | export const pushDebugGroupImpl = (computePassEncoder, groupLabel) => 42 | computePassEncoder.pushDebugGroup(groupLabel); 43 | export const popDebugGroupImpl = computePassEncoder => 44 | computePassEncoder.popDebugGroup(); 45 | export const insertDebugMarkerImpl = (computePassEncoder, markerLabel) => 46 | computePassEncoder.insertDebugMarker(markerLabel); 47 | -------------------------------------------------------------------------------- /src/Web/GPU/BufferSource.purs: -------------------------------------------------------------------------------- 1 | -- @inline export fromArrayBuffer arity=1 2 | -- @inline export fromInt8Array arity=1 3 | -- @inline export fromInt16Array arity=1 4 | -- @inline export fromInt32Array arity=1 5 | -- @inline export fromUint8Array arity=1 6 | -- @inline export fromUint16Array arity=1 7 | -- @inline export fromUint32Array arity=1 8 | -- @inline export fromUint8ClampedArray arity=1 9 | -- @inline export fromFloat32Array arity=1 10 | -- @inline export fromFloat64Array arity=1 11 | -- @inline export fromDataView arity=1 12 | module Web.GPU.BufferSource where 13 | 14 | import Data.ArrayBuffer.Types (ArrayBuffer, DataView, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray) 15 | import Unsafe.Coerce (unsafeCoerce) 16 | 17 | data BufferSource 18 | 19 | fromArrayBuffer :: ArrayBuffer -> BufferSource 20 | fromArrayBuffer = unsafeCoerce 21 | 22 | fromInt8Array :: Int8Array -> BufferSource 23 | fromInt8Array = unsafeCoerce 24 | 25 | fromInt16Array :: Int16Array -> BufferSource 26 | fromInt16Array = unsafeCoerce 27 | 28 | fromInt32Array :: Int32Array -> BufferSource 29 | fromInt32Array = unsafeCoerce 30 | 31 | fromUint8Array :: Uint8Array -> BufferSource 32 | fromUint8Array = unsafeCoerce 33 | 34 | fromUint16Array :: Uint16Array -> BufferSource 35 | fromUint16Array = unsafeCoerce 36 | 37 | fromUint32Array :: Uint32Array -> BufferSource 38 | fromUint32Array = unsafeCoerce 39 | 40 | fromUint8ClampedArray :: Uint8ClampedArray -> BufferSource 41 | fromUint8ClampedArray = unsafeCoerce 42 | 43 | -- todo: get these added to a PS lib 44 | -- fromBigInt64Array :: BigInt64Array -> BufferSource 45 | -- fromBigInt64Array = unsafeCoerce 46 | 47 | -- fromBigUint64Array :: BigUint64Array -> BufferSource 48 | -- fromBigUint64Array = unsafeCoerce 49 | 50 | fromFloat32Array :: Float32Array -> BufferSource 51 | fromFloat32Array = unsafeCoerce 52 | 53 | fromFloat64Array :: Float64Array -> BufferSource 54 | fromFloat64Array = unsafeCoerce 55 | 56 | fromDataView :: DataView -> BufferSource 57 | fromDataView = unsafeCoerce -------------------------------------------------------------------------------- /apply-backend-es-annotations.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | for root, dirs, files in os.walk("src", topdown=False): 4 | for name in files: 5 | p = os.path.join(root, name) 6 | if 'RequiredAndOptional' in p: continue 7 | with open(p, "r") as f: 8 | content = f.read() 9 | content = content.splitlines() 10 | content = [x for x in content if '-- @inline export' not in x] 11 | # find functions candidates 12 | candidates = [] 13 | for x in range(len(content)): 14 | l = content[x] 15 | if l[:4] == ' ::': candidates.append(content[x-1]) 16 | elif '::' in l and '->' in l: candidates.append(content[x]) 17 | candidates = [x.replace('foreign import','').split('::')[0].strip() for x in candidates] 18 | candidates = [x for x in candidates if '--' not in x] 19 | candidates = [x for x in candidates if 'Impl' not in x] # no ffi yet 20 | arity = {} 21 | for candidate in candidates: 22 | for x in range(len(content)): 23 | l = content[x] 24 | fi = 'foreign import ' 25 | if (l[:len(candidate)] == candidate)| (l[:len(fi+candidate)] == fi+candidate): 26 | if '::' in l: 27 | arity[candidate] = l.split('::')[1].count('->') 28 | elif ('::' in content[x+1]) & ('->' in content[x+1]): 29 | arity[candidate] = content[x+1].split('::')[1].count('->') 30 | else: 31 | a = 0 32 | y = x + 2 33 | while True: 34 | if ' ->' in content[y]: 35 | a += 1 36 | y += 1 37 | else: break 38 | arity[candidate] = a 39 | break 40 | content = [f'-- @inline export {k} arity={v}' for k,v in arity.items() if v != 0] + content 41 | content = '\n'.join(content) 42 | with open(p, "w") as f: 43 | f.write(content) 44 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUCommandEncoder.js: -------------------------------------------------------------------------------- 1 | export const beginRenderPassImpl = (commandEncoder, descriptor) => 2 | commandEncoder.beginRenderPass(descriptor); 3 | export const beginComputePassImpl = (commandEncoder, descriptor) => 4 | commandEncoder.beginComputePass(descriptor); 5 | export const copyBufferToBufferImpl = ( 6 | commandEncoder, 7 | source, 8 | sourceOffset, 9 | destination, 10 | destinationOffset, 11 | size 12 | ) => 13 | commandEncoder.copyBufferToBuffer( 14 | source, 15 | sourceOffset, 16 | destination, 17 | destinationOffset, 18 | size 19 | ); 20 | export const copyBufferToTextureImpl = ( 21 | commandEncoder, 22 | source, 23 | destination, 24 | copySize 25 | ) => commandEncoder.copyBufferToTexture(source, destination, copySize); 26 | export const copyTextureToBufferImpl = ( 27 | commandEncoder, 28 | source, 29 | destination, 30 | copySize 31 | ) => commandEncoder.copyTextureToBuffer(source, destination, copySize); 32 | export const copyTextureToTextureImpl = ( 33 | commandEncoder, 34 | source, 35 | destination, 36 | copySize 37 | ) => commandEncoder.copyTextureToTexture(source, destination, copySize); 38 | export const clearBufferImpl = (commandEncoder, buffer) => 39 | commandEncoder.clearBuffer(buffer); 40 | export const clearBufferWithOffsetImpl = (commandEncoder, buffer, offset) => 41 | commandEncoder.clearBuffer(buffer, offset); 42 | export const clearBufferWithSizeImpl = (commandEncoder, buffer, size) => 43 | commandEncoder.clearBuffer(buffer, undefined, size); 44 | export const clearBufferWithOffsetAndSizeImpl = ( 45 | commandEncoder, 46 | buffer, 47 | offset, 48 | size 49 | ) => commandEncoder.clearBuffer(buffer, offset, size); 50 | export const writeTimestampImpl = (commandEncoder, querySet, queryIndex) => 51 | commandEncoder.writeTimestamp(querySet, queryIndex); 52 | export const resolveQuerySetImpl = ( 53 | commandEncoder, 54 | querySet, 55 | firstQuery, 56 | queryCount, 57 | destination, 58 | destinationOffset 59 | ) => 60 | commandEncoder.resolveQuerySet( 61 | querySet, 62 | firstQuery, 63 | queryCount, 64 | destination, 65 | destinationOffset 66 | ); 67 | export const finishImpl = commandEncoder => commandEncoder.finish(); 68 | export const pushDebugGroupImpl = (commandEncoder, groupLabel) => 69 | commandEncoder.pushDebugGroup(groupLabel); 70 | export const popDebugGroupImpl = commandEncoder => 71 | commandEncoder.popDebugGroup(); 72 | export const insertDebugMarkerImpl = (commandEncoder, markerLabel) => 73 | commandEncoder.insertDebugMarker(markerLabel); 74 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUAdapter.purs: -------------------------------------------------------------------------------- 1 | -- @inline export features arity=2 2 | -- @inline export limits arity=1 3 | -- @inline export isFallbackAdapter arity=1 4 | -- @inline export requestDevice arity=1 5 | -- @inline export requestAdapterInfo arity=2 6 | module Web.GPU.GPUAdapter 7 | ( GPUAdapter(..) 8 | , GPUAdapterInfo 9 | , features 10 | , isFallbackAdapter 11 | , limits 12 | , requestAdapterInfo 13 | , requestDevice 14 | ) where 15 | 16 | import Data.Maybe (Maybe(..)) 17 | import Effect.Uncurried (EffectFn1, runEffectFn1, EffectFn2, runEffectFn2, EffectFn3, runEffectFn3, EffectFn4, runEffectFn4) 18 | import Data.Set as Set 19 | import Effect (Effect) 20 | import Web.GPU.GPUDeviceDescriptor (GPUDeviceDescriptor) 21 | import Web.GPU.GPUFeatureName (GPUFeatureName) 22 | import Web.GPU.GPUDevice (GPUDevice) 23 | import Web.GPU.GPUSupportedLimits (GPUSupportedLimits) 24 | import Web.GPU.UnmaskHint (UnmaskHint) 25 | import Promise (Promise) 26 | 27 | data GPUAdapter 28 | 29 | -- features 30 | foreign import featuresImpl 31 | :: EffectFn3 32 | (GPUFeatureName -> Set.Set GPUFeatureName -> Set.Set GPUFeatureName) 33 | (Set.Set GPUFeatureName) 34 | GPUAdapter 35 | (Set.Set GPUFeatureName) 36 | 37 | features :: GPUAdapter -> Effect (Set.Set GPUFeatureName) 38 | features a = runEffectFn3 featuresImpl Set.insert Set.empty a 39 | 40 | foreign import limitsImpl :: EffectFn1 GPUAdapter { | GPUSupportedLimits } 41 | 42 | limits :: GPUAdapter -> Effect { | GPUSupportedLimits } 43 | limits a = runEffectFn1 limitsImpl a 44 | 45 | foreign import isFallbackAdapterImpl :: EffectFn1 GPUAdapter Boolean 46 | 47 | isFallbackAdapter :: GPUAdapter -> Effect Boolean 48 | isFallbackAdapter a = runEffectFn1 isFallbackAdapterImpl a 49 | 50 | -- requestDevice 51 | 52 | foreign import requestDeviceImpl 53 | :: EffectFn4 (GPUDevice -> Maybe GPUDevice) (Maybe GPUDevice) GPUAdapter 54 | GPUDeviceDescriptor 55 | (Promise (Maybe GPUDevice)) 56 | 57 | requestDevice 58 | :: GPUAdapter 59 | -> GPUDeviceDescriptor 60 | -> Effect (Promise (Maybe GPUDevice)) 61 | requestDevice a b = runEffectFn4 requestDeviceImpl Just Nothing a b 62 | 63 | -- requestAdapterInfo 64 | 65 | foreign import requestAdapterInfoImpl 66 | :: EffectFn2 GPUAdapter (Array UnmaskHint) (Promise GPUAdapterInfo) 67 | 68 | type GPUAdapterInfo = 69 | { vendor :: String 70 | , architecture :: String 71 | , device :: String 72 | , description :: String 73 | } 74 | 75 | requestAdapterInfo 76 | :: GPUAdapter -> Array UnmaskHint -> Effect (Promise GPUAdapterInfo) 77 | requestAdapterInfo a b = runEffectFn2 requestAdapterInfoImpl a b 78 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUVertexFormat.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUVertexFormat 2 | ( GPUVertexFormat 3 | , float16x2 4 | , float16x4 5 | , float32 6 | , float32x2 7 | , float32x3 8 | , float32x4 9 | , sint16x2 10 | , sint16x4 11 | , sint32 12 | , sint32x2 13 | , sint32x3 14 | , sint32x4 15 | , sint8x2 16 | , sint8x4 17 | , snorm16x2 18 | , snorm16x4 19 | , snorm8x2 20 | , snorm8x4 21 | , uint16x2 22 | , uint16x4 23 | , uint32 24 | , uint32x2 25 | , uint32x3 26 | , uint32x4 27 | , uint8x2 28 | , uint8x4 29 | , unorm16x2 30 | , unorm16x4 31 | , unorm8x2 32 | , unorm8x4 33 | ) where 34 | 35 | import Prelude 36 | 37 | newtype GPUVertexFormat = GPUVertexFormat String 38 | 39 | derive instance Eq GPUVertexFormat 40 | derive instance Ord GPUVertexFormat 41 | derive newtype instance Show GPUVertexFormat 42 | 43 | uint8x2 = GPUVertexFormat "uint8x2" :: GPUVertexFormat 44 | uint8x4 = GPUVertexFormat "uint8x4" :: GPUVertexFormat 45 | sint8x2 = GPUVertexFormat "sint8x2" :: GPUVertexFormat 46 | sint8x4 = GPUVertexFormat "sint8x4" :: GPUVertexFormat 47 | unorm8x2 = GPUVertexFormat "unorm8x2" :: GPUVertexFormat 48 | unorm8x4 = GPUVertexFormat "unorm8x4" :: GPUVertexFormat 49 | snorm8x2 = GPUVertexFormat "snorm8x2" :: GPUVertexFormat 50 | snorm8x4 = GPUVertexFormat "snorm8x4" :: GPUVertexFormat 51 | uint16x2 = GPUVertexFormat "uint16x2" :: GPUVertexFormat 52 | uint16x4 = GPUVertexFormat "uint16x4" :: GPUVertexFormat 53 | sint16x2 = GPUVertexFormat "sint16x2" :: GPUVertexFormat 54 | sint16x4 = GPUVertexFormat "sint16x4" :: GPUVertexFormat 55 | unorm16x2 = GPUVertexFormat "unorm16x2" :: GPUVertexFormat 56 | unorm16x4 = GPUVertexFormat "unorm16x4" :: GPUVertexFormat 57 | snorm16x2 = GPUVertexFormat "snorm16x2" :: GPUVertexFormat 58 | snorm16x4 = GPUVertexFormat "snorm16x4" :: GPUVertexFormat 59 | float16x2 = GPUVertexFormat "float16x2" :: GPUVertexFormat 60 | float16x4 = GPUVertexFormat "float16x4" :: GPUVertexFormat 61 | float32 = GPUVertexFormat "float32" :: GPUVertexFormat 62 | float32x2 = GPUVertexFormat "float32x2" :: GPUVertexFormat 63 | float32x3 = GPUVertexFormat "float32x3" :: GPUVertexFormat 64 | float32x4 = GPUVertexFormat "float32x4" :: GPUVertexFormat 65 | uint32 = GPUVertexFormat "uint32" :: GPUVertexFormat 66 | uint32x2 = GPUVertexFormat "uint32x2" :: GPUVertexFormat 67 | uint32x3 = GPUVertexFormat "uint32x3" :: GPUVertexFormat 68 | uint32x4 = GPUVertexFormat "uint32x4" :: GPUVertexFormat 69 | sint32 = GPUVertexFormat "sint32" :: GPUVertexFormat 70 | sint32x2 = GPUVertexFormat "sint32x2" :: GPUVertexFormat 71 | sint32x3 = GPUVertexFormat "sint32x3" :: GPUVertexFormat 72 | sint32x4 = GPUVertexFormat "sint32x4" :: GPUVertexFormat -------------------------------------------------------------------------------- /src/Web/GPU/GPUDevice.js: -------------------------------------------------------------------------------- 1 | export const featuresImpl = (insert, empty, adapter) => { 2 | const iterator1 = adapter.features.entries(); 3 | let out = empty; 4 | for (const entry of iterator1) { 5 | out = insert(entry)(out); 6 | } 7 | return out; 8 | }; 9 | export const limitsImpl = adapter => adapter.limits; 10 | export const queueImpl = device => device.queue; 11 | export const destroyImpl = device => device.destroy(); 12 | export const createBufferImpl = (device, descriptor) => 13 | device.createBuffer(descriptor); 14 | export const createTextureImpl = (device, descriptor) => 15 | device.createTexture(descriptor); 16 | export const createSamplerImpl = (device, descriptor) => 17 | device.createSampler(descriptor); 18 | export const importExternalTextureImpl = (device, descriptor) => 19 | device.importExternalTexture(descriptor); 20 | export const bindGroupLayoutEntryForBufferImpl = options => buffer => ({ 21 | buffer, 22 | ...options, 23 | }); 24 | export const bindGroupLayoutEntryForSamplerImpl = options => sampler => ({ 25 | sampler, 26 | ...options, 27 | }); 28 | export const bindGroupLayoutEntryForTextureImpl = options => texture => ({ 29 | texture, 30 | ...options, 31 | }); 32 | export const bindGroupLayoutEntryForStorageTextureImpl = 33 | options => storageTexture => ({ storageTexture, ...options }); 34 | export const bindGroupLayoutEntryForExternalTextureImpl = 35 | options => externalTexture => ({ externalTexture, ...options }); 36 | export const createBindGroupLayoutImpl = (device, descriptor) => 37 | device.createBindGroupLayout(descriptor); 38 | export const createPipelineLayoutImpl = (device, descriptor) => 39 | device.createPipelineLayout(descriptor); 40 | export const createBindGroupImpl = (device, descriptor) => 41 | device.createBindGroup(descriptor); 42 | export const createShaderModuleImpl = (device, descriptor) => 43 | device.createShaderModule(descriptor); 44 | export const createComputePipelineImpl = (device, descriptor) => 45 | device.createComputePipeline(descriptor); 46 | export const createRenderPipelineImpl = (device, descriptor) => 47 | device.createRenderPipeline(descriptor); 48 | export const createComputePipelineAsyncImpl = (device, descriptor) => 49 | device.createComputePipelineAsync(descriptor); 50 | export const createRenderPipelineAsyncImpl = (device, descriptor) => 51 | device.createRenderPipelineAsync(descriptor); 52 | export const createCommandEncoderImpl = (device, descriptor) => 53 | device.createCommandEncoder(descriptor); 54 | export const createRenderBundleEncoderImpl = (device, descriptor) => 55 | device.createRenderBundleEncoder(descriptor); 56 | export const createQuerySetImpl = (device, descriptor) => 57 | device.createQuerySet(descriptor); 58 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUTexture.purs: -------------------------------------------------------------------------------- 1 | -- @inline export createViewWithDescriptor arity=2 2 | -- @inline export createView arity=2 3 | -- @inline export destroy arity=1 4 | -- @inline export width arity=1 5 | -- @inline export height arity=1 6 | -- @inline export depthOrArrayLayers arity=1 7 | -- @inline export mipLevelCount arity=1 8 | -- @inline export sampleCount arity=1 9 | -- @inline export dimension arity=1 10 | -- @inline export format arity=1 11 | -- @inline export usage arity=1 12 | module Web.GPU.GPUTexture 13 | ( GPUTexture 14 | , createViewWithDescriptor 15 | , createView 16 | , destroy 17 | , width 18 | , height 19 | , depthOrArrayLayers 20 | , mipLevelCount 21 | , sampleCount 22 | , dimension 23 | , format 24 | , usage 25 | ) where 26 | 27 | import Prelude 28 | import Effect.Uncurried(EffectFn1, runEffectFn1,EffectFn2, runEffectFn2) 29 | 30 | import Effect (Effect) 31 | import Web.GPU.GPUTextureDimension (GPUTextureDimension) 32 | import Web.GPU.GPUTextureFormat (GPUTextureFormat) 33 | import Web.GPU.GPUTextureUsage (GPUTextureUsage) 34 | import Web.GPU.GPUTextureView (GPUTextureView) 35 | import Web.GPU.GPUTextureViewDescriptor (GPUTextureViewDescriptor) 36 | import Web.GPU.Internal.Types (GPUIntegerCoordinate, GPUSize32) 37 | 38 | data GPUTexture 39 | 40 | foreign import createViewWithDescriptorImpl :: EffectFn2 GPUTexture GPUTextureViewDescriptor GPUTextureView 41 | createViewWithDescriptor 42 | :: GPUTexture 43 | -> GPUTextureViewDescriptor 44 | -> Effect GPUTextureView 45 | createViewWithDescriptor a b = runEffectFn2 createViewWithDescriptorImpl a b 46 | 47 | foreign import createViewImpl :: EffectFn1 GPUTexture GPUTextureView 48 | createView 49 | :: GPUTexture 50 | -> Effect GPUTextureView 51 | createView a = runEffectFn1 createViewImpl a 52 | 53 | foreign import destroyImpl :: EffectFn1 GPUTexture Unit 54 | destroy :: GPUTexture -> Effect Unit 55 | destroy a = runEffectFn1 destroyImpl a 56 | 57 | foreign import widthImpl :: EffectFn1 GPUTexture GPUIntegerCoordinate 58 | width :: GPUTexture -> Effect GPUIntegerCoordinate 59 | width a = runEffectFn1 widthImpl a 60 | 61 | foreign import heightImpl :: EffectFn1 GPUTexture GPUIntegerCoordinate 62 | height :: GPUTexture -> Effect GPUIntegerCoordinate 63 | height a = runEffectFn1 heightImpl a 64 | 65 | foreign import depthOrArrayLayersImpl :: EffectFn1 GPUTexture GPUIntegerCoordinate 66 | depthOrArrayLayers :: GPUTexture -> Effect GPUIntegerCoordinate 67 | depthOrArrayLayers a = runEffectFn1 depthOrArrayLayersImpl a 68 | 69 | foreign import mipLevelCountImpl :: EffectFn1 GPUTexture GPUIntegerCoordinate 70 | mipLevelCount :: GPUTexture -> Effect GPUIntegerCoordinate 71 | mipLevelCount a = runEffectFn1 mipLevelCountImpl a 72 | 73 | foreign import sampleCountImpl :: EffectFn1 GPUTexture GPUSize32 74 | sampleCount :: GPUTexture -> Effect GPUSize32 75 | sampleCount a = runEffectFn1 sampleCountImpl a 76 | 77 | foreign import dimensionImpl :: EffectFn1 GPUTexture GPUTextureDimension 78 | dimension :: GPUTexture -> Effect GPUTextureDimension 79 | dimension a = runEffectFn1 dimensionImpl a 80 | 81 | foreign import formatImpl :: EffectFn1 GPUTexture GPUTextureFormat 82 | format :: GPUTexture -> Effect GPUTextureFormat 83 | format a = runEffectFn1 formatImpl a 84 | 85 | foreign import usageImpl :: EffectFn1 GPUTexture GPUTextureUsage 86 | usage :: GPUTexture -> Effect GPUTextureUsage 87 | usage a = runEffectFn1 usageImpl a -------------------------------------------------------------------------------- /packages.dhall: -------------------------------------------------------------------------------- 1 | {- 2 | Welcome to your new Dhall package-set! 3 | 4 | Below are instructions for how to edit this file for most use 5 | cases, so that you don't need to know Dhall to use it. 6 | 7 | ## Use Cases 8 | 9 | Most will want to do one or both of these options: 10 | 1. Override/Patch a package's dependency 11 | 2. Add a package not already in the default package set 12 | 13 | This file will continue to work whether you use one or both options. 14 | Instructions for each option are explained below. 15 | 16 | ### Overriding/Patching a package 17 | 18 | Purpose: 19 | - Change a package's dependency to a newer/older release than the 20 | default package set's release 21 | - Use your own modified version of some dependency that may 22 | include new API, changed API, removed API by 23 | using your custom git repo of the library rather than 24 | the package set's repo 25 | 26 | Syntax: 27 | where `entityName` is one of the following: 28 | - dependencies 29 | - repo 30 | - version 31 | ------------------------------- 32 | let upstream = -- 33 | in upstream 34 | with packageName.entityName = "new value" 35 | ------------------------------- 36 | 37 | Example: 38 | ------------------------------- 39 | let upstream = -- 40 | in upstream 41 | with halogen.version = "master" 42 | with halogen.repo = "https://example.com/path/to/git/repo.git" 43 | 44 | with halogen-vdom.version = "v4.0.0" 45 | with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies 46 | ------------------------------- 47 | 48 | ### Additions 49 | 50 | Purpose: 51 | - Add packages that aren't already included in the default package set 52 | 53 | Syntax: 54 | where `` is: 55 | - a tag (i.e. "v4.0.0") 56 | - a branch (i.e. "master") 57 | - commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977") 58 | ------------------------------- 59 | let upstream = -- 60 | in upstream 61 | with new-package-name = 62 | { dependencies = 63 | [ "dependency1" 64 | , "dependency2" 65 | ] 66 | , repo = 67 | "https://example.com/path/to/git/repo.git" 68 | , version = 69 | "" 70 | } 71 | ------------------------------- 72 | 73 | Example: 74 | ------------------------------- 75 | let upstream = -- 76 | in upstream 77 | with benchotron = 78 | { dependencies = 79 | [ "arrays" 80 | , "exists" 81 | , "profunctor" 82 | , "strings" 83 | , "quickcheck" 84 | , "lcg" 85 | , "transformers" 86 | , "foldable-traversable" 87 | , "exceptions" 88 | , "node-fs" 89 | , "node-buffer" 90 | , "node-readline" 91 | , "datetime" 92 | , "now" 93 | ] 94 | , repo = 95 | "https://github.com/hdgarrood/purescript-benchotron.git" 96 | , version = 97 | "v7.0.0" 98 | } 99 | ------------------------------- 100 | -} 101 | let upstream = 102 | https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221229/packages.dhall 103 | sha256:a6af1091425f806ec0da34934bb6c0ab0ac1598620bbcbb60a7d463354e7d87c 104 | 105 | in upstream 106 | with gl-matrix = 107 | { dependencies = 108 | ["numbers" 109 | ] 110 | , repo = 111 | "https://github.com/mikesol/purescript-gl-matrix.git" 112 | , version = 113 | "fixes" -- branch, tag, or commit hash 114 | } -------------------------------------------------------------------------------- /src/Web/GPU/GPUQueue.purs: -------------------------------------------------------------------------------- 1 | -- @inline export onSubmittedWorkDone arity=1 2 | -- @inline export writeBuffer arity=4 3 | -- @inline export writeBufferWithOffset arity=5 4 | -- @inline export writeBufferWithSize arity=5 5 | -- @inline export writeBufferWithOffsetAndSize arity=6 6 | -- @inline export writeTexture arity=5 7 | -- @inline export copyExternalImageToTexture arity=4 8 | module Web.GPU.GPUQueue 9 | ( GPUQueue 10 | , copyExternalImageToTexture 11 | , onSubmittedWorkDone 12 | , submit 13 | , writeBuffer 14 | , writeBufferWithOffset 15 | , writeBufferWithOffsetAndSize 16 | , writeBufferWithSize 17 | , writeTexture 18 | ) where 19 | 20 | import Prelude 21 | import Effect.Uncurried (EffectFn1, runEffectFn1, EffectFn2, runEffectFn2, EffectFn4, runEffectFn4, EffectFn5, runEffectFn5, EffectFn6, runEffectFn6) 22 | 23 | import Effect (Effect) 24 | import Web.GPU.BufferSource (BufferSource) 25 | import Web.GPU.GPUBuffer (GPUBuffer) 26 | import Web.GPU.GPUExtent3D (GPUExtent3D) 27 | import Web.GPU.GPUImageCopyExternalImage (GPUImageCopyExternalImage) 28 | import Web.GPU.GPUImageCopyTexture (GPUImageCopyTexture) 29 | import Web.GPU.GPUImageCopyTextureTagged (GPUImageCopyTextureTagged) 30 | import Web.GPU.GPUImageDataLayout (GPUImageDataLayout) 31 | import Web.GPU.Internal.GPUCommandBuffer (GPUCommandBuffer) 32 | import Web.GPU.Internal.Types (GPUSize64) 33 | import Promise (Promise) 34 | 35 | data GPUQueue 36 | 37 | foreign import submitImpl :: EffectFn2 GPUQueue (Array GPUCommandBuffer) Unit 38 | 39 | submit ∷ GPUQueue → Array GPUCommandBuffer → Effect Unit 40 | submit a b = runEffectFn2 submitImpl a b 41 | 42 | foreign import onSubmittedWorkDoneImpl :: EffectFn1 GPUQueue (Promise Unit) 43 | 44 | onSubmittedWorkDone :: GPUQueue -> Effect (Promise Unit) 45 | onSubmittedWorkDone a = runEffectFn1 onSubmittedWorkDoneImpl a 46 | 47 | foreign import writeBufferImpl 48 | :: EffectFn4 GPUQueue GPUBuffer GPUSize64 BufferSource Unit 49 | 50 | writeBuffer :: GPUQueue -> GPUBuffer -> Int -> BufferSource -> Effect Unit 51 | writeBuffer a b c d = runEffectFn4 writeBufferImpl a b c d 52 | 53 | foreign import writeBufferWithOffsetImpl 54 | :: EffectFn5 GPUQueue GPUBuffer GPUSize64 BufferSource GPUSize64 Unit 55 | 56 | writeBufferWithOffset 57 | :: GPUQueue -> GPUBuffer -> Int -> BufferSource -> Int -> Effect Unit 58 | writeBufferWithOffset a b c d e = runEffectFn5 writeBufferWithOffsetImpl a b c d 59 | e 60 | 61 | foreign import writeBufferWithSizeImpl 62 | :: EffectFn5 GPUQueue GPUBuffer GPUSize64 BufferSource GPUSize64 Unit 63 | 64 | writeBufferWithSize 65 | :: GPUQueue -> GPUBuffer -> Int -> BufferSource -> Int -> Effect Unit 66 | writeBufferWithSize a b c d e = runEffectFn5 writeBufferWithSizeImpl a b c d e 67 | 68 | foreign import writeBufferWithOffsetAndSizeImpl 69 | :: EffectFn6 GPUQueue GPUBuffer GPUSize64 BufferSource GPUSize64 GPUSize64 70 | Unit 71 | 72 | writeBufferWithOffsetAndSize 73 | :: GPUQueue -> GPUBuffer -> Int -> BufferSource -> Int -> Int -> Effect Unit 74 | writeBufferWithOffsetAndSize a b c d e f = runEffectFn6 75 | writeBufferWithOffsetAndSizeImpl 76 | a 77 | b 78 | c 79 | d 80 | e 81 | f 82 | 83 | foreign import writeTextureImpl 84 | :: EffectFn5 GPUQueue GPUImageCopyTexture BufferSource GPUImageDataLayout 85 | GPUExtent3D 86 | Unit 87 | 88 | writeTexture 89 | :: GPUQueue 90 | -> GPUImageCopyTexture 91 | -> BufferSource 92 | -> GPUImageDataLayout 93 | -> GPUExtent3D 94 | -> Effect Unit 95 | writeTexture a b c d e = runEffectFn5 writeTextureImpl a b c d e 96 | 97 | foreign import copyExternalImageToTextureImpl 98 | :: EffectFn4 GPUQueue GPUImageCopyExternalImage GPUImageCopyTextureTagged 99 | GPUExtent3D 100 | Unit 101 | 102 | copyExternalImageToTexture 103 | :: GPUQueue 104 | -> GPUImageCopyExternalImage 105 | -> GPUImageCopyTextureTagged 106 | -> GPUExtent3D 107 | -> Effect Unit 108 | copyExternalImageToTexture a b c d = runEffectFn4 copyExternalImageToTextureImpl 109 | a 110 | b 111 | c 112 | d 113 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUBuffer.purs: -------------------------------------------------------------------------------- 1 | -- @inline export size arity=1 2 | -- @inline export usage arity=1 3 | -- @inline export mapState arity=1 4 | -- @inline export mapAsync arity=2 5 | -- @inline export mapAsyncWithOffset arity=3 6 | -- @inline export mapAsyncWithSize arity=3 7 | -- @inline export mapAsyncWithOffsetAndSize arity=4 8 | -- @inline export getMappedRange arity=1 9 | -- @inline export getMappedRangeWithOffset arity=2 10 | -- @inline export getMappedRangeWithSize arity=2 11 | -- @inline export getMappedRangeWithOffsetAndSize arity=3 12 | -- @inline export unmap arity=1 13 | -- @inline export destroy arity=1 14 | module Web.GPU.GPUBuffer 15 | ( GPUBuffer 16 | , destroy 17 | , getMappedRange 18 | , getMappedRangeWithOffset 19 | , getMappedRangeWithOffsetAndSize 20 | , getMappedRangeWithSize 21 | , mapAsync 22 | , mapAsyncWithOffset 23 | , mapAsyncWithOffsetAndSize 24 | , mapAsyncWithSize 25 | , mapState 26 | , size 27 | , unmap 28 | , usage 29 | ) where 30 | 31 | import Prelude 32 | import Effect.Uncurried (EffectFn1, runEffectFn1, EffectFn2, runEffectFn2, EffectFn3, runEffectFn3, EffectFn4, runEffectFn4) 33 | 34 | import Data.ArrayBuffer.Types (ArrayBuffer) 35 | import Effect (Effect) 36 | import Web.GPU.GPUBufferMapState (GPUBufferMapState) 37 | import Web.GPU.GPUBufferUsage (GPUBufferUsage) 38 | import Web.GPU.GPUMapMode (GPUMapMode) 39 | import Web.GPU.Internal.Types (GPUSize64) 40 | import Promise (Promise) 41 | 42 | data GPUBuffer 43 | 44 | foreign import sizeImpl :: EffectFn1 GPUBuffer GPUSize64 45 | 46 | size :: GPUBuffer -> Effect GPUSize64 47 | size a = runEffectFn1 sizeImpl a 48 | 49 | foreign import usageImpl :: EffectFn1 GPUBuffer GPUBufferUsage 50 | 51 | usage :: GPUBuffer -> Effect GPUBufferUsage 52 | usage a = runEffectFn1 usageImpl a 53 | 54 | foreign import mapStateImpl :: EffectFn1 GPUBuffer GPUBufferMapState 55 | 56 | mapState :: GPUBuffer -> Effect GPUBufferMapState 57 | mapState a = runEffectFn1 mapStateImpl a 58 | 59 | foreign import mapAsyncImpl :: EffectFn2 GPUBuffer GPUMapMode (Promise Unit) 60 | 61 | mapAsync :: GPUBuffer -> GPUMapMode -> Effect (Promise Unit) 62 | mapAsync a b = runEffectFn2 mapAsyncImpl a b 63 | 64 | foreign import mapAsyncWithOffsetImpl 65 | :: EffectFn3 GPUBuffer GPUMapMode GPUSize64 (Promise Unit) 66 | 67 | mapAsyncWithOffset 68 | :: GPUBuffer -> GPUMapMode -> GPUSize64 -> Effect (Promise Unit) 69 | mapAsyncWithOffset a b c = runEffectFn3 mapAsyncWithOffsetImpl a b c 70 | 71 | foreign import mapAsyncWithSizeImpl 72 | :: EffectFn3 GPUBuffer GPUMapMode GPUSize64 (Promise Unit) 73 | 74 | mapAsyncWithSize 75 | :: GPUBuffer -> GPUMapMode -> GPUSize64 -> Effect (Promise Unit) 76 | mapAsyncWithSize a b c = runEffectFn3 mapAsyncWithSizeImpl a b c 77 | 78 | foreign import mapAsyncWithOffsetAndSizeImpl 79 | :: EffectFn4 GPUBuffer GPUMapMode GPUSize64 GPUSize64 (Promise Unit) 80 | 81 | mapAsyncWithOffsetAndSize 82 | :: GPUBuffer -> GPUMapMode -> GPUSize64 -> GPUSize64 -> Effect (Promise Unit) 83 | mapAsyncWithOffsetAndSize a b c d = runEffectFn4 mapAsyncWithOffsetAndSizeImpl a 84 | b 85 | c 86 | d 87 | 88 | foreign import getMappedRangeImpl :: EffectFn1 GPUBuffer ArrayBuffer 89 | 90 | getMappedRange :: GPUBuffer -> Effect ArrayBuffer 91 | getMappedRange a = runEffectFn1 getMappedRangeImpl a 92 | 93 | foreign import getMappedRangeWithOffsetImpl 94 | :: EffectFn2 GPUBuffer GPUSize64 ArrayBuffer 95 | 96 | getMappedRangeWithOffset :: GPUBuffer -> GPUSize64 -> Effect ArrayBuffer 97 | getMappedRangeWithOffset a b = runEffectFn2 getMappedRangeWithOffsetImpl a b 98 | 99 | foreign import getMappedRangeWithSizeImpl 100 | :: EffectFn2 GPUBuffer GPUSize64 ArrayBuffer 101 | 102 | getMappedRangeWithSize :: GPUBuffer -> GPUSize64 -> Effect ArrayBuffer 103 | getMappedRangeWithSize a b = runEffectFn2 getMappedRangeWithSizeImpl a b 104 | 105 | foreign import getMappedRangeWithOffsetAndSizeImpl 106 | :: EffectFn3 GPUBuffer GPUSize64 GPUSize64 ArrayBuffer 107 | 108 | getMappedRangeWithOffsetAndSize 109 | :: GPUBuffer -> GPUSize64 -> GPUSize64 -> Effect ArrayBuffer 110 | getMappedRangeWithOffsetAndSize a b c = runEffectFn3 111 | getMappedRangeWithOffsetAndSizeImpl 112 | a 113 | b 114 | c 115 | 116 | foreign import unmapImpl :: EffectFn1 GPUBuffer Unit 117 | 118 | unmap :: GPUBuffer -> Effect Unit 119 | unmap a = runEffectFn1 unmapImpl a 120 | 121 | foreign import destroyImpl :: EffectFn1 GPUBuffer Unit 122 | 123 | destroy :: GPUBuffer -> Effect Unit 124 | destroy a = runEffectFn1 destroyImpl a 125 | -------------------------------------------------------------------------------- /src/Web/GPU/GPUComputePassEncoder.purs: -------------------------------------------------------------------------------- 1 | -- @inline export dispatchWorkgroupsXY arity=3 2 | -- @inline export dispatchWorkgroupsXYZ arity=4 3 | -- @inline export dispatchWorkgroupsIndirect arity=3 4 | -- @inline export end arity=1 5 | -- @inline export setBindGroup arity=3 6 | -- @inline export setBindGroupWithDynamicOffsets arity=4 7 | -- @inline export setBindGroupWithDyanmicOffsetBounds arity=6 8 | -- @inline export pushDebugGroup arity=2 9 | -- @inline export popDebugGroup arity=1 10 | -- @inline export insertDebugMarker arity=2 11 | module Web.GPU.GPUComputePassEncoder 12 | ( GPUComputePassEncoder(..) 13 | , dispatchWorkgroups 14 | , dispatchWorkgroupsIndirect 15 | , dispatchWorkgroupsX 16 | , dispatchWorkgroupsXY 17 | , dispatchWorkgroupsXYZ 18 | , end 19 | , insertDebugMarker 20 | , popDebugGroup 21 | , pushDebugGroup 22 | , setBindGroup 23 | , setBindGroupWithDyanmicOffsetBounds 24 | , setBindGroupWithDynamicOffsets 25 | , setPipeline 26 | ) where 27 | 28 | import Prelude 29 | import Data.ArrayBuffer.Types (Uint32Array) 30 | import Effect (Effect) 31 | import Effect.Uncurried (EffectFn1, runEffectFn1, EffectFn2, EffectFn3, EffectFn4, EffectFn6, runEffectFn2, runEffectFn3, runEffectFn4, runEffectFn6) 32 | import Web.GPU.GPUBindGroup (GPUBindGroup) 33 | import Web.GPU.GPUBuffer (GPUBuffer) 34 | import Web.GPU.GPUComputePipeline (GPUComputePipeline) 35 | import Web.GPU.Internal.Types (GPUIndex32, GPUSize32, GPUSize64, GPUBufferDynamicOffset) 36 | 37 | data GPUComputePassEncoder 38 | 39 | foreign import setPipelineImpl 40 | :: EffectFn2 GPUComputePassEncoder GPUComputePipeline Unit 41 | 42 | setPipeline ∷ GPUComputePassEncoder → GPUComputePipeline → Effect Unit 43 | setPipeline a b = runEffectFn2 setPipelineImpl a b 44 | 45 | foreign import dispatchWorkgroupsImpl 46 | ::EffectFn2 GPUComputePassEncoder GPUSize32 Unit 47 | 48 | dispatchWorkgroups ∷ GPUComputePassEncoder → Int → Effect Unit 49 | dispatchWorkgroups a b = runEffectFn2 dispatchWorkgroupsImpl a b 50 | 51 | foreign import dispatchWorkgroupsXImpl 52 | :: EffectFn2 GPUComputePassEncoder GPUSize32 Unit 53 | 54 | dispatchWorkgroupsX ∷ GPUComputePassEncoder → Int → Effect Unit 55 | dispatchWorkgroupsX a b = runEffectFn2 dispatchWorkgroupsXImpl a b 56 | 57 | foreign import dispatchWorkgroupsXYImpl 58 | :: EffectFn3 GPUComputePassEncoder GPUSize32 GPUSize32 Unit 59 | 60 | dispatchWorkgroupsXY :: GPUComputePassEncoder -> Int -> Int -> Effect Unit 61 | dispatchWorkgroupsXY a b c = runEffectFn3 dispatchWorkgroupsXYImpl a b c 62 | 63 | foreign import dispatchWorkgroupsXYZImpl 64 | :: EffectFn4 GPUComputePassEncoder GPUSize32 GPUSize32 GPUSize32 Unit 65 | 66 | dispatchWorkgroupsXYZ 67 | :: GPUComputePassEncoder -> Int -> Int -> Int -> Effect Unit 68 | dispatchWorkgroupsXYZ a b c d = runEffectFn4 dispatchWorkgroupsXYZImpl a b c d 69 | 70 | foreign import dispatchWorkgroupsIndirectImpl 71 | :: EffectFn3 GPUComputePassEncoder GPUBuffer GPUSize64 Unit 72 | 73 | dispatchWorkgroupsIndirect 74 | :: GPUComputePassEncoder -> GPUBuffer -> Int -> Effect Unit 75 | dispatchWorkgroupsIndirect a b c = runEffectFn3 76 | dispatchWorkgroupsIndirectImpl 77 | a 78 | b 79 | c 80 | 81 | foreign import endImpl :: EffectFn1 GPUComputePassEncoder Unit 82 | end :: GPUComputePassEncoder -> Effect Unit 83 | end a = runEffectFn1 endImpl a 84 | 85 | foreign import setBindGroupImpl 86 | :: EffectFn3 GPUComputePassEncoder GPUIndex32 GPUBindGroup Unit 87 | 88 | setBindGroup :: GPUComputePassEncoder -> Int -> GPUBindGroup -> Effect Unit 89 | setBindGroup a b c = runEffectFn3 setBindGroupImpl a b c 90 | 91 | foreign import setBindGroupWithDynamicOffsetsImpl 92 | :: EffectFn4 GPUComputePassEncoder 93 | GPUIndex32 GPUBindGroup (Array GPUBufferDynamicOffset) Unit 94 | 95 | setBindGroupWithDynamicOffsets 96 | :: GPUComputePassEncoder -> Int -> GPUBindGroup -> Array Int -> Effect Unit 97 | setBindGroupWithDynamicOffsets a b c d = runEffectFn4 98 | setBindGroupWithDynamicOffsetsImpl 99 | a 100 | b 101 | c 102 | d 103 | 104 | foreign import setBindGroupWithDyanmicOffsetBoundsImpl 105 | :: EffectFn6 GPUComputePassEncoder 106 | GPUIndex32 GPUBindGroup Uint32Array GPUSize64 GPUSize32 Unit 107 | 108 | setBindGroupWithDyanmicOffsetBounds 109 | :: GPUComputePassEncoder 110 | -> Int 111 | -> GPUBindGroup 112 | -> Uint32Array 113 | -> Int 114 | -> Int 115 | -> Effect Unit 116 | setBindGroupWithDyanmicOffsetBounds a b c d e f = runEffectFn6 117 | setBindGroupWithDyanmicOffsetBoundsImpl 118 | a 119 | b 120 | c 121 | d 122 | e 123 | f 124 | 125 | foreign import pushDebugGroupImpl 126 | :: EffectFn2 GPUComputePassEncoder String Unit 127 | 128 | pushDebugGroup :: GPUComputePassEncoder -> String -> Effect Unit 129 | pushDebugGroup a b = runEffectFn2 pushDebugGroupImpl a b 130 | 131 | foreign import popDebugGroupImpl :: EffectFn1 GPUComputePassEncoder Unit 132 | popDebugGroup :: GPUComputePassEncoder -> Effect Unit 133 | popDebugGroup a = runEffectFn1 popDebugGroupImpl a 134 | 135 | foreign import insertDebugMarkerImpl 136 | :: EffectFn2 GPUComputePassEncoder String Unit 137 | 138 | insertDebugMarker :: GPUComputePassEncoder -> String -> Effect Unit 139 | insertDebugMarker a b = runEffectFn2 insertDebugMarkerImpl a b -------------------------------------------------------------------------------- /src/Web/GPU/GPUCommandEncoder.purs: -------------------------------------------------------------------------------- 1 | -- @inline export beginRenderPass arity=2 2 | -- @inline export beginComputePass arity=2 3 | -- @inline export copyBufferToBuffer arity=6 4 | -- @inline export copyTextureToBuffer arity=4 5 | -- @inline export copyTextureToTexture arity=4 6 | -- @inline export clearBuffer arity=2 7 | -- @inline export clearBufferWithOffset arity=3 8 | -- @inline export clearBufferWithSize arity=3 9 | -- @inline export clearBufferWithOffsetAndSize arity=4 10 | -- @inline export writeTimestamp arity=3 11 | -- @inline export resolveQuerySet arity=6 12 | -- @inline export finish arity=1 13 | -- @inline export pushDebugGroup arity=2 14 | -- @inline export popDebugGroup arity=1 15 | -- @inline export insertDebugMarker arity=2 16 | module Web.GPU.GPUCommandEncoder 17 | ( GPUCommandEncoder(..) 18 | , beginComputePass 19 | , beginRenderPass 20 | , clearBuffer 21 | , clearBufferWithOffset 22 | , clearBufferWithOffsetAndSize 23 | , clearBufferWithSize 24 | , copyBufferToBuffer 25 | , copyBufferToTexture 26 | , copyTextureToBuffer 27 | , copyTextureToTexture 28 | , finish 29 | , insertDebugMarker 30 | , popDebugGroup 31 | , pushDebugGroup 32 | , resolveQuerySet 33 | , writeTimestamp 34 | ) where 35 | 36 | import Prelude 37 | import Effect (Effect) 38 | import Effect.Uncurried (EffectFn1, runEffectFn1, EffectFn2, EffectFn3, EffectFn4, EffectFn6, runEffectFn2, runEffectFn3, runEffectFn4, runEffectFn6) 39 | import Web.GPU.GPUBuffer (GPUBuffer) 40 | import Web.GPU.GPUComputePassDescriptor (GPUComputePassDescriptor) 41 | import Web.GPU.GPUComputePassEncoder (GPUComputePassEncoder) 42 | import Web.GPU.GPUExtent3D (GPUExtent3D) 43 | import Web.GPU.GPUImageCopyBuffer (GPUImageCopyBuffer) 44 | import Web.GPU.GPUImageCopyTexture (GPUImageCopyTexture) 45 | import Web.GPU.GPUQuerySet (GPUQuerySet) 46 | import Web.GPU.GPURenderPassDescriptor (GPURenderPassDescriptor) 47 | import Web.GPU.GPURenderPassEncoder (GPURenderPassEncoder) 48 | import Web.GPU.Internal.GPUCommandBuffer (GPUCommandBuffer) 49 | import Web.GPU.Internal.Types (GPUSize32, GPUSize64) 50 | 51 | data GPUCommandEncoder 52 | 53 | foreign import beginRenderPassImpl 54 | :: EffectFn2 GPUCommandEncoder GPURenderPassDescriptor GPURenderPassEncoder 55 | 56 | beginRenderPass 57 | :: GPUCommandEncoder -> GPURenderPassDescriptor -> Effect GPURenderPassEncoder 58 | beginRenderPass a b = runEffectFn2 beginRenderPassImpl a b 59 | 60 | foreign import beginComputePassImpl 61 | :: EffectFn2 GPUCommandEncoder 62 | GPUComputePassDescriptor GPUComputePassEncoder 63 | 64 | beginComputePass 65 | :: GPUCommandEncoder 66 | -> GPUComputePassDescriptor 67 | -> Effect GPUComputePassEncoder 68 | beginComputePass a b = runEffectFn2 beginComputePassImpl a b 69 | 70 | foreign import copyBufferToBufferImpl 71 | :: EffectFn6 GPUCommandEncoder 72 | GPUBuffer GPUSize64 GPUBuffer GPUSize64 GPUSize64 Unit 73 | 74 | copyBufferToBuffer 75 | :: GPUCommandEncoder 76 | -> GPUBuffer 77 | -> Int 78 | -> GPUBuffer 79 | -> Int 80 | -> Int 81 | -> Effect Unit 82 | copyBufferToBuffer a b c d e f = runEffectFn6 copyBufferToBufferImpl a b c d e 83 | f 84 | 85 | foreign import copyBufferToTextureImpl 86 | :: EffectFn4 GPUCommandEncoder 87 | GPUImageCopyBuffer GPUImageCopyTexture GPUExtent3D Unit 88 | 89 | copyBufferToTexture 90 | ∷ GPUCommandEncoder 91 | → GPUImageCopyBuffer 92 | → GPUImageCopyTexture 93 | → GPUExtent3D 94 | → Effect Unit 95 | copyBufferToTexture a b c d = runEffectFn4 copyBufferToTextureImpl a b c d 96 | 97 | foreign import copyTextureToBufferImpl 98 | :: EffectFn4 GPUCommandEncoder 99 | GPUImageCopyTexture GPUImageCopyBuffer GPUExtent3D Unit 100 | 101 | copyTextureToBuffer 102 | :: GPUCommandEncoder 103 | -> GPUImageCopyTexture 104 | -> GPUImageCopyBuffer 105 | -> GPUExtent3D 106 | -> Effect Unit 107 | copyTextureToBuffer a b c d = runEffectFn4 copyTextureToBufferImpl a b c d 108 | 109 | foreign import copyTextureToTextureImpl 110 | :: EffectFn4 GPUCommandEncoder 111 | GPUImageCopyTexture GPUImageCopyTexture GPUExtent3D Unit 112 | 113 | copyTextureToTexture 114 | :: GPUCommandEncoder 115 | -> GPUImageCopyTexture 116 | -> GPUImageCopyTexture 117 | -> GPUExtent3D 118 | -> Effect Unit 119 | copyTextureToTexture a b c d = runEffectFn4 copyTextureToTextureImpl a b c d 120 | 121 | foreign import clearBufferImpl 122 | :: EffectFn2 GPUCommandEncoder 123 | GPUBuffer Unit 124 | 125 | clearBuffer :: GPUCommandEncoder -> GPUBuffer -> Effect Unit 126 | clearBuffer a b = runEffectFn2 clearBufferImpl a b 127 | 128 | foreign import clearBufferWithOffsetImpl 129 | :: EffectFn3 GPUCommandEncoder 130 | GPUBuffer GPUSize64 Unit 131 | 132 | clearBufferWithOffset :: GPUCommandEncoder -> GPUBuffer -> Int -> Effect Unit 133 | clearBufferWithOffset a b c = runEffectFn3 clearBufferWithOffsetImpl a b c 134 | 135 | foreign import clearBufferWithSizeImpl 136 | :: EffectFn3 GPUCommandEncoder 137 | GPUBuffer GPUSize64 Unit 138 | 139 | clearBufferWithSize :: GPUCommandEncoder -> GPUBuffer -> Int -> Effect Unit 140 | clearBufferWithSize a b c = runEffectFn3 clearBufferWithSizeImpl a b c 141 | 142 | foreign import clearBufferWithOffsetAndSizeImpl 143 | :: EffectFn4 GPUCommandEncoder 144 | GPUBuffer GPUSize64 GPUSize64 Unit 145 | 146 | clearBufferWithOffsetAndSize 147 | :: GPUCommandEncoder -> GPUBuffer -> Int -> Int -> Effect Unit 148 | clearBufferWithOffsetAndSize a b c d = runEffectFn4 149 | clearBufferWithOffsetAndSizeImpl 150 | a 151 | b 152 | c 153 | d 154 | 155 | foreign import writeTimestampImpl 156 | :: EffectFn3 GPUCommandEncoder GPUQuerySet GPUSize32 Unit 157 | 158 | writeTimestamp :: GPUCommandEncoder -> GPUQuerySet -> Int -> Effect Unit 159 | writeTimestamp a b c = runEffectFn3 writeTimestampImpl a b c 160 | 161 | foreign import resolveQuerySetImpl 162 | :: EffectFn6 GPUCommandEncoder 163 | GPUQuerySet GPUSize32 GPUSize32 GPUBuffer GPUSize64 Unit 164 | 165 | resolveQuerySet 166 | :: GPUCommandEncoder 167 | -> GPUQuerySet 168 | -> Int 169 | -> Int 170 | -> GPUBuffer 171 | -> Int 172 | -> Effect Unit 173 | resolveQuerySet a b c d e f = runEffectFn6 resolveQuerySetImpl a b c d e f 174 | 175 | foreign import finishImpl :: EffectFn1 GPUCommandEncoder GPUCommandBuffer 176 | finish :: GPUCommandEncoder -> Effect GPUCommandBuffer 177 | finish a = runEffectFn1 finishImpl a 178 | 179 | foreign import pushDebugGroupImpl :: EffectFn2 GPUCommandEncoder String Unit 180 | 181 | pushDebugGroup :: GPUCommandEncoder -> String -> Effect Unit 182 | pushDebugGroup a b = runEffectFn2 pushDebugGroupImpl a b 183 | 184 | foreign import popDebugGroupImpl :: EffectFn1 GPUCommandEncoder Unit 185 | popDebugGroup :: GPUCommandEncoder -> Effect Unit 186 | popDebugGroup a = runEffectFn1 popDebugGroupImpl a 187 | 188 | foreign import insertDebugMarkerImpl 189 | :: EffectFn2 GPUCommandEncoder String Unit 190 | 191 | insertDebugMarker :: GPUCommandEncoder -> String -> Effect Unit 192 | insertDebugMarker a b = runEffectFn2 insertDebugMarkerImpl a b -------------------------------------------------------------------------------- /src/Web/GPU/GPUTextureFormat.purs: -------------------------------------------------------------------------------- 1 | module Web.GPU.GPUTextureFormat 2 | ( GPUTextureFormat 3 | , astc10x10Unorm 4 | , astc10x10UnormSrgb 5 | , astc10x5Unorm 6 | , astc10x5UnormSrgb 7 | , astc10x6Unorm 8 | , astc10x6UnormSrgb 9 | , astc10x8Unorm 10 | , astc10x8UnormSrgb 11 | , astc12x10Unorm 12 | , astc12x10UnormSrgb 13 | , astc12x12Unorm 14 | , astc12x12UnormSrgb 15 | , astc4x4Unorm 16 | , astc4x4UnormSrgb 17 | , astc5x4Unorm 18 | , astc5x4UnormSrgb 19 | , astc5x5Unorm 20 | , astc5x5UnormSrgb 21 | , astc6x5Unorm 22 | , astc6x5UnormSrgb 23 | , astc6x6Unorm 24 | , astc6x6UnormSrgb 25 | , astc8x5Unorm 26 | , astc8x5UnormSrgb 27 | , astc8x6Unorm 28 | , astc8x6UnormSrgb 29 | , astc8x8Unorm 30 | , astc8x8UnormSrgb 31 | , bc1RgbaUnorm 32 | , bc1RgbaUnormSrgb 33 | , bc2RgbaUnorm 34 | , bc2RgbaUnormSrgb 35 | , bc3RgbaUnorm 36 | , bc3RgbaUnormSrgb 37 | , bc4RSnorm 38 | , bc4RUnorm 39 | , bc5RgSnorm 40 | , bc5RgUnorm 41 | , bc6hRgbFloat 42 | , bc6hRgbUfloat 43 | , bc7RgbaUnorm 44 | , bc7RgbaUnormSrgb 45 | , bgra8unorm 46 | , bgra8unormSrgb 47 | , depth16unorm 48 | , depth24plus 49 | , depth24plusStencil8 50 | , depth32float 51 | , depth32floatStencil8 52 | , eacR11snorm 53 | , eacR11unorm 54 | , eacRg11snorm 55 | , eacRg11unorm 56 | , etc2Rgb8a1unorm 57 | , etc2Rgb8a1unormSrgb 58 | , etc2Rgb8unorm 59 | , etc2Rgb8unormSrgb 60 | , etc2Rgba8unorm 61 | , etc2Rgba8unormSrgb 62 | , r16float 63 | , r16sint 64 | , r16uint 65 | , r32float 66 | , r32sint 67 | , r32uint 68 | , r8sint 69 | , r8snorm 70 | , r8uint 71 | , r8unorm 72 | , rg11b10ufloat 73 | , rg16float 74 | , rg16sint 75 | , rg16uint 76 | , rg32float 77 | , rg32sint 78 | , rg32uint 79 | , rg8sint 80 | , rg8snorm 81 | , rg8uint 82 | , rg8unorm 83 | , rgb10a2unorm 84 | , rgb9e5ufloat 85 | , rgba16float 86 | , rgba16sint 87 | , rgba16uint 88 | , rgba32float 89 | , rgba32sint 90 | , rgba32uint 91 | , rgba8sint 92 | , rgba8snorm 93 | , rgba8uint 94 | , rgba8unorm 95 | , rgba8unormSrgb 96 | , stencil8 97 | ) where 98 | 99 | import Prelude 100 | 101 | newtype GPUTextureFormat = GPUTextureFormat String 102 | 103 | derive instance Eq GPUTextureFormat 104 | derive instance Ord GPUTextureFormat 105 | derive newtype instance Show GPUTextureFormat 106 | 107 | r8unorm = GPUTextureFormat "r8unorm" :: GPUTextureFormat 108 | r8snorm = GPUTextureFormat "r8snorm" :: GPUTextureFormat 109 | r8uint = GPUTextureFormat "r8uint" :: GPUTextureFormat 110 | r8sint = GPUTextureFormat "r8sint" :: GPUTextureFormat 111 | r16uint = GPUTextureFormat "r16uint" :: GPUTextureFormat 112 | r16sint = GPUTextureFormat "r16sint" :: GPUTextureFormat 113 | r16float = GPUTextureFormat "r16float" :: GPUTextureFormat 114 | rg8unorm = GPUTextureFormat "rg8unorm" :: GPUTextureFormat 115 | rg8snorm = GPUTextureFormat "rg8snorm" :: GPUTextureFormat 116 | rg8uint = GPUTextureFormat "rg8uint" :: GPUTextureFormat 117 | rg8sint = GPUTextureFormat "rg8sint" :: GPUTextureFormat 118 | r32uint = GPUTextureFormat "r32uint" :: GPUTextureFormat 119 | r32sint = GPUTextureFormat "r32sint" :: GPUTextureFormat 120 | r32float = GPUTextureFormat "r32float" :: GPUTextureFormat 121 | rg16uint = GPUTextureFormat "rg16uint" :: GPUTextureFormat 122 | rg16sint = GPUTextureFormat "rg16sint" :: GPUTextureFormat 123 | rg16float = GPUTextureFormat "rg16float" :: GPUTextureFormat 124 | rgba8unorm = GPUTextureFormat "rgba8unorm" :: GPUTextureFormat 125 | rgba8unormSrgb = GPUTextureFormat "rgba8unorm-srgb" :: GPUTextureFormat 126 | rgba8snorm = GPUTextureFormat "rgba8snorm" :: GPUTextureFormat 127 | rgba8uint = GPUTextureFormat "rgba8uint" :: GPUTextureFormat 128 | rgba8sint = GPUTextureFormat "rgba8sint" :: GPUTextureFormat 129 | bgra8unorm = GPUTextureFormat "bgra8unorm" :: GPUTextureFormat 130 | bgra8unormSrgb = GPUTextureFormat "bgra8unorm-srgb" :: GPUTextureFormat 131 | rgb9e5ufloat = GPUTextureFormat "rgb9e5ufloat" :: GPUTextureFormat 132 | rgb10a2unorm = GPUTextureFormat "rgb10a2unorm" :: GPUTextureFormat 133 | rg11b10ufloat = GPUTextureFormat "rg11b10ufloat" :: GPUTextureFormat 134 | rg32uint = GPUTextureFormat "rg32uint" :: GPUTextureFormat 135 | rg32sint = GPUTextureFormat "rg32sint" :: GPUTextureFormat 136 | rg32float = GPUTextureFormat "rg32float" :: GPUTextureFormat 137 | rgba16uint = GPUTextureFormat "rgba16uint" :: GPUTextureFormat 138 | rgba16sint = GPUTextureFormat "rgba16sint" :: GPUTextureFormat 139 | rgba16float = GPUTextureFormat "rgba16float" :: GPUTextureFormat 140 | rgba32uint = GPUTextureFormat "rgba32uint" :: GPUTextureFormat 141 | rgba32sint = GPUTextureFormat "rgba32sint" :: GPUTextureFormat 142 | rgba32float = GPUTextureFormat "rgba32float" :: GPUTextureFormat 143 | stencil8 = GPUTextureFormat "stencil8" :: GPUTextureFormat 144 | depth16unorm = GPUTextureFormat "depth16unorm" :: GPUTextureFormat 145 | depth24plus = GPUTextureFormat "depth24plus" :: GPUTextureFormat 146 | depth24plusStencil8 = 147 | GPUTextureFormat "depth24plus-stencil8" :: GPUTextureFormat 148 | 149 | depth32float = GPUTextureFormat "depth32float" :: GPUTextureFormat 150 | depth32floatStencil8 = 151 | GPUTextureFormat "depth32float-stencil8" :: GPUTextureFormat 152 | 153 | bc1RgbaUnorm = GPUTextureFormat "bc1-rgba-unorm" :: GPUTextureFormat 154 | bc1RgbaUnormSrgb = GPUTextureFormat "bc1-rgba-unorm-srgb" :: GPUTextureFormat 155 | bc2RgbaUnorm = GPUTextureFormat "bc2-rgba-unorm" :: GPUTextureFormat 156 | bc2RgbaUnormSrgb = GPUTextureFormat "bc2-rgba-unorm-srgb" :: GPUTextureFormat 157 | bc3RgbaUnorm = GPUTextureFormat "bc3-rgba-unorm" :: GPUTextureFormat 158 | bc3RgbaUnormSrgb = GPUTextureFormat "bc3-rgba-unorm-srgb" :: GPUTextureFormat 159 | bc4RUnorm = GPUTextureFormat "bc4-r-unorm" :: GPUTextureFormat 160 | bc4RSnorm = GPUTextureFormat "bc4-r-snorm" :: GPUTextureFormat 161 | bc5RgUnorm = GPUTextureFormat "bc5-rg-unorm" :: GPUTextureFormat 162 | bc5RgSnorm = GPUTextureFormat "bc5-rg-snorm" :: GPUTextureFormat 163 | bc6hRgbUfloat = GPUTextureFormat "bc6h-rgb-ufloat" :: GPUTextureFormat 164 | bc6hRgbFloat = GPUTextureFormat "bc6h-rgb-float" :: GPUTextureFormat 165 | bc7RgbaUnorm = GPUTextureFormat "bc7-rgba-unorm" :: GPUTextureFormat 166 | bc7RgbaUnormSrgb = GPUTextureFormat "bc7-rgba-unorm-srgb" :: GPUTextureFormat 167 | etc2Rgb8unorm = GPUTextureFormat "etc2-rgb8unorm" :: GPUTextureFormat 168 | etc2Rgb8unormSrgb = GPUTextureFormat "etc2-rgb8unorm-srgb" :: GPUTextureFormat 169 | etc2Rgb8a1unorm = GPUTextureFormat "etc2-rgb8a1unorm" :: GPUTextureFormat 170 | etc2Rgb8a1unormSrgb = 171 | GPUTextureFormat "etc2-rgb8a1unorm-srgb" :: GPUTextureFormat 172 | 173 | etc2Rgba8unorm = GPUTextureFormat "etc2-rgba8unorm" :: GPUTextureFormat 174 | etc2Rgba8unormSrgb = GPUTextureFormat "etc2-rgba8unorm-srgb" :: GPUTextureFormat 175 | eacR11unorm = GPUTextureFormat "eac-r11unorm" :: GPUTextureFormat 176 | eacR11snorm = GPUTextureFormat "eac-r11snorm" :: GPUTextureFormat 177 | eacRg11unorm = GPUTextureFormat "eac-rg11unorm" :: GPUTextureFormat 178 | eacRg11snorm = GPUTextureFormat "eac-rg11snorm" :: GPUTextureFormat 179 | astc4x4Unorm = GPUTextureFormat "astc-4x4-unorm" :: GPUTextureFormat 180 | astc4x4UnormSrgb = GPUTextureFormat "astc-4x4-unorm-srgb" :: GPUTextureFormat 181 | astc5x4Unorm = GPUTextureFormat "astc-5x4-unorm" :: GPUTextureFormat 182 | astc5x4UnormSrgb = GPUTextureFormat "astc-5x4-unorm-srgb" :: GPUTextureFormat 183 | astc5x5Unorm = GPUTextureFormat "astc-5x5-unorm" :: GPUTextureFormat 184 | astc5x5UnormSrgb = GPUTextureFormat "astc-5x5-unorm-srgb" :: GPUTextureFormat 185 | astc6x5Unorm = GPUTextureFormat "astc-6x5-unorm" :: GPUTextureFormat 186 | astc6x5UnormSrgb = GPUTextureFormat "astc-6x5-unorm-srgb" :: GPUTextureFormat 187 | astc6x6Unorm = GPUTextureFormat "astc-6x6-unorm" :: GPUTextureFormat 188 | astc6x6UnormSrgb = GPUTextureFormat "astc-6x6-unorm-srgb" :: GPUTextureFormat 189 | astc8x5Unorm = GPUTextureFormat "astc-8x5-unorm" :: GPUTextureFormat 190 | astc8x5UnormSrgb = GPUTextureFormat "astc-8x5-unorm-srgb" :: GPUTextureFormat 191 | astc8x6Unorm = GPUTextureFormat "astc-8x6-unorm" :: GPUTextureFormat 192 | astc8x6UnormSrgb = GPUTextureFormat "astc-8x6-unorm-srgb" :: GPUTextureFormat 193 | astc8x8Unorm = GPUTextureFormat "astc-8x8-unorm" :: GPUTextureFormat 194 | astc8x8UnormSrgb = GPUTextureFormat "astc-8x8-unorm-srgb" :: GPUTextureFormat 195 | astc10x5Unorm = GPUTextureFormat "astc-10x5-unorm" :: GPUTextureFormat 196 | astc10x5UnormSrgb = GPUTextureFormat "astc-10x5-unorm-srgb" :: GPUTextureFormat 197 | astc10x6Unorm = GPUTextureFormat "astc-10x6-unorm" :: GPUTextureFormat 198 | astc10x6UnormSrgb = GPUTextureFormat "astc-10x6-unorm-srgb" :: GPUTextureFormat 199 | astc10x8Unorm = GPUTextureFormat "astc-10x8-unorm" :: GPUTextureFormat 200 | astc10x8UnormSrgb = GPUTextureFormat "astc-10x8-unorm-srgb" :: GPUTextureFormat 201 | astc10x10Unorm = GPUTextureFormat "astc-10x10-unorm" :: GPUTextureFormat 202 | astc10x10UnormSrgb = 203 | GPUTextureFormat "astc-10x10-unorm-srgb" :: GPUTextureFormat 204 | 205 | astc12x10Unorm = GPUTextureFormat "astc-12x10-unorm" :: GPUTextureFormat 206 | astc12x10UnormSrgb = 207 | GPUTextureFormat "astc-12x10-unorm-srgb" :: GPUTextureFormat 208 | 209 | astc12x12Unorm = GPUTextureFormat "astc-12x12-unorm" :: GPUTextureFormat 210 | astc12x12UnormSrgb = 211 | GPUTextureFormat "astc-12x12-unorm-srgb" :: GPUTextureFormat -------------------------------------------------------------------------------- /src/Web/GPU/GPUDevice.purs: -------------------------------------------------------------------------------- 1 | -- @inline export features arity=2 2 | -- @inline export limits arity=1 3 | -- @inline export queue arity=1 4 | -- @inline export destroy arity=1 5 | -- @inline export createBuffer arity=2 6 | -- @inline export createTexture arity=2 7 | -- @inline export createSampler arity=2 8 | -- @inline export importExternalTexture arity=2 9 | -- @inline export createBindGroupLayout arity=2 10 | -- @inline export createPipelineLayout arity=2 11 | -- @inline export createBindGroup arity=2 12 | -- @inline export createShaderModule arity=2 13 | -- @inline export createComputePipeline arity=2 14 | -- @inline export createRenderPipeline arity=2 15 | -- @inline export createComputePipelineAsnyc arity=2 16 | -- @inline export createRenderPipelineAsync arity=2 17 | -- @inline export createCommandEncoder arity=2 18 | -- @inline export createRenderBundleEncoder arity=2 19 | -- @inline export createQuerySet arity=2 20 | -- @inline export toEventTarget arity=1 21 | module Web.GPU.GPUDevice 22 | ( GPUDevice 23 | , createBindGroup 24 | , createBindGroupLayout 25 | , createBuffer 26 | , createCommandEncoder 27 | , createComputePipeline 28 | , createComputePipelineAsnyc 29 | , createPipelineLayout 30 | , createQuerySet 31 | , createRenderBundleEncoder 32 | , createRenderPipeline 33 | , createRenderPipelineAsync 34 | , createSampler 35 | , createShaderModule 36 | , createTexture 37 | , destroy 38 | , features 39 | , importExternalTexture 40 | , limits 41 | , queue 42 | , toEventTarget 43 | ) where 44 | 45 | import Prelude 46 | 47 | import Data.Set as Set 48 | import Effect (Effect) 49 | import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, runEffectFn1, runEffectFn2, runEffectFn3) 50 | import Unsafe.Coerce (unsafeCoerce) 51 | import Web.Event.Internal.Types (EventTarget) 52 | import Web.GPU.GPUBindGroup (GPUBindGroup) 53 | import Web.GPU.GPUBindGroupDescriptor (GPUBindGroupDescriptor) 54 | import Web.GPU.GPUBindGroupLayout (GPUBindGroupLayout) 55 | import Web.GPU.GPUBindGroupLayoutDescriptor (GPUBindGroupLayoutDescriptor) 56 | import Web.GPU.GPUBuffer (GPUBuffer) 57 | import Web.GPU.GPUBufferDescriptor (GPUBufferDescriptor) 58 | import Web.GPU.GPUCommandEncoder (GPUCommandEncoder) 59 | import Web.GPU.GPUCommandEncoderDescriptor (GPUCommandEncoderDescriptor) 60 | import Web.GPU.GPUComputePipeline (GPUComputePipeline) 61 | import Web.GPU.GPUComputePipelineDescriptor (GPUComputePipelineDescriptor) 62 | import Web.GPU.GPUExternalTexture (GPUExternalTexture) 63 | import Web.GPU.GPUExternalTextureDescriptor (GPUExternalTextureDescriptor) 64 | import Web.GPU.GPUFeatureName (GPUFeatureName) 65 | import Web.GPU.GPUPipelineLayout (GPUPipelineLayout) 66 | import Web.GPU.GPUPipelineLayoutDescriptor (GPUPipelineLayoutDescriptor) 67 | import Web.GPU.GPUQuerySet (GPUQuerySet) 68 | import Web.GPU.GPUQuerySetDescriptor (GPUQuerySetDescriptor) 69 | import Web.GPU.GPUQueue (GPUQueue) 70 | import Web.GPU.GPURenderBundleEncoderDescriptor (GPURenderBundleEncoderDescriptor) 71 | import Web.GPU.GPURenderPipeline (GPURenderPipeline) 72 | import Web.GPU.GPURenderPipelineDescriptor (GPURenderPipelineDescriptor) 73 | import Web.GPU.GPUSampler (GPUSampler) 74 | import Web.GPU.GPUSamplerDescriptor (GPUSamplerDescriptor) 75 | import Web.GPU.GPUShaderModule (GPUShaderModule) 76 | import Web.GPU.GPUShaderModuleDescriptor (GPUShaderModuleDescriptor) 77 | import Web.GPU.GPUSupportedLimits (GPUSupportedLimits) 78 | import Web.GPU.GPUTexture (GPUTexture) 79 | import Web.GPU.GPUTextureDescriptor (GPUTextureDescriptor) 80 | import Promise (Promise) 81 | 82 | data GPUDevice 83 | 84 | -- features 85 | foreign import featuresImpl 86 | :: EffectFn3 87 | (GPUFeatureName -> Set.Set GPUFeatureName -> Set.Set GPUFeatureName) 88 | (Set.Set GPUFeatureName) 89 | GPUDevice 90 | (Set.Set GPUFeatureName) 91 | 92 | features :: GPUDevice -> Effect (Set.Set GPUFeatureName) 93 | features a = runEffectFn3 featuresImpl Set.insert Set.empty a 94 | 95 | -- limits 96 | foreign import limitsImpl :: EffectFn1 GPUDevice { | GPUSupportedLimits } 97 | 98 | limits :: GPUDevice -> Effect { | GPUSupportedLimits } 99 | limits a = runEffectFn1 limitsImpl a 100 | 101 | -- queue 102 | 103 | foreign import queueImpl :: EffectFn1 GPUDevice GPUQueue 104 | 105 | queue :: GPUDevice -> Effect GPUQueue 106 | queue a = runEffectFn1 queueImpl a 107 | 108 | -- destroy 109 | 110 | foreign import destroyImpl :: EffectFn1 GPUDevice Unit 111 | 112 | destroy :: GPUDevice -> Effect Unit 113 | destroy a = runEffectFn1 destroyImpl a 114 | 115 | -- createBuffer 116 | foreign import createBufferImpl 117 | :: EffectFn2 GPUDevice GPUBufferDescriptor GPUBuffer 118 | 119 | createBuffer 120 | :: GPUDevice 121 | -> GPUBufferDescriptor 122 | -> Effect GPUBuffer 123 | createBuffer a b = runEffectFn2 createBufferImpl a b 124 | 125 | -- createTexture 126 | foreign import createTextureImpl 127 | :: EffectFn2 GPUDevice GPUTextureDescriptor GPUTexture 128 | 129 | createTexture 130 | :: GPUDevice 131 | -> GPUTextureDescriptor 132 | -> Effect GPUTexture 133 | createTexture a b = runEffectFn2 createTextureImpl a b 134 | 135 | -- createSampler 136 | 137 | foreign import createSamplerImpl 138 | :: EffectFn2 GPUDevice GPUSamplerDescriptor GPUSampler 139 | 140 | createSampler 141 | :: GPUDevice 142 | -> GPUSamplerDescriptor 143 | -> Effect GPUSampler 144 | createSampler a b = runEffectFn2 createSamplerImpl a b 145 | 146 | -- importExternalTexture 147 | 148 | foreign import importExternalTextureImpl 149 | :: EffectFn2 GPUDevice GPUExternalTextureDescriptor GPUExternalTexture 150 | 151 | importExternalTexture 152 | :: GPUDevice 153 | -> GPUExternalTextureDescriptor 154 | -> Effect GPUExternalTexture 155 | importExternalTexture a b = runEffectFn2 importExternalTextureImpl a b 156 | 157 | -- createBindGroupLayout 158 | 159 | foreign import createBindGroupLayoutImpl 160 | :: EffectFn2 GPUDevice GPUBindGroupLayoutDescriptor GPUBindGroupLayout 161 | 162 | createBindGroupLayout 163 | :: GPUDevice 164 | -> GPUBindGroupLayoutDescriptor 165 | -> Effect GPUBindGroupLayout 166 | createBindGroupLayout a b = runEffectFn2 createBindGroupLayoutImpl a b 167 | 168 | -- createPipelineLayout 169 | 170 | foreign import createPipelineLayoutImpl 171 | :: EffectFn2 GPUDevice GPUPipelineLayoutDescriptor GPUPipelineLayout 172 | 173 | createPipelineLayout 174 | :: GPUDevice 175 | -> GPUPipelineLayoutDescriptor 176 | -> Effect GPUPipelineLayout 177 | createPipelineLayout a b = runEffectFn2 createPipelineLayoutImpl a b 178 | 179 | -- createBindGroup 180 | 181 | foreign import createBindGroupImpl 182 | :: EffectFn2 GPUDevice GPUBindGroupDescriptor GPUBindGroup 183 | 184 | createBindGroup :: GPUDevice -> GPUBindGroupDescriptor -> Effect GPUBindGroup 185 | createBindGroup a b = runEffectFn2 createBindGroupImpl a b 186 | 187 | -- createShaderModule 188 | 189 | foreign import createShaderModuleImpl 190 | :: EffectFn2 GPUDevice GPUShaderModuleDescriptor GPUShaderModule 191 | 192 | createShaderModule 193 | :: GPUDevice 194 | -> GPUShaderModuleDescriptor 195 | -> Effect GPUShaderModule 196 | createShaderModule a b = runEffectFn2 createShaderModuleImpl a b 197 | 198 | -- createComputePipeline 199 | foreign import createComputePipelineImpl 200 | :: EffectFn2 GPUDevice GPUComputePipelineDescriptor GPUComputePipeline 201 | 202 | createComputePipeline 203 | :: GPUDevice 204 | -> GPUComputePipelineDescriptor 205 | -> Effect GPUComputePipeline 206 | createComputePipeline a b = runEffectFn2 createComputePipelineImpl a b 207 | 208 | -- createRenderPipeline 209 | 210 | foreign import createRenderPipelineImpl 211 | :: EffectFn2 GPUDevice GPURenderPipelineDescriptor GPURenderPipeline 212 | 213 | createRenderPipeline 214 | :: GPUDevice 215 | -> GPURenderPipelineDescriptor 216 | -> Effect GPURenderPipeline 217 | createRenderPipeline a b = runEffectFn2 createRenderPipelineImpl a b 218 | 219 | -- createComputePipelineAsnyc 220 | foreign import createComputePipelineAsyncImpl 221 | :: EffectFn2 GPUDevice GPUComputePipelineDescriptor 222 | (Promise GPUComputePipeline) 223 | 224 | createComputePipelineAsnyc 225 | :: GPUDevice 226 | -> GPUComputePipelineDescriptor 227 | -> Effect (Promise GPUComputePipeline) 228 | createComputePipelineAsnyc a b = runEffectFn2 createComputePipelineAsyncImpl a b 229 | 230 | -- createRenderPipelineAsync 231 | 232 | foreign import createRenderPipelineAsyncImpl 233 | :: EffectFn2 GPUDevice GPURenderPipelineDescriptor (Promise GPURenderPipeline) 234 | 235 | createRenderPipelineAsync 236 | :: GPUDevice 237 | -> GPURenderPipelineDescriptor 238 | -> Effect (Promise GPURenderPipeline) 239 | createRenderPipelineAsync a b = runEffectFn2 createRenderPipelineAsyncImpl a b 240 | 241 | -- createCommandEncoder 242 | 243 | foreign import createCommandEncoderImpl 244 | :: EffectFn2 GPUDevice GPUCommandEncoderDescriptor GPUCommandEncoder 245 | 246 | createCommandEncoder 247 | :: GPUDevice -> GPUCommandEncoderDescriptor -> Effect GPUCommandEncoder 248 | createCommandEncoder a b = runEffectFn2 createCommandEncoderImpl a b 249 | 250 | -- createRenderBundleEncoder 251 | 252 | foreign import createRenderBundleEncoderImpl 253 | :: EffectFn2 GPUDevice GPURenderBundleEncoderDescriptor GPUBuffer 254 | 255 | createRenderBundleEncoder 256 | :: GPUDevice 257 | -> GPURenderBundleEncoderDescriptor 258 | -> Effect GPUBuffer 259 | createRenderBundleEncoder a b = runEffectFn2 createRenderBundleEncoderImpl a b 260 | 261 | -- createQuerySet 262 | 263 | foreign import createQuerySetImpl 264 | :: EffectFn2 GPUDevice GPUQuerySetDescriptor GPUQuerySet 265 | 266 | createQuerySet :: GPUDevice -> GPUQuerySetDescriptor -> Effect GPUQuerySet 267 | createQuerySet a b = runEffectFn2 createQuerySetImpl a b 268 | 269 | toEventTarget :: GPUDevice -> EventTarget 270 | toEventTarget = unsafeCoerce 271 | -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderBundleEncoder.js: -------------------------------------------------------------------------------- 1 | export const finishImpl = (gpuRenderBundleEncoder, descriptor) => 2 | gpuRenderBundleEncoder.finish(descriptor); 3 | export const setPipelineImpl = (gpuRenderBundleEncoder, gpuRenderPipeline$1) => 4 | gpuRenderBundleEncoder.setPipeline(gpuRenderPipeline$1); 5 | export const setIndexBufferImpl = ( 6 | gpuRenderBundleEncoder, 7 | gpuBuffer$1, 8 | gpuIndexFormat$2 9 | ) => gpuRenderBundleEncoder.setIndexBuffer(gpuBuffer$1, gpuIndexFormat$2); 10 | export const setIndexBufferWithSizeImpl = ( 11 | gpuRenderBundleEncoder, 12 | gpuBuffer$1, 13 | gpuIndexFormat$2, 14 | gpuSize64$3 15 | ) => 16 | gpuRenderBundleEncoder.setIndexBuffer( 17 | gpuBuffer$1, 18 | gpuIndexFormat$2, 19 | gpuSize64$3 20 | ); 21 | export const setIndexBufferWithOffsetImpl = ( 22 | gpuRenderBundleEncoder, 23 | gpuBuffer$1, 24 | gpuIndexFormat$2, 25 | gpuSize64$3 26 | ) => 27 | gpuRenderBundleEncoder.setIndexBuffer( 28 | gpuBuffer$1, 29 | gpuIndexFormat$2, 30 | undefined, 31 | gpuSize64$3 32 | ); 33 | export const setIndexBufferWithOffsetAndSizeImpl = ( 34 | gpuRenderBundleEncoder, 35 | gpuBuffer$1, 36 | gpuIndexFormat$2, 37 | gpuSize64$3, 38 | gpuSize64$4 39 | ) => 40 | gpuRenderBundleEncoder.setIndexBuffer( 41 | gpuBuffer$1, 42 | gpuIndexFormat$2, 43 | gpuSize64$3, 44 | gpuSize64$4 45 | ); 46 | export const setVertexBufferImpl = ( 47 | gpuRenderBundleEncoder, 48 | gpuIndex32$1, 49 | gpuBuffer$2 50 | ) => gpuRenderBundleEncoder.setVertexBuffer(gpuIndex32$1, gpuBuffer$2); 51 | export const setVertexBufferWithOffsetImpl = ( 52 | gpuRenderBundleEncoder, 53 | gpuIndex32$1, 54 | gpuBuffer$2, 55 | gpuSize64$3 56 | ) => 57 | gpuRenderBundleEncoder.setVertexBuffer( 58 | gpuIndex32$1, 59 | gpuBuffer$2, 60 | gpuSize64$3 61 | ); 62 | export const setVertexBufferWithSizeImpl = ( 63 | gpuRenderBundleEncoder, 64 | gpuIndex32$1, 65 | gpuBuffer$2, 66 | gpuSize64$3 67 | ) => 68 | gpuRenderBundleEncoder.setVertexBuffer( 69 | gpuIndex32$1, 70 | gpuBuffer$2, 71 | undefined, 72 | gpuSize64$3 73 | ); 74 | export const setVertexBufferWithOffsetAndSizeImpl = ( 75 | gpuRenderBundleEncoder, 76 | gpuIndex32$1, 77 | gpuBuffer$2, 78 | gpuSize64$3, 79 | gpuSize64$4 80 | ) => 81 | gpuRenderBundleEncoder.setVertexBuffer( 82 | gpuIndex32$1, 83 | gpuBuffer$2, 84 | gpuSize64$3, 85 | gpuSize64$4 86 | ); 87 | export const drawImpl = (gpuRenderBundleEncoder, gpuSize32$1) => 88 | gpuRenderBundleEncoder.draw(gpuSize32$1); 89 | export const drawWithInstanceCountImpl = ( 90 | gpuRenderBundleEncoder, 91 | gpuSize32$1, 92 | gpuSize32$2 93 | ) => gpuRenderBundleEncoder.draw(gpuSize32$1, gpuSize32$2); 94 | export const drawWithFirstVertexImpl = ( 95 | gpuRenderBundleEncoder, 96 | gpuSize32$1, 97 | gpuSize32$2 98 | ) => gpuRenderBundleEncoder.draw(gpuSize32$1, undefined, gpuSize32$2); 99 | export const drawWithFirstInstanceImpl = ( 100 | gpuRenderBundleEncoder, 101 | gpuSize32$1, 102 | gpuSize32$2 103 | ) => 104 | gpuRenderBundleEncoder.draw(gpuSize32$1, undefined, undefined, gpuSize32$2); 105 | export const drawWithInstanceCountAndFirstVertexImpl = ( 106 | gpuRenderBundleEncoder, 107 | gpuSize32$1, 108 | gpuSize32$2, 109 | gpuSize32$3 110 | ) => gpuRenderBundleEncoder.draw(gpuSize32$1, gpuSize32$2, gpuSize32$3); 111 | export const drawWithInstanceCountAndFirstInstanceImpl = ( 112 | gpuRenderBundleEncoder, 113 | gpuSize32$1, 114 | gpuSize32$2, 115 | gpuSize32$3 116 | ) => 117 | gpuRenderBundleEncoder.draw(gpuSize32$1, gpuSize32$2, undefined, gpuSize32$3); 118 | export const drawWithFirstVertexAndFirstInstanceImpl = ( 119 | gpuRenderBundleEncoder, 120 | gpuSize32$1, 121 | gpuSize32$2, 122 | gpuSize32$3 123 | ) => 124 | gpuRenderBundleEncoder.draw(gpuSize32$1, undefined, gpuSize32$2, gpuSize32$3); 125 | export const drawWithInstanceCountAndFirstVertexAndFirstInstanceImpl = ( 126 | gpuRenderBundleEncoder, 127 | gpuSize32$1, 128 | gpuSize32$2, 129 | gpuSize32$3, 130 | gpuSize32$4 131 | ) => 132 | gpuRenderBundleEncoder.draw( 133 | gpuSize32$1, 134 | gpuSize32$2, 135 | gpuSize32$3, 136 | gpuSize32$4 137 | ); 138 | // 139 | export const drawIndexedImpl = (gpuRenderBundleEncoder, gpuSize32$1) => 140 | gpuRenderBundleEncoder.drawIndexed(gpuSize32$1); 141 | export const drawIndexedWithInstanceCountImpl = ( 142 | gpuRenderBundleEncoder, 143 | gpuSize32$1, 144 | gpuSize32$2 145 | ) => gpuRenderBundleEncoder.drawIndexed(gpuSize32$1, gpuSize32$2); 146 | export const drawIndexedWithFirstIndexImpl = ( 147 | gpuRenderBundleEncoder, 148 | gpuSize32$1, 149 | gpuSize32$2 150 | ) => gpuRenderBundleEncoder.drawIndexed(gpuSize32$1, undefined, gpuSize32$2); 151 | export const drawIndexedWithBaseVertexImpl = ( 152 | gpuRenderBundleEncoder, 153 | gpuSize32$1, 154 | gpuSignedOffset32$2 155 | ) => 156 | gpuRenderBundleEncoder.drawIndexed( 157 | gpuSize32$1, 158 | undefined, 159 | undefined, 160 | gpuSignedOffset32$2 161 | ); 162 | export const drawIndexedWithFirstInstanceImpl = ( 163 | gpuRenderBundleEncoder, 164 | gpuSize32$1, 165 | gpuSize32$2 166 | ) => 167 | gpuRenderBundleEncoder.drawIndexed( 168 | gpuSize32$1, 169 | undefined, 170 | undefined, 171 | undefined, 172 | gpuSize32$2 173 | ); 174 | export const drawIndexedWithInstanceCountAndFirstIndexImpl = ( 175 | gpuRenderBundleEncoder, 176 | gpuSize32$1, 177 | gpuSize32$2, 178 | gpuSize32$3 179 | ) => gpuRenderBundleEncoder.drawIndexed(gpuSize32$1, gpuSize32$2, gpuSize32$3); 180 | export const drawIndexedWithInstanceCountAndBaseVertexImpl = ( 181 | gpuRenderBundleEncoder, 182 | gpuSize32$1, 183 | gpuSize32$2, 184 | gpuSignedOffset32$3 185 | ) => 186 | gpuRenderBundleEncoder.drawIndexed( 187 | gpuSize32$1, 188 | gpuSize32$2, 189 | undefined, 190 | gpuSignedOffset32$3 191 | ); 192 | export const drawIndexedWithInstanceCountAndFirstInstanceImpl = ( 193 | gpuRenderBundleEncoder, 194 | gpuSize32$1, 195 | gpuSize32$2, 196 | gpuSize32$3 197 | ) => 198 | gpuRenderBundleEncoder.drawIndexed( 199 | gpuSize32$1, 200 | gpuSize32$2, 201 | undefined, 202 | undefined, 203 | gpuSize32$3 204 | ); 205 | export const drawIndexedWithFirstIndexAndBaseVertexImpl = ( 206 | gpuRenderBundleEncoder, 207 | gpuSize32$1, 208 | gpuSize32$2, 209 | gpuSignedOffset32$3 210 | ) => 211 | gpuRenderBundleEncoder.drawIndexed( 212 | gpuSize32$1, 213 | undefined, 214 | gpuSize32$2, 215 | gpuSignedOffset32$3 216 | ); 217 | export const drawIndexedWithFirstIndexAndFirstInstanceImpl = ( 218 | gpuRenderBundleEncoder, 219 | gpuSize32$1, 220 | gpuSize32$2, 221 | gpuSize32$3 222 | ) => 223 | gpuRenderBundleEncoder.drawIndexed( 224 | gpuSize32$1, 225 | undefined, 226 | gpuSize32$2, 227 | undefined, 228 | gpuSize32$3 229 | ); 230 | export const drawIndexedWithBaseVertexAndFirstInstanceImpl = ( 231 | gpuRenderBundleEncoder, 232 | gpuSize32$1, 233 | gpuSignedOffset32$2, 234 | gpuSize32$3 235 | ) => 236 | gpuRenderBundleEncoder.drawIndexed( 237 | gpuSize32$1, 238 | undefined, 239 | undefined, 240 | gpuSignedOffset32$2, 241 | gpuSize32$3 242 | ); 243 | export const drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexImpl = ( 244 | gpuRenderBundleEncoder, 245 | gpuSize32$1, 246 | gpuSize32$2, 247 | gpuSize32$3, 248 | gpuSignedOffset32$4 249 | ) => 250 | gpuRenderBundleEncoder.drawIndexed( 251 | gpuSize32$1, 252 | gpuSize32$2, 253 | gpuSize32$3, 254 | gpuSignedOffset32$4 255 | ); 256 | export const drawIndexedWithInstanceCountAndFirstIndexAndFirstInstanceImpl = ( 257 | gpuRenderBundleEncoder, 258 | gpuSize32$1, 259 | gpuSize32$2, 260 | gpuSize32$3, 261 | gpuSize32$4 262 | ) => 263 | gpuRenderBundleEncoder.drawIndexed( 264 | gpuSize32$1, 265 | gpuSize32$2, 266 | gpuSize32$3, 267 | undefined, 268 | gpuSize32$4 269 | ); 270 | export const drawIndexedWithFirstIndexAndBaseVertexAndFirstInstanceImpl = ( 271 | gpuRenderBundleEncoder, 272 | gpuSize32$1, 273 | gpuSize32$2, 274 | gpuSignedOffset32$3, 275 | gpuSize32$4 276 | ) => 277 | gpuRenderBundleEncoder.drawIndexed( 278 | gpuSize32$1, 279 | undefined, 280 | gpuSize32$2, 281 | gpuSignedOffset32$3, 282 | gpuSize32$4 283 | ); 284 | export const drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstanceImpl = 285 | ( 286 | gpuRenderBundleEncoder, 287 | gpuSize32$1, 288 | gpuSize32$2, 289 | gpuSize32$3, 290 | gpuSignedOffset32$4, 291 | gpuSize32$5 292 | ) => 293 | gpuRenderBundleEncoder.drawIndexed( 294 | gpuSize32$1, 295 | gpuSize32$2, 296 | gpuSize32$3, 297 | gpuSignedOffset32$4, 298 | gpuSize32$5 299 | ); 300 | // 301 | export const drawIndirectImpl = ( 302 | gpuRenderBundleEncoder, 303 | gpuBuffer$1, 304 | gpuSize64$2 305 | ) => gpuRenderBundleEncoder.drawIndirect(gpuBuffer$1, gpuSize64$2); 306 | export const drawIndexedIndirectImpl = ( 307 | gpuRenderBundleEncoder, 308 | gpuBuffer$1, 309 | gpuSize64$2 310 | ) => gpuRenderBundleEncoder.drawIndexedIndirect(gpuBuffer$1, gpuSize64$2); 311 | export const setBindGroupImpl = ( 312 | gpuRenderBundleEncoder, 313 | gpuIndex32$1, 314 | gpuBindGroup$2 315 | ) => gpuRenderBundleEncoder.setBindGroup(gpuIndex32$1, gpuBindGroup$2); 316 | export const setBindGroupWithDynamicOffsetsImpl = ( 317 | gpuRenderBundleEncoder, 318 | gpuIndex32$1, 319 | gpuBindGroup$2, 320 | arraygpuBufferDynamicOffset$3 321 | ) => 322 | gpuRenderBundleEncoder.setBindGroup( 323 | gpuIndex32$1, 324 | gpuBindGroup$2, 325 | arraygpuBufferDynamicOffset$3 326 | ); 327 | export const setBindGroupWithDyanmicOffsetBoundsImpl = ( 328 | gpuRenderBundleEncoder, 329 | gpuIndex32$1, 330 | gpuBindGroup$2, 331 | uint32array$3, 332 | gpuSize64$4, 333 | gpuSize32$5 334 | ) => 335 | gpuRenderBundleEncoder.setBindGroup( 336 | gpuIndex32$1, 337 | gpuBindGroup$2, 338 | uint32array$3, 339 | gpuSize64$4, 340 | gpuSize32$5 341 | ); 342 | export const pushDebugGroupImpl = (gpuRenderBundleEncoder, str$1) => 343 | gpuRenderBundleEncoder.pushDebugGroup(str$1); 344 | export const popDebugGroupImpl = gpuRenderBundleEncoder => 345 | gpuRenderBundleEncoder.popDebugGroup(); 346 | export const insertDebugMarkerImpl = (gpuRenderBundleEncoder, str$1) => 347 | gpuRenderBundleEncoder.insertDebugMarker(str$1); 348 | -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderPassEncoder.js: -------------------------------------------------------------------------------- 1 | export const setViewportImpl = ( 2 | gpuRenderPassEncoder, 3 | num$1, 4 | num$2, 5 | num$3, 6 | num$4, 7 | num$5, 8 | num$6 9 | ) => gpuRenderPassEncoder.setViewport(num$1, num$2, num$3, num$4, num$5, num$6); 10 | export const setScissorRectImpl = ( 11 | gpuRenderPassEncoder, 12 | gpuIntegerCoordinate$1, 13 | gpuIntegerCoordinate$2, 14 | gpuIntegerCoordinate$3, 15 | gpuIntegerCoordinate$4 16 | ) => 17 | gpuRenderPassEncoder.setScissorRect( 18 | gpuIntegerCoordinate$1, 19 | gpuIntegerCoordinate$2, 20 | gpuIntegerCoordinate$3, 21 | gpuIntegerCoordinate$4 22 | ); 23 | export const setBlendConstantImpl = (gpuRenderPassEncoder, gpuColor$1) => 24 | gpuRenderPassEncoder.setBlendConstant(gpuColor$1); 25 | export const setStencilReferenceImpl = ( 26 | gpuRenderPassEncoder, 27 | gpuStencilValue$1 28 | ) => gpuRenderPassEncoder.setStencilReference(gpuStencilValue$1); 29 | export const beginOcclusionQueryImpl = (gpuRenderPassEncoder, gpuSize32$1) => 30 | gpuRenderPassEncoder.beginOcclusionQuery(gpuSize32$1); 31 | export const endOcclusionQueryImpl = gpuRenderPassEncoder => 32 | gpuRenderPassEncoder.endOcclusionQuery(); 33 | export const executeBundlesImpl = ( 34 | gpuRenderPassEncoder, 35 | arraygpuRenderBundle$1 36 | ) => gpuRenderPassEncoder.executeBundles(arraygpuRenderBundle$1); 37 | export const endImpl = gpuRenderPassEncoder => gpuRenderPassEncoder.end(); 38 | export const setPipelineImpl = (gpuRenderPassEncoder, gpuRenderPipeline$1) => 39 | gpuRenderPassEncoder.setPipeline(gpuRenderPipeline$1); 40 | export const setIndexBufferImpl = ( 41 | gpuRenderPassEncoder, 42 | gpuBuffer$1, 43 | gpuIndexFormat$2 44 | ) => gpuRenderPassEncoder.setIndexBuffer(gpuBuffer$1, gpuIndexFormat$2); 45 | export const setIndexBufferWithSizeImpl = ( 46 | gpuRenderPassEncoder, 47 | gpuBuffer$1, 48 | gpuIndexFormat$2, 49 | gpuSize64$3 50 | ) => 51 | gpuRenderPassEncoder.setIndexBuffer( 52 | gpuBuffer$1, 53 | gpuIndexFormat$2, 54 | gpuSize64$3 55 | ); 56 | export const setIndexBufferWithOffsetImpl = ( 57 | gpuRenderPassEncoder, 58 | gpuBuffer$1, 59 | gpuIndexFormat$2, 60 | gpuSize64$3 61 | ) => 62 | gpuRenderPassEncoder.setIndexBuffer( 63 | gpuBuffer$1, 64 | gpuIndexFormat$2, 65 | undefined, 66 | gpuSize64$3 67 | ); 68 | export const setIndexBufferWithOffsetAndSizeImpl = ( 69 | gpuRenderPassEncoder, 70 | gpuBuffer$1, 71 | gpuIndexFormat$2, 72 | gpuSize64$3, 73 | gpuSize64$4 74 | ) => 75 | gpuRenderPassEncoder.setIndexBuffer( 76 | gpuBuffer$1, 77 | gpuIndexFormat$2, 78 | gpuSize64$3, 79 | gpuSize64$4 80 | ); 81 | export const setVertexBufferImpl = ( 82 | gpuRenderPassEncoder, 83 | gpuIndex32$1, 84 | gpuBuffer$2 85 | ) => gpuRenderPassEncoder.setVertexBuffer(gpuIndex32$1, gpuBuffer$2); 86 | export const setVertexBufferWithOffsetImpl = ( 87 | gpuRenderPassEncoder, 88 | gpuIndex32$1, 89 | gpuBuffer$2, 90 | gpuSize64$3 91 | ) => 92 | gpuRenderPassEncoder.setVertexBuffer(gpuIndex32$1, gpuBuffer$2, gpuSize64$3); 93 | export const setVertexBufferWithSizeImpl = ( 94 | gpuRenderPassEncoder, 95 | gpuIndex32$1, 96 | gpuBuffer$2, 97 | gpuSize64$3 98 | ) => 99 | gpuRenderPassEncoder.setVertexBuffer( 100 | gpuIndex32$1, 101 | gpuBuffer$2, 102 | undefined, 103 | gpuSize64$3 104 | ); 105 | export const setVertexBufferWithOffsetAndSizeImpl = ( 106 | gpuRenderPassEncoder, 107 | gpuIndex32$1, 108 | gpuBuffer$2, 109 | gpuSize64$3, 110 | gpuSize64$4 111 | ) => 112 | gpuRenderPassEncoder.setVertexBuffer( 113 | gpuIndex32$1, 114 | gpuBuffer$2, 115 | gpuSize64$3, 116 | gpuSize64$4 117 | ); 118 | export const drawImpl = (gpuRenderPassEncoder, gpuSize32$1) => 119 | gpuRenderPassEncoder.draw(gpuSize32$1); 120 | export const drawWithInstanceCountImpl = ( 121 | gpuRenderPassEncoder, 122 | gpuSize32$1, 123 | gpuSize32$2 124 | ) => gpuRenderPassEncoder.draw(gpuSize32$1, gpuSize32$2); 125 | export const drawWithFirstVertexImpl = ( 126 | gpuRenderPassEncoder, 127 | gpuSize32$1, 128 | gpuSize32$2 129 | ) => gpuRenderPassEncoder.draw(gpuSize32$1, undefined, gpuSize32$2); 130 | export const drawWithFirstInstanceImpl = ( 131 | gpuRenderPassEncoder, 132 | gpuSize32$1, 133 | gpuSize32$2 134 | ) => gpuRenderPassEncoder.draw(gpuSize32$1, undefined, undefined, gpuSize32$2); 135 | export const drawWithInstanceCountAndFirstVertexImpl = ( 136 | gpuRenderPassEncoder, 137 | gpuSize32$1, 138 | gpuSize32$2, 139 | gpuSize32$3 140 | ) => gpuRenderPassEncoder.draw(gpuSize32$1, gpuSize32$2, gpuSize32$3); 141 | export const drawWithInstanceCountAndFirstInstanceImpl = ( 142 | gpuRenderPassEncoder, 143 | gpuSize32$1, 144 | gpuSize32$2, 145 | gpuSize32$3 146 | ) => 147 | gpuRenderPassEncoder.draw(gpuSize32$1, gpuSize32$2, undefined, gpuSize32$3); 148 | export const drawWithFirstVertexAndFirstInstanceImpl = ( 149 | gpuRenderPassEncoder, 150 | gpuSize32$1, 151 | gpuSize32$2, 152 | gpuSize32$3 153 | ) => 154 | gpuRenderPassEncoder.draw(gpuSize32$1, undefined, gpuSize32$2, gpuSize32$3); 155 | export const drawWithInstanceCountAndFirstVertexAndFirstInstanceImpl = ( 156 | gpuRenderPassEncoder, 157 | gpuSize32$1, 158 | gpuSize32$2, 159 | gpuSize32$3, 160 | gpuSize32$4 161 | ) => 162 | gpuRenderPassEncoder.draw(gpuSize32$1, gpuSize32$2, gpuSize32$3, gpuSize32$4); 163 | // 164 | export const drawIndexedImpl = (gpuRenderPassEncoder, gpuSize32$1) => 165 | gpuRenderPassEncoder.drawIndexed(gpuSize32$1); 166 | export const drawIndexedWithInstanceCountImpl = ( 167 | gpuRenderPassEncoder, 168 | gpuSize32$1, 169 | gpuSize32$2 170 | ) => gpuRenderPassEncoder.drawIndexed(gpuSize32$1, gpuSize32$2); 171 | export const drawIndexedWithFirstIndexImpl = ( 172 | gpuRenderPassEncoder, 173 | gpuSize32$1, 174 | gpuSize32$2 175 | ) => gpuRenderPassEncoder.drawIndexed(gpuSize32$1, undefined, gpuSize32$2); 176 | export const drawIndexedWithBaseVertexImpl = ( 177 | gpuRenderPassEncoder, 178 | gpuSize32$1, 179 | gpuSignedOffset32$2 180 | ) => 181 | gpuRenderPassEncoder.drawIndexed( 182 | gpuSize32$1, 183 | undefined, 184 | undefined, 185 | gpuSignedOffset32$2 186 | ); 187 | export const drawIndexedWithFirstInstanceImpl = ( 188 | gpuRenderPassEncoder, 189 | gpuSize32$1, 190 | gpuSize32$2 191 | ) => 192 | gpuRenderPassEncoder.drawIndexed( 193 | gpuSize32$1, 194 | undefined, 195 | undefined, 196 | undefined, 197 | gpuSize32$2 198 | ); 199 | export const drawIndexedWithInstanceCountAndFirstIndexImpl = ( 200 | gpuRenderPassEncoder, 201 | gpuSize32$1, 202 | gpuSize32$2, 203 | gpuSize32$3 204 | ) => gpuRenderPassEncoder.drawIndexed(gpuSize32$1, gpuSize32$2, gpuSize32$3); 205 | export const drawIndexedWithInstanceCountAndBaseVertexImpl = ( 206 | gpuRenderPassEncoder, 207 | gpuSize32$1, 208 | gpuSize32$2, 209 | gpuSignedOffset32$3 210 | ) => 211 | gpuRenderPassEncoder.drawIndexed( 212 | gpuSize32$1, 213 | gpuSize32$2, 214 | undefined, 215 | gpuSignedOffset32$3 216 | ); 217 | export const drawIndexedWithInstanceCountAndFirstInstanceImpl = ( 218 | gpuRenderPassEncoder, 219 | gpuSize32$1, 220 | gpuSize32$2, 221 | gpuSize32$3 222 | ) => 223 | gpuRenderPassEncoder.drawIndexed( 224 | gpuSize32$1, 225 | gpuSize32$2, 226 | undefined, 227 | undefined, 228 | gpuSize32$3 229 | ); 230 | export const drawIndexedWithFirstIndexAndBaseVertexImpl = ( 231 | gpuRenderPassEncoder, 232 | gpuSize32$1, 233 | gpuSize32$2, 234 | gpuSignedOffset32$3 235 | ) => 236 | gpuRenderPassEncoder.drawIndexed( 237 | gpuSize32$1, 238 | undefined, 239 | gpuSize32$2, 240 | gpuSignedOffset32$3 241 | ); 242 | export const drawIndexedWithFirstIndexAndFirstInstanceImpl = ( 243 | gpuRenderPassEncoder, 244 | gpuSize32$1, 245 | gpuSize32$2, 246 | gpuSize32$3 247 | ) => 248 | gpuRenderPassEncoder.drawIndexed( 249 | gpuSize32$1, 250 | undefined, 251 | gpuSize32$2, 252 | undefined, 253 | gpuSize32$3 254 | ); 255 | export const drawIndexedWithBaseVertexAndFirstInstanceImpl = ( 256 | gpuRenderPassEncoder, 257 | gpuSize32$1, 258 | gpuSignedOffset32$2, 259 | gpuSize32$3 260 | ) => 261 | gpuRenderPassEncoder.drawIndexed( 262 | gpuSize32$1, 263 | undefined, 264 | undefined, 265 | gpuSignedOffset32$2, 266 | gpuSize32$3 267 | ); 268 | export const drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexImpl = ( 269 | gpuRenderPassEncoder, 270 | gpuSize32$1, 271 | gpuSize32$2, 272 | gpuSize32$3, 273 | gpuSignedOffset32$4 274 | ) => 275 | gpuRenderPassEncoder.drawIndexed( 276 | gpuSize32$1, 277 | gpuSize32$2, 278 | gpuSize32$3, 279 | gpuSignedOffset32$4 280 | ); 281 | export const drawIndexedWithInstanceCountAndFirstIndexAndFirstInstanceImpl = ( 282 | gpuRenderPassEncoder, 283 | gpuSize32$1, 284 | gpuSize32$2, 285 | gpuSize32$3, 286 | gpuSize32$4 287 | ) => 288 | gpuRenderPassEncoder.drawIndexed( 289 | gpuSize32$1, 290 | gpuSize32$2, 291 | gpuSize32$3, 292 | undefined, 293 | gpuSize32$4 294 | ); 295 | export const drawIndexedWithFirstIndexAndBaseVertexAndFirstInstanceImpl = ( 296 | gpuRenderPassEncoder, 297 | gpuSize32$1, 298 | gpuSize32$2, 299 | gpuSignedOffset32$3, 300 | gpuSize32$4 301 | ) => 302 | gpuRenderPassEncoder.drawIndexed( 303 | gpuSize32$1, 304 | undefined, 305 | gpuSize32$2, 306 | gpuSignedOffset32$3, 307 | gpuSize32$4 308 | ); 309 | export const drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstanceImpl = 310 | ( 311 | gpuRenderPassEncoder, 312 | gpuSize32$1, 313 | gpuSize32$2, 314 | gpuSize32$3, 315 | gpuSignedOffset32$4, 316 | gpuSize32$5 317 | ) => 318 | gpuRenderPassEncoder.drawIndexed( 319 | gpuSize32$1, 320 | gpuSize32$2, 321 | gpuSize32$3, 322 | gpuSignedOffset32$4, 323 | gpuSize32$5 324 | ); 325 | // 326 | export const drawIndirectImpl = ( 327 | gpuRenderPassEncoder, 328 | gpuBuffer$1, 329 | gpuSize64$2 330 | ) => gpuRenderPassEncoder.drawIndirect(gpuBuffer$1, gpuSize64$2); 331 | export const drawIndexedIndirectImpl = ( 332 | gpuRenderPassEncoder, 333 | gpuBuffer$1, 334 | gpuSize64$2 335 | ) => gpuRenderPassEncoder.drawIndexedIndirect(gpuBuffer$1, gpuSize64$2); 336 | export const setBindGroupImpl = ( 337 | gpuRenderPassEncoder, 338 | gpuIndex32$1, 339 | gpuBindGroup$2 340 | ) => gpuRenderPassEncoder.setBindGroup(gpuIndex32$1, gpuBindGroup$2); 341 | export const setBindGroupWithDynamicOffsetsImpl = ( 342 | gpuRenderPassEncoder, 343 | gpuIndex32$1, 344 | gpuBindGroup$2, 345 | arraygpuBufferDynamicOffset$3 346 | ) => 347 | gpuRenderPassEncoder.setBindGroup( 348 | gpuIndex32$1, 349 | gpuBindGroup$2, 350 | arraygpuBufferDynamicOffset$3 351 | ); 352 | export const setBindGroupWithDyanmicOffsetBoundsImpl = ( 353 | gpuRenderPassEncoder, 354 | gpuIndex32$1, 355 | gpuBindGroup$2, 356 | uint32array$3, 357 | gpuSize64$4, 358 | gpuSize32$5 359 | ) => 360 | gpuRenderPassEncoder.setBindGroup( 361 | gpuIndex32$1, 362 | gpuBindGroup$2, 363 | uint32array$3, 364 | gpuSize64$4, 365 | gpuSize32$5 366 | ); 367 | export const pushDebugGroupImpl = (gpuRenderPassEncoder, str$1) => 368 | gpuRenderPassEncoder.pushDebugGroup(str$1); 369 | export const popDebugGroupImpl = gpuRenderPassEncoder => 370 | gpuRenderPassEncoder.popDebugGroup(); 371 | export const insertDebugMarkerImpl = (gpuRenderPassEncoder, str$1) => 372 | gpuRenderPassEncoder.insertDebugMarker(str$1); 373 | -------------------------------------------------------------------------------- /src/Web/GPU/GPURenderBundleEncoder.purs: -------------------------------------------------------------------------------- 1 | -- @inline export setPipeline arity=2 2 | -- @inline export setIndexBuffer arity=3 3 | -- @inline export setIndexBufferWithSize arity=4 4 | -- @inline export setIndexBufferWithOffset arity=4 5 | -- @inline export setIndexBufferWithOffsetAndSize arity=5 6 | -- @inline export setVertexBuffer arity=3 7 | -- @inline export setVertexBufferWithOffset arity=4 8 | -- @inline export setVertexBufferWithSize arity=4 9 | -- @inline export setVertexBufferWithOffsetAndSize arity=5 10 | -- @inline export draw arity=2 11 | -- @inline export drawWithInstanceCount arity=3 12 | -- @inline export drawWithFirstVertex arity=2 13 | -- @inline export drawWithFirstInstance arity=2 14 | -- @inline export drawWithInstanceCountAndFirstVertex arity=4 15 | -- @inline export drawWithInstanceCountAndFirstInstance arity=4 16 | -- @inline export drawWithFirstVertexAndFirstInstance arity=4 17 | -- @inline export drawWithInstanceCountAndFirstVertexAndFirstInstance arity=5 18 | -- @inline export drawIndexed arity=2 19 | -- @inline export drawIndexedWithInstanceCount arity=3 20 | -- @inline export drawIndexedWithFirstIndex arity=3 21 | -- @inline export drawIndexedWithBaseVertex arity=3 22 | -- @inline export drawIndexedWithFirstInstance arity=3 23 | -- @inline export drawIndexedWithInstanceCountAndFirstIndex arity=4 24 | -- @inline export drawIndexedWithInstanceCountAndBaseVertex arity=4 25 | -- @inline export drawIndexedWithInstanceCountAndFirstInstance arity=4 26 | -- @inline export drawIndexedWithFirstIndexAndBaseVertex arity=4 27 | -- @inline export drawIndexedWithFirstIndexAndFirstInstance arity=4 28 | -- @inline export drawIndexedWithBaseVertexAndFirstInstance arity=4 29 | -- @inline export drawIndexedWithInstanceCountAndFirstIndexAndBaseVertex arity=5 30 | -- @inline export drawIndexedWithInstanceCountAndFirstIndexAndFirstInstance arity=5 31 | -- @inline export drawIndexedWithFirstIndexAndBaseVertexAndFirstInstance arity=5 32 | -- @inline export drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstance arity=6 33 | -- @inline export drawIndirect arity=3 34 | -- @inline export drawIndexedIndirect arity=3 35 | -- @inline export setBindGroup arity=3 36 | -- @inline export setBindGroupWithDynamicOffsets arity=4 37 | -- @inline export setBindGroupWithDyanmicOffsetBounds arity=6 38 | -- @inline export pushDebugGroup arity=2 39 | -- @inline export popDebugGroup arity=1 40 | -- @inline export insertDebugMarker arity=2 41 | module Web.GPU.GPURenderBundleEncoder 42 | ( GPURenderBundleEncoder 43 | , draw 44 | , drawIndexed 45 | , drawIndexedIndirect 46 | , drawIndexedWithBaseVertex 47 | , drawIndexedWithBaseVertexAndFirstInstance 48 | , drawIndexedWithFirstIndex 49 | , drawIndexedWithFirstIndexAndBaseVertex 50 | , drawIndexedWithFirstIndexAndBaseVertexAndFirstInstance 51 | , drawIndexedWithFirstIndexAndFirstInstance 52 | , drawIndexedWithFirstInstance 53 | , drawIndexedWithInstanceCount 54 | , drawIndexedWithInstanceCountAndBaseVertex 55 | , drawIndexedWithInstanceCountAndFirstIndex 56 | , drawIndexedWithInstanceCountAndFirstIndexAndBaseVertex 57 | , drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstance 58 | , drawIndexedWithInstanceCountAndFirstIndexAndFirstInstance 59 | , drawIndexedWithInstanceCountAndFirstInstance 60 | , drawIndirect 61 | , drawWithFirstInstance 62 | , drawWithFirstVertex 63 | , drawWithFirstVertexAndFirstInstance 64 | , drawWithInstanceCount 65 | , drawWithInstanceCountAndFirstInstance 66 | , drawWithInstanceCountAndFirstVertex 67 | , drawWithInstanceCountAndFirstVertexAndFirstInstance 68 | , finish 69 | , insertDebugMarker 70 | , popDebugGroup 71 | , pushDebugGroup 72 | , setBindGroup 73 | , setBindGroupWithDyanmicOffsetBounds 74 | , setBindGroupWithDynamicOffsets 75 | , setIndexBuffer 76 | , setIndexBufferWithOffset 77 | , setIndexBufferWithOffsetAndSize 78 | , setIndexBufferWithSize 79 | , setPipeline 80 | , setVertexBuffer 81 | , setVertexBufferWithOffset 82 | , setVertexBufferWithOffsetAndSize 83 | , setVertexBufferWithSize 84 | ) where 85 | 86 | import Prelude 87 | 88 | import Data.ArrayBuffer.Types (Uint32Array) 89 | import Effect (Effect) 90 | import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, EffectFn5, EffectFn6, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4, runEffectFn5, runEffectFn6) 91 | import Web.GPU.GPUBindGroup (GPUBindGroup) 92 | import Web.GPU.GPUBuffer (GPUBuffer) 93 | import Web.GPU.GPUIndexFormat (GPUIndexFormat) 94 | import Web.GPU.GPURenderBundle (GPURenderBundle) 95 | import Web.GPU.GPURenderBundleDescriptor (GPURenderBundleDescriptor) 96 | import Web.GPU.GPURenderPipeline (GPURenderPipeline) 97 | import Web.GPU.Internal.Types (GPUBufferDynamicOffset, GPUIndex32, GPUSignedOffset32, GPUSize32, GPUSize64) 98 | 99 | data GPURenderBundleEncoder 100 | 101 | foreign import finishImpl :: EffectFn2 GPURenderBundleEncoder GPURenderBundleDescriptor GPURenderBundle 102 | finish 103 | ∷ GPURenderBundleEncoder -> GPURenderBundleDescriptor → Effect GPURenderBundle 104 | finish a b = runEffectFn2 finishImpl a b 105 | 106 | foreign import setPipelineImpl :: EffectFn2 GPURenderBundleEncoder GPURenderPipeline Unit 107 | setPipeline :: GPURenderBundleEncoder -> GPURenderPipeline -> Effect Unit 108 | setPipeline a b = runEffectFn2 setPipelineImpl a b 109 | 110 | foreign import setIndexBufferImpl :: EffectFn3 GPURenderBundleEncoder GPUBuffer GPUIndexFormat Unit 111 | setIndexBuffer 112 | :: GPURenderBundleEncoder -> GPUBuffer -> GPUIndexFormat -> Effect Unit 113 | setIndexBuffer a b c = runEffectFn3 setIndexBufferImpl a b c 114 | 115 | foreign import setIndexBufferWithSizeImpl :: EffectFn4 GPURenderBundleEncoder GPUBuffer GPUIndexFormat GPUSize64 Unit 116 | setIndexBufferWithSize 117 | :: GPURenderBundleEncoder 118 | -> GPUBuffer 119 | -> GPUIndexFormat 120 | -> GPUSize64 121 | -> Effect Unit 122 | setIndexBufferWithSize a b c d = runEffectFn4 setIndexBufferWithSizeImpl a b c d 123 | 124 | foreign import setIndexBufferWithOffsetImpl :: EffectFn4 GPURenderBundleEncoder GPUBuffer GPUIndexFormat GPUSize64 Unit 125 | setIndexBufferWithOffset 126 | :: GPURenderBundleEncoder 127 | -> GPUBuffer 128 | -> GPUIndexFormat 129 | -> GPUSize64 130 | -> Effect Unit 131 | setIndexBufferWithOffset a b c d = runEffectFn4 setIndexBufferWithOffsetImpl a b c d 132 | 133 | foreign import setIndexBufferWithOffsetAndSizeImpl :: EffectFn5 GPURenderBundleEncoder GPUBuffer GPUIndexFormat GPUSize64 GPUSize64 Unit 134 | setIndexBufferWithOffsetAndSize 135 | :: GPURenderBundleEncoder 136 | -> GPUBuffer 137 | -> GPUIndexFormat 138 | -> GPUSize64 139 | -> GPUSize64 140 | -> Effect Unit 141 | setIndexBufferWithOffsetAndSize a b c d e = runEffectFn5 setIndexBufferWithOffsetAndSizeImpl a b c d e 142 | 143 | foreign import setVertexBufferImpl :: EffectFn3 GPURenderBundleEncoder GPUIndex32 GPUBuffer Unit 144 | setVertexBuffer 145 | :: GPURenderBundleEncoder -> GPUIndex32 -> GPUBuffer -> Effect Unit 146 | setVertexBuffer a b c = runEffectFn3 setVertexBufferImpl a b c 147 | 148 | foreign import setVertexBufferWithOffsetImpl :: EffectFn4 GPURenderBundleEncoder GPUIndex32 GPUBuffer GPUSize64 Unit 149 | setVertexBufferWithOffset 150 | :: GPURenderBundleEncoder 151 | -> GPUIndex32 152 | -> GPUBuffer 153 | -> GPUSize64 154 | -> Effect Unit 155 | setVertexBufferWithOffset a b c d = runEffectFn4 setVertexBufferWithOffsetImpl a b c d 156 | 157 | foreign import setVertexBufferWithSizeImpl :: EffectFn4 GPURenderBundleEncoder GPUIndex32 GPUBuffer GPUSize64 Unit 158 | setVertexBufferWithSize 159 | :: GPURenderBundleEncoder 160 | -> GPUIndex32 161 | -> GPUBuffer 162 | -> GPUSize64 163 | -> Effect Unit 164 | setVertexBufferWithSize a b c d = runEffectFn4 setVertexBufferWithSizeImpl a b c d 165 | 166 | foreign import setVertexBufferWithOffsetAndSizeImpl :: EffectFn5 GPURenderBundleEncoder GPUIndex32 GPUBuffer GPUSize64 GPUSize64 Unit 167 | setVertexBufferWithOffsetAndSize 168 | :: GPURenderBundleEncoder 169 | -> GPUIndex32 170 | -> GPUBuffer 171 | -> GPUSize64 172 | -> GPUSize64 173 | -> Effect Unit 174 | setVertexBufferWithOffsetAndSize a b c d e = runEffectFn5 setVertexBufferWithOffsetAndSizeImpl a b c d e 175 | 176 | foreign import drawImpl :: EffectFn2 GPURenderBundleEncoder GPUSize32 Unit 177 | draw :: GPURenderBundleEncoder -> GPUSize32 -> Effect Unit 178 | draw a b = runEffectFn2 drawImpl a b 179 | 180 | foreign import drawWithInstanceCountImpl :: EffectFn3 GPURenderBundleEncoder GPUSize32 GPUSize32 Unit 181 | drawWithInstanceCount 182 | :: GPURenderBundleEncoder -> GPUSize32 -> GPUSize32 -> Effect Unit 183 | drawWithInstanceCount a b c = runEffectFn3 drawWithInstanceCountImpl a b c 184 | 185 | foreign import drawWithFirstVertexImpl :: EffectFn2 GPURenderBundleEncoder GPUSize32 Unit 186 | drawWithFirstVertex 187 | :: GPURenderBundleEncoder -> GPUSize32 -> Effect Unit 188 | drawWithFirstVertex a b = runEffectFn2 drawWithFirstVertexImpl a b 189 | 190 | foreign import drawWithFirstInstanceImpl :: EffectFn2 GPURenderBundleEncoder GPUSize32 Unit 191 | drawWithFirstInstance 192 | :: GPURenderBundleEncoder -> GPUSize32 -> Effect Unit 193 | drawWithFirstInstance a b = runEffectFn2 drawWithFirstInstanceImpl a b 194 | 195 | foreign import drawWithInstanceCountAndFirstVertexImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 Unit 196 | drawWithInstanceCountAndFirstVertex 197 | :: GPURenderBundleEncoder 198 | -> GPUSize32 199 | -> GPUSize32 200 | -> GPUSize32 201 | -> Effect Unit 202 | drawWithInstanceCountAndFirstVertex a b c d = runEffectFn4 drawWithInstanceCountAndFirstVertexImpl a b c d 203 | 204 | foreign import drawWithInstanceCountAndFirstInstanceImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 Unit 205 | drawWithInstanceCountAndFirstInstance 206 | :: GPURenderBundleEncoder 207 | -> GPUSize32 208 | -> GPUSize32 209 | -> GPUSize32 210 | -> Effect Unit 211 | drawWithInstanceCountAndFirstInstance a b c d = 212 | runEffectFn4 drawWithInstanceCountAndFirstInstanceImpl a b c d 213 | 214 | foreign import drawWithFirstVertexAndFirstInstanceImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 Unit 215 | drawWithFirstVertexAndFirstInstance 216 | :: GPURenderBundleEncoder 217 | -> GPUSize32 218 | -> GPUSize32 219 | -> GPUSize32 220 | -> Effect Unit 221 | drawWithFirstVertexAndFirstInstance a b c d = runEffectFn4 drawWithFirstVertexAndFirstInstanceImpl a b c d 222 | 223 | foreign import drawWithInstanceCountAndFirstVertexAndFirstInstanceImpl :: EffectFn5 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 GPUSize32 Unit 224 | drawWithInstanceCountAndFirstVertexAndFirstInstance 225 | :: GPURenderBundleEncoder 226 | -> GPUSize32 227 | -> GPUSize32 228 | -> GPUSize32 229 | -> GPUSize32 230 | -> Effect Unit 231 | drawWithInstanceCountAndFirstVertexAndFirstInstance a b c d e = 232 | runEffectFn5 drawWithInstanceCountAndFirstVertexAndFirstInstanceImpl a b c d e 233 | 234 | foreign import drawIndexedImpl :: EffectFn2 GPURenderBundleEncoder GPUSize32 Unit 235 | drawIndexed :: GPURenderBundleEncoder -> GPUSize32 -> Effect Unit 236 | drawIndexed a b = runEffectFn2 drawIndexedImpl a b 237 | 238 | foreign import drawIndexedWithInstanceCountImpl :: EffectFn3 GPURenderBundleEncoder GPUSize32 GPUSize32 Unit 239 | drawIndexedWithInstanceCount 240 | :: GPURenderBundleEncoder -> GPUSize32 -> GPUSize32 -> Effect Unit 241 | drawIndexedWithInstanceCount a b c = runEffectFn3 drawIndexedWithInstanceCountImpl a b c 242 | 243 | foreign import drawIndexedWithFirstIndexImpl :: EffectFn3 GPURenderBundleEncoder GPUSize32 GPUSize32 Unit 244 | drawIndexedWithFirstIndex 245 | :: GPURenderBundleEncoder -> GPUSize32 -> GPUSize32 -> Effect Unit 246 | drawIndexedWithFirstIndex a b c = runEffectFn3 drawIndexedWithFirstIndexImpl a b c 247 | 248 | foreign import drawIndexedWithBaseVertexImpl :: EffectFn3 GPURenderBundleEncoder GPUSize32 GPUSignedOffset32 Unit 249 | drawIndexedWithBaseVertex 250 | :: GPURenderBundleEncoder -> GPUSize32 -> GPUSignedOffset32 -> Effect Unit 251 | drawIndexedWithBaseVertex a b c = runEffectFn3 drawIndexedWithBaseVertexImpl a b c 252 | 253 | foreign import drawIndexedWithFirstInstanceImpl :: EffectFn3 GPURenderBundleEncoder GPUSize32 GPUSize32 Unit 254 | drawIndexedWithFirstInstance 255 | :: GPURenderBundleEncoder -> GPUSize32 -> GPUSize32 -> Effect Unit 256 | drawIndexedWithFirstInstance a b c = runEffectFn3 drawIndexedWithFirstInstanceImpl a b c 257 | 258 | foreign import drawIndexedWithInstanceCountAndFirstIndexImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 Unit 259 | drawIndexedWithInstanceCountAndFirstIndex 260 | :: GPURenderBundleEncoder 261 | -> GPUSize32 262 | -> GPUSize32 263 | -> GPUSize32 264 | -> Effect Unit 265 | drawIndexedWithInstanceCountAndFirstIndex a b c d = 266 | runEffectFn4 drawIndexedWithInstanceCountAndFirstIndexImpl a b c d 267 | 268 | foreign import drawIndexedWithInstanceCountAndBaseVertexImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSignedOffset32 Unit 269 | drawIndexedWithInstanceCountAndBaseVertex 270 | :: GPURenderBundleEncoder 271 | -> GPUSize32 272 | -> GPUSize32 273 | -> GPUSignedOffset32 274 | -> Effect Unit 275 | drawIndexedWithInstanceCountAndBaseVertex a b c d = 276 | runEffectFn4 drawIndexedWithInstanceCountAndBaseVertexImpl a b c d 277 | 278 | foreign import drawIndexedWithInstanceCountAndFirstInstanceImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 Unit 279 | drawIndexedWithInstanceCountAndFirstInstance 280 | :: GPURenderBundleEncoder 281 | -> GPUSize32 282 | -> GPUSize32 283 | -> GPUSize32 284 | -> Effect Unit 285 | drawIndexedWithInstanceCountAndFirstInstance a b c d = 286 | runEffectFn4 drawIndexedWithInstanceCountAndFirstInstanceImpl a b c d 287 | 288 | foreign import drawIndexedWithFirstIndexAndBaseVertexImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSignedOffset32 Unit 289 | drawIndexedWithFirstIndexAndBaseVertex 290 | :: GPURenderBundleEncoder 291 | -> GPUSize32 292 | -> GPUSize32 293 | -> GPUSignedOffset32 294 | -> Effect Unit 295 | drawIndexedWithFirstIndexAndBaseVertex a b c d = 296 | runEffectFn4 drawIndexedWithFirstIndexAndBaseVertexImpl a b c d 297 | 298 | foreign import drawIndexedWithFirstIndexAndFirstInstanceImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 Unit 299 | drawIndexedWithFirstIndexAndFirstInstance 300 | :: GPURenderBundleEncoder 301 | -> GPUSize32 302 | -> GPUSize32 303 | -> GPUSize32 304 | -> Effect Unit 305 | drawIndexedWithFirstIndexAndFirstInstance a b c d = 306 | runEffectFn4 drawIndexedWithFirstIndexAndFirstInstanceImpl a b c d 307 | 308 | foreign import drawIndexedWithBaseVertexAndFirstInstanceImpl :: EffectFn4 GPURenderBundleEncoder GPUSize32 GPUSignedOffset32 GPUSize32 Unit 309 | drawIndexedWithBaseVertexAndFirstInstance 310 | :: GPURenderBundleEncoder 311 | -> GPUSize32 312 | -> GPUSignedOffset32 313 | -> GPUSize32 314 | -> Effect Unit 315 | drawIndexedWithBaseVertexAndFirstInstance a b c d = 316 | runEffectFn4 drawIndexedWithBaseVertexAndFirstInstanceImpl a b c d 317 | 318 | foreign import drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexImpl :: EffectFn5 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 GPUSignedOffset32 Unit 319 | drawIndexedWithInstanceCountAndFirstIndexAndBaseVertex 320 | :: GPURenderBundleEncoder 321 | -> GPUSize32 322 | -> GPUSize32 323 | -> GPUSize32 324 | -> GPUSignedOffset32 325 | -> Effect Unit 326 | drawIndexedWithInstanceCountAndFirstIndexAndBaseVertex a b c d e = 327 | runEffectFn5 drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexImpl a b c d e 328 | 329 | foreign import drawIndexedWithInstanceCountAndFirstIndexAndFirstInstanceImpl :: EffectFn5 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 GPUSize32 Unit 330 | drawIndexedWithInstanceCountAndFirstIndexAndFirstInstance 331 | :: GPURenderBundleEncoder 332 | -> GPUSize32 333 | -> GPUSize32 334 | -> GPUSize32 335 | -> GPUSize32 336 | -> Effect Unit 337 | drawIndexedWithInstanceCountAndFirstIndexAndFirstInstance a b c d e = runEffectFn5 338 | drawIndexedWithInstanceCountAndFirstIndexAndFirstInstanceImpl a b c d e 339 | 340 | foreign import drawIndexedWithFirstIndexAndBaseVertexAndFirstInstanceImpl :: EffectFn5 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSignedOffset32 GPUSize32 Unit 341 | drawIndexedWithFirstIndexAndBaseVertexAndFirstInstance 342 | :: GPURenderBundleEncoder 343 | -> GPUSize32 344 | -> GPUSize32 345 | -> GPUSignedOffset32 346 | -> GPUSize32 347 | -> Effect Unit 348 | drawIndexedWithFirstIndexAndBaseVertexAndFirstInstance a b c d e = 349 | runEffectFn5 drawIndexedWithFirstIndexAndBaseVertexAndFirstInstanceImpl a b c d e 350 | 351 | foreign import drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstanceImpl :: EffectFn6 GPURenderBundleEncoder GPUSize32 GPUSize32 GPUSize32 GPUSignedOffset32 GPUSize32 Unit 352 | drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstance 353 | :: GPURenderBundleEncoder 354 | -> GPUSize32 355 | -> GPUSize32 356 | -> GPUSize32 357 | -> GPUSignedOffset32 358 | -> GPUSize32 359 | -> Effect Unit 360 | drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstance a b c d e f = 361 | runEffectFn6 drawIndexedWithInstanceCountAndFirstIndexAndBaseVertexAndFirstInstanceImpl a b c d e f 362 | 363 | foreign import drawIndirectImpl :: EffectFn3 GPURenderBundleEncoder GPUBuffer GPUSize64 Unit 364 | drawIndirect :: GPURenderBundleEncoder -> GPUBuffer -> GPUSize64 -> Effect Unit 365 | drawIndirect a b c = runEffectFn3 drawIndirectImpl a b c 366 | 367 | foreign import drawIndexedIndirectImpl :: EffectFn3 GPURenderBundleEncoder GPUBuffer GPUSize64 Unit 368 | drawIndexedIndirect 369 | :: GPURenderBundleEncoder -> GPUBuffer -> GPUSize64 -> Effect Unit 370 | drawIndexedIndirect a b c = runEffectFn3 drawIndexedIndirectImpl a b c 371 | 372 | foreign import setBindGroupImpl :: EffectFn3 GPURenderBundleEncoder GPUIndex32 GPUBindGroup Unit 373 | setBindGroup 374 | :: GPURenderBundleEncoder -> GPUIndex32 -> GPUBindGroup -> Effect Unit 375 | setBindGroup a b c = runEffectFn3 setBindGroupImpl a b c 376 | 377 | foreign import setBindGroupWithDynamicOffsetsImpl :: EffectFn4 GPURenderBundleEncoder GPUIndex32 GPUBindGroup (Array GPUBufferDynamicOffset) Unit 378 | setBindGroupWithDynamicOffsets 379 | :: GPURenderBundleEncoder 380 | -> GPUIndex32 381 | -> GPUBindGroup 382 | -> Array GPUBufferDynamicOffset 383 | -> Effect Unit 384 | setBindGroupWithDynamicOffsets a b c d = runEffectFn4 setBindGroupWithDynamicOffsetsImpl a b c d 385 | 386 | foreign import setBindGroupWithDyanmicOffsetBoundsImpl :: EffectFn6 GPURenderBundleEncoder GPUIndex32 GPUBindGroup Uint32Array GPUSize64 GPUSize32 Unit 387 | setBindGroupWithDyanmicOffsetBounds 388 | :: GPURenderBundleEncoder 389 | -> GPUIndex32 390 | -> GPUBindGroup 391 | -> Uint32Array 392 | -> GPUSize64 393 | -> GPUSize32 394 | -> Effect Unit 395 | setBindGroupWithDyanmicOffsetBounds a b c d e f = runEffectFn6 setBindGroupWithDyanmicOffsetBoundsImpl a b c d e f 396 | 397 | foreign import pushDebugGroupImpl :: EffectFn2 GPURenderBundleEncoder String Unit 398 | pushDebugGroup :: GPURenderBundleEncoder -> String -> Effect Unit 399 | pushDebugGroup a b = runEffectFn2 pushDebugGroupImpl a b 400 | 401 | foreign import popDebugGroupImpl :: EffectFn1 GPURenderBundleEncoder Unit 402 | popDebugGroup :: GPURenderBundleEncoder -> Effect Unit 403 | popDebugGroup a = runEffectFn1 popDebugGroupImpl a 404 | 405 | foreign import insertDebugMarkerImpl :: EffectFn2 GPURenderBundleEncoder String Unit 406 | insertDebugMarker :: GPURenderBundleEncoder -> String -> Effect Unit 407 | insertDebugMarker a b = runEffectFn2 insertDebugMarkerImpl a b --------------------------------------------------------------------------------