@agpu/bindings 0.2.9 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ import DC_MEMBER from "../../../helpers/types/DCMember";
2
+ import { BRAND, LABEL, RAW } from "@agpu/helpers/decorators";
3
+ import BindGroupLayoutCreator from "./bindGroupLayout";
4
+ import BufferCreator from "./buffers";
5
+ import SamplerCreator from "../pipeline/sampler";
6
+ import TextureCreator from "./texture";
7
+ export interface BindGroupCreator extends RAW<GPUBindGroup>, BRAND<"BindGroupCreator">, LABEL {
8
+ }
9
+ /**
10
+ * Wrapper around {@link GPUBindGroup}.
11
+ */
12
+ export declare class BindGroupCreator {
13
+ #private;
14
+ readonly bindGroup: GPUBindGroup;
15
+ constructor(device: GPUDevice, options: BIND_GROUP_OPTIONS | GPUBindGroup);
16
+ /**
17
+ * Returns the layout wrapper used to create this bind group
18
+ */
19
+ layout(): BindGroupLayoutCreator | {
20
+ "__#private@#device"?: GPUDevice;
21
+ "__#private@#descriptor"?: GPUBindGroupLayoutDescriptor;
22
+ readonly bindGroupLayout: GPUBindGroupLayout;
23
+ clone(): BindGroupLayoutCreator;
24
+ raw(): GPUBindGroupLayout;
25
+ readonly __brand: "BindGroupLayoutCreator";
26
+ [Symbol.hasInstance](instance: any): boolean;
27
+ label(): string;
28
+ label<T extends string>(val: T): T;
29
+ };
30
+ /**
31
+ * Recreates the bind group from its original layout and entries when available.
32
+ */
33
+ clone(): BindGroupCreator;
34
+ }
35
+ export default BindGroupCreator;
36
+ /**
37
+ * Options used to create a bind group wrapper.
38
+ */
39
+ export interface BIND_GROUP_OPTIONS extends GPUObjectDescriptorBase {
40
+ /**The layout of the bind group.*/
41
+ layout: BindGroupLayoutCreator | DC_MEMBER<"BindGroupLayout">;
42
+ /**entries in the bind group. */
43
+ entries: {
44
+ /**The @binding(n) of the entry.*/
45
+ binding: number;
46
+ /**The resource.*/
47
+ resource: TextureCreator | DC_MEMBER<"Texture"> | BufferCreator | DC_MEMBER<"Buffer"> | SamplerCreator | DC_MEMBER<"Sampler">;
48
+ }[];
49
+ }
@@ -0,0 +1 @@
1
+ "use strict";var e=this&&this.__esDecorate||((e,t,r,i,o,n)=>{function a(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var s,l=i.kind,u="getter"===l?"get":"setter"===l?"set":"value",c=!t&&e?i.static?e:e.prototype:null,p=t||(c?Object.getOwnPropertyDescriptor(c,i.name):{}),d=!1,b=r.length-1;b>=0;b--){var h={};for(var f in i)h[f]="access"===f?{}:i[f];for(var f in i.access)h.access[f]=i.access[f];h.addInitializer=e=>{if(d)throw new TypeError("Cannot add initializers after decoration has completed");n.push(a(e||null))};var y=(0,r[b])("accessor"===l?{get:p.get,set:p.set}:p[u],h);if("accessor"===l){if(void 0===y)continue;if(null===y||"object"!=typeof y)throw new TypeError("Object expected");(s=a(y.get))&&(p.get=s),(s=a(y.set))&&(p.set=s),(s=a(y.init))&&o.unshift(s)}else(s=a(y))&&("field"===l?o.unshift(s):p[u]=s)}c&&Object.defineProperty(c,i.name,p),d=!0}),t=this&&this.__runInitializers||function(e,t,r){for(var i=arguments.length>2,o=0;t.length>o;o++)r=i?t[o].call(e,r):t[o].call(e);return i?r:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BindGroupCreator=void 0;const r=require("@agpu/helpers/decorators"),i=require("@agpu/helpers/decorators"),o=require("@agpu/helpers/decorators");let n=(()=>{let n,a,s=[(0,r.brand)("BindGroupCreator"),(0,o.raw)("bindGroup"),(0,i.labeling)({get:e=>e.bindGroup.label,set:(e,t)=>e.bindGroup.label=t})],l=[];var u=class{static{a=this}static{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;e(null,n={value:a},s,{kind:"class",name:a.name,metadata:r},null,l),u=a=n.value,r&&Object.defineProperty(a,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),t(a,l)}#e;#t;#r;bindGroup;constructor(e,t){this.#r=t.layout,t.layout?(this.#e=e,this.#t={...t,entries:t.entries.map(e=>({...e}))},this.bindGroup=e.createBindGroup(this.#i(t))):this.bindGroup=t}#i(e){return{layout:e.layout.raw(),entries:e.entries.map(e=>({binding:e.binding,resource:e.resource.raw()})),label:e.label}}layout(){return this.#r}clone(){if(!this.#e||!this.#t)throw new TypeError("Cannot clone a BindGroupCreator created from a raw GPUBindGroup.");return new u(this.#e,{...this.#t,label:this.bindGroup.label||this.#t.label,entries:this.#t.entries.map(e=>({...e}))})}};return u=a})();exports.BindGroupCreator=n,exports.default=n;
@@ -0,0 +1,16 @@
1
+ import { BRAND, LABEL, RAW } from "@agpu/helpers/decorators";
2
+ export interface BindGroupLayoutCreator extends RAW<GPUBindGroupLayout>, BRAND<"BindGroupLayoutCreator">, LABEL {
3
+ }
4
+ /**
5
+ * Wrapper around {@link GPUBindGroupLayout}.
6
+ */
7
+ export declare class BindGroupLayoutCreator {
8
+ #private;
9
+ readonly bindGroupLayout: GPUBindGroupLayout;
10
+ constructor(device: GPUDevice, bgldOrBgl: GPUBindGroupLayoutDescriptor | GPUBindGroupLayout);
11
+ /**
12
+ * Recreates the bind group layout from its original descriptor when available.
13
+ */
14
+ clone(): BindGroupLayoutCreator;
15
+ }
16
+ export default BindGroupLayoutCreator;
@@ -0,0 +1 @@
1
+ "use strict";var e=this&&this.__esDecorate||((e,t,r,o,i,a)=>{function n(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var s,u=o.kind,c="getter"===u?"get":"setter"===u?"set":"value",l=!t&&e?o.static?e:e.prototype:null,d=t||(l?Object.getOwnPropertyDescriptor(l,o.name):{}),p=!1,y=r.length-1;y>=0;y--){var f={};for(var h in o)f[h]="access"===h?{}:o[h];for(var h in o.access)f.access[h]=o.access[h];f.addInitializer=e=>{if(p)throw new TypeError("Cannot add initializers after decoration has completed");a.push(n(e||null))};var b=(0,r[y])("accessor"===u?{get:d.get,set:d.set}:d[c],f);if("accessor"===u){if(void 0===b)continue;if(null===b||"object"!=typeof b)throw new TypeError("Object expected");(s=n(b.get))&&(d.get=s),(s=n(b.set))&&(d.set=s),(s=n(b.init))&&i.unshift(s)}else(s=n(b))&&("field"===u?i.unshift(s):d[c]=s)}l&&Object.defineProperty(l,o.name,d),p=!0}),t=this&&this.__runInitializers||function(e,t,r){for(var o=arguments.length>2,i=0;t.length>i;i++)r=o?t[i].call(e,r):t[i].call(e);return o?r:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BindGroupLayoutCreator=void 0;const r=require("@agpu/helpers/decorators"),o=require("@agpu/helpers/decorators"),i=require("@agpu/helpers/decorators");let a=(()=>{let a,n,s=[(0,r.brand)("BindGroupLayoutCreator"),(0,i.raw)("bindGroupLayoutDescriptor"),(0,o.labeling)({get:e=>e.bindGroupLayout.label,set:(e,t)=>e.bindGroupLayout.label=t})],u=[];var c=class{static{n=this}static{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;e(null,a={value:n},s,{kind:"class",name:n.name,metadata:r},null,u),c=n=a.value,r&&Object.defineProperty(n,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),t(n,u)}#e;#t;bindGroupLayout;constructor(e,t){t instanceof GPUBindGroupLayout?this.bindGroupLayout=t:(this.#e=e,this.#t={...t,entries:Array.from(t.entries,e=>({...e}))},this.bindGroupLayout=e.createBindGroupLayout(t))}clone(){if(!this.#e||!this.#t)throw new TypeError("Cannot clone a BindGroupLayoutCreator created from a raw GPUBindGroupLayout.");return new c(this.#e,{...this.#t,entries:Array.from(this.#t.entries,e=>({...e})),label:this.bindGroupLayout.label||this.#t.label})}};return c=n})();exports.BindGroupLayoutCreator=a,exports.default=a;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Fine-grained copy flags for buffer usage construction.
3
+ */
4
+ export interface BUFFER_COPY_OPTIONS {
5
+ /**Whether the buffer can be read while being copied. */
6
+ read?: boolean;
7
+ /**Whether the buffer can be written to while being copied */
8
+ write?: boolean;
9
+ }
10
+ export interface BUFFER_BINDING_OPTIONS {
11
+ /**Whether the buffer can be bound as a vertex buffer */
12
+ vertex?: boolean;
13
+ /**Whether the buffer can be bound as a index buffer */
14
+ index?: boolean;
15
+ /**Whether the buffer can be bound as a uniform buffer */
16
+ uniform?: boolean;
17
+ /**Whether the buffer can be bound as a storage buffer */
18
+ storage?: boolean;
19
+ /**Whether the buffer can be bound as a indirect buffer */
20
+ indirect?: boolean;
21
+ }
22
+ /**
23
+ * CPU mapping flags for buffer usage construction.
24
+ */
25
+ export interface BUFFER_MAP_OPTIONS {
26
+ /**Whether the buffer can be read while mapping */
27
+ read?: boolean;
28
+ /**Whether the buffer can be written to while mapping */
29
+ write?: boolean;
30
+ }
31
+ export interface BUFFER_USAGE_OPTIONS {
32
+ /**
33
+ * Copy operations
34
+ * - `true`: Enable both texture and buffer copy (COPY_SRC | COPY_DST)
35
+ * - `false`: Disable copy operations
36
+ * - `object`: Specify which copy types to enable
37
+ */
38
+ copy?: BUFFER_COPY_OPTIONS | boolean;
39
+ /**
40
+ * Buffer binding types
41
+ * Specify how this buffer will be bound to shaders
42
+ */
43
+ buffer?: BUFFER_BINDING_OPTIONS;
44
+ /**
45
+ * Map operations (CPU access)
46
+ * - `true`: Enable read and write mapping
47
+ * - `false`: Disable mapping
48
+ * - `object`: Specify read/write separately
49
+ */
50
+ map?: BUFFER_MAP_OPTIONS | boolean;
51
+ /**
52
+ * Can be used as a query result destination
53
+ */
54
+ queryable?: boolean;
55
+ }
56
+ export default BUFFER_USAGE_OPTIONS;
57
+ /**
58
+ * Converts a structured buffer usage object into native `GPUBufferUsage` bits.
59
+ */
60
+ export declare function getBufferUsage(options?: BUFFER_USAGE_OPTIONS): number;
61
+ /**
62
+ * Expands native `GPUBufferUsage` bits into the structured options shape used
63
+ * by this package.
64
+ */
65
+ export declare function getOptionsFromUsage(usage: number): BUFFER_USAGE_OPTIONS;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getBufferUsage=(e={})=>{let f=0,r=e.copy;r&&("boolean"==typeof r?(f|=GPUBufferUsage.COPY_DST,f|=GPUBufferUsage.COPY_SRC):(r.read&&(f|=GPUBufferUsage.COPY_SRC),r.write&&(f|=GPUBufferUsage.COPY_DST)));let U=e.buffer;U&&(U.index&&(f|=GPUBufferUsage.INDEX),U.indirect&&(f|=GPUBufferUsage.INDIRECT),U.storage&&(f|=GPUBufferUsage.STORAGE),U.uniform&&(f|=GPUBufferUsage.UNIFORM),U.vertex&&(f|=GPUBufferUsage.VERTEX));let a=e.map;return a&&("boolean"==typeof a?(f|=GPUBufferUsage.MAP_READ,f|=GPUBufferUsage.MAP_WRITE):(a.read&&(f|=GPUBufferUsage.MAP_READ),a.write&&(f|=GPUBufferUsage.MAP_WRITE))),e.queryable&&(f|=GPUBufferUsage.QUERY_RESOLVE),f},exports.getOptionsFromUsage=e=>{const f={},r=!!(e&GPUBufferUsage.COPY_SRC),U=!!(e&GPUBufferUsage.COPY_DST);r&&U?f.copy=!0:(r||U)&&(f.copy={read:r,write:U});const a={};e&GPUBufferUsage.INDEX&&(a.index=!0),e&GPUBufferUsage.INDIRECT&&(a.indirect=!0),e&GPUBufferUsage.STORAGE&&(a.storage=!0),e&GPUBufferUsage.UNIFORM&&(a.uniform=!0),e&GPUBufferUsage.VERTEX&&(a.vertex=!0),Object.keys(a).length>0&&(f.buffer=a);const s=!!(e&GPUBufferUsage.MAP_READ),P=!!(e&GPUBufferUsage.MAP_WRITE);return s&&P?f.map=!0:(s||P)&&(f.map={read:s,write:P}),e&GPUBufferUsage.QUERY_RESOLVE&&(f.queryable=!0),f};
@@ -0,0 +1,180 @@
1
+ import UNSURE from "@agpu/helpers/unsure";
2
+ import BUFFER_USAGE_OPTIONS from "./buffers/bufferUsageOptions";
3
+ /**
4
+ * Construction options for {@link BufferCreator}.
5
+ */
6
+ export interface BUFFER_CONSTRUCTION_OPTIONS extends GPUObjectDescriptorBase {
7
+ /**
8
+ * The initial value of the Buffer
9
+ *
10
+ * Using this requires usage.copy.write to be true
11
+ *
12
+ * If this is passed but copy.write is false or undefined, the constructor throws a error.
13
+ * @example
14
+ *
15
+ * // Float 32 array
16
+ * Float32Array
17
+ *
18
+ * // Float 16 Array
19
+ * Float16Array
20
+ *
21
+ * // 64 bit unsigned integer array
22
+ * BigUint64Array
23
+ */
24
+ value?: GPUAllowSharedBufferSource;
25
+ /**
26
+ * The GPUBufferUsage of the Buffer.
27
+ *
28
+ * @example
29
+ * BufferUsage.VERTEX | BufferUsage.COPY_DST
30
+ */
31
+ usage?: BUFFER_USAGE_OPTIONS | number;
32
+ }
33
+ export declare const bufferDestroyedError: import("@agpu/helpers/errors").AndromedaError;
34
+ export declare const cannotBeRead: import("@agpu/helpers/errors").AndromedaError;
35
+ export declare const initCannotRead: import("@agpu/helpers/errors").AndromedaError;
36
+ export declare const initCouldNotAssignValue: import("@agpu/helpers/errors").AndromedaError;
37
+ export declare const couldNotAssignValue: import("@agpu/helpers/errors").AndromedaError;
38
+ export declare const cannotBeWrittenTo: import("@agpu/helpers/errors").AndromedaError;
39
+ export declare const otherCannotBeWrittenTo: import("@agpu/helpers/errors").AndromedaError;
40
+ export declare const otherTextureCannotBeWrittenTo: import("@agpu/helpers/errors").AndromedaError;
41
+ export declare const invalidBufferSize: import("@agpu/helpers/errors").AndromedaError;
42
+ export declare const invalidBufferCopySize: import("@agpu/helpers/errors").AndromedaError;
43
+ /**
44
+ * Minimal texture surface accepted by {@link BufferCreator.copyToTexture}.
45
+ */
46
+ export interface TEXTURE_COPY_DESTINATION {
47
+ raw(): GPUTexture;
48
+ can: {
49
+ copy: {
50
+ write: boolean;
51
+ };
52
+ };
53
+ }
54
+ export interface BUFFER_TO_TEXTURE_OPTIONS {
55
+ offset?: number;
56
+ bytesPerRow?: number;
57
+ rowsPerImage?: number;
58
+ origin?: GPUOrigin3D;
59
+ mipLevel?: number;
60
+ aspect?: GPUTextureAspect;
61
+ size?: GPUExtent3D;
62
+ }
63
+ /**
64
+ * Wrapper around {@link GPUBuffer} with cached CPU-side state and convenience
65
+ * copy helpers.
66
+ */
67
+ export declare class BufferCreator {
68
+ #private;
69
+ constructor(device: GPUDevice, options?: BUFFER_CONSTRUCTION_OPTIONS);
70
+ /**
71
+ * Returns the raw GPUBuffer of the Buffer.
72
+ *
73
+ * Changing this may cause issues
74
+ */
75
+ raw(): GPUBuffer;
76
+ /**
77
+ * Creates a new buffer wrapper with duplicated CPU-side contents and usage.
78
+ */
79
+ clone(): BufferCreator;
80
+ /**
81
+ * Getter / Setter for destroying the buffer
82
+ *
83
+ * ● If no value is passed, it returns if the buffer is destroyed
84
+ *
85
+ * ● If the buffer is destroyed and destroy parameter is true, then it returns true
86
+ *
87
+ * ● If the buffer is not destroyed but destroy parameter is true, then it returns true and destroys the buffer
88
+ *
89
+ * ● If the buffer is not destroyed and destroy parameter is false, then it returns false
90
+ *
91
+ * ● If the buffer is destroyed and destroy parameter is true, then it recreates the buffer and returns true
92
+ */
93
+ destroy(): boolean;
94
+ destroy<T extends boolean>(destroy: T): T;
95
+ /**
96
+ * Getter/Setter for Value.
97
+ *
98
+ * ● Marks the buffer as "**dirty**" if changed.
99
+ *
100
+ * ● If no value is passed, the function returns a promise that resolves to the current value of the buffer.
101
+ *
102
+ * ● If a value is passed, the function returns the same value passed.
103
+ *
104
+ * ● Throws AGPU_1 if the buffer was destroyed
105
+ */
106
+ value(): UNSURE<GPUAllowSharedBufferSource>;
107
+ value<T extends GPUAllowSharedBufferSource>(val: T): T;
108
+ /**
109
+ * Getter/Setter for label.
110
+ *
111
+ * ● If no value is passed, the function returns the current label of the buffer.
112
+ *
113
+ * ● If a value is passed, the function returns the same label passed.
114
+ *
115
+ * ● Throws AGPU_1 if the buffer was destroyed
116
+ */
117
+ label(): string;
118
+ label<T extends string>(label: T): T;
119
+ /**
120
+ * Synchronizes local state with GPU hardware.
121
+ *
122
+ * ● Only runs if #dirty is true. That means if any changes were made.
123
+ *
124
+ * ● Throws AGPU_1 if the buffer was destroyed
125
+ */
126
+ sync(): void;
127
+ /**
128
+ * Reads the buffer.
129
+ *
130
+ * #### Different from .value(newValue). How?
131
+ * This is different from .value as it reads the value from the GPU instead of relying on what's stored in this class
132
+ *
133
+ * ● This does not update the stored value though! You will have to manually change that.
134
+ */
135
+ read(): Promise<ArrayBuffer>;
136
+ /**
137
+ * Returns a capability summary inferred from the current buffer usage flags.
138
+ */
139
+ get can(): {
140
+ copy: {
141
+ read: boolean;
142
+ write: boolean;
143
+ };
144
+ map: {
145
+ read: boolean;
146
+ write: boolean;
147
+ };
148
+ beBoundAs: {
149
+ index: boolean;
150
+ vertex: boolean;
151
+ uniform: boolean;
152
+ storage: boolean;
153
+ indirect: boolean;
154
+ };
155
+ query: boolean;
156
+ };
157
+ /**
158
+ * Copies this buffer's data to another BufferCreator or GPUBuffer.
159
+ */
160
+ copyToBuffer(destination: BufferCreator | GPUBuffer, size?: number): void;
161
+ copyToTexture(destination: TEXTURE_COPY_DESTINATION | GPUTexture, options?: BUFFER_TO_TEXTURE_OPTIONS): void;
162
+ /**
163
+ * Resolves a QuerySet into this buffer.
164
+ * Requires the buffer to have the 'queryResolve' usage flag.
165
+ */
166
+ query(querySet: GPUQuerySet, firstQuery?: number, queryCount?: number, destinationOffset?: number): void;
167
+ [Symbol.hasInstance](instance: BufferCreator): instance is BufferCreator;
168
+ readonly __brand = "BufferCreator";
169
+ }
170
+ export declare namespace BufferCreator {
171
+ namespace bufferUsage {
172
+ /**
173
+ * Shape returned by `bufferUsage()` in getter mode.
174
+ */
175
+ interface RETURNS extends BUFFER_USAGE_OPTIONS {
176
+ number: number;
177
+ }
178
+ }
179
+ }
180
+ export default BufferCreator;
@@ -0,0 +1 @@
1
+ "use strict";function e(e,r,t,i){if(0>=r.byteLength)throw exports.invalidBufferSize;let s={size:r.byteLength,usage:t,label:i};return i&&(s.label=i),e.createBuffer(s)}function r(e){return"function"==typeof e.raw}function t(e){if(e instanceof ArrayBuffer)return e.slice(0);if(ArrayBuffer.isView(e)){const r=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),t=e.constructor;return e instanceof DataView?new DataView(r):new t(r,0,e.byteLength/(t.BYTES_PER_ELEMENT??1))}return e.slice(0)}var i=this&&this.__importDefault||(e=>e&&e.__esModule?e:{default:e});Object.defineProperty(exports,"__esModule",{value:!0}),exports.BufferCreator=exports.invalidBufferCopySize=exports.invalidBufferSize=exports.otherTextureCannotBeWrittenTo=exports.otherCannotBeWrittenTo=exports.cannotBeWrittenTo=exports.couldNotAssignValue=exports.initCouldNotAssignValue=exports.initCannotRead=exports.cannotBeRead=exports.bufferDestroyedError=void 0;const s=i(require("../../../helpers/defaults")),o=i(require("../../../helpers/errors")),u=require("./buffers/bufferUsageOptions"),f=require("./texture/textureUsageOptions"),n=require("./buffers/bufferUsageOptions"),a=i(require("../../../helpers/align"));exports.bufferDestroyedError=(0,o.default)(1,"The buffer is already destroyed!"),exports.cannotBeRead=(0,o.default)(3,"Buffer cannot be read"),exports.initCannotRead=(0,o.default)(4,"Buffer could not be initialized since the given buffer cannot be read"),exports.initCouldNotAssignValue=(0,o.default)(5,"Buffer could not be initialized since the flag 'usage.copy.write' is false or undefined"),exports.couldNotAssignValue=(0,o.default)(6,"Buffer.value didnt work as the flag 'usage.copy.write' is set to false."),exports.cannotBeWrittenTo=(0,o.default)(7,"Buffer could not be copied because the flag 'usage.copy.write' is disabled in it"),exports.otherCannotBeWrittenTo=(0,o.default)(8,"Buffer could not be copied since the other buffer doesnt allow so."),exports.otherTextureCannotBeWrittenTo=(0,o.default)(10,"Buffer could not be copied since the other texture doesnt allow writing to it"),exports.invalidBufferSize=(0,o.default)(36,"Buffer size must be greater than zero.","Provide a non-empty typed array or other GPUAllowSharedBufferSource when creating the buffer."),exports.invalidBufferCopySize=(0,o.default)(37,"Buffer copy size must be greater than zero and fit in both source and destination buffers.","Pass a positive copy size that does not exceed either buffer's size.");const d={r8unorm:1,r8snorm:1,r8uint:1,r8sint:1,r16uint:2,r16sint:2,r16float:2,rg8unorm:2,rgba8unorm:4,"rgba8unorm-srgb":4,bgra8unorm:4,rg16float:4,r32float:4,rgba16float:8,rg32float:8,rgba32float:16};class h{#e;#r;#t;#i=!1;#s=!1;constructor(r,t){if(t?.value&&!(t?.usage).copy)throw exports.initCouldNotAssignValue;if(this.#r=r,this.#t=t?.value??new Float32Array(16),this.#e=e(r,this.#t,"object"==typeof t?.usage?(0,n.getBufferUsage)(t?.usage):"number"==typeof t?.usage?t?.usage:s.default.bufferUsage,t?.label),this.#r.queue.writeBuffer(this.#e,0,this.#t),!this.#o())throw(0,o.default)(18,"Buffer flag validation error")}#o(){const e=this.can,r=this.#t,t=r.byteLength;if(e.beBoundAs.index&&!(r instanceof Uint32Array||r instanceof Uint16Array))return!1;if(e.beBoundAs.indirect&&!(r instanceof Uint32Array))return!1;if(e.beBoundAs.vertex&&t%4!=0)return!1;if(e.beBoundAs.uniform){if(t%16!=0)return!1;if(t>65536)return!1}return!e.beBoundAs.storage||t%4==0}raw(){return this.#e}clone(){if(this.#s)throw exports.bufferDestroyedError;return new h(this.#r,{value:t(this.#t),usage:this.#e.usage,label:this.#e.label})}[Symbol("Symbol.disposable")](){this.destroy(!0)}destroy(r){return void 0===r?this.#s:!(!this.#s||!r)||(!this.#s&&r?(this.#s=!0,this.#e.destroy(),!0):!(!this.#s&&!r)&&(this.#s&&!r?(this.#e=e(this.#r,this.#t,this.#e.usage,this.#e.label),this.#r.queue.writeBuffer(this.#e,0,this.#t),this.#s=!1,!1):this.#s))}value(e){if(this.#s)throw exports.bufferDestroyedError;return void 0===e?this.#t:(e!==this.#t&&(this.#t=e,this.#i=!0),e)}label(e){if(this.#s)throw exports.bufferDestroyedError;return void 0===e?this.#e.label??this.#e.label:(e!==this.#e.label&&(this.#e.label=e),e)}sync(){if(this.#s)throw exports.bufferDestroyedError;if(!this.#i)return;const r=this.#e.size;if(this.#t.byteLength>r&&(this.#e.destroy(),this.#e=e(this.#r,this.#t,this.#e.usage,this.#e.label)),!this.can.copy.write)throw exports.couldNotAssignValue;this.#r.queue.writeBuffer(this.#e,0,this.#t),this.#i=!1}async read(){if(!this.can.map.read)throw exports.cannotBeRead;const e=this.#r.createBuffer({size:this.#e.size,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),r=this.#r.createCommandEncoder();r.copyBufferToBuffer(this.#e,0,e,0,this.#e.size),this.#r.queue.submit([r.finish()]),await e.mapAsync(GPUMapMode.READ);const t=e.getMappedRange().slice();return e.unmap(),e.destroy(),t}get can(){const e=this.#e.usage;return{copy:{read:!!(e&GPUBufferUsage.COPY_SRC),write:!!(e&GPUBufferUsage.COPY_DST)},map:{read:!!(e&GPUBufferUsage.MAP_READ),write:!!(e&GPUBufferUsage.MAP_WRITE)},beBoundAs:{index:!!(e&GPUBufferUsage.INDEX),vertex:!!(e&GPUBufferUsage.VERTEX),uniform:!!(e&GPUBufferUsage.UNIFORM),storage:!!(e&GPUBufferUsage.STORAGE),indirect:!!(e&GPUBufferUsage.INDIRECT)},query:!!(e&GPUBufferUsage.QUERY_RESOLVE)}}copyToBuffer(e,r){if(!this.can.copy.read)throw exports.cannotBeRead;if(e instanceof h){if(!e.can.copy.write)throw exports.otherCannotBeWrittenTo}else{const r=(0,u.getOptionsFromUsage)(e.usage);if(!r.copy?.write)throw exports.otherCannotBeWrittenTo}const t=e instanceof h?e.raw():e,i=r??this.#e.size;if(0>=i||i>this.#e.size||i>t.size)throw exports.invalidBufferCopySize;const s=this.#r.createCommandEncoder();s.copyBufferToBuffer(this.#e,0,t,0,i),this.#r.queue.submit([s.finish()])}copyToTexture(e,t={}){if(!this.can.copy.read)throw exports.cannotBeRead;if(r(e)){if(!e.can.copy.write)throw exports.otherTextureCannotBeWrittenTo}else{const r=(0,f.getOptionsFromTextureUsage)(e.usage);if(!1===r.copy||!0!==r.copy&&!r.copy?.write)throw exports.otherTextureCannotBeWrittenTo}const i=r(e)?e.raw():e,s=t.size?(e=>{if("number"==typeof e)return{width:e,height:1,depthOrArrayLayers:1};if(Symbol.iterator in Object(e)){const r=Array.from(e);return{width:r[0]??1,height:r[1]??1,depthOrArrayLayers:r[2]??1}}return{width:e.width,height:e.height??1,depthOrArrayLayers:e.depthOrArrayLayers??1}})(t.size):{width:i.width,height:i.height,depthOrArrayLayers:i.depthOrArrayLayers},o=t.bytesPerRow??(0,a.default)(s.width*(d[i.format]??4),256),u=t.rowsPerImage??s.height,n=this.#r.createCommandEncoder();n.copyBufferToTexture({buffer:this.#e,offset:t.offset,bytesPerRow:o,rowsPerImage:u},{texture:i,origin:t.origin,mipLevel:t.mipLevel,aspect:t.aspect},s),this.#r.queue.submit([n.finish()])}query(e,r=0,t=1,i=0){if(!this.can.query)throw(0,o.default)(9,"The given buffer does not support GPUBufferUsage.QUERY_RESOLVE");const s=this.#r.createCommandEncoder();s.resolveQuerySet(e,r,t,this.#e,i),this.#r.queue.submit([s.finish()])}[Symbol.hasInstance](e){return"BufferCreator"===this.__brand}__brand="BufferCreator"}exports.BufferCreator=h,exports.default=h;
@@ -0,0 +1,11 @@
1
+ import { BRAND, LABEL, RAW } from "@agpu/helpers/decorators";
2
+ export interface CommandBufferCreator extends BRAND<"CommandBufferCreator">, LABEL, RAW<GPUCommandBuffer> {
3
+ }
4
+ /**
5
+ * Wrapper around {@link GPUCommandBuffer}.
6
+ */
7
+ export declare class CommandBufferCreator {
8
+ readonly commandBuffer: GPUCommandBuffer;
9
+ constructor(cmdbuf: GPUCommandBuffer);
10
+ }
11
+ export default CommandBufferCreator;
@@ -0,0 +1 @@
1
+ "use strict";var e=this&&this.__esDecorate||((e,t,r,a,o,n)=>{function s(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var i,c=a.kind,l="getter"===c?"get":"setter"===c?"set":"value",u=!t&&e?a.static?e:e.prototype:null,f=t||(u?Object.getOwnPropertyDescriptor(u,a.name):{}),d=!1,m=r.length-1;m>=0;m--){var p={};for(var h in a)p[h]="access"===h?{}:a[h];for(var h in a.access)p.access[h]=a.access[h];p.addInitializer=e=>{if(d)throw new TypeError("Cannot add initializers after decoration has completed");n.push(s(e||null))};var b=(0,r[m])("accessor"===c?{get:f.get,set:f.set}:f[l],p);if("accessor"===c){if(void 0===b)continue;if(null===b||"object"!=typeof b)throw new TypeError("Object expected");(i=s(b.get))&&(f.get=i),(i=s(b.set))&&(f.set=i),(i=s(b.init))&&o.unshift(i)}else(i=s(b))&&("field"===c?o.unshift(i):f[l]=i)}u&&Object.defineProperty(u,a.name,f),d=!0}),t=this&&this.__runInitializers||function(e,t,r){for(var a=arguments.length>2,o=0;t.length>o;o++)r=a?t[o].call(e,r):t[o].call(e);return a?r:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CommandBufferCreator=void 0;const r=require("@agpu/helpers/decorators"),a=require("@agpu/helpers/decorators"),o=require("@agpu/helpers/decorators");let n=(()=>{let n,s,i=[(0,r.brand)("CommandBufferCreator"),(0,a.labeling)({get:e=>e.commandBuffer.label,set:(e,t)=>e.commandBuffer.label=t}),(0,o.raw)("commandBuffer")],c=[];return class{static{s=this}static{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;e(null,n={value:s},i,{kind:"class",name:s.name,metadata:r},null,c),s=n.value,r&&Object.defineProperty(s,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),t(s,c)}commandBuffer;constructor(e){this.commandBuffer=e}},s})();exports.CommandBufferCreator=n,exports.default=n;
@@ -0,0 +1,62 @@
1
+ import { BRAND, LABEL, RAW } from "@agpu/helpers/decorators";
2
+ import UNSURE from "@agpu/helpers/unsure";
3
+ /**
4
+ * Options used when creating a shader module from WGSL source.
5
+ */
6
+ export interface SHADER_MODULE_OPTIONS extends GPUObjectDescriptorBase {
7
+ /**Hints for the compiler.*/
8
+ hints?: Iterable<GPUShaderModuleCompilationHint>;
9
+ /**The entry point of the shader module.*/
10
+ entryPoint?: string;
11
+ constants?: Record<string, number>;
12
+ }
13
+ /**
14
+ * Wrapper around {@link GPUShaderModule}.
15
+ */
16
+ export interface ShaderModuleCreator extends RAW<GPUShaderModule>, BRAND<"ShaderModuleCreator">, LABEL {
17
+ }
18
+ export declare class ShaderModuleCreator {
19
+ #private;
20
+ readonly module: GPUShaderModule;
21
+ constructor(device: GPUDevice, codeOrModule: string | GPUShaderModule, options?: SHADER_MODULE_OPTIONS);
22
+ /**
23
+ * Recreates the shader module from its original WGSL source when available.
24
+ */
25
+ clone(): ShaderModuleCreator;
26
+ /**
27
+ * Returns the cached entry point configured on this wrapper, if any.
28
+ *
29
+ * This will be undefined if either:
30
+ *
31
+ * - It was not provided in the options
32
+ *
33
+ * - A GPUShaderModule was passed instead of a options object.
34
+ */
35
+ entryPoint(): UNSURE<string>;
36
+ /**
37
+ * Returns the cached shader constants configured on this wrapper, if any.
38
+ * This will be undefined if either:
39
+ *
40
+ * - It was not provided in the options
41
+ *
42
+ * - A GPUShaderModule was passed instead of a options object.
43
+ */
44
+ constants(): UNSURE<Record<string, number>>;
45
+ /**
46
+ * Returns the raw code of the shader module.
47
+ *
48
+ * This will be undefined if a GPUShaderModule was passed instead of a options object.
49
+ */
50
+ code(): string | undefined;
51
+ /**
52
+ * Requests compilation info for the shader module.
53
+ */
54
+ compilationInfo(): Promise<GPUCompilationInfo>;
55
+ /**
56
+ * Returns what bindGroups are used in the source code of the shader
57
+ *
58
+ * Always Set<undefined> if a GPUShaderModule was passed instead of a options object.
59
+ */
60
+ bindGroups(): Set<number>;
61
+ }
62
+ export default ShaderModuleCreator;
@@ -0,0 +1 @@
1
+ "use strict";var e=this&&this.__esDecorate||((e,t,i,r,o,s)=>{function n(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var a,c=r.kind,l="getter"===c?"get":"setter"===c?"set":"value",h=!t&&e?r.static?e:e.prototype:null,d=t||(h?Object.getOwnPropertyDescriptor(h,r.name):{}),u=!1,p=i.length-1;p>=0;p--){var f={};for(var b in r)f[b]="access"===b?{}:r[b];for(var b in r.access)f.access[b]=r.access[b];f.addInitializer=e=>{if(u)throw new TypeError("Cannot add initializers after decoration has completed");s.push(n(e||null))};var v=(0,i[p])("accessor"===c?{get:d.get,set:d.set}:d[l],f);if("accessor"===c){if(void 0===v)continue;if(null===v||"object"!=typeof v)throw new TypeError("Object expected");(a=n(v.get))&&(d.get=a),(a=n(v.set))&&(d.set=a),(a=n(v.init))&&o.unshift(a)}else(a=n(v))&&("field"===c?o.unshift(a):d[l]=a)}h&&Object.defineProperty(h,r.name,d),u=!0}),t=this&&this.__runInitializers||function(e,t,i){for(var r=arguments.length>2,o=0;t.length>o;o++)i=r?t[o].call(e,i):t[o].call(e);return r?i:void 0},i=this&&this.__importDefault||(e=>e&&e.__esModule?e:{default:e});Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShaderModuleCreator=void 0;const r=require("@agpu/helpers/decorators"),o=require("@agpu/helpers/decorators"),s=require("@agpu/helpers/decorators"),n=i(require("../../../helpers/shaderRegex"));let a=(()=>{let i,a,c=[(0,r.brand)("ShaderModuleCreator"),(0,s.raw)("module"),(0,o.labeling)({get:e=>e.module.label,set:(e,t)=>e.module.label=t})],l=[];var h=class{static{a=this}static{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;e(null,i={value:a},c,{kind:"class",name:a.name,metadata:r},null,l),h=a=i.value,r&&Object.defineProperty(a,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),t(a,l)}#e;#t;#i;#r;#o;#s;module;constructor(e,t,i){if("string"==typeof t){this.#e=e,this.#t=t,this.#i=i?.entryPoint,this.#r=i?.constants,this.#o=i?.label??"",this.#s=i?.hints;let r={code:t,label:i?.label??""};i?.hints&&(r.compilationHints=i.hints),this.module=e.createShaderModule(r)}else this.module=t,this.#t=void 0,this.#i=void 0,this.#r=void 0}clone(){if(!this.#e||"string"!=typeof this.#t)throw new TypeError("Cannot clone a ShaderModuleCreator created from a raw GPUShaderModule.");return new h(this.#e,this.#t,{label:this.module.label||this.#o,hints:this.#s,entryPoint:this.#i,constants:this.#r?{...this.#r}:void 0})}entryPoint(){return this.#i}constants(){return this.#r}code(){return this.#t}async compilationInfo(){return this.#n?this.#n:this.#n=await this.module.getCompilationInfo()}#n;bindGroups(){return this.#a?this.#a:this.#a=(0,n.default)(this.#t??"")}#a};return h=a})();exports.ShaderModuleCreator=a,exports.default=a;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Structured texture usage flags used by this package.
3
+ */
4
+ interface TEXTURE_COPY_OPTIONS {
5
+ /**Whether the texture can be read while copying. */
6
+ read?: boolean;
7
+ /**Whether the texture can be read while writing. */
8
+ write?: boolean;
9
+ }
10
+ interface TEXTURE_BINDING_OPTIONS {
11
+ /**Whether the texture can be bound as a storage texture */
12
+ storage?: boolean;
13
+ texture?: boolean;
14
+ }
15
+ /**
16
+ * Structured texture usage flags used by this package.
17
+ */
18
+ interface TEXTURE_USAGE_OPTIONS {
19
+ /**
20
+ * Copy operations
21
+ * - `true`: Enable both texture and buffer copy (COPY_SRC | COPY_DST)
22
+ * - `false`: Disable copy operations
23
+ * - `object`: Specify which copy types to enable
24
+ *
25
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/GPUTexture/usage Read about GPUTextureUsage-s here}
26
+ */
27
+ copy?: TEXTURE_COPY_OPTIONS | boolean;
28
+ /**
29
+ * The texture can be used as a color or depth/stencil attachment in a render pass, for example as the view property of the descriptor object in a beginRenderPass() call.
30
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/GPUTexture/usage Read about GPUTextureUsage-s here}
31
+ */
32
+ renderAttachment?: boolean;
33
+ /**
34
+ * Texture binding types
35
+ * Specify how this texture will be bound to shaders
36
+ */
37
+ binding?: TEXTURE_BINDING_OPTIONS;
38
+ transientAttachment?: boolean;
39
+ }
40
+ export default TEXTURE_USAGE_OPTIONS;
41
+ export declare function getOptionsFromTextureUsage(usage: number): TEXTURE_USAGE_OPTIONS;
42
+ export declare function getTextureUsage(options: TEXTURE_USAGE_OPTIONS): number;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getOptionsFromTextureUsage=e=>{const t=!!(e&GPUTextureUsage.COPY_SRC),r=!!(e&GPUTextureUsage.COPY_DST);return{copy:!(!t||!r)||{read:t,write:r},renderAttachment:!!(e&GPUTextureUsage.RENDER_ATTACHMENT),binding:{texture:!!(e&GPUTextureUsage.TEXTURE_BINDING),storage:!!(e&GPUTextureUsage.STORAGE_BINDING)},transientAttachment:!(!e||!GPUTextureUsage.TRANSIENT_ATTACHMENT)}},exports.getTextureUsage=e=>{let t=0;return!0===e.copy?t|=GPUTextureUsage.COPY_SRC|GPUTextureUsage.COPY_DST:"object"==typeof e.copy&&(e.copy.read&&(t|=GPUTextureUsage.COPY_SRC),e.copy.write&&(t|=GPUTextureUsage.COPY_DST)),e.renderAttachment&&(t|=GPUTextureUsage.RENDER_ATTACHMENT),e.binding&&(e.binding.texture&&(t|=GPUTextureUsage.TEXTURE_BINDING),e.binding.storage&&(t|=GPUTextureUsage.STORAGE_BINDING)),e.transientAttachment&&(t|=GPUTextureUsage.TRANSIENT_ATTACHMENT),t};
@@ -0,0 +1,12 @@
1
+ import { BRAND, LABEL, RAW } from "@agpu/helpers/decorators";
2
+ export interface TextureViewCreator extends RAW<GPUTextureView>, BRAND<"TextureViewCreator">, LABEL {
3
+ }
4
+ /**
5
+ * Thin wrapper around {@link GPUTextureView}.
6
+ */
7
+ export declare class TextureViewCreator {
8
+ /**The raw GPUTextureView of the TextureView */
9
+ readonly view: GPUTextureView;
10
+ constructor(view: GPUTextureView);
11
+ }
12
+ export default TextureViewCreator;
@@ -0,0 +1 @@
1
+ "use strict";var e=this&&this.__esDecorate||((e,t,r,a,i,o)=>{function s(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var n,l=a.kind,c="getter"===l?"get":"setter"===l?"set":"value",u=!t&&e?a.static?e:e.prototype:null,d=t||(u?Object.getOwnPropertyDescriptor(u,a.name):{}),p=!1,f=r.length-1;f>=0;f--){var v={};for(var h in a)v[h]="access"===h?{}:a[h];for(var h in a.access)v.access[h]=a.access[h];v.addInitializer=e=>{if(p)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(e||null))};var b=(0,r[f])("accessor"===l?{get:d.get,set:d.set}:d[c],v);if("accessor"===l){if(void 0===b)continue;if(null===b||"object"!=typeof b)throw new TypeError("Object expected");(n=s(b.get))&&(d.get=n),(n=s(b.set))&&(d.set=n),(n=s(b.init))&&i.unshift(n)}else(n=s(b))&&("field"===l?i.unshift(n):d[c]=n)}u&&Object.defineProperty(u,a.name,d),p=!0}),t=this&&this.__runInitializers||function(e,t,r){for(var a=arguments.length>2,i=0;t.length>i;i++)r=a?t[i].call(e,r):t[i].call(e);return a?r:void 0};Object.defineProperty(exports,"__esModule",{value:!0}),exports.TextureViewCreator=void 0;const r=require("@agpu/helpers/decorators"),a=require("@agpu/helpers/decorators"),i=require("@agpu/helpers/decorators");let o=(()=>{let o,s,n=[(0,r.brand)("TextureViewCreator"),(0,i.raw)("view"),(0,a.labeling)({get:e=>e.view.label,set:(e,t)=>e.view.label=t})],l=[];return class{static{s=this}static{const r="function"==typeof Symbol&&Symbol.metadata?Object.create(null):void 0;e(null,o={value:s},n,{kind:"class",name:s.name,metadata:r},null,l),s=o.value,r&&Object.defineProperty(s,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r}),t(s,l)}view;constructor(e){this.view=e}},s})();exports.TextureViewCreator=o,exports.default=o;
@@ -0,0 +1,157 @@
1
+ import DC_MEMBER from "../../../helpers/types/DCMember";
2
+ import UNSURE from "@agpu/helpers/unsure";
3
+ import BufferCreator from "./buffers";
4
+ import TEXTURE_USAGE_OPTIONS from "./texture/textureUsageOptions";
5
+ import TextureViewCreator from "./texture/textureView";
6
+ /**
7
+ * Public texture construction options.
8
+ */
9
+ interface TCO_BASE {
10
+ /** Initial value for the texture creator */
11
+ value?: GPUAllowSharedBufferSource;
12
+ /**The size of the texture*/
13
+ size: GPUExtent3DStrict;
14
+ /**the miplevel count */
15
+ mipLevelCount?: number | undefined;
16
+ /**the sample count */
17
+ sampleCount?: number | undefined;
18
+ /**dimension, 1d, 2d or 3d */
19
+ dimension?: GPUTextureDimension | undefined;
20
+ /**format of the texture. */
21
+ format: GPUTextureFormat;
22
+ /**formats for the view of the texture. */
23
+ viewFormats?: Iterable<GPUTextureFormat> | undefined;
24
+ /**Texture binding view dimension*/
25
+ textureBindingViewDimension?: GPUTextureViewDimension | undefined;
26
+ }
27
+ export interface TEXTURE_CREATOR_OPTIONS extends TCO_BASE {
28
+ /**usage options for the texture */
29
+ usage?: TEXTURE_USAGE_OPTIONS | number;
30
+ }
31
+ export interface TEXTURE_TO_BUFFER_OPTIONS {
32
+ offset?: number;
33
+ bytesPerRow?: number;
34
+ rowsPerImage?: number;
35
+ origin?: GPUOrigin3D;
36
+ aspect?: GPUTextureAspect;
37
+ mipLevel?: number;
38
+ size?: GPUExtent3D;
39
+ }
40
+ export interface TEXTURE_TO_TEXTURE_OPTIONS {
41
+ sourceMipLevel?: number;
42
+ destinationMipLevel?: number;
43
+ sourceOrigin?: GPUOrigin3D;
44
+ destinationOrigin?: GPUOrigin3D;
45
+ size?: GPUExtent3D;
46
+ }
47
+ /**
48
+ * Wrapper around {@link GPUTexture} with cached usage/value helpers and
49
+ * convenience copy operations.
50
+ */
51
+ export declare class TextureCreator {
52
+ #private;
53
+ constructor(device: GPUDevice, optionsOrTexture: TEXTURE_CREATOR_OPTIONS | GPUTexture);
54
+ readonly View: {
55
+ new (): {
56
+ readonly view: GPUTextureView;
57
+ raw(): GPUTextureView;
58
+ readonly __brand: "TextureViewCreator";
59
+ [Symbol.hasInstance](instance: any): boolean;
60
+ label(): string;
61
+ label<T extends string>(val: T): T;
62
+ };
63
+ };
64
+ /**
65
+ * Getter/Setter for the texture data.
66
+ *
67
+ * ● If a value is passed, It marks the texture dirty and returns the given value again.
68
+ *
69
+ * ● If no value is passed, It returns the current texture value.
70
+ *
71
+ * ● Throws AGPU_2 if the texture was destroyed
72
+ */
73
+ value(): GPUAllowSharedBufferSource | undefined;
74
+ value<T extends GPUAllowSharedBufferSource>(data: T): T;
75
+ /**
76
+ * Returns a capability summary inferred from the current texture usage flags.
77
+ */
78
+ get can(): {
79
+ copy: {
80
+ read: boolean;
81
+ write: boolean;
82
+ };
83
+ binding: {
84
+ texture: boolean;
85
+ storage: boolean;
86
+ };
87
+ renderAttachment: boolean;
88
+ };
89
+ /**
90
+ * Sync changes made.
91
+ *
92
+ * ● Throws AGPU_2 if the texture was destroyed
93
+ */
94
+ sync(): void;
95
+ /**
96
+ * Represents the raw GPUTexture
97
+ */
98
+ raw(): GPUTexture;
99
+ /**
100
+ * Recreates this texture from its cached descriptor and optionally copies the
101
+ * cached CPU-side value if one is present.
102
+ */
103
+ clone(): TextureCreator;
104
+ /**
105
+ * Represents the raw GPUTextureView
106
+ */
107
+ view(): TextureViewCreator;
108
+ /**
109
+ * Copies this texture into a buffer destination.
110
+ */
111
+ copyToBuffer(destination: BufferCreator | DC_MEMBER<"Buffer"> | GPUBuffer, options?: TEXTURE_TO_BUFFER_OPTIONS): void;
112
+ /**
113
+ * Copies this texture into another texture destination.
114
+ */
115
+ copyToTexture(destination: TextureCreator | DC_MEMBER<"Texture"> | GPUTexture, options?: TEXTURE_TO_TEXTURE_OPTIONS): void;
116
+ /**
117
+ * Returns the aspect ratio of the width and height of the texture
118
+ */
119
+ aspect(): number;
120
+ /**
121
+ * Resizes the given texture.
122
+ *
123
+ * ● Throws AGPU_2 if the texture was already destroyed
124
+ *
125
+ * ● Recreates texture and therefore expensive
126
+ */
127
+ resize(newWidth: number, newHeight: number, newDepthOrArrayLayers?: number): void;
128
+ /**
129
+ * Getter / Setter for destruction state.
130
+ */
131
+ destroy(): boolean;
132
+ destroy<T extends boolean>(val: T): T;
133
+ /**
134
+ * Getter/Setter for label.
135
+ *
136
+ * ● If no value is passed, the function returns the current label of the texture.
137
+ *
138
+ * ● If a value is passed, the function returns the same label passed.
139
+ *
140
+ * ● Throws AGPU_2 if the texture was destroyed
141
+ */
142
+ label(): UNSURE<string>;
143
+ label<T extends string>(label: T): T;
144
+ [Symbol.hasInstance](instance: TextureCreator): instance is TextureCreator;
145
+ readonly __brand = "TextureCreator";
146
+ }
147
+ export declare namespace TextureCreator {
148
+ namespace bufferUsage {
149
+ /**
150
+ * Shape returned by `textureUsage()` in getter mode.
151
+ */
152
+ interface RETURNS extends TEXTURE_USAGE_OPTIONS {
153
+ number?: number;
154
+ }
155
+ }
156
+ }
157
+ export default TextureCreator;
@@ -0,0 +1 @@
1
+ "use strict";function e(e,t,r){if(r)return i(r);const s=t??0;return{width:Math.max(1,e.width>>s),height:Math.max(1,e.height>>s),depthOrArrayLayers:e.depthOrArrayLayers}}function t(e){return"function"==typeof e.raw}function r(e){return"function"==typeof e.raw}function i(e){if("number"==typeof e)return{width:e,height:1,depthOrArrayLayers:1};if(Symbol.iterator in Object(e)){const t=Array.from(e);return{width:t[0]??1,height:t[1]??1,depthOrArrayLayers:t[2]??1}}return{width:e.width,height:e.height??1,depthOrArrayLayers:e.depthOrArrayLayers??1}}function s(e){if(e instanceof ArrayBuffer)return e.slice(0);if(ArrayBuffer.isView(e)){const t=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),r=e.constructor;return e instanceof DataView?new DataView(t):new r(t,0,e.byteLength/(r.BYTES_PER_ELEMENT??1))}return e.slice(0)}var o=this&&this.__importDefault||(e=>e&&e.__esModule?e:{default:e});Object.defineProperty(exports,"__esModule",{value:!0}),exports.TextureCreator=void 0;const u=o(require("../../../helpers/align")),a=o(require("../../../helpers/defaults")),h=o(require("../../../helpers/errors")),n=require("./texture/textureUsageOptions"),d=o(require("./texture/textureView")),c={r8unorm:1,r8snorm:1,r8uint:1,r8sint:1,r16uint:2,r16sint:2,r16float:2,rg8unorm:2,rgba8unorm:4,"rgba8unorm-srgb":4,bgra8unorm:4,rg16float:4,r32float:4,rgba16float:8,rg32float:8,rgba32float:16},f=(0,h.default)(2,"Texture already destroyed!"),l=(0,h.default)(10,"Cannot write to texture since the flag 'usage.copy.write' is false or undefined"),y=(0,h.default)(11,"Texture cannot be copied because the flag 'usage.copy.read' is false or undefined"),w=(0,h.default)(12,"Texture could not be copied since the other texture doesnt allow writing to it"),p=(0,h.default)(13,"Texture could not be copied since the other buffer doesnt allow writing to it"),x=(0,h.default)(38,"Cannot recreate a raw GPUTexture because no original descriptor was stored.","Construct the texture through TextureCreator options if you need resize/resurrection support."),g=(0,h.default)(39,"Texture size must be greater than zero in every dimension.","Pass width, height, and depthOrArrayLayers values of at least 1.");class v{#e;#t;#r;#i;#s;#o=!1;#u;constructor(e,t){if(this.#e=e,"function"!=typeof t.createView){const{value:r,usage:s,...o}=t,u="number"==typeof s?s:"object"==typeof s?(0,n.getTextureUsage)(s):a.default.textureUsage;this.#u=(0,n.getOptionsFromTextureUsage)(u);const h=i(t.size);if(0>=h.width||0>=h.height||0>=h.depthOrArrayLayers)throw g;this.#i={...t,usage:u},this.#t=e.createTexture({...o,usage:u}),this.#r=new d.default(this.#t.createView()),r&&(this.value(r),this.#s=r)}else{const e=t;this.#u=(0,n.getOptionsFromTextureUsage)(e.usage),this.#t=e,this.#r=new d.default(e.createView()),this.#i=void 0,this.#s=void 0}const r=this;this.View=class extends d.default{constructor(){super(r.#t.createView())}}}View;#a=!1;value(e){if(this.#o)throw f;if(void 0===e)return this.#s;if(!this.can.copy.write)throw l;return e!==this.#s&&(this.#s=e,this.#a=!0),e}get can(){const e=this.#u,t=e.copy,r=e.binding;return{copy:{read:!1!==t&&(!0===t||!!t?.read),write:!1!==t&&(!0===t||!!t?.write)},binding:{texture:!!r?.texture,storage:!!r?.storage},renderAttachment:!!e.renderAttachment}}#h(e){const t=this.#t.format,r=this.#t.width*(c[t]??4),i=(0,u.default)(r,256);this.#e.queue.writeTexture({texture:this.#t},e,{bytesPerRow:i,rowsPerImage:this.#t.height},{width:this.#t.width,height:this.#t.height,depthOrArrayLayers:this.#t.depthOrArrayLayers})}sync(){if(this.#o)throw f;if(this.#a){if(this.#s){if(!this.can.copy.write)throw l;this.#h(this.#s)}this.#a=!1}}raw(){return this.#t}clone(){if(this.#o)throw f;if(!this.#i)throw x;const{value:e,...t}=this.#i,r=new v(this.#e,{...t,value:this.#s?s(this.#s):void 0});return this.#t.label&&r.label(this.#t.label),r}view(){return this.#r}copyToBuffer(r,i={}){if(this.#o)throw f;if(!this.can.copy.read)throw y;if(this.#a&&this.sync(),t(r)){if(!r.can.copy.write)throw p}else if(!(r.usage&GPUBufferUsage.COPY_DST))throw p;const s=e(this.#t,i.mipLevel,i.size),o=i.bytesPerRow??(0,u.default)(s.width*(a=this.#t.format,c[a]??4),256);var a;const h=i.rowsPerImage??s.height,n=t(r)?r.raw():r,d=this.#e.createCommandEncoder();d.copyTextureToBuffer({texture:this.#t,origin:i.origin,aspect:i.aspect,mipLevel:i.mipLevel},{buffer:n,offset:i.offset,bytesPerRow:o,rowsPerImage:h},s),this.#e.queue.submit([d.finish()])}copyToTexture(t,i={}){if(this.#o)throw f;if(!this.can.copy.read)throw y;if(this.#a&&this.sync(),r(t)){if(!t.can.copy.write)throw w}else{const e=(0,n.getOptionsFromTextureUsage)(t.usage);if(!1===e.copy||!0!==e.copy&&!e.copy?.write)throw w}const s=r(t)?t.raw():t,o=e(this.#t,i.sourceMipLevel,i.size),u=this.#e.createCommandEncoder();u.copyTextureToTexture({texture:this.#t,mipLevel:i.sourceMipLevel,origin:i.sourceOrigin},{texture:s,mipLevel:i.destinationMipLevel,origin:i.destinationOrigin},o),this.#e.queue.submit([u.finish()])}aspect(){if(this.#o)throw f;return this.#t.width/this.#t.height}resize(e,t,r=this.#t.depthOrArrayLayers){if(this.#o)throw f;if(!this.#i)throw x;if(0>=e||0>=t||0>=r)throw g;e===this.#t.width&&t===this.#t.height&&r===this.#t.depthOrArrayLayers||(this.#t.destroy(),this.#t=this.#e.createTexture({...this.#i,size:[e,t,r]}),this.#r=new d.default(this.#t.createView()),this.#s&&(this.#a=!0,this.sync()))}destroy(e){if(void 0===e)return this.#o;if(!0===e&&!this.#o)return this.#t.destroy(),this.#o=!0,!0;if(!1===e&&this.#o)throw(0,h.default)(22,"You can not resurrect a texture. This feature is deprecated");return this.#o=e}label(e){if(this.#o)throw f;return void 0===e?this.#i?.label:this.#t.label=e}[Symbol.hasInstance](e){return"TextureCreator"===e.__brand}__brand="TextureCreator"}exports.TextureCreator=v,exports.default=v;
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "@webgpu/types": "^0.1.69"
17
17
  },
18
18
  "name": "@agpu/bindings",
19
- "version": "0.2.9",
19
+ "version": "0.2.10",
20
20
  "author": {
21
21
  "name": "Kryft Studios",
22
22
  "email": "AfriaStudios@outlook.in",