Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
First pass on rewrite
  • Loading branch information
Mike Solomon committed Apr 25, 2023
commit 369565925d17a0ca5c947d4aae4b2adff24e5adb
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ to generate this file without the comments in this block.
, "newtype"
, "ordered-collections"
, "prelude"
, "uint"
, "unsafe-coerce"
, "web-events"
, "web-html"
Expand Down
4 changes: 2 additions & 2 deletions src/Web/GPU/GPU.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const requestAdapterImpl = just => nothing => gpu => options => () =>
export const requestAdapterImpl = (just, nothing, gpu, options) =>
gpu.requestAdapter(options).then(o => (o ? just(o) : nothing));

export const getPreferredCanvasFormatImpl = gpu => () =>
export const getPreferredCanvasFormatImpl = gpu =>
gpu.getPreferredCanvasFormat();
16 changes: 5 additions & 11 deletions src/Web/GPU/GPU.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Web.GPU.GPU
) where

import Data.Maybe (Maybe(..))
import Effect.Uncurried(EffectFn1, runEffectFn1,EffectFn4, runEffectFn4)
import Effect (Effect)
import Web.GPU.GPURequestAdapterOptions (GPURequestAdapterOptions)
import Web.GPU.GPUTextureFormat (GPUTextureFormat)
Expand All @@ -17,22 +18,15 @@ data GPU

-- requestAdapter

foreign import requestAdapterImpl
:: (GPUAdapter -> Maybe GPUAdapter)
-> Maybe GPUAdapter
-> GPU
-> GPURequestAdapterOptions
-> Effect (Promise (Maybe GPUAdapter))

foreign import requestAdapterImpl :: EffectFn4 (GPUAdapter -> Maybe GPUAdapter) (Maybe GPUAdapter) GPU GPURequestAdapterOptions (Promise (Maybe GPUAdapter))
requestAdapter
:: GPU
-> GPURequestAdapterOptions
-> Effect (Promise (Maybe GPUAdapter))
requestAdapter = requestAdapterImpl Just Nothing
requestAdapter a b = runEffectFn4 requestAdapterImpl Just Nothing a b

-- getPreferredCanvasFormat

foreign import getPreferredCanvasFormatImpl :: GPU -> Effect GPUTextureFormat

foreign import getPreferredCanvasFormatImpl :: EffectFn1 GPU GPUTextureFormat
getPreferredCanvasFormat :: GPU -> Effect GPUTextureFormat
getPreferredCanvasFormat = getPreferredCanvasFormatImpl
getPreferredCanvasFormat a = runEffectFn1 getPreferredCanvasFormatImpl a
10 changes: 5 additions & 5 deletions src/Web/GPU/GPUAdapter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export const featuresImpl = insert => empty => adapter => () => {
export const featuresImpl = (insert, empty, adapter) => {
const iterator1 = adapter.features.entries();
let out = empty;
for (const entry of iterator1) {
out = insert(entry)(out);
}
return out;
};
export const limitsImpl = adapter => () => adapter.limits;
export const isFallbackAdapterImpl = adapter => () => adapter.isFallbackAdapter;
export const requestDeviceImpl = just => nothing => adapter => options => () =>
export const limitsImpl = adapter => adapter.limits;
export const isFallbackAdapterImpl = adapter => adapter.isFallbackAdapter;
export const requestDeviceImpl = (just, nothing, adapter, options) =>
adapter.requestDevice(options).then(o => (o ? just(o) : nothing));
export const requestAdapterInfoImpl = adapter => unmaskHints => () =>
export const requestAdapterInfoImpl = (adapter, unmaskHints) =>
adapter.requestAdapterInfo(unmaskHints);
36 changes: 11 additions & 25 deletions src/Web/GPU/GPUAdapter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Web.GPU.GPUAdapter
) where

import Data.Maybe (Maybe(..))
import Effect.Uncurried(EffectFn1, runEffectFn1,EffectFn2, runEffectFn2,EffectFn3, runEffectFn3,EffectFn4, runEffectFn4)
import Data.Set as Set
import Effect (Effect)
import Web.GPU.GPUDeviceDescriptor (GPUDeviceDescriptor)
Expand All @@ -26,45 +27,30 @@ import Web.Promise (Promise)
data GPUAdapter

-- features
foreign import featuresImpl
:: (GPUFeatureName -> Set.Set GPUFeatureName -> Set.Set GPUFeatureName)
-> Set.Set GPUFeatureName
-> GPUAdapter
-> Effect (Set.Set GPUFeatureName)

foreign import featuresImpl :: EffectFn3 (GPUFeatureName -> Set.Set GPUFeatureName -> Set.Set GPUFeatureName) (Set.Set GPUFeatureName) GPUAdapter (Set.Set GPUFeatureName)
features :: GPUAdapter -> Effect (Set.Set GPUFeatureName)
features = featuresImpl Set.insert Set.empty

foreign import limitsImpl :: GPUAdapter -> Effect { | GPUSupportedLimits }
features a = runEffectFn3 featuresImpl Set.insert Set.empty a

foreign import limitsImpl :: EffectFn1 GPUAdapter { | GPUSupportedLimits }
limits :: GPUAdapter -> Effect { | GPUSupportedLimits }
limits = limitsImpl

foreign import isFallbackAdapterImpl :: GPUAdapter -> Effect Boolean
limits a = runEffectFn1 limitsImpl a

foreign import isFallbackAdapterImpl :: EffectFn1 GPUAdapter Boolean
isFallbackAdapter :: GPUAdapter -> Effect Boolean
isFallbackAdapter = isFallbackAdapterImpl
isFallbackAdapter a = runEffectFn1 isFallbackAdapterImpl a

-- requestDevice

foreign import requestDeviceImpl
:: (GPUDevice -> Maybe GPUDevice)
-> Maybe GPUDevice
-> GPUAdapter
-> GPUDeviceDescriptor
-> Effect (Promise (Maybe GPUDevice))

foreign import requestDeviceImpl :: EffectFn4 (GPUDevice -> Maybe GPUDevice)( Maybe GPUDevice) GPUAdapter GPUDeviceDescriptor (Promise (Maybe GPUDevice))
requestDevice
:: GPUAdapter
-> GPUDeviceDescriptor
-> Effect (Promise (Maybe GPUDevice))
requestDevice = requestDeviceImpl Just Nothing
requestDevice a b= runEffectFn4 requestDeviceImpl Just Nothing a b

-- requestAdapterInfo

foreign import requestAdapterInfoImpl
:: GPUAdapter -> Array (UnmaskHint) -> Effect (Promise GPUAdapterInfo)

foreign import requestAdapterInfoImpl :: EffectFn2 GPUAdapter (Array UnmaskHint) (Promise GPUAdapterInfo)
type GPUAdapterInfo =
{ vendor :: String
, architecture :: String
Expand All @@ -74,4 +60,4 @@ type GPUAdapterInfo =

requestAdapterInfo
:: GPUAdapter -> Array UnmaskHint -> Effect (Promise GPUAdapterInfo)
requestAdapterInfo = requestAdapterInfoImpl
requestAdapterInfo a b = runEffectFn2 requestAdapterInfoImpl a b
32 changes: 15 additions & 17 deletions src/Web/GPU/GPUBuffer.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
export const sizeImpl = buffer => () => buffer.size;
export const usageImpl = buffer => () => buffer.usage;
export const mapStateImpl = buffer => () => buffer.mapState;
export const mapAsyncImpl = buffer => mode => () => buffer.mapAsync(mode);
export const mapAsyncWithOffsetImpl = buffer => mode => offset => () =>
export const sizeImpl = buffer => buffer.size;
export const usageImpl = buffer => buffer.usage;
export const mapStateImpl = buffer => buffer.mapState;
export const mapAsyncImpl = (buffer, mode) => buffer.mapAsync(mode);
export const mapAsyncWithOffsetImpl = (buffer, mode, offset) =>
buffer.mapAsync(mode, offset);
export const mapAsyncWithSizeImpl = buffer => mode => size => () =>
export const mapAsyncWithSizeImpl = (buffer, mode, size) =>
buffer.mapAsync(mode, undefined, size);
export const mapAsyncWithOffsetAndSizeImpl =
buffer => mode => offset => size => () =>
buffer.mapAsync(mode, offset, size);
export const getMappedRangeImpl = buffer => () => buffer.getMappedRange();
export const getMappedRangeWithOffsetImpl = buffer => offset => () =>
export const mapAsyncWithOffsetAndSizeImpl = (buffer, mode, offset, size) =>
buffer.mapAsync(mode, offset, size);
export const getMappedRangeImpl = buffer => buffer.getMappedRange();
export const getMappedRangeWithOffsetImpl = (buffer, offset) =>
buffer.getMappedRange(offset);
export const getMappedRangeWithSizeImpl = buffer => size => () =>
export const getMappedRangeWithSizeImpl = (buffer, size) =>
buffer.getMappedRange(undefined, size);
export const getMappedRangeWithOffsetAndSizeImpl =
buffer => offset => size => () =>
buffer.getMappedRange(offset, size);
export const unmapImpl = buffer => () => buffer.unmap();
export const destroyImpl = buffer => () => buffer.destroy();
export const getMappedRangeWithOffsetAndSizeImpl = (buffer, offset, size) =>
buffer.getMappedRange(offset, size);
export const unmapImpl = buffer => buffer.unmap();
export const destroyImpl = buffer => buffer.destroy();
72 changes: 27 additions & 45 deletions src/Web/GPU/GPUBuffer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Web.GPU.GPUBuffer
) where

import Prelude
import Effect.Uncurried(EffectFn1, runEffectFn1,EffectFn2, runEffectFn2,EffectFn3, runEffectFn3,EffectFn4, runEffectFn4)

import Data.ArrayBuffer.Types (ArrayBuffer)
import Effect (Effect)
Expand All @@ -40,77 +41,58 @@ import Web.Promise (Promise)

data GPUBuffer

foreign import sizeImpl :: GPUBuffer -> Effect GPUSize64

foreign import sizeImpl :: EffectFn1 GPUBuffer GPUSize64
size :: GPUBuffer -> Effect GPUSize64
size = sizeImpl

foreign import usageImpl :: GPUBuffer -> Effect GPUBufferUsage
size a = runEffectFn1 sizeImpl a

foreign import usageImpl :: EffectFn1 GPUBuffer GPUBufferUsage
usage :: GPUBuffer -> Effect GPUBufferUsage
usage = usageImpl

foreign import mapStateImpl :: GPUBuffer -> Effect GPUBufferMapState
usage a = runEffectFn1 usageImpl a

foreign import mapStateImpl :: EffectFn1 GPUBuffer GPUBufferMapState
mapState :: GPUBuffer -> Effect GPUBufferMapState
mapState = mapStateImpl

foreign import mapAsyncImpl :: GPUBuffer -> GPUMapMode -> Effect (Promise Unit)
mapState a = runEffectFn1 mapStateImpl a

foreign import mapAsyncImpl :: EffectFn2 GPUBuffer GPUMapMode (Promise Unit)
mapAsync :: GPUBuffer -> GPUMapMode -> Effect (Promise Unit)
mapAsync = mapAsyncImpl

foreign import mapAsyncWithOffsetImpl
:: GPUBuffer -> GPUMapMode -> GPUSize64 -> Effect (Promise Unit)
mapAsync a b = runEffectFn2 mapAsyncImpl a b

foreign import mapAsyncWithOffsetImpl :: EffectFn3 GPUBuffer GPUMapMode GPUSize64 (Promise Unit)
mapAsyncWithOffset
:: GPUBuffer -> GPUMapMode -> GPUSize64 -> Effect (Promise Unit)
mapAsyncWithOffset = mapAsyncWithOffsetImpl

foreign import mapAsyncWithSizeImpl
:: GPUBuffer -> GPUMapMode -> GPUSize64 -> Effect (Promise Unit)
mapAsyncWithOffset a b c = runEffectFn3 mapAsyncWithOffsetImpl a b c

foreign import mapAsyncWithSizeImpl :: EffectFn3 GPUBuffer GPUMapMode GPUSize64 (Promise Unit)
mapAsyncWithSize
:: GPUBuffer -> GPUMapMode -> GPUSize64 -> Effect (Promise Unit)
mapAsyncWithSize = mapAsyncWithSizeImpl

foreign import mapAsyncWithOffsetAndSizeImpl
:: GPUBuffer -> GPUMapMode -> GPUSize64 -> GPUSize64 -> Effect (Promise Unit)
mapAsyncWithSize a b c = runEffectFn3 mapAsyncWithSizeImpl a b c

foreign import mapAsyncWithOffsetAndSizeImpl :: EffectFn4 GPUBuffer GPUMapMode GPUSize64 GPUSize64 (Promise Unit)
mapAsyncWithOffsetAndSize
:: GPUBuffer -> GPUMapMode -> GPUSize64 -> GPUSize64 -> Effect (Promise Unit)
mapAsyncWithOffsetAndSize = mapAsyncWithOffsetAndSizeImpl

foreign import getMappedRangeImpl :: GPUBuffer -> Effect ArrayBuffer
mapAsyncWithOffsetAndSize a b c d = runEffectFn4 mapAsyncWithOffsetAndSizeImpl a b c d

foreign import getMappedRangeImpl :: EffectFn1 GPUBuffer ArrayBuffer
getMappedRange :: GPUBuffer -> Effect ArrayBuffer
getMappedRange = getMappedRangeImpl

foreign import getMappedRangeWithOffsetImpl
:: GPUBuffer -> GPUSize64 -> Effect ArrayBuffer
getMappedRange a = runEffectFn1 getMappedRangeImpl a

foreign import getMappedRangeWithOffsetImpl :: EffectFn2 GPUBuffer GPUSize64 ArrayBuffer
getMappedRangeWithOffset :: GPUBuffer -> GPUSize64 -> Effect ArrayBuffer
getMappedRangeWithOffset = getMappedRangeWithOffsetImpl

foreign import getMappedRangeWithSizeImpl
:: GPUBuffer -> GPUSize64 -> Effect ArrayBuffer
getMappedRangeWithOffset a b = runEffectFn2 getMappedRangeWithOffsetImpl a b

foreign import getMappedRangeWithSizeImpl :: EffectFn2 GPUBuffer GPUSize64 ArrayBuffer
getMappedRangeWithSize :: GPUBuffer -> GPUSize64 -> Effect ArrayBuffer
getMappedRangeWithSize = getMappedRangeWithSizeImpl

foreign import getMappedRangeWithOffsetAndSizeImpl
:: GPUBuffer -> GPUSize64 -> GPUSize64 -> Effect ArrayBuffer
getMappedRangeWithSize a b = runEffectFn2 getMappedRangeWithSizeImpl a b

foreign import getMappedRangeWithOffsetAndSizeImpl :: EffectFn3 GPUBuffer GPUSize64 GPUSize64 ArrayBuffer
getMappedRangeWithOffsetAndSize
:: GPUBuffer -> GPUSize64 -> GPUSize64 -> Effect ArrayBuffer
getMappedRangeWithOffsetAndSize = getMappedRangeWithOffsetAndSizeImpl

foreign import unmapImpl :: GPUBuffer -> Effect Unit
getMappedRangeWithOffsetAndSize a b c = runEffectFn3 getMappedRangeWithOffsetAndSizeImpl a b c

foreign import unmapImpl :: EffectFn1 GPUBuffer Unit
unmap :: GPUBuffer -> Effect Unit
unmap = unmapImpl

foreign import destroyImpl :: GPUBuffer -> Effect Unit
unmap a = runEffectFn1 unmapImpl a

foreign import destroyImpl :: EffectFn1 GPUBuffer Unit
destroy :: GPUBuffer -> Effect Unit
destroy = destroyImpl
destroy a = runEffectFn1 destroyImpl a
9 changes: 4 additions & 5 deletions src/Web/GPU/GPUCanvasContext.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const canvasImpl = context => () => context.canvas;
export const configureImpl = context => descriptor => () =>
export const canvasImpl = context => context.canvas;
export const configureImpl = (context, descriptor) =>
context.configure(descriptor);
export const unconfigureImpl = context => () => context.unconfigure();
export const getCurrentTextureImpl = context => () =>
context.getCurrentTexture();
export const unconfigureImpl = context => context.unconfigure();
export const getCurrentTextureImpl = context => context.getCurrentTexture();
22 changes: 9 additions & 13 deletions src/Web/GPU/GPUCanvasContext.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Web.GPU.GPUCanvasContext
) where

import Prelude
import Effect.Uncurried(EffectFn1, runEffectFn1,EffectFn2, runEffectFn2)

import Effect (Effect)
import Web.GPU.GPUCanvasConfiguration (GPUCanvasConfiguration)
Expand All @@ -19,23 +20,18 @@ import Web.HTML (HTMLCanvasElement)

data GPUCanvasContext

foreign import canvasImpl :: GPUCanvasContext -> Effect HTMLCanvasElement

foreign import canvasImpl :: EffectFn1 GPUCanvasContext HTMLCanvasElement
canvas :: GPUCanvasContext -> Effect HTMLCanvasElement
canvas = canvasImpl

foreign import configureImpl
:: GPUCanvasContext -> GPUCanvasConfiguration -> Effect Unit
canvas a = runEffectFn1 canvasImpl a

foreign import configureImpl :: EffectFn2 GPUCanvasContext GPUCanvasConfiguration Unit
configure :: GPUCanvasContext -> GPUCanvasConfiguration -> Effect Unit
configure = configureImpl

foreign import unconfigureImpl :: GPUCanvasContext -> Effect Unit
configure a b = runEffectFn2 configureImpl a b

foreign import unconfigureImpl :: EffectFn1 GPUCanvasContext Unit
unconfigure :: GPUCanvasContext -> Effect Unit
unconfigure = unconfigureImpl

foreign import getCurrentTextureImpl :: GPUCanvasContext -> Effect GPUTexture
unconfigure a = runEffectFn1 unconfigureImpl a

foreign import getCurrentTextureImpl :: EffectFn1 GPUCanvasContext GPUTexture
getCurrentTexture :: GPUCanvasContext -> Effect GPUTexture
getCurrentTexture = getCurrentTextureImpl
getCurrentTexture a = runEffectFn1 getCurrentTextureImpl a
4 changes: 2 additions & 2 deletions src/Web/GPU/GPUCommandEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export const resolveQuerySetImpl = (
destination,
destinationOffset
);
export const finishImpl = commandEncoder => () => commandEncoder.finish();
export const finishImpl = commandEncoder => commandEncoder.finish();
export const pushDebugGroupImpl = (commandEncoder, groupLabel) =>
commandEncoder.pushDebugGroup(groupLabel);
export const popDebugGroupImpl = commandEncoder => () =>
export const popDebugGroupImpl = commandEncoder =>
commandEncoder.popDebugGroup();
export const insertDebugMarkerImpl = (commandEncoder, markerLabel) =>
commandEncoder.insertDebugMarker(markerLabel);
11 changes: 5 additions & 6 deletions src/Web/GPU/GPUCommandEncoder.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Web.GPU.GPUCommandEncoder
) where

import Prelude
import Effect.Uncurried(EffectFn1, runEffectFn1)

import Effect (Effect)
import Effect.Uncurried (EffectFn2, EffectFn3, EffectFn4, EffectFn6, runEffectFn2, runEffectFn3, runEffectFn4, runEffectFn6)
Expand Down Expand Up @@ -173,20 +174,18 @@ resolveQuerySet
-> Effect Unit
resolveQuerySet a b c d e f = runEffectFn6 resolveQuerySetImpl a b c d e f

foreign import finishImpl :: GPUCommandEncoder -> Effect GPUCommandBuffer

foreign import finishImpl :: EffectFn1 GPUCommandEncoder GPUCommandBuffer
finish :: GPUCommandEncoder -> Effect GPUCommandBuffer
finish = finishImpl
finish a = runEffectFn1 finishImpl a

foreign import pushDebugGroupImpl :: EffectFn2 GPUCommandEncoder String Unit

pushDebugGroup :: GPUCommandEncoder -> String -> Effect Unit
pushDebugGroup a b = runEffectFn2 pushDebugGroupImpl a b

foreign import popDebugGroupImpl :: GPUCommandEncoder -> Effect Unit

foreign import popDebugGroupImpl :: EffectFn1 GPUCommandEncoder Unit
popDebugGroup :: GPUCommandEncoder -> Effect Unit
popDebugGroup = popDebugGroupImpl
popDebugGroup a = runEffectFn1 popDebugGroupImpl a

foreign import insertDebugMarkerImpl
:: EffectFn2 GPUCommandEncoder String Unit
Expand Down
Loading