2 * Copyright (C) 2018 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 constructor(nameContext)
30 this._map = new Map();
32 // NOTE: Intrinsic resolution happens before type name resolution, so the strings we use here
33 // to catch the intrinsics must be based on the type names that StandardLibrary.js uses.
34 // For example, if a native function is declared using "int" rather than "int", then we must
35 // use "int" here, since we don't yet know that they are the same type.
38 "native typedef void",
42 type.populateDefaultValue = () => { };
46 "native typedef bool",
49 type.isPrimitive = true;
51 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, false);
55 "native typedef uchar",
58 type.isPrimitive = true;
61 type.isSigned = false;
62 type.canRepresent = value => isBitwiseEquivalent(castToUchar(value), value);
64 type.defaultValue = 0;
65 type.createLiteral = (origin, value) => IntLiteral.withType(origin, castToUchar(value), type);
66 type.successorValue = value => castToUchar(value + 1);
67 type.valuesEqual = (a, b) => a === b;
68 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
69 type.formatValueFromIntLiteral = value => castToUchar(value);
70 type.formatValueFromUintLiteral = value => castToUchar(value);
71 type.allValues = function*() {
72 for (let i = 0; i <= 0xff; ++i)
73 yield {value: i, name: i};
79 "native typedef ushort",
82 type.isPrimitive = true;
85 type.isSigned = false;
86 type.canRepresent = value => isBitwiseEquivalent(castToUshort(value), value);
88 type.defaultValue = 0;
89 type.createLiteral = (origin, value) => IntLiteral.withType(origin, castToUshort(value), type);
90 type.successorValue = value => castToUshort(value + 1);
91 type.valuesEqual = (a, b) => a === b;
92 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
93 type.formatValueFromIntLiteral = value => castToUshort(value);
94 type.formatValueFromUintLiteral = value => castToUshort(value);
95 type.allValues = function*() {
96 for (let i = 0; i <= 0xffff; ++i)
97 yield {value: i, name: i};
102 "native typedef uint",
105 type.isPrimitive = true;
107 type.isNumber = true;
108 type.isSigned = false;
109 type.canRepresent = value => isBitwiseEquivalent(castToUint(value), value);
111 type.defaultValue = 0;
112 type.createLiteral = (origin, value) => IntLiteral.withType(origin, castToUint(value), type);
113 type.successorValue = value => castToUint(value + 1);
114 type.valuesEqual = (a, b) => a === b;
115 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
116 type.formatValueFromIntLiteral = value => castToUint(value);
117 type.formatValueFromUintLiteral = value => castToUint(value);
118 type.allValues = function*() {
119 for (let i = 0; i <= 0xffffffff; ++i)
120 yield {value: i, name: i};
125 "native typedef char",
128 type.isPrimitive = true;
130 type.isNumber = true;
131 type.isSigned = true;
132 type.canRepresent = value => isBitwiseEquivalent(castToChar(value), value);
134 type.defaultValue = 0;
135 type.createLiteral = (origin, value) => IntLiteral.withType(origin, castToChar(value), type);
136 type.successorValue = value => castToChar(value + 1);
137 type.valuesEqual = (a, b) => a === b;
138 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
139 type.formatValueFromIntLiteral = value => castToChar(value);
140 type.formatValueFromUintLiteral = value => castToChar(value);
141 type.allValues = function*() {
142 for (let i = 0; i <= 0xff; ++i) {
143 let value = castToChar(i);
144 yield {value: value, name: value};
150 "native typedef short",
153 type.isPrimitive = true;
155 type.isNumber = true;
156 type.isSigned = true;
157 type.canRepresent = value => isBitwiseEquivalent(castToShort(value), value);
159 type.defaultValue = 0;
160 type.createLiteral = (origin, value) => IntLiteral.withType(origin, castToShort(value), type);
161 type.successorValue = value => castToShort(value + 1);
162 type.valuesEqual = (a, b) => a === b;
163 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
164 type.formatValueFromIntLiteral = value => castToShort(value);
165 type.formatValueFromUintLiteral = value => castToShort(value);
166 type.allValues = function*() {
167 for (let i = 0; i <= 0xffff; ++i) {
168 let value = castToShort(i);
169 yield {value: value, name: value};
175 "native typedef int",
178 type.isPrimitive = true;
180 type.isNumber = true;
181 type.isSigned = true;
182 type.canRepresent = value => isBitwiseEquivalent(castToInt(value), value);
184 type.defaultValue = 0;
185 type.createLiteral = (origin, value) => IntLiteral.withType(origin, castToInt(value), type);
186 type.successorValue = value => castToInt(value + 1);
187 type.valuesEqual = (a, b) => a === b;
188 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
189 type.formatValueFromIntLiteral = value => castToInt(value);
190 type.formatValueFromUintLiteral = value => castToInt(value);
191 type.allValues = function*() {
192 for (let i = 0; i <= 0xffffffff; ++i) {
193 let value = castToInt(i);
194 yield {value: value, name: value};
200 "native typedef half",
203 type.isPrimitive = true;
205 type.isFloating = true;
206 type.isNumber = true;
207 type.canRepresent = value => true;
208 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
209 type.formatValueFromIntLiteral = value => value;
210 type.formatValueFromUintLiteral = value => value;
211 type.formatValueFromFloatLiteral = value => castToHalf(value);
215 "native typedef float",
218 type.isPrimitive = true;
220 type.isFloating = true;
221 type.isNumber = true;
222 type.canRepresent = value => true;
223 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
224 type.formatValueFromIntLiteral = value => value;
225 type.formatValueFromUintLiteral = value => value;
226 type.formatValueFromFloatLiteral = value => castToFloat(value);
230 "native typedef atomic_int",
232 this.atomic_int = type;
234 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
238 "native typedef atomic_uint",
240 this.atomic_uint = type;
242 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
245 for (let vectorType of VectorElementTypes) {
246 for (let vectorSize of VectorElementSizes) {
247 this._map.set(`native typedef vector<${vectorType}, ${vectorSize}>`, type => {
248 this[`vector<${vectorType}, ${vectorSize}>`] = type;
249 type.isPrimitive = true;
254 for (let typeName of ["half", "float"]) {
255 for (let height = 2; height <= 4; ++height) {
256 for (let width = 2; width <= 4; ++width) {
257 this._map.set(`native typedef matrix<${typeName}, ${height}, ${width}>`, type => {
258 this[`matrix<${typeName}, ${height}, ${width}>`] = type;
265 "native typedef sampler",
269 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
272 for (let textureType of ["Texture1D", "RWTexture1D", "Texture1DArray", "RWTexture1DArray", "Texture2D", "RWTexture2D", "Texture2DArray", "RWTexture2DArray", "Texture3D", "RWTexture3D", "TextureCube"]) {
273 for (let typeArgument of ["bool", "uchar", "ushort", "uint", "char", "short", "int", "half", "float"]) {
275 `native typedef ${textureType}<${typeArgument}>`,
277 this[`${textureType}<${typeArgument}>`] = type;
279 type.isTexture = true;
280 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
282 for (let i = 2; i <= 4; ++i) {
284 `native typedef ${textureType}<${typeArgument}${i}>`,
286 this[`${textureType}<${typeArgument}${i}>`] = type;
288 type.isTexture = true;
289 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
295 for (let textureType of ["TextureDepth2D", "RWTextureDepth2D", "TextureDepth2DArray", "RWTextureDepth2DArray", "TextureDepthCube"]) {
296 for (let typeArgument of ["float", "half"]) {
298 `native typedef ${textureType}<${typeArgument}>`,
300 this[`${textureType}<${typeArgument}>`] = type;
302 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
307 for (let primitiveType of ["ushort", "uint", "char", "short", "int", "half", "float"]) {
309 `native operator uchar(${primitiveType})`,
311 func.implementation = ([value]) => EPtr.box(castToUchar(value.loadValue()));
315 for (let primitiveType of ["uchar", "uint", "char", "short", "int", "half", "float"]) {
317 `native operator ushort(${primitiveType})`,
319 func.implementation = ([value]) => EPtr.box(castToUshort(value.loadValue()));
323 for (let primitiveType of ["uchar", "ushort", "char", "short", "int", "half", "float"]) {
325 `native operator uint(${primitiveType})`,
327 func.implementation = ([value]) => EPtr.box(castToUint(value.loadValue()));
331 for (let primitiveType of ["uchar", "ushort", "uint", "short", "int", "half", "float"]) {
333 `native operator char(${primitiveType})`,
335 func.implementation = ([value]) => EPtr.box(castToChar(value.loadValue()));
339 for (let primitiveType of ["uchar", "ushort", "uint", "char", "int", "half", "float"]) {
341 `native operator short(${primitiveType})`,
343 func.implementation = ([value]) => EPtr.box(castToShort(value.loadValue()));
347 for (let primitiveType of ["uchar", "ushort", "uint", "char", "short", "half", "float"]) {
349 `native operator int(${primitiveType})`,
351 func.implementation = ([value]) => EPtr.box(cast(Int32Array, value.loadValue()));
355 for (let primitiveType of ["uchar", "ushort", "uint", "char", "short", "int", "float"]) {
357 `native operator half(${primitiveType})`,
359 func.implementation = ([value]) => EPtr.box(castToHalf(value.loadValue()));
363 for (let primitiveType of ["uchar", "ushort", "uint", "char", "short", "int", "half"]) {
365 `native operator float(${primitiveType})`,
367 func.implementation = ([value]) => EPtr.box(castToFloat(value.loadValue()));
372 `native operator int(atomic_int)`,
374 func.implementation = ([value]) => EPtr.box(value.loadValue());
378 `native operator uint(atomic_uint)`,
380 func.implementation = ([value]) => EPtr.box(value.loadValue());
384 "native bool operator==(bool,bool)",
386 func.implementation = ([left, right]) =>
387 EPtr.box(left.loadValue() == right.loadValue());
390 for (let primitiveType of ["uint", "int", "float"]) {
392 `native bool operator==(${primitiveType},${primitiveType})`,
394 func.implementation = ([left, right]) =>
395 EPtr.box(left.loadValue() == right.loadValue());
399 `native bool operator<(${primitiveType},${primitiveType})`,
401 func.implementation = ([left, right]) =>
402 EPtr.box(left.loadValue() < right.loadValue());
406 `native bool operator<=(${primitiveType},${primitiveType})`,
408 func.implementation = ([left, right]) =>
409 EPtr.box(left.loadValue() <= right.loadValue());
413 `native bool operator>(${primitiveType},${primitiveType})`,
415 func.implementation = ([left, right]) =>
416 EPtr.box(left.loadValue() > right.loadValue());
420 `native bool operator>=(${primitiveType},${primitiveType})`,
422 func.implementation = ([left, right]) =>
423 EPtr.box(left.loadValue() >= right.loadValue());
428 "native int operator-(int)",
430 func.implementation = ([value]) =>
431 EPtr.box(castToInt(-value.loadValue()));
435 "native float operator-(float)",
437 func.implementation = ([value]) =>
438 EPtr.box(castToFloat(-value.loadValue()));
442 "native int operator+(int,int)",
444 func.implementation = ([left, right]) =>
445 EPtr.box(castToInt(left.loadValue() + right.loadValue()));
449 "native int operator-(int,int)",
451 func.implementation = ([left, right]) =>
452 EPtr.box(castToInt(left.loadValue() - right.loadValue()));
456 "native int operator*(int,int)",
458 func.implementation = ([left, right]) =>
459 EPtr.box(castToInt(left.loadValue() * right.loadValue()));
463 "native int operator/(int,int)",
465 func.implementation = ([left, right]) =>
466 EPtr.box(castToInt(left.loadValue() / right.loadValue()));
470 "native uint operator+(uint,uint)",
472 func.implementation = ([left, right]) =>
473 EPtr.box(castToUint(left.loadValue() + right.loadValue()));
477 "native uint operator-(uint,uint)",
479 func.implementation = ([left, right]) =>
480 EPtr.box(castToUint(left.loadValue() - right.loadValue()));
484 "native uint operator*(uint,uint)",
486 func.implementation = ([left, right]) =>
487 EPtr.box(castToUint(left.loadValue() * right.loadValue()));
491 "native uint operator/(uint,uint)",
493 func.implementation = ([left, right]) =>
494 EPtr.box(castToUint(left.loadValue() / right.loadValue()));
498 "native float operator+(float,float)",
500 func.implementation = ([left, right]) =>
501 EPtr.box(castToFloat(left.loadValue() + right.loadValue()));
505 "native float operator-(float,float)",
507 func.implementation = ([left, right]) =>
508 EPtr.box(castToFloat(left.loadValue() - right.loadValue()));
512 "native float operator*(float,float)",
514 func.implementation = ([left, right]) =>
515 EPtr.box(castToFloat(left.loadValue() * right.loadValue()));
519 "native float operator/(float,float)",
521 func.implementation = ([left, right]) =>
522 EPtr.box(castToFloat(left.loadValue() / right.loadValue()));
526 "native int operator&(int,int)",
528 func.implementation = ([left, right]) =>
529 EPtr.box(castToInt(left.loadValue() & right.loadValue()));
533 "native int operator|(int,int)",
535 func.implementation = ([left, right]) =>
536 EPtr.box(castToInt(left.loadValue() | right.loadValue()));
540 "native int operator^(int,int)",
542 func.implementation = ([left, right]) =>
543 EPtr.box(castToInt(left.loadValue() ^ right.loadValue()));
547 "native int operator~(int)",
549 func.implementation = ([value]) => EPtr.box(castToInt(~value.loadValue()));
553 "native int operator<<(int,uint)",
555 func.implementation = ([left, right]) =>
556 EPtr.box(castToInt(left.loadValue() << right.loadValue()));
560 "native int operator>>(int,uint)",
562 func.implementation = ([left, right]) =>
563 EPtr.box(castToInt(left.loadValue() >> right.loadValue()));
567 "native uint operator&(uint,uint)",
569 func.implementation = ([left, right]) =>
570 EPtr.box(castToUint(left.loadValue() & right.loadValue()));
574 "native uint operator|(uint,uint)",
576 func.implementation = ([left, right]) =>
577 EPtr.box(castToUint(left.loadValue() | right.loadValue()));
581 "native uint operator^(uint,uint)",
583 func.implementation = ([left, right]) =>
584 EPtr.box(castToUint(left.loadValue() ^ right.loadValue()));
588 "native uint operator~(uint)",
590 func.implementation = ([value]) => EPtr.box(castToUint(~value.loadValue()));
594 "native uint operator<<(uint,uint)",
596 func.implementation = ([left, right]) =>
597 EPtr.box(castToUint(left.loadValue() << right.loadValue()));
601 "native uint operator>>(uint,uint)",
603 func.implementation = ([left, right]) =>
604 EPtr.box(castToUint(left.loadValue() >>> right.loadValue()));
608 "native float cos(float)",
610 func.implementation = ([value]) =>
611 EPtr.box(castToFloat(Math.cos(value.loadValue())));
615 "native float sin(float)",
617 func.implementation = ([value]) =>
618 EPtr.box(castToFloat(Math.sin(value.loadValue())));
622 "native float tan(float)",
624 func.implementation = ([value]) =>
625 EPtr.box(castToFloat(Math.tan(value.loadValue())));
629 "native float acos(float)",
631 func.implementation = ([value]) =>
632 EPtr.box(castToFloat(Math.acos(value.loadValue())));
636 "native float asin(float)",
638 func.implementation = ([value]) =>
639 EPtr.box(castToFloat(Math.asin(value.loadValue())));
643 "native float atan(float)",
645 func.implementation = ([value]) =>
646 EPtr.box(castToFloat(Math.atan(value.loadValue())));
650 "native float cosh(float)",
652 func.implementation = ([value]) =>
653 EPtr.box(castToFloat(Math.cosh(value.loadValue())));
657 "native float sinh(float)",
659 func.implementation = ([value]) =>
660 EPtr.box(castToFloat(Math.sinh(value.loadValue())));
664 "native float tanh(float)",
666 func.implementation = ([value]) =>
667 EPtr.box(castToFloat(Math.tanh(value.loadValue())));
671 "native float ceil(float)",
673 func.implementation = ([value]) =>
674 EPtr.box(castToFloat(Math.ceil(value.loadValue())));
678 "native float exp(float)",
680 func.implementation = ([value]) =>
681 EPtr.box(castToFloat(Math.exp(value.loadValue())));
685 "native float floor(float)",
687 func.implementation = ([value]) =>
688 EPtr.box(castToFloat(Math.floor(value.loadValue())));
692 "native float log(float)",
694 func.implementation = ([value]) =>
695 EPtr.box(castToFloat(Math.log(value.loadValue())));
699 "native float round(float)",
701 func.implementation = ([value]) =>
702 EPtr.box(castToFloat(Math.round(value.loadValue())));
706 "native float sqrt(float)",
708 func.implementation = ([value]) =>
709 EPtr.box(castToFloat(Math.sqrt(value.loadValue())));
713 "native float trunc(float)",
715 func.implementation = ([value]) =>
716 EPtr.box(castToFloat(Math.trunc(value.loadValue())));
720 "native fragment float ddx(float)",
722 func.implementation = ([value]) => EPtr.box(0);
726 "native fragment float ddy(float)",
728 func.implementation = ([value]) => EPtr.box(0);
732 "native float pow(float,float)",
734 func.implementation = ([left, right]) =>
735 EPtr.box(castToFloat(Math.pow(left.loadValue(), right.loadValue())));
739 "native bool isfinite(float)",
741 func.implementation = ([value]) =>
742 EPtr.box(Number.isFinite(value.loadValue()));
746 "native bool isinf(float)",
748 func.implementation = ([value]) =>
749 EPtr.box((value.loadValue() == Number.POSITIVE_INFINITY) || (value.loadValue() == Number.NEGATIVE_INFINITY));
753 "native bool isnan(float)",
755 func.implementation = ([value]) =>
756 EPtr.box(Number.isNaN(value.loadValue()));
759 // FIXME: Implement this.
761 "native bool isnormal(half)",
763 func.implementation = ([value]) =>
764 EPtr.box(isNaN(value.loadValue()));
767 // FIXME: Implement this.
769 "native bool isnormal(float)",
771 func.implementation = ([value]) =>
772 EPtr.box(isNaN(value.loadValue()));
776 "native float atan2(float,float)",
778 func.implementation = ([left, right]) =>
779 EPtr.box(castToFloat(Math.atan2(left.loadValue(), right.loadValue())));
783 "native int asint(float)",
785 func.implementation = ([value]) =>
786 EPtr.box(bitwiseCast(Float32Array, Int32Array, value.loadValue()));
790 "native uint asuint(float)",
792 func.implementation = ([value]) =>
793 EPtr.box(bitwiseCast(Float32Array, Uint32Array, value.loadValue()));
797 "native float asfloat(int)",
799 func.implementation = ([value]) =>
800 EPtr.box(bitwiseCast(Int32Array, Float32Array, value.loadValue()));
804 "native float asfloat(uint)",
806 func.implementation = ([value]) =>
807 EPtr.box(bitwiseCast(Uint32Array, Float32Array, value.loadValue()));
810 // FIXME: Implement this.
812 "native float f16tof32(uint)",
814 func.implementation = ([value]) =>
818 // FIXME: Implement this.
820 "native uint f32tof16(float)",
822 func.implementation = ([value]) =>
827 "native compute void AllMemoryBarrierWithGroupSync()",
829 func.implementation = function() {};
833 "native compute void DeviceMemoryBarrierWithGroupSync()",
835 func.implementation = function() {};
839 "native compute void GroupMemoryBarrierWithGroupSync()",
841 func.implementation = function() {};
844 for (let nativeVectorTypeName of allVectorTypeNames()) {
845 this._map.set(`native typedef ${nativeVectorTypeName}`, type => {
846 type.isPrimitive = true;
850 for (let getter of BuiltinVectorGetter.functions())
851 this._map.set(getter.toString(), func => getter.instantiateImplementation(func));
853 for (let setter of BuiltinVectorSetter.functions())
854 this._map.set(setter.toString(), func => setter.instantiateImplementation(func));
856 for (let getter of BuiltinMatrixGetter.functions())
857 this._map.set(getter.toString(), func => getter.instantiateImplementation(func));
859 for (let setter of BuiltinMatrixSetter.functions())
860 this._map.set(setter.toString(), func => setter.instantiateImplementation(func));
862 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
863 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
865 `native void InterlockedAdd(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
867 func.implementation = function([atomic, value, originalValue], node) {
868 if (!atomic.loadValue())
869 throw new WTrapError(node.origin.originString, "Null atomic pointer");
870 let a = atomic.loadValue().loadValue();
871 let b = value.loadValue();
872 let result = castToUint(a + b);
873 if (originalValue.loadValue())
874 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
875 atomic.loadValue().copyFrom(EPtr.box(result), 1);
880 `native void InterlockedAdd(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
882 func.implementation = function([atomic, value, originalValue], node) {
883 if (!atomic.loadValue())
884 throw new WTrapError(node.origin.originString, "Null atomic pointer");
885 let a = atomic.loadValue().loadValue();
886 let b = value.loadValue();
887 let result = castToInt(a + b);
888 if (originalValue.loadValue())
889 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
890 atomic.loadValue().copyFrom(EPtr.box(result), 1);
895 `native void InterlockedAnd(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
897 func.implementation = function([atomic, value, originalValue], node) {
898 if (!atomic.loadValue())
899 throw new WTrapError(node.origin.originString, "Null atomic pointer");
900 let a = atomic.loadValue().loadValue();
901 let b = value.loadValue();
902 let result = castToUint(a & b);
903 if (originalValue.loadValue())
904 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
905 atomic.loadValue().copyFrom(EPtr.box(result), 1);
910 `native void InterlockedAnd(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
912 func.implementation = function([atomic, value, originalValue], node) {
913 if (!atomic.loadValue())
914 throw new WTrapError(node.origin.originString, "Null atomic pointer");
915 let a = atomic.loadValue().loadValue();
916 let b = value.loadValue();
917 let result = castToInt(a & b);
918 if (originalValue.loadValue())
919 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
920 atomic.loadValue().copyFrom(EPtr.box(result), 1);
925 `native void InterlockedExchange(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
927 func.implementation = function([atomic, value, originalValue], node) {
928 if (!atomic.loadValue())
929 throw new WTrapError(node.origin.originString, "Null atomic pointer");
930 let a = atomic.loadValue().loadValue();
931 let b = value.loadValue();
932 if (originalValue.loadValue())
933 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
934 atomic.loadValue().copyFrom(EPtr.box(b), 1);
939 `native void InterlockedExchange(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
941 func.implementation = function([atomic, value, originalValue], node) {
942 if (!atomic.loadValue())
943 throw new WTrapError(node.origin.originString, "Null atomic pointer");
944 let a = atomic.loadValue().loadValue();
945 let b = value.loadValue();
946 if (originalValue.loadValue())
947 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
948 atomic.loadValue().copyFrom(EPtr.box(b), 1);
953 `native void InterlockedMax(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
955 func.implementation = function([atomic, value, originalValue], node) {
956 if (!atomic.loadValue())
957 throw new WTrapError(node.origin.originString, "Null atomic pointer");
958 let a = atomic.loadValue().loadValue();
959 let b = value.loadValue();
960 let result = castToUint(a > b ? a : b);
961 if (originalValue.loadValue())
962 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
963 atomic.loadValue().copyFrom(EPtr.box(result), 1);
968 `native void InterlockedMax(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
970 func.implementation = function([atomic, value, originalValue], node) {
971 if (!atomic.loadValue())
972 throw new WTrapError(node.origin.originString, "Null atomic pointer");
973 let a = atomic.loadValue().loadValue();
974 let b = value.loadValue();
975 let result = castToInt(a > b ? a : b);
976 if (originalValue.loadValue())
977 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
978 atomic.loadValue().copyFrom(EPtr.box(result), 1);
983 `native void InterlockedMin(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
985 func.implementation = function([atomic, value, originalValue], node) {
986 if (!atomic.loadValue())
987 throw new WTrapError(node.origin.originString, "Null atomic pointer");
988 let a = atomic.loadValue().loadValue();
989 let b = value.loadValue();
990 let result = castToUint(a < b ? a : b);
991 if (originalValue.loadValue())
992 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
993 atomic.loadValue().copyFrom(EPtr.box(result), 1);
998 `native void InterlockedMin(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
1000 func.implementation = function([atomic, value, originalValue], node) {
1001 if (!atomic.loadValue())
1002 throw new WTrapError(node.origin.originString, "Null atomic pointer");
1003 let a = atomic.loadValue().loadValue();
1004 let b = value.loadValue();
1005 let result = castToInt(a < b ? a : b);
1006 if (originalValue.loadValue())
1007 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1008 atomic.loadValue().copyFrom(EPtr.box(result), 1);
1013 `native void InterlockedOr(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
1015 func.implementation = function([atomic, value, originalValue], node) {
1016 if (!atomic.loadValue())
1017 throw new WTrapError(node.origin.originString, "Null atomic pointer");
1018 let a = atomic.loadValue().loadValue();
1019 let b = value.loadValue();
1020 let result = castToUint(a | b);
1021 if (originalValue.loadValue())
1022 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1023 atomic.loadValue().copyFrom(EPtr.box(result), 1);
1028 `native void InterlockedOr(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
1030 func.implementation = function([atomic, value, originalValue], node) {
1031 if (!atomic.loadValue())
1032 throw new WTrapError(node.origin.originString, "Null atomic pointer");
1033 let a = atomic.loadValue().loadValue();
1034 let b = value.loadValue();
1035 let result = castToInt(a | b);
1036 if (originalValue.loadValue())
1037 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1038 atomic.loadValue().copyFrom(EPtr.box(result), 1);
1043 `native void InterlockedXor(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
1045 func.implementation = function([atomic, value, originalValue], node) {
1046 if (!atomic.loadValue())
1047 throw new WTrapError(node.origin.originString, "Null atomic pointer");
1048 let a = atomic.loadValue().loadValue();
1049 let b = value.loadValue();
1050 let result = castToUint(a ^ b);
1051 if (originalValue.loadValue())
1052 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1053 atomic.loadValue().copyFrom(EPtr.box(result), 1);
1058 `native void InterlockedXor(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
1060 func.implementation = function([atomic, value, originalValue], node) {
1061 if (!atomic.loadValue())
1062 throw new WTrapError(node.origin.originString, "Null atomic pointer");
1063 let a = atomic.loadValue().loadValue();
1064 let b = value.loadValue();
1065 let result = castToInt(a ^ b);
1066 if (originalValue.loadValue())
1067 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1068 atomic.loadValue().copyFrom(EPtr.box(result), 1);
1073 `native void InterlockedCompareExchange(atomic_uint* ${addressSpace1},uint,uint,uint* ${addressSpace2})`,
1075 func.implementation = function([atomic, compareValue, value, originalValue]) {
1076 if (!atomic.loadValue())
1077 throw new WTrapError(node.origin.originString, "Null atomic pointer");
1078 let a = atomic.loadValue().loadValue();
1079 let b = compareValue.loadValue();
1080 let c = value.loadValue();
1082 atomic.loadValue().copyFrom(EPtr.box(c), 1);
1083 if (originalValue.loadValue())
1084 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1089 `native void InterlockedCompareExchange(atomic_int* ${addressSpace1},int,int,int* ${addressSpace2})`,
1091 func.implementation = function([atomic, compareValue, value, originalValue]) {
1092 if (!atomic.loadValue())
1093 throw new WTrapError(node.origin.originString, "Null atomic pointer");
1094 let a = atomic.loadValue().loadValue();
1095 let b = compareValue.loadValue();
1096 let c = value.loadValue();
1098 atomic.loadValue().copyFrom(EPtr.box(c), 1);
1099 if (originalValue.loadValue())
1100 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1106 function checkUndefined(origin, explanation, value)
1108 if (value == undefined)
1109 throw new WTrapError(origin, "Texture read out of bounds");
1113 function checkFalse(origin, explanation, value)
1116 throw new WTrapError(origin, "Texture store out of bounds");
1119 function boxVector(a)
1121 if (a instanceof Array) {
1122 let result = new EPtr(new EBuffer(a.length), 0);
1123 for (let i = 0; i < a.length; ++i)
1124 result.set(i, a[i]);
1130 function unboxVector(a, length)
1133 length = Number.parseInt(length);
1135 for (let i = 0; i < length; ++i)
1136 result.push(a.get(i));
1139 return a.loadValue();
1142 for (let type of ["uchar", "ushort", "uint", "char", "short", "int", "half", "float"]) {
1143 for (var lengthVariable of [``, `2`, `3`, `4`]) {
1144 let length = lengthVariable;
1146 `native ${type}${length} Sample(Texture1D<${type}${length}>,sampler,float location)`,
1148 func.implementation = function([texture, sampler, location]) {
1149 let locationArray = [location.loadValue(), 0, 0, 1, 0];
1150 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
1154 `native ${type}${length} Sample(Texture1D<${type}${length}>,sampler,float location,int offset)`,
1156 func.implementation = function([texture, sampler, location, offset]) {
1157 let locationArray = [location.loadValue(), 0, 0, 1, 0];
1158 let deltaArray = [offset.loadValue(), 0, 0];
1159 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined));
1163 `native ${type}${length} Load(Texture1D<${type}${length}>,int2 location)`,
1165 func.implementation = function ([texture, location], node) {
1166 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(1), 0, 0, location.get(0))));
1170 `native ${type}${length} Load(Texture1D<${type}${length}>,int2 location,int offset)`,
1172 func.implementation = function ([texture, location, offset], node) {
1173 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(1), 0, 0, location.get(0) + offset.loadValue())));
1176 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1177 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1179 `native void GetDimensions(Texture1D<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} NumberOfLevels)`,
1181 func.implementation = function([texture, miplevel, width, numberOfLevels], node) {
1182 let tex = texture.loadValue();
1183 let mipID = miplevel.loadValue();
1184 if (mipID >= tex.levelCount)
1185 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
1186 if (width.loadValue())
1187 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
1188 if (numberOfLevels.loadValue())
1189 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
1196 `native ${type}${length} Sample(Texture1DArray<${type}${length}>,sampler,float2 location)`,
1198 func.implementation = function([texture, sampler, location]) {
1199 let locationArray = [location.get(0), 0, 0, 1, location.get(1)];
1200 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
1204 `native ${type}${length} Sample(Texture1DArray<${type}${length}>,sampler,float2 location,int offset)`,
1206 func.implementation = function([texture, sampler, location, offset]) {
1207 let locationArray = [location.get(0), 0, 0, 1, location.get(1)];
1208 let deltaArray = [offset.loadValue(), 0, 0];
1209 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined));
1213 `native ${type}${length} Load(Texture1DArray<${type}${length}>,int3 location)`,
1215 func.implementation = function ([texture, location], node) {
1216 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(2), location.get(1), 0, 0, location.get(0))));
1220 `native ${type}${length} Load(Texture1DArray<${type}${length}>,int3 location,int offset)`,
1222 func.implementation = function ([texture, location, offset], node) {
1223 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(2), location.get(1), 0, 0, location.get(0) + offset.loadValue())));
1226 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1227 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1228 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1230 `native void GetDimensions(Texture1DArray<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Elements,uint* ${addressSpace3} NumberOfLevels)`,
1232 func.implementation = function([texture, miplevel, width, elements, numberOfLevels], node) {
1233 let tex = texture.loadValue();
1234 let mipID = miplevel.loadValue();
1235 if (mipID >= tex.levelCount)
1236 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
1237 if (width.loadValue())
1238 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
1239 if (elements.loadValue())
1240 elements.loadValue().copyFrom(EPtr.box(tex.layerCount), 1);
1241 if (numberOfLevels.loadValue())
1242 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
1250 `native ${type}${length} Sample(Texture2D<${type}${length}>,sampler,float2 location)`,
1252 func.implementation = function([texture, sampler, location]) {
1253 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1254 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
1258 `native ${type}${length} Sample(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1260 func.implementation = function([texture, sampler, location, offset]) {
1261 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1262 let deltaArray = [offset.get(0), offset.get(1), 0];
1263 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined));
1267 `native ${type}${length} SampleBias(Texture2D<${type}${length}>,sampler,float2 location,float Bias)`,
1269 func.implementation = function([texture, sampler, location, bias]) {
1270 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1271 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, bias.loadValue(), undefined, undefined, undefined, undefined));
1275 `native ${type}${length} SampleBias(Texture2D<${type}${length}>,sampler,float2 location,float Bias,int2 offset)`,
1277 func.implementation = function([texture, sampler, location, bias, offset]) {
1278 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1279 let deltaArray = [offset.get(0), offset.get(1), 0];
1280 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, bias.loadValue(), undefined, undefined, undefined, undefined));
1284 `native ${type}${length} SampleGrad(Texture2D<${type}${length}>,sampler,float2 location,float2 DDX,float2 DDY)`,
1286 func.implementation = function([texture, sampler, location, ddx, ddy]) {
1287 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1288 let ddxArray = [ddx.get(0), ddx.get(1), 0];
1289 let ddyArray = [ddy.get(0), ddy.get(1), 0];
1290 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, ddxArray, ddyArray, undefined, undefined));
1294 `native ${type}${length} SampleGrad(Texture2D<${type}${length}>,sampler,float2 location,float2 DDX,float2 DDY,int2 offset)`,
1296 func.implementation = function([texture, sampler, location, ddx, ddy, offset]) {
1297 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1298 let ddxArray = [ddx.get(0), ddx.get(1), 0];
1299 let ddyArray = [ddy.get(0), ddy.get(1), 0];
1300 let deltaArray = [offset.get(0), offset.get(1), 0];
1301 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, ddxArray, ddyArray, undefined, undefined));
1305 `native ${type}${length} SampleLevel(Texture2D<${type}${length}>,sampler,float2 location,float LOD)`,
1307 func.implementation = function([texture, sampler, location, lod]) {
1308 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1309 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, lod.loadValue(), undefined));
1313 `native ${type}${length} SampleLevel(Texture2D<${type}${length}>,sampler,float2 location,float LOD,int2 offset)`,
1315 func.implementation = function([texture, sampler, location, lod, offset]) {
1316 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1317 let deltaArray = [offset.get(0), offset.get(1), 0];
1318 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, lod.loadValue(), undefined));
1322 `native ${type}4 Gather(Texture2D<${type}${length}>,sampler,float2 location)`,
1324 func.implementation = function([texture, sampler, location]) {
1325 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1326 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
1330 `native ${type}4 Gather(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1332 func.implementation = function([texture, sampler, location, offset]) {
1333 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1334 let deltaArray = [offset.get(0), offset.get(1), 0];
1335 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
1339 `native ${type}4 GatherRed(Texture2D<${type}${length}>,sampler,float2 location)`,
1341 func.implementation = function([texture, sampler, location]) {
1342 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1343 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
1347 `native ${type}4 GatherRed(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1349 func.implementation = function([texture, sampler, location, offset]) {
1350 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1351 let deltaArray = [offset.get(0), offset.get(1), 0];
1352 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
1355 if (length == "2" || length == "3" || length == "4") {
1357 `native ${type}4 GatherGreen(Texture2D<${type}${length}>,sampler,float2 location)`,
1359 func.implementation = function([texture, sampler, location]) {
1360 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1361 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 1));
1365 `native ${type}4 GatherGreen(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1367 func.implementation = function([texture, sampler, location, offset]) {
1368 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1369 let deltaArray = [offset.get(0), offset.get(1), 0];
1370 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 1));
1373 if (length == "3" || length == "4") {
1375 `native ${type}4 GatherBlue(Texture2D<${type}${length}>,sampler,float2 location)`,
1377 func.implementation = function([texture, sampler, location]) {
1378 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1379 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 2));
1383 `native ${type}4 GatherBlue(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1385 func.implementation = function([texture, sampler, location, offset]) {
1386 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1387 let deltaArray = [offset.get(0), offset.get(1), 0];
1388 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 2));
1391 if (length == "4") {
1393 `native ${type}4 GatherAlpha(Texture2D<${type}${length}>,sampler,float2 location)`,
1395 func.implementation = function([texture, sampler, location]) {
1396 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1397 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 3));
1401 `native ${type}4 GatherAlpha(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1403 func.implementation = function([texture, sampler, location, offset]) {
1404 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
1405 let deltaArray = [offset.get(0), offset.get(1), 0];
1406 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 3));
1413 `native ${type}${length} Load(Texture2D<${type}${length}>,int3 location)`,
1415 func.implementation = function ([texture, location], node) {
1416 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(2), 0, location.get(1), location.get(0))));
1420 `native ${type}${length} Load(Texture2D<${type}${length}>,int3 location,int2 offset)`,
1422 func.implementation = function ([texture, location, offset], node) {
1423 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(2), 0, location.get(1) + offset.get(1), location.get(0) + offset.get(0))));
1426 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1427 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1428 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1430 `native void GetDimensions(Texture2D<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
1432 func.implementation = function([texture, miplevel, width, height, numberOfLevels], node) {
1433 let tex = texture.loadValue();
1434 let mipID = miplevel.loadValue();
1435 if (mipID >= tex.levelCount)
1436 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
1437 if (width.loadValue())
1438 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
1439 if (height.loadValue())
1440 height.loadValue().copyFrom(EPtr.box(tex.heightAtLevel(mipID)), 1);
1441 if (numberOfLevels.loadValue())
1442 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
1450 `native ${type}${length} Sample(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1452 func.implementation = function([texture, sampler, location]) {
1453 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1454 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
1458 `native ${type}${length} Sample(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1460 func.implementation = function([texture, sampler, location, offset]) {
1461 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1462 let deltaArray = [offset.get(0), offset.get(1), 0];
1463 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined));
1467 `native ${type}${length} SampleBias(Texture2DArray<${type}${length}>,sampler,float3 location,float Bias)`,
1469 func.implementation = function([texture, sampler, location, bias]) {
1470 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1471 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, bias.loadValue(), undefined, undefined, undefined, undefined));
1475 `native ${type}${length} SampleBias(Texture2DArray<${type}${length}>,sampler,float3 location,float Bias,int2 offset)`,
1477 func.implementation = function([texture, sampler, location, bias, offset]) {
1478 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1479 let deltaArray = [offset.get(0), offset.get(1), 0];
1480 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, bias.loadValue(), undefined, undefined, undefined, undefined));
1484 `native ${type}${length} SampleGrad(Texture2DArray<${type}${length}>,sampler,float3 location,float2 DDX,float2 DDY)`,
1486 func.implementation = function([texture, sampler, location, ddx, ddy]) {
1487 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1488 let ddxArray = [ddx.get(0), ddx.get(1), 0];
1489 let ddyArray = [ddy.get(0), ddy.get(1), 0];
1490 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, ddxArray, ddyArray, undefined, undefined));
1494 `native ${type}${length} SampleGrad(Texture2DArray<${type}${length}>,sampler,float3 location,float2 DDX,float2 DDY,int2 offset)`,
1496 func.implementation = function([texture, sampler, location, ddx, ddy, offset]) {
1497 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1498 let ddxArray = [ddx.get(0), ddx.get(1), 0];
1499 let ddyArray = [ddy.get(0), ddy.get(1), 0];
1500 let deltaArray = [offset.get(0), offset.get(1), 0];
1501 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, ddxArray, ddyArray, undefined, undefined));
1505 `native ${type}${length} SampleLevel(Texture2DArray<${type}${length}>,sampler,float3 location,float LOD)`,
1507 func.implementation = function([texture, sampler, location, lod]) {
1508 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1509 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, lod.loadValue(), undefined));
1513 `native ${type}${length} SampleLevel(Texture2DArray<${type}${length}>,sampler,float3 location,float LOD,int2 offset)`,
1515 func.implementation = function([texture, sampler, location, lod, offset]) {
1516 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1517 let deltaArray = [offset.get(0), offset.get(1), 0];
1518 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, lod.loadValue(), undefined));
1522 `native ${type}4 Gather(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1524 func.implementation = function([texture, sampler, location]) {
1525 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1526 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
1530 `native ${type}4 Gather(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1532 func.implementation = function([texture, sampler, location, offset]) {
1533 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1534 let deltaArray = [offset.get(0), offset.get(1), 0];
1535 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
1539 `native ${type}4 GatherRed(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1541 func.implementation = function([texture, sampler, location]) {
1542 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1543 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
1547 `native ${type}4 GatherRed(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1549 func.implementation = function([texture, sampler, location, offset]) {
1550 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1551 let deltaArray = [offset.get(0), offset.get(1), 0];
1552 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
1555 if (length == "2" || length == "3" || length == "4") {
1557 `native ${type}4 GatherGreen(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1559 func.implementation = function([texture, sampler, location]) {
1560 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1561 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 1));
1565 `native ${type}4 GatherGreen(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1567 func.implementation = function([texture, sampler, location, offset]) {
1568 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1569 let deltaArray = [offset.get(0), offset.get(1), 0];
1570 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 1));
1573 if (length == "3" || length == "4") {
1575 `native ${type}4 GatherBlue(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1577 func.implementation = function([texture, sampler, location]) {
1578 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1579 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 2));
1583 `native ${type}4 GatherBlue(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1585 func.implementation = function([texture, sampler, location, offset]) {
1586 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1587 let deltaArray = [offset.get(0), offset.get(1), 0];
1588 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 2));
1591 if (length == "4") {
1593 `native ${type}4 GatherAlpha(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1595 func.implementation = function([texture, sampler, location]) {
1596 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1597 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 3));
1601 `native ${type}4 GatherAlpha(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1603 func.implementation = function([texture, sampler, location, offset]) {
1604 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
1605 let deltaArray = [offset.get(0), offset.get(1), 0];
1606 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 4));
1613 `native ${type}${length} Load(Texture2DArray<${type}${length}>,int4 location)`,
1615 func.implementation = function ([texture, location], node) {
1616 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(3), location.get(2), 0, location.get(1), location.get(0))));
1620 `native ${type}${length} Load(Texture2DArray<${type}${length}>,int4 location,int2 offset)`,
1622 func.implementation = function ([texture, location, offset], node) {
1623 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(3), location.get(2), 0, location.get(1) + offset.get(1), location.get(0) + offset.get(0))));
1626 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1627 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1628 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1629 for (let addressSpace4 of ["thread", "threadgroup", "device"]) {
1631 `native void GetDimensions(Texture2DArray<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Elements,uint* ${addressSpace4} NumberOfLevels)`,
1633 func.implementation = function([texture, miplevel, width, height, elements, numberOfLevels], node) {
1634 let tex = texture.loadValue();
1635 let mipID = miplevel.loadValue();
1636 if (mipID >= tex.levelCount)
1637 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
1638 if (width.loadValue())
1639 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
1640 if (height.loadValue())
1641 height.loadValue().copyFrom(EPtr.box(tex.heightAtLevel(mipID)), 1);
1642 if (elements.loadValue())
1643 elements.loadValue().copyFrom(EPtr.box(tex.layerCount), 1);
1644 if (numberOfLevels.loadValue())
1645 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
1654 `native ${type}${length} Sample(Texture3D<${type}${length}>,sampler,float3 location)`,
1656 func.implementation = function([texture, sampler, location]) {
1657 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1658 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
1662 `native ${type}${length} Sample(Texture3D<${type}${length}>,sampler,float3 location,int3 offset)`,
1664 func.implementation = function([texture, sampler, location, offset]) {
1665 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1666 let deltaArray = [offset.get(0), offset.get(1), offset.get(2)];
1667 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined));
1671 `native ${type}${length} Load(Texture3D<${type}${length}>,int4 location)`,
1673 func.implementation = function ([texture, location], node) {
1674 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(3), location.get(2), location.get(1), location.get(0))));
1678 `native ${type}${length} Load(Texture3D<${type}${length}>,int4 location,int3 offset)`,
1680 func.implementation = function ([texture, location, offset], node) {
1681 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(3), location.get(2) + offset.get(2), location.get(1) + offset.get(1), location.get(0) + offset.get(0))));
1684 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1685 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1686 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1687 for (let addressSpace4 of ["thread", "threadgroup", "device"]) {
1689 `native void GetDimensions(Texture3D<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Depth,uint* ${addressSpace4} NumberOfLevels)`,
1691 func.implementation = function([texture, miplevel, width, height, depth, numberOfLevels], node) {
1692 let tex = texture.loadValue();
1693 let mipID = miplevel.loadValue();
1694 if (mipID >= tex.levelCount)
1695 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
1696 if (width.loadValue())
1697 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
1698 if (height.loadValue())
1699 height.loadValue().copyFrom(EPtr.box(tex.heightAtLevel(mipID)), 1);
1700 if (depth.loadValue())
1701 depth.loadValue().copyFrom(EPtr.box(tex.depthAtLevel(mipID)), 1);
1702 if (numberOfLevels.loadValue())
1703 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
1712 `native ${type}${length} Sample(TextureCube<${type}${length}>,sampler,float3 location)`,
1714 func.implementation = function([texture, sampler, location]) {
1715 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1716 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
1720 `native ${type}${length} SampleBias(TextureCube<${type}${length}>,sampler,float3 location,float Bias)`,
1722 func.implementation = function([texture, sampler, location, bias]) {
1723 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1724 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, bias.loadValue(), undefined, undefined, undefined, undefined));
1728 `native ${type}${length} SampleGrad(TextureCube<${type}${length}>,sampler,float3 location,float3 DDX,float3 DDY)`,
1730 func.implementation = function([texture, sampler, location, ddx, ddy]) {
1731 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1732 let ddxArray = [ddx.get(0), ddx.get(1), ddx.get(2)];
1733 let ddyArray = [ddy.get(0), ddy.get(1), ddy.get(2)];
1734 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, ddxArray, ddyArray, undefined, undefined));
1738 `native ${type}${length} SampleLevel(TextureCube<${type}${length}>,sampler,float3 location,float LOD)`,
1740 func.implementation = function([texture, sampler, location, lod]) {
1741 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1742 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, lod.loadValue(), undefined));
1746 `native ${type}4 Gather(TextureCube<${type}${length}>,sampler,float3 location)`,
1748 func.implementation = function([texture, sampler, location]) {
1749 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1750 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
1754 `native ${type}4 GatherRed(TextureCube<${type}${length}>,sampler,float3 location)`,
1756 func.implementation = function([texture, sampler, location]) {
1757 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1758 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
1761 if (length == "2" || length == "3" || length == "4") {
1763 `native ${type}4 GatherGreen(TextureCube<${type}${length}>,sampler,float3 location)`,
1765 func.implementation = function([texture, sampler, location]) {
1766 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1767 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 1));
1770 if (length == "3" || length == "4") {
1772 `native ${type}4 GatherBlue(TextureCube<${type}${length}>,sampler,float3 location)`,
1774 func.implementation = function([texture, sampler, location]) {
1775 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1776 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 2));
1779 if (length == "4") {
1781 `native ${type}4 GatherAlpha(TextureCube<${type}${length}>,sampler,float3 location)`,
1783 func.implementation = function([texture, sampler, location]) {
1784 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
1785 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 3));
1791 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1792 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1793 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1795 `native void GetDimensions(TextureCube<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
1797 func.implementation = function([texture, miplevel, width, height, numberOfLevels], node) {
1798 let tex = texture.loadValue();
1799 let mipID = miplevel.loadValue();
1800 if (tex.layerCount != 6)
1801 throw new Error("Cube texture doesn't have 6 faces");
1802 if (mipID >= tex.levelCount)
1803 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
1804 if (width.loadValue())
1805 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
1806 if (height.loadValue())
1807 height.loadValue().copyFrom(EPtr.box(tex.heightAtLevel(mipID)), 1);
1808 if (numberOfLevels.loadValue())
1809 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
1816 for (let addressSpace of ["thread", "threadgroup", "device"]) {
1818 `native void GetDimensions(RWTexture1D<${type}${length}>,uint* ${addressSpace} Width)`,
1820 func.implementation = function([texture, width]) {
1821 if (width.loadValue())
1822 width.loadValue().copyFrom(EPtr.box(texture.loadValue().width), 1);
1826 `native void GetDimensions(RWTexture1D<${type}${length}>,float* ${addressSpace} Width)`,
1828 func.implementation = function([texture, width]) {
1829 if (width.loadValue())
1830 width.loadValue().copyFrom(EPtr.box(texture.loadValue().width), 1);
1835 `native ${type}${length} Load(RWTexture1D<${type}${length}>,int location)`,
1837 func.implementation = function ([texture, location], node) {
1838 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, 0, 0, 0, location.loadValue())));
1842 `native void Store(RWTexture1D<${type}${length}>,${type}${length},uint location)`,
1844 func.implementation = function ([texture, value, location], node) {
1845 checkFalse(node.origin.originString, "Texture write out of bounds", texture.loadValue().setElementChecked(0, 0, 0, 0, location.loadValue(), unboxVector(value, length)));
1849 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1850 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1852 `native void GetDimensions(RWTexture1DArray<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Elements)`,
1854 func.implementation = function([texture, width, elements]) {
1855 let tex = texture.loadValue();
1856 if (width.loadValue())
1857 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
1858 if (elements.loadValue())
1859 elements.loadValue().copyFrom(EPtr.box(tex.layerCount), 1);
1863 `native void GetDimensions(RWTexture1DArray<${type}${length}>,float* ${addressSpace1} Width,uint* ${addressSpace2} Elements)`,
1865 func.implementation = function([texture, width, elements]) {
1866 let tex = texture.loadValue();
1867 if (width.loadValue())
1868 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
1869 if (elements.loadValue())
1870 elements.loadValue().copyFrom(EPtr.box(tex.layerCount), 1);
1876 `native ${type}${length} Load(RWTexture1DArray<${type}${length}>,int2 location)`,
1878 func.implementation = function ([texture, location], node) {
1879 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(1), 0, 0, 0, location.get(0))));
1883 `native void Store(RWTexture1DArray<${type}${length}>,${type}${length},uint2 location)`,
1885 func.implementation = function ([texture, value, location], node) {
1886 checkFalse(node.origin.originString, "Texture write out of bounds", texture.loadValue().setElementChecked(location.get(1), 0, 0, 0, location.get(0), unboxVector(value, length)));
1890 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1891 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1893 `native void GetDimensions(RWTexture2D<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height)`,
1895 func.implementation = function([texture, width, height]) {
1896 let tex = texture.loadValue();
1897 if (width.loadValue())
1898 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
1899 if (height.loadValue())
1900 height.loadValue().copyFrom(EPtr.box(tex.height), 1);
1904 `native void GetDimensions(RWTexture2D<${type}${length}>,float* ${addressSpace1} Width,float* ${addressSpace2} Height)`,
1906 func.implementation = function([texture, width, height]) {
1907 let tex = texture.loadValue();
1908 if (width.loadValue())
1909 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
1910 if (height.loadValue())
1911 height.loadValue().copyFrom(EPtr.box(tex.height), 1);
1917 `native ${type}${length} Load(RWTexture2D<${type}${length}>,int2 location)`,
1919 func.implementation = function ([texture, location], node) {
1920 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, 0, 0, location.get(1), location.get(0))));
1924 `native void Store(RWTexture2D<${type}${length}>,${type}${length},uint2 location)`,
1926 func.implementation = function ([texture, value, location], node) {
1927 checkFalse(node.origin.originString, "Texture write out of bounds", texture.loadValue().setElementChecked(0, 0, 0, location.get(1), location.get(0), unboxVector(value, length)));
1931 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1932 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1933 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1935 `native void GetDimensions(RWTexture2DArray<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Elements)`,
1937 func.implementation = function([texture, width, height, elements]) {
1938 let tex = texture.loadValue();
1939 if (width.loadValue())
1940 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
1941 if (height.loadValue())
1942 height.loadValue().copyFrom(EPtr.box(tex.height), 1);
1943 if (elements.loadValue())
1944 elements.loadValue().copyFrom(EPtr.box(tex.layerCount), 1);
1948 `native void GetDimensions(RWTexture2DArray<${type}${length}>,float* ${addressSpace1} Width,float* ${addressSpace2} Height,float* ${addressSpace3} Elements)`,
1950 func.implementation = function([texture, width, height, elements]) {
1951 let tex = texture.loadValue();
1952 if (width.loadValue())
1953 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
1954 if (height.loadValue())
1955 height.loadValue().copyFrom(EPtr.box(tex.height), 1);
1956 if (elements.loadValue())
1957 elements.loadValue().copyFrom(EPtr.box(tex.layerCount), 1);
1964 `native ${type}${length} Load(RWTexture2DArray<${type}${length}>,int3 location)`,
1966 func.implementation = function ([texture, location], node) {
1967 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(2), 0, 0, location.get(1), location.get(0))));
1971 `native void Store(RWTexture2DArray<${type}${length}>,${type}${length},uint3 location)`,
1973 func.implementation = function ([texture, value, location], node) {
1974 checkFalse(node.origin.originString, "Texture write out of bounds", texture.loadValue().setElementChecked(location.get(2), 0, 0, location.get(1), location.get(0), unboxVector(value, length)));
1978 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1979 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1980 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1982 `native void GetDimensions(RWTexture3D<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Depth)`,
1984 func.implementation = function([texture, width, height, depth]) {
1985 let tex = texture.loadValue();
1986 if (width.loadValue())
1987 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
1988 if (height.loadValue())
1989 height.loadValue().copyFrom(EPtr.box(tex.height), 1);
1990 if (depth.loadValue())
1991 depth.loadValue().copyFrom(EPtr.box(tex.depth), 1);
1995 `native void GetDimensions(RWTexture3D<${type}${length}>,float* ${addressSpace1} Width,float* ${addressSpace2} Height,float* ${addressSpace3} Depth)`,
1997 func.implementation = function([texture, width, height, depth]) {
1998 let tex = texture.loadValue();
1999 if (width.loadValue())
2000 width.loadValue().copyFrom(EPtr.box(tex.width), 1);
2001 if (height.loadValue())
2002 height.loadValue().copyFrom(EPtr.box(tex.height), 1);
2003 if (depth.loadValue())
2004 depth.loadValue().copyFrom(EPtr.box(tex.depth), 1);
2011 `native ${type}${length} Load(RWTexture3D<${type}${length}>,int3 location)`,
2013 func.implementation = function ([texture, location], node) {
2014 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, 0, location.get(2), location.get(1), location.get(0))));
2018 `native void Store(RWTexture3D<${type}${length}>,${type}${length},uint3 location)`,
2020 func.implementation = function ([texture, value, location], node) {
2021 checkFalse(node.origin.originString, "Texture write out of bounds", texture.loadValue().setElementChecked(0, 0, location.get(2), location.get(1), location.get(0), unboxVector(value, length)));
2027 for (let type of ["half", "float"]) {
2029 `native ${type} Sample(TextureDepth2D<${type}>,sampler,float2 location)`,
2031 func.implementation = function ([texture, sampler, location]) {
2032 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2033 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
2037 `native ${type} Sample(TextureDepth2D<${type}>,sampler,float2 location,int2 offset)`,
2039 func.implementation = function ([texture, sampler, location, offset]) {
2040 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2041 let deltaArray = [offset.get(0), offset.get(1), 0];
2042 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined));
2046 `native ${type} SampleCmp(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue)`,
2048 func.implementation = function ([texture, sampler, location, compareValue]) {
2049 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2050 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue()));
2054 `native ${type} SampleCmp(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue,int2 offset)`,
2056 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2057 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2058 let deltaArray = [offset.get(0), offset.get(1), 0];
2059 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, compareValue.loadValue()));
2063 `native ${type} SampleCmpLevelZero(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue)`,
2065 func.implementation = function ([texture, sampler, location, compareValue]) {
2066 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2067 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, 0, compareValue.loadValue()));
2071 `native ${type} SampleCmpLevelZero(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue,int2 offset)`,
2073 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2074 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2075 let deltaArray = [offset.get(0), offset.get(1), 0];
2076 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, 0, compareValue.loadValue()));
2080 `native ${type} SampleBias(TextureDepth2D<${type}>,sampler,float2 location,float Bias)`,
2082 func.implementation = function ([texture, sampler, location, bias]) {
2083 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2084 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, bias.loadValue(), undefined, undefined, undefined, undefined));
2088 `native ${type} SampleBias(TextureDepth2D<${type}>,sampler,float2 location,float Bias,int2 offset)`,
2090 func.implementation = function ([texture, sampler, location, bias, offset]) {
2091 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2092 let deltaArray = [offset.get(0), offset.get(1), 0];
2093 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, bias.loadValue(), undefined, undefined, undefined, undefined));
2097 `native ${type} SampleGrad(TextureDepth2D<${type}>,sampler,float2 location,float2 DDX,float2 DDY)`,
2099 func.implementation = function ([texture, sampler, location, ddx, ddy]) {
2100 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2101 let ddxArray = [ddx.get(0), ddx.get(1), 0];
2102 let ddyArray = [ddy.get(0), ddy.get(1), 0];
2103 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, ddxArray, ddyArray, undefined, undefined));
2107 `native ${type} SampleGrad(TextureDepth2D<${type}>,sampler,float2 location,float2 DDX,float2 DDY,int2 offset)`,
2109 func.implementation = function ([texture, sampler, location, ddx, ddy, offset]) {
2110 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2111 let ddxArray = [ddx.get(0), ddx.get(1), 0];
2112 let ddyArray = [ddy.get(0), ddy.get(1), 0];
2113 let deltaArray = [offset.get(0), offset.get(1), 0];
2114 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, ddxArray, ddyArray, undefined, undefined));
2118 `native ${type} SampleLevel(TextureDepth2D<${type}>,sampler,float2 location,float LOD)`,
2120 func.implementation = function ([texture, sampler, location, lod]) {
2121 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2122 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, lod.loadValue(), undefined));
2126 `native ${type} SampleLevel(TextureDepth2D<${type}>,sampler,float2 location,float LOD,int2 offset)`,
2128 func.implementation = function ([texture, sampler, location, lod, offset]) {
2129 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2130 let deltaArray = [offset.get(0), offset.get(1), 0];
2131 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, lod.loadValue(), undefined));
2135 `native ${type}4 Gather(TextureDepth2D<${type}>,sampler,float2 location)`,
2137 func.implementation = function ([texture, sampler, location]) {
2138 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2139 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
2143 `native ${type}4 Gather(TextureDepth2D<${type}>,sampler,float2 location,int2 offset)`,
2145 func.implementation = function ([texture, sampler, location, offset]) {
2146 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2147 let deltaArray = [offset.get(0), offset.get(1), 0];
2148 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
2152 `native ${type}4 GatherRed(TextureDepth2D<${type}>,sampler,float2 location)`,
2154 func.implementation = function ([texture, sampler, location]) {
2155 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2156 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
2160 `native ${type}4 GatherRed(TextureDepth2D<${type}>,sampler,float2 location,int2 offset)`,
2162 func.implementation = function ([texture, sampler, location, offset]) {
2163 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2164 let deltaArray = [offset.get(0), offset.get(1), 0];
2165 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
2169 `native ${type}4 GatherCmp(TextureDepth2D<${type}>,sampler,float2 location,float compare_value)`,
2171 func.implementation = function ([texture, sampler, location, compareValue]) {
2172 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2173 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2177 `native ${type}4 GatherCmp(TextureDepth2D<${type}>,sampler,float2 location,float compare_value,int2 offset)`,
2179 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2180 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2181 let deltaArray = [offset.get(0), offset.get(1), 0];
2182 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2186 `native ${type}4 GatherCmpRed(TextureDepth2D<${type}>,sampler,float2 location,float compare_value)`,
2188 func.implementation = function ([texture, sampler, location, compareValue]) {
2189 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2190 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2194 `native ${type}4 GatherCmpRed(TextureDepth2D<${type}>,sampler,float2 location,float compare_value,int2 offset)`,
2196 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2197 let locationArray = [location.get(0), location.get(1), 0, 1, 0];
2198 let deltaArray = [offset.get(0), offset.get(1), 0];
2199 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2203 `native ${type} Load(TextureDepth2D<${type}>,int3 location)`,
2205 func.implementation = function ([texture, location], node) {
2206 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(2), 0, location.get(1), location.get(0))));
2210 `native ${type} Load(TextureDepth2D<${type}>,int3 location,int2 offset)`,
2212 func.implementation = function ([texture, location, offset], node) {
2213 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(0, location.get(2), 0, location.get(1) + offset.get(1), location.get(0) + offset.get(0))));
2216 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
2217 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
2218 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
2220 `native void GetDimensions(TextureDepth2D<${type}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
2222 func.implementation = function ([texture, miplevel, width, height, numberOfLevels], node) {
2223 let tex = texture.loadValue();
2224 let mipID = miplevel.loadValue();
2225 if (mipID >= tex.levelCount)
2226 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
2227 if (width.loadValue())
2228 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
2229 if (height.loadValue())
2230 height.loadValue().copyFrom(EPtr.box(tex.heightAtLevel(mipID)), 1);
2231 if (numberOfLevels.loadValue())
2232 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
2239 `native ${type} Sample(TextureDepth2DArray<${type}>,sampler,float3 location)`,
2241 func.implementation = function ([texture, sampler, location]) {
2242 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2243 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
2247 `native ${type} Sample(TextureDepth2DArray<${type}>,sampler,float3 location,int2 offset)`,
2249 func.implementation = function ([texture, sampler, location, offset]) {
2250 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2251 let deltaArray = [offset.get(0), offset.get(1), 0];
2252 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined));
2256 `native ${type} SampleCmp(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue)`,
2258 func.implementation = function ([texture, sampler, location, compareValue]) {
2259 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2260 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue()));
2264 `native ${type} SampleCmp(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue,int2 offset)`,
2266 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2267 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2268 let deltaArray = [offset.get(0), offset.get(1), 0];
2269 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, compareValue.loadValue()));
2273 `native ${type} SampleCmpLevelZero(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue)`,
2275 func.implementation = function ([texture, sampler, location, compareValue]) {
2276 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2277 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, 0, compareValue.loadValue()));
2281 `native ${type} SampleCmpLevelZero(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue,int2 offset)`,
2283 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2284 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2285 let deltaArray = [offset.get(0), offset.get(1), 0];
2286 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, 0, compareValue.loadValue()));
2290 `native ${type} SampleBias(TextureDepth2DArray<${type}>,sampler,float3 location,float Bias)`,
2292 func.implementation = function ([texture, sampler, location, bias]) {
2293 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2294 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, bias.loadValue(), undefined, undefined, undefined, undefined));
2298 `native ${type} SampleBias(TextureDepth2DArray<${type}>,sampler,float3 location,float Bias,int2 offset)`,
2300 func.implementation = function ([texture, sampler, location, bias, offset]) {
2301 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2302 let deltaArray = [offset.get(0), offset.get(1), 0];
2303 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, bias.loadValue(), undefined, undefined, undefined, undefined));
2307 `native ${type} SampleGrad(TextureDepth2DArray<${type}>,sampler,float3 location,float2 DDX,float2 DDY)`,
2309 func.implementation = function ([texture, sampler, location, ddx, ddy]) {
2310 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2311 let ddxArray = [ddx.get(0), ddx.get(1), 0];
2312 let ddyArray = [ddy.get(0), ddy.get(1), 0];
2313 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, ddxArray, ddyArray, undefined, undefined));
2317 `native ${type} SampleGrad(TextureDepth2DArray<${type}>,sampler,float3 location,float2 DDX,float2 DDY,int2 offset)`,
2319 func.implementation = function ([texture, sampler, location, ddx, ddy, offset]) {
2320 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2321 let ddxArray = [ddx.get(0), ddx.get(1), 0];
2322 let ddyArray = [ddy.get(0), ddy.get(1), 0];
2323 let deltaArray = [offset.get(0), offset.get(1), 0];
2324 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, ddxArray, ddyArray, undefined, undefined));
2328 `native ${type} SampleLevel(TextureDepth2DArray<${type}>,sampler,float3 location,float LOD)`,
2330 func.implementation = function ([texture, sampler, location, lod]) {
2331 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2332 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, lod.loadValue(), undefined));
2336 `native ${type} SampleLevel(TextureDepth2DArray<${type}>,sampler,float3 location,float LOD,int2 offset)`,
2338 func.implementation = function ([texture, sampler, location, lod, offset]) {
2339 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2340 let deltaArray = [offset.get(0), offset.get(1), 0];
2341 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, lod.loadValue(), undefined));
2345 `native ${type}4 Gather(TextureDepth2DArray<${type}>,sampler,float3 location)`,
2347 func.implementation = function ([texture, sampler, location]) {
2348 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2349 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
2353 `native ${type}4 Gather(TextureDepth2DArray<${type}>,sampler,float3 location,int2 offset)`,
2355 func.implementation = function ([texture, sampler, location, offset]) {
2356 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2357 let deltaArray = [offset.get(0), offset.get(1), 0];
2358 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
2362 `native ${type}4 GatherRed(TextureDepth2DArray<${type}>,sampler,float3 location)`,
2364 func.implementation = function ([texture, sampler, location]) {
2365 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2366 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
2370 `native ${type}4 GatherRed(TextureDepth2DArray<${type}>,sampler,float3 location,int2 offset)`,
2372 func.implementation = function ([texture, sampler, location, offset]) {
2373 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2374 let deltaArray = [offset.get(0), offset.get(1), 0];
2375 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, undefined, 0));
2379 `native ${type}4 GatherCmp(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value)`,
2381 func.implementation = function ([texture, sampler, location, compareValue]) {
2382 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2383 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2387 `native ${type}4 GatherCmp(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value,int2 offset)`,
2389 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2390 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2391 let deltaArray = [offset.get(0), offset.get(1), 0];
2392 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2396 `native ${type}4 GatherCmpRed(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value)`,
2398 func.implementation = function ([texture, sampler, location, compareValue]) {
2399 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2400 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2404 `native ${type}4 GatherCmpRed(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value,int2 offset)`,
2406 func.implementation = function ([texture, sampler, location, compareValue, offset]) {
2407 let locationArray = [location.get(0), location.get(1), 0, 1, location.get(2)];
2408 let deltaArray = [offset.get(0), offset.get(1), 0];
2409 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, deltaArray, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2413 `native ${type} Load(TextureDepth2DArray<${type}>,int4 location)`,
2415 func.implementation = function ([texture, location], node) {
2416 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(3), location.get(2), 0, location.get(1), location.get(0))));
2420 `native ${type} Load(TextureDepth2DArray<${type}>,int4 location,int2 offset)`,
2422 func.implementation = function ([texture, location, offset], node) {
2423 return boxVector(checkUndefined(node.origin.originString, "Texture read out of bounds", texture.loadValue().elementChecked(location.get(3), location.get(2), 0, location.get(1) + offset.get(1), location.get(0) + offset.get(0))));
2426 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
2427 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
2428 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
2429 for (let addressSpace4 of ["thread", "threadgroup", "device"]) {
2431 `native void GetDimensions(TextureDepth2DArray<${type}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Elements,uint* ${addressSpace4} NumberOfLevels)`,
2433 func.implementation = function ([texture, miplevel, width, height, elements, numberOfLevels], node) {
2434 let tex = texture.loadValue();
2435 let mipID = miplevel.loadValue();
2436 if (mipID >= tex.levelCount)
2437 throw new WTrapError(node.origin.originString, "Reading from nonexistant mip level of texture");
2438 if (width.loadValue())
2439 width.loadValue().copyFrom(EPtr.box(tex.widthAtLevel(mipID)), 1);
2440 if (height.loadValue())
2441 height.loadValue().copyFrom(EPtr.box(tex.heightAtLevel(mipID)), 1);
2442 if (elements.loadValue())
2443 elements.loadValue().copyFrom(EPtr.box(tex.layerCount), 1);
2444 if (numberOfLevels.loadValue())
2445 numberOfLevels.loadValue().copyFrom(EPtr.box(tex.levelCount), 1);
2453 `native ${type} Sample(TextureDepthCube<${type}>,sampler,float3 location)`,
2455 func.implementation = function ([texture, sampler, location]) {
2456 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2457 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined));
2461 `native ${type} SampleCmp(TextureDepthCube<${type}>,sampler,float3 location,${type} CompareValue)`,
2463 func.implementation = function ([texture, sampler, location, compareValue]) {
2464 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2465 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue()));
2469 `native ${type} SampleCmpLevelZero(TextureDepthCube<${type}>,sampler,float3 location,${type} CompareValue)`,
2471 func.implementation = function ([texture, sampler, location, compareValue]) {
2472 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2473 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, 0, compareValue.loadValue()));
2477 `native ${type} SampleBias(TextureDepthCube<${type}>,sampler,float3 location,float Bias)`,
2479 func.implementation = function ([texture, sampler, location, bias]) {
2480 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2481 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, bias.loadValue(), undefined, undefined, undefined, undefined));
2485 `native ${type} SampleGrad(TextureDepthCube<${type}>,sampler,float3 location,float3 DDX,float3 DDY)`,
2487 func.implementation = function ([texture, sampler, location, ddx, ddy]) {
2488 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2489 let ddxArray = [ddx.get(0), ddx.get(1), ddx.get(2)];
2490 let ddyArray = [ddy.get(0), ddy.get(1), ddy.get(2)];
2491 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, ddxArray, ddyArray, undefined, undefined));
2495 `native ${type} SampleLevel(TextureDepthCube<${type}>,sampler,float3 location,float LOD)`,
2497 func.implementation = function ([texture, sampler, location, lod]) {
2498 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2499 return boxVector(sampleTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, lod.loadValue(), undefined));
2503 `native ${type}4 Gather(TextureDepthCube<${type}>,sampler,float3 location)`,
2505 func.implementation = function ([texture, sampler, location]) {
2506 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2507 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
2511 `native ${type}4 GatherRed(TextureDepthCube<${type}>,sampler,float3 location)`,
2513 func.implementation = function ([texture, sampler, location]) {
2514 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2515 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, undefined, 0));
2519 `native ${type}4 GatherCmp(TextureDepthCube<${type}>,sampler,float3 location,float compare_value)`,
2521 func.implementation = function ([texture, sampler, location, compareValue]) {
2522 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2523 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2527 `native ${type}4 GatherCmpRed(TextureDepthCube<${type}>,sampler,float3 location,float compare_value)`,
2529 func.implementation = function ([texture, sampler, location, compareValue]) {
2530 let locationArray = [location.get(0), location.get(1), location.get(2), 1, 0];
2531 return boxVector(gatherTexture(texture.loadValue(), sampler.loadValue(), locationArray, undefined, undefined, undefined, undefined, undefined, compareValue.loadValue(), 0));
2534 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
2535 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
2536 for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
2538 `native void GetDimensions(TextureDepthCube<${type}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
2540 func.implementation = function ([texture, miplevel, width, height, numberOfLevels], node) {
2541 let tex = texture.loadValue();
2542 let mipID = miplevel.loadValue();
2543 if (tex.layerCount != 6)
2544 throw new Error("Cube texture doesn't have 6 faces");
2545 if (mipID >= tex.levelCount)