Skip to content

Adds more EffectFn bindings #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"sandbox": "spago -x sandbox.dhall build && vite build sandbox/",
"sandbox-dev": "spago -x sandbox-dev.dhall build && vite dev sandbox/",
"format": "purs-tidy format-in-place \"src/**/*.purs sandbox/**/*.purs\" && prettier --write \"src/**/*.js\""
"format": "purs-tidy format-in-place \"src/**/*.purs sandbox/**/*.purs\" && prettier --arrow-parens avoid --write \"src/**/*.js\""
},
"keywords": [],
"author": "",
Expand Down
2 changes: 2 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ to generate this file without the comments in this block.
, "effect"
, "foreign"
, "foreign-object"
, "functions"
, "integers"
, "maybe"
, "newtype"
, "ordered-collections"
, "prelude"
, "uint"
, "unsafe-coerce"
, "web-events"
, "web-html"
Expand Down
1 change: 1 addition & 0 deletions src/Web/GPU/BufferSource.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Data.ArrayBuffer.Types (ArrayBuffer, DataView, Float32Array, Float64Array
import Unsafe.Coerce (unsafeCoerce)

data BufferSource

fromArrayBuffer :: ArrayBuffer -> BufferSource
fromArrayBuffer = unsafeCoerce

Expand Down
7 changes: 3 additions & 4 deletions src/Web/GPU/GPU.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const requestAdapterImpl =
(just) => (nothing) => (gpu) => (options) => () =>
gpu.requestAdapter(options).then((o) => (o ? just(o) : nothing));
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();
22 changes: 9 additions & 13 deletions src/Web/GPU/GPU.purs
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
-- @inline export requestAdapter arity=1
-- @inline export getPreferredCanvasFormat arity=1
module Web.GPU.GPU
( GPU,requestAdapter
( GPU
, requestAdapter
, getPreferredCanvasFormat
) 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)
import Web.Promise (Promise)
import Web.GPU.GPUAdapter(GPUAdapter)
import Web.GPU.GPUAdapter (GPUAdapter)

data GPU
-- requestAdapter

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

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
14 changes: 6 additions & 8 deletions src/Web/GPU/GPUAdapter.js
Original file line number Diff line number Diff line change
@@ -1,16 +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) => () =>
adapter.requestDevice(options).then((o) => (o ? just(o) : nothing));
export const requestAdapterInfoImpl = (adapter) => (unmaskHints) => () =>
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) =>
adapter.requestAdapterInfo(unmaskHints);
41 changes: 13 additions & 28 deletions src/Web/GPU/GPUAdapter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,46 @@ module Web.GPU.GPUAdapter
, limits
, requestAdapterInfo
, requestDevice
)
where
) 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)
import Web.GPU.GPUFeatureName (GPUFeatureName)
import Web.GPU.GPUDevice(GPUDevice)
import Web.GPU.GPUDevice (GPUDevice)
import Web.GPU.GPUSupportedLimits (GPUSupportedLimits)
import Web.GPU.UnmaskHint (UnmaskHint)
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 @@ -75,4 +60,4 @@ type GPUAdapterInfo =

requestAdapterInfo
:: GPUAdapter -> Array UnmaskHint -> Effect (Promise GPUAdapterInfo)
requestAdapterInfo = requestAdapterInfoImpl
requestAdapterInfo a b = runEffectFn2 requestAdapterInfoImpl a b
3 changes: 1 addition & 2 deletions src/Web/GPU/GPUBindGroup.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Web.GPU.GPUBindGroup
( GPUBindGroup
)
where
) where

data GPUBindGroup
3 changes: 1 addition & 2 deletions src/Web/GPU/GPUBindGroupLayout.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Web.GPU.GPUBindGroupLayout
( GPUBindGroupLayout
)
where
) where

data GPUBindGroupLayout
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();
74 changes: 28 additions & 46 deletions src/Web/GPU/GPUBuffer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ module Web.GPU.GPUBuffer
, size
, unmap
, usage
)
where
) 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 +40,59 @@ import Web.GPU.Internal.Types (GPUSize64)
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
1 change: 1 addition & 0 deletions src/Web/GPU/GPUCanvasConfiguration.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Web.GPU.GPUTextureUsage (GPUTextureUsageFlags)
import Web.GPU.Internal.RequiredAndOptional (RequiredAndOptional)
import Web.GPU.PredefinedColorSpace (PredefinedColorSpace)
import Web.GPU.GPUDevice (GPUDevice)

newtype GPUCanvasConfiguration = GPUCanvasConfiguration
( RequiredAndOptional
( device :: GPUDevice
Expand Down
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();
Loading