[WHLSL] Allow uniform buffers to be used in the interpreter
[WebKit-https.git] / Tools / WebGPUShadingLanguageRI / Intrinsics.js
1 /*
2  * Copyright (C) 2018 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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. 
24  */
25 "use strict";
26
27 class Intrinsics {
28     constructor(nameContext)
29     {
30         this._map = new Map();
31
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.
36
37         this._map.set(
38             "native typedef void",
39             type => {
40                 this.void = type;
41                 type.size = 0;
42                 type.populateDefaultValue = () => { };
43             });
44
45         this._map.set(
46             "native typedef bool",
47             type => {
48                 this.bool = type;
49                 type.isPrimitive = true;
50                 type.size = 1;
51                 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, false);
52             });
53
54         this._map.set(
55             "native typedef uchar",
56             type => {
57                 this.uchar = type;
58                 type.isPrimitive = true;
59                 type.isInt = true;
60                 type.isNumber = true;
61                 type.isSigned = false;
62                 type.canRepresent = value => isBitwiseEquivalent(castToUchar(value), value);
63                 type.size = 1;
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};
74                 };
75             });
76
77
78             this._map.set(
79              "native typedef ushort",
80              type => {
81                  this.ushort = type;
82                  type.isPrimitive = true;
83                  type.isInt = true;
84                  type.isNumber = true;
85                  type.isSigned = false;
86                  type.canRepresent = value => isBitwiseEquivalent(castToUshort(value), value);
87                  type.size = 1;
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};
98                  };
99              });
100
101         this._map.set(
102              "native typedef uint",
103              type => {
104                  this.uint = type;
105                  type.isPrimitive = true;
106                  type.isInt = true;
107                  type.isNumber = true;
108                  type.isSigned = false;
109                  type.canRepresent = value => isBitwiseEquivalent(castToUint(value), value);
110                  type.size = 1;
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};
121                  };
122              });
123
124         this._map.set(
125              "native typedef char",
126              type => {
127                  this.char = type;
128                  type.isPrimitive = true;
129                  type.isInt = true;
130                  type.isNumber = true;
131                  type.isSigned = true;
132                  type.canRepresent = value => isBitwiseEquivalent(castToChar(value), value);
133                  type.size = 1;
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};
145                      }
146                  };
147              });
148
149         this._map.set(
150              "native typedef short",
151              type => {
152                  this.short = type;
153                  type.isPrimitive = true;
154                  type.isInt = true;
155                  type.isNumber = true;
156                  type.isSigned = true;
157                  type.canRepresent = value => isBitwiseEquivalent(castToShort(value), value);
158                  type.size = 1;
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};
170                      }
171                  };
172              });
173
174         this._map.set(
175              "native typedef int",
176              type => {
177                  this.int = type;
178                  type.isPrimitive = true;
179                  type.isInt = true;
180                  type.isNumber = true;
181                  type.isSigned = true;
182                  type.canRepresent = value => isBitwiseEquivalent(castToInt(value), value);
183                  type.size = 1;
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};
195                      }
196                  };
197              });
198
199          this._map.set(
200              "native typedef half",
201              type => {
202                  this.half = type;
203                  type.isPrimitive = true;
204                  type.size = 1;
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);
212              });
213
214          this._map.set(
215              "native typedef float",
216              type => {
217                  this.float = type;
218                  type.isPrimitive = true;
219                  type.size = 1;
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);
227              });
228
229         this._map.set(
230              "native typedef atomic_int",
231              type => {
232                  this.atomic_int = type;
233                  type.size = 1;
234                  type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
235              });
236
237         this._map.set(
238              "native typedef atomic_uint",
239              type => {
240                  this.atomic_uint = type;
241                  type.size = 1;
242                  type.populateDefaultValue = (buffer, offset) => buffer.set(offset, 0);
243              });
244
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;
250                 });
251             }
252         }
253
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;
259                     });
260                 }
261             }
262         }
263
264         this._map.set(
265             "native typedef sampler",
266             type => {
267                 this.sampler = type;
268                 type.size = 1;
269                 type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
270             });
271
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"]) {
274                 this._map.set(
275                     `native typedef ${textureType}<${typeArgument}>`,
276                     type => {
277                         this[`${textureType}<${typeArgument}>`] = type;
278                         type.size = 1;
279                         type.isTexture = true;
280                         type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
281                     });
282                 for (let i = 2; i <= 4; ++i) {
283                     this._map.set(
284                         `native typedef ${textureType}<${typeArgument}${i}>`,
285                         type => {
286                             this[`${textureType}<${typeArgument}${i}>`] = type;
287                             type.size = 1;
288                             type.isTexture = true;
289                             type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
290                         });
291                 }
292             }
293         }
294
295         for (let textureType of ["TextureDepth2D", "RWTextureDepth2D", "TextureDepth2DArray", "RWTextureDepth2DArray", "TextureDepthCube"]) {
296             for (let typeArgument of ["float", "half"]) {
297                 this._map.set(
298                     `native typedef ${textureType}<${typeArgument}>`,
299                     type => {
300                         this[`${textureType}<${typeArgument}>`] = type;
301                         type.size = 1;
302                         type.populateDefaultValue = (buffer, offset) => buffer.set(offset, {});
303                     });
304             }
305         }
306
307         for (let primitiveType of ["ushort", "uint", "char", "short", "int", "half", "float"]) {
308             this._map.set(
309                 `native operator uchar(${primitiveType})`,
310                 func => {
311                     func.implementation = ([value]) => EPtr.box(castToUchar(value.loadValue()));
312                 });
313         }
314
315         for (let primitiveType of ["uchar", "uint", "char", "short", "int", "half", "float"]) {
316             this._map.set(
317                 `native operator ushort(${primitiveType})`,
318                 func => {
319                     func.implementation = ([value]) => EPtr.box(castToUshort(value.loadValue()));
320                 });
321         }
322
323         for (let primitiveType of ["uchar", "ushort", "char", "short", "int", "half", "float"]) {
324             this._map.set(
325                 `native operator uint(${primitiveType})`,
326                 func => {
327                     func.implementation = ([value]) => EPtr.box(castToUint(value.loadValue()));
328                 });
329         }
330
331         for (let primitiveType of ["uchar", "ushort", "uint", "short", "int", "half", "float"]) {
332             this._map.set(
333                 `native operator char(${primitiveType})`,
334                 func => {
335                     func.implementation = ([value]) => EPtr.box(castToChar(value.loadValue()));
336                 });
337         }
338
339         for (let primitiveType of ["uchar", "ushort", "uint", "char", "int", "half", "float"]) {
340             this._map.set(
341                 `native operator short(${primitiveType})`,
342                 func => {
343                     func.implementation = ([value]) => EPtr.box(castToShort(value.loadValue()));
344                 });
345         }
346
347         for (let primitiveType of ["uchar", "ushort", "uint", "char", "short", "half", "float"]) {
348             this._map.set(
349                 `native operator int(${primitiveType})`,
350                 func => {
351                     func.implementation = ([value]) => EPtr.box(cast(Int32Array, value.loadValue()));
352                 });
353         }
354
355         for (let primitiveType of ["uchar", "ushort", "uint", "char", "short", "int", "float"]) {
356             this._map.set(
357                 `native operator half(${primitiveType})`,
358                 func => {
359                     func.implementation = ([value]) => EPtr.box(castToHalf(value.loadValue()));
360                 });
361         }
362
363         for (let primitiveType of ["uchar", "ushort", "uint", "char", "short", "int", "half"]) {
364             this._map.set(
365                 `native operator float(${primitiveType})`,
366                 func => {
367                     func.implementation = ([value]) => EPtr.box(castToFloat(value.loadValue()));
368                 });
369         }
370
371         this._map.set(
372             `native operator int(atomic_int)`,
373             func => {
374                 func.implementation = ([value]) => EPtr.box(value.loadValue());
375             });
376
377         this._map.set(
378             `native operator uint(atomic_uint)`,
379             func => {
380                 func.implementation = ([value]) => EPtr.box(value.loadValue());
381             });
382
383         this._map.set(
384             "native bool operator==(bool,bool)",
385             func => {
386                 func.implementation = ([left, right]) =>
387                     EPtr.box(left.loadValue() == right.loadValue());
388             });
389
390         for (let primitiveType of ["uint", "int", "float"]) {
391             this._map.set(
392                 `native bool operator==(${primitiveType},${primitiveType})`,
393                 func => {
394                     func.implementation = ([left, right]) =>
395                         EPtr.box(left.loadValue() == right.loadValue());
396                 });
397
398             this._map.set(
399                 `native bool operator<(${primitiveType},${primitiveType})`,
400                 func => {
401                     func.implementation = ([left, right]) =>
402                         EPtr.box(left.loadValue() < right.loadValue());
403                 });
404
405             this._map.set(
406                 `native bool operator<=(${primitiveType},${primitiveType})`,
407                 func => {
408                     func.implementation = ([left, right]) =>
409                         EPtr.box(left.loadValue() <= right.loadValue());
410                 });
411
412             this._map.set(
413                 `native bool operator>(${primitiveType},${primitiveType})`,
414                 func => {
415                     func.implementation = ([left, right]) =>
416                         EPtr.box(left.loadValue() > right.loadValue());
417                 });
418
419             this._map.set(
420                 `native bool operator>=(${primitiveType},${primitiveType})`,
421                 func => {
422                     func.implementation = ([left, right]) =>
423                         EPtr.box(left.loadValue() >= right.loadValue());
424                 });
425         }
426
427         this._map.set(
428             "native int operator-(int)",
429             func => {
430                 func.implementation = ([value]) =>
431                     EPtr.box(castToInt(-value.loadValue()));
432             });
433
434         this._map.set(
435             "native float operator-(float)",
436             func => {
437                 func.implementation = ([value]) =>
438                     EPtr.box(castToFloat(-value.loadValue()));
439             });
440
441         this._map.set(
442             "native int operator+(int,int)",
443             func => {
444                 func.implementation = ([left, right]) =>
445                     EPtr.box(castToInt(left.loadValue() + right.loadValue()));
446             });
447
448         this._map.set(
449             "native int operator-(int,int)",
450             func => {
451                 func.implementation = ([left, right]) =>
452                     EPtr.box(castToInt(left.loadValue() - right.loadValue()));
453             });
454
455         this._map.set(
456             "native int operator*(int,int)",
457             func => {
458                 func.implementation = ([left, right]) =>
459                     EPtr.box(castToInt(left.loadValue() * right.loadValue()));
460             });
461
462         this._map.set(
463             "native int operator/(int,int)",
464             func => {
465                 func.implementation = ([left, right]) =>
466                     EPtr.box(castToInt(left.loadValue() / right.loadValue()));
467             });
468
469         this._map.set(
470             "native uint operator+(uint,uint)",
471             func => {
472                 func.implementation = ([left, right]) =>
473                     EPtr.box(castToUint(left.loadValue() + right.loadValue()));
474             });
475
476         this._map.set(
477             "native uint operator-(uint,uint)",
478             func => {
479                 func.implementation = ([left, right]) =>
480                     EPtr.box(castToUint(left.loadValue() - right.loadValue()));
481             });
482
483         this._map.set(
484             "native uint operator*(uint,uint)",
485             func => {
486                 func.implementation = ([left, right]) =>
487                     EPtr.box(castToUint(left.loadValue() * right.loadValue()));
488             });
489
490         this._map.set(
491             "native uint operator/(uint,uint)",
492             func => {
493                 func.implementation = ([left, right]) =>
494                     EPtr.box(castToUint(left.loadValue() / right.loadValue()));
495             });
496
497         this._map.set(
498             "native float operator+(float,float)",
499             func => {
500                 func.implementation = ([left, right]) =>
501                     EPtr.box(castToFloat(left.loadValue() + right.loadValue()));
502             });
503
504         this._map.set(
505             "native float operator-(float,float)",
506             func => {
507                 func.implementation = ([left, right]) =>
508                     EPtr.box(castToFloat(left.loadValue() - right.loadValue()));
509             });
510
511         this._map.set(
512             "native float operator*(float,float)",
513             func => {
514                 func.implementation = ([left, right]) =>
515                     EPtr.box(castToFloat(left.loadValue() * right.loadValue()));
516             });
517
518         this._map.set(
519             "native float operator/(float,float)",
520             func => {
521                 func.implementation = ([left, right]) =>
522                     EPtr.box(castToFloat(left.loadValue() / right.loadValue()));
523             });
524
525         this._map.set(
526             "native int operator&(int,int)",
527             func => {
528                 func.implementation = ([left, right]) =>
529                     EPtr.box(castToInt(left.loadValue() & right.loadValue()));
530             });
531
532         this._map.set(
533             "native int operator|(int,int)",
534             func => {
535                 func.implementation = ([left, right]) =>
536                     EPtr.box(castToInt(left.loadValue() | right.loadValue()));
537             });
538
539         this._map.set(
540             "native int operator^(int,int)",
541             func => {
542                 func.implementation = ([left, right]) =>
543                     EPtr.box(castToInt(left.loadValue() ^ right.loadValue()));
544             });
545
546         this._map.set(
547             "native int operator~(int)",
548             func => {
549                 func.implementation = ([value]) => EPtr.box(castToInt(~value.loadValue()));
550             });
551
552         this._map.set(
553             "native int operator<<(int,uint)",
554             func => {
555                 func.implementation = ([left, right]) =>
556                     EPtr.box(castToInt(left.loadValue() << right.loadValue()));
557             });
558
559         this._map.set(
560             "native int operator>>(int,uint)",
561             func => {
562                 func.implementation = ([left, right]) =>
563                     EPtr.box(castToInt(left.loadValue() >> right.loadValue()));
564             });
565
566         this._map.set(
567             "native uint operator&(uint,uint)",
568             func => {
569                 func.implementation = ([left, right]) =>
570                     EPtr.box(castToUint(left.loadValue() & right.loadValue()));
571             });
572
573         this._map.set(
574             "native uint operator|(uint,uint)",
575             func => {
576                 func.implementation = ([left, right]) =>
577                     EPtr.box(castToUint(left.loadValue() | right.loadValue()));
578             });
579
580         this._map.set(
581             "native uint operator^(uint,uint)",
582             func => {
583                 func.implementation = ([left, right]) =>
584                     EPtr.box(castToUint(left.loadValue() ^ right.loadValue()));
585             });
586
587         this._map.set(
588             "native uint operator~(uint)",
589             func => {
590                 func.implementation = ([value]) => EPtr.box(castToUint(~value.loadValue()));
591             });
592
593         this._map.set(
594             "native uint operator<<(uint,uint)",
595             func => {
596                 func.implementation = ([left, right]) =>
597                     EPtr.box(castToUint(left.loadValue() << right.loadValue()));
598             });
599
600         this._map.set(
601             "native uint operator>>(uint,uint)",
602             func => {
603                 func.implementation = ([left, right]) =>
604                     EPtr.box(castToUint(left.loadValue() >>> right.loadValue()));
605             });
606
607         this._map.set(
608             "native float cos(float)",
609             func => {
610                 func.implementation = ([value]) =>
611                     EPtr.box(castToFloat(Math.cos(value.loadValue())));
612             });
613
614         this._map.set(
615             "native float sin(float)",
616             func => {
617                 func.implementation = ([value]) =>
618                     EPtr.box(castToFloat(Math.sin(value.loadValue())));
619             });
620
621         this._map.set(
622             "native float tan(float)",
623             func => {
624                 func.implementation = ([value]) =>
625                     EPtr.box(castToFloat(Math.tan(value.loadValue())));
626             });
627
628         this._map.set(
629             "native float acos(float)",
630             func => {
631                 func.implementation = ([value]) =>
632                     EPtr.box(castToFloat(Math.acos(value.loadValue())));
633             });
634
635         this._map.set(
636             "native float asin(float)",
637             func => {
638                 func.implementation = ([value]) =>
639                     EPtr.box(castToFloat(Math.asin(value.loadValue())));
640             });
641
642         this._map.set(
643             "native float atan(float)",
644             func => {
645                 func.implementation = ([value]) =>
646                     EPtr.box(castToFloat(Math.atan(value.loadValue())));
647             });
648
649         this._map.set(
650             "native float cosh(float)",
651             func => {
652                 func.implementation = ([value]) =>
653                     EPtr.box(castToFloat(Math.cosh(value.loadValue())));
654             });
655
656         this._map.set(
657             "native float sinh(float)",
658             func => {
659                 func.implementation = ([value]) =>
660                     EPtr.box(castToFloat(Math.sinh(value.loadValue())));
661             });
662
663         this._map.set(
664             "native float tanh(float)",
665             func => {
666                 func.implementation = ([value]) =>
667                     EPtr.box(castToFloat(Math.tanh(value.loadValue())));
668             });
669
670         this._map.set(
671             "native float ceil(float)",
672             func => {
673                 func.implementation = ([value]) =>
674                     EPtr.box(castToFloat(Math.ceil(value.loadValue())));
675             });
676
677         this._map.set(
678             "native float exp(float)",
679             func => {
680                 func.implementation = ([value]) =>
681                     EPtr.box(castToFloat(Math.exp(value.loadValue())));
682             });
683
684         this._map.set(
685             "native float floor(float)",
686             func => {
687                 func.implementation = ([value]) =>
688                     EPtr.box(castToFloat(Math.floor(value.loadValue())));
689             });
690
691         this._map.set(
692             "native float log(float)",
693             func => {
694                 func.implementation = ([value]) =>
695                     EPtr.box(castToFloat(Math.log(value.loadValue())));
696             });
697
698         this._map.set(
699             "native float round(float)",
700             func => {
701                 func.implementation = ([value]) =>
702                     EPtr.box(castToFloat(Math.round(value.loadValue())));
703             });
704
705         this._map.set(
706             "native float sqrt(float)",
707             func => {
708                 func.implementation = ([value]) =>
709                     EPtr.box(castToFloat(Math.sqrt(value.loadValue())));
710             });
711
712         this._map.set(
713             "native float trunc(float)",
714             func => {
715                 func.implementation = ([value]) =>
716                     EPtr.box(castToFloat(Math.trunc(value.loadValue())));
717             });
718
719         this._map.set(
720             "native fragment float ddx(float)",
721             func => {
722                 func.implementation = ([value]) => EPtr.box(0);
723             });
724
725         this._map.set(
726             "native fragment float ddy(float)",
727             func => {
728                 func.implementation = ([value]) => EPtr.box(0);
729             });
730
731         this._map.set(
732             "native float pow(float,float)",
733             func => {
734                 func.implementation = ([left, right]) =>
735                     EPtr.box(castToFloat(Math.pow(left.loadValue(), right.loadValue())));
736             });
737
738         this._map.set(
739             "native bool isfinite(float)",
740             func => {
741                 func.implementation = ([value]) =>
742                     EPtr.box(Number.isFinite(value.loadValue()));
743             });
744
745         this._map.set(
746             "native bool isinf(float)",
747             func => {
748                 func.implementation = ([value]) =>
749                     EPtr.box((value.loadValue() == Number.POSITIVE_INFINITY) || (value.loadValue() == Number.NEGATIVE_INFINITY));
750             });
751
752         this._map.set(
753             "native bool isnan(float)",
754             func => {
755                 func.implementation = ([value]) =>
756                     EPtr.box(Number.isNaN(value.loadValue()));
757             });
758
759         // FIXME: Implement this.
760         this._map.set(
761             "native bool isnormal(half)",
762             func => {
763                 func.implementation = ([value]) =>
764                     EPtr.box(isNaN(value.loadValue()));
765             });
766
767         // FIXME: Implement this.
768         this._map.set(
769             "native bool isnormal(float)",
770             func => {
771                 func.implementation = ([value]) =>
772                     EPtr.box(isNaN(value.loadValue()));
773             });
774
775         this._map.set(
776             "native float atan2(float,float)",
777             func => {
778                 func.implementation = ([left, right]) =>
779                     EPtr.box(castToFloat(Math.atan2(left.loadValue(), right.loadValue())));
780             });
781
782         this._map.set(
783             "native int asint(float)",
784             func => {
785                 func.implementation = ([value]) =>
786                     EPtr.box(bitwiseCast(Float32Array, Int32Array, value.loadValue()));
787             });
788
789         this._map.set(
790             "native uint asuint(float)",
791             func => {
792                 func.implementation = ([value]) =>
793                     EPtr.box(bitwiseCast(Float32Array, Uint32Array, value.loadValue()));
794             });
795
796         this._map.set(
797             "native float asfloat(int)",
798             func => {
799                 func.implementation = ([value]) =>
800                     EPtr.box(bitwiseCast(Int32Array, Float32Array, value.loadValue()));
801             });
802
803         this._map.set(
804             "native float asfloat(uint)",
805             func => {
806                 func.implementation = ([value]) =>
807                     EPtr.box(bitwiseCast(Uint32Array, Float32Array, value.loadValue()));
808             });
809
810         // FIXME: Implement this.
811         this._map.set(
812             "native float f16tof32(uint)",
813             func => {
814                 func.implementation = ([value]) =>
815                     EPtr.box(0);
816             });
817
818         // FIXME: Implement this.
819         this._map.set(
820             "native uint f32tof16(float)",
821             func => {
822                 func.implementation = ([value]) =>
823                     EPtr.box(0);
824             });
825
826         this._map.set(
827             "native compute void AllMemoryBarrierWithGroupSync()",
828             func => {
829                 func.implementation = function() {};
830             });
831
832         this._map.set(
833             "native compute void DeviceMemoryBarrierWithGroupSync()",
834             func => {
835                 func.implementation = function() {};
836             });
837
838         this._map.set(
839             "native compute void GroupMemoryBarrierWithGroupSync()",
840             func => {
841                 func.implementation = function() {};
842             });
843
844         for (let nativeVectorTypeName of allVectorTypeNames()) {
845             this._map.set(`native typedef ${nativeVectorTypeName}`, type => {
846                 type.isPrimitive = true;
847             });
848         }
849
850         for (let getter of BuiltinVectorGetter.functions())
851             this._map.set(getter.toString(), func => getter.instantiateImplementation(func));
852
853         for (let setter of BuiltinVectorSetter.functions())
854             this._map.set(setter.toString(), func => setter.instantiateImplementation(func));
855
856         for (let getter of BuiltinMatrixGetter.functions())
857             this._map.set(getter.toString(), func => getter.instantiateImplementation(func));
858
859         for (let setter of BuiltinMatrixSetter.functions())
860             this._map.set(setter.toString(), func => setter.instantiateImplementation(func));
861
862         for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
863             for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
864                 this._map.set(
865                     `native void InterlockedAdd(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
866                     func => {
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);
876                         }
877                     });
878
879                 this._map.set(
880                     `native void InterlockedAdd(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
881                     func => {
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);
891                         }
892                     });
893
894                 this._map.set(
895                     `native void InterlockedAnd(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
896                     func => {
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);
906                         }
907                     });
908
909                 this._map.set(
910                     `native void InterlockedAnd(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
911                     func => {
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);
921                         }
922                     });
923
924                 this._map.set(
925                     `native void InterlockedExchange(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
926                     func => {
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);
935                         }
936                     });
937
938                 this._map.set(
939                     `native void InterlockedExchange(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
940                     func => {
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);
949                         }
950                     });
951
952                 this._map.set(
953                     `native void InterlockedMax(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
954                     func => {
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);
964                         }
965                     });
966
967                 this._map.set(
968                     `native void InterlockedMax(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
969                     func => {
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);
979                         }
980                     });
981
982                 this._map.set(
983                     `native void InterlockedMin(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
984                     func => {
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);
994                         }
995                     });
996
997                 this._map.set(
998                     `native void InterlockedMin(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
999                     func => {
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);
1009                         }
1010                     });
1011
1012                 this._map.set(
1013                     `native void InterlockedOr(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
1014                     func => {
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);
1024                         }
1025                     });
1026
1027                 this._map.set(
1028                     `native void InterlockedOr(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
1029                     func => {
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);
1039                         }
1040                     });
1041
1042                 this._map.set(
1043                     `native void InterlockedXor(atomic_uint* ${addressSpace1},uint,uint* ${addressSpace2})`,
1044                     func => {
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);
1054                         }
1055                     });
1056
1057                 this._map.set(
1058                     `native void InterlockedXor(atomic_int* ${addressSpace1},int,int* ${addressSpace2})`,
1059                     func => {
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);
1069                         }
1070                     });
1071
1072                 this._map.set(
1073                     `native void InterlockedCompareExchange(atomic_uint* ${addressSpace1},uint,uint,uint* ${addressSpace2})`,
1074                     func => {
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();
1081                             if (a == b)
1082                                 atomic.loadValue().copyFrom(EPtr.box(c), 1);
1083                             if (originalValue.loadValue())
1084                                 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1085                         }
1086                     });
1087
1088                 this._map.set(
1089                     `native void InterlockedCompareExchange(atomic_int* ${addressSpace1},int,int,int* ${addressSpace2})`,
1090                     func => {
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();
1097                             if (a == b)
1098                                 atomic.loadValue().copyFrom(EPtr.box(c), 1);
1099                             if (originalValue.loadValue())
1100                                 originalValue.loadValue().copyFrom(EPtr.box(a), 1);
1101                         }
1102                     });
1103             }
1104         }
1105
1106         function checkUndefined(origin, explanation, value)
1107         {
1108             if (value == undefined)
1109                 throw new WTrapError(origin, "Texture read out of bounds");
1110             return value;
1111         }
1112
1113         function checkFalse(origin, explanation, value)
1114         {
1115             if (value == false)
1116                 throw new WTrapError(origin, "Texture store out of bounds");
1117         }
1118
1119         function boxVector(a)
1120         {
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]);
1125                 return result;
1126             } else
1127                 return EPtr.box(a);
1128         }
1129
1130         function unboxVector(a, length)
1131         {
1132             if (length != "") {
1133                 length = Number.parseInt(length);
1134                 let result = [];
1135                 for (let i = 0; i < length; ++i)
1136                     result.push(a.get(i));
1137                 return result;
1138             } else
1139                 return a.loadValue();
1140         }
1141
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;
1145                 this._map.set(
1146                     `native ${type}${length} Sample(Texture1D<${type}${length}>,sampler,float location)`,
1147                     func => {
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));
1151                         }
1152                     });
1153                 this._map.set(
1154                     `native ${type}${length} Sample(Texture1D<${type}${length}>,sampler,float location,int offset)`,
1155                     func => {
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));
1160                         }
1161                     });
1162                 this._map.set(
1163                     `native ${type}${length} Load(Texture1D<${type}${length}>,int2 location)`,
1164                     func => {
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))));
1167                         }
1168                     });
1169                 this._map.set(
1170                     `native ${type}${length} Load(Texture1D<${type}${length}>,int2 location,int offset)`,
1171                     func => {
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())));
1174                         }
1175                     });
1176                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1177                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1178                         this._map.set(
1179                             `native void GetDimensions(Texture1D<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} NumberOfLevels)`,
1180                             func => {
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);
1190                                 }
1191                             });
1192                     }
1193                 }
1194
1195                 this._map.set(
1196                     `native ${type}${length} Sample(Texture1DArray<${type}${length}>,sampler,float2 location)`,
1197                     func => {
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));
1201                         }
1202                     });
1203                 this._map.set(
1204                     `native ${type}${length} Sample(Texture1DArray<${type}${length}>,sampler,float2 location,int offset)`,
1205                     func => {
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));
1210                         }
1211                     });
1212                 this._map.set(
1213                     `native ${type}${length} Load(Texture1DArray<${type}${length}>,int3 location)`,
1214                     func => {
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))));
1217                         }
1218                     });
1219                 this._map.set(
1220                     `native ${type}${length} Load(Texture1DArray<${type}${length}>,int3 location,int offset)`,
1221                     func => {
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())));
1224                         }
1225                     });
1226                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1227                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1228                         for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1229                             this._map.set(
1230                                 `native void GetDimensions(Texture1DArray<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Elements,uint* ${addressSpace3} NumberOfLevels)`,
1231                                 func => {
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);
1243                                     }
1244                                 });
1245                         }
1246                     }
1247                 }
1248
1249                 this._map.set(
1250                     `native ${type}${length} Sample(Texture2D<${type}${length}>,sampler,float2 location)`,
1251                     func => {
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));
1255                         }
1256                     });
1257                 this._map.set(
1258                     `native ${type}${length} Sample(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1259                     func => {
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));
1264                         }
1265                     });
1266                 this._map.set(
1267                     `native ${type}${length} SampleBias(Texture2D<${type}${length}>,sampler,float2 location,float Bias)`,
1268                     func => {
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));
1272                         }
1273                     });
1274                 this._map.set(
1275                     `native ${type}${length} SampleBias(Texture2D<${type}${length}>,sampler,float2 location,float Bias,int2 offset)`,
1276                     func => {
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));
1281                         }
1282                     });
1283                 this._map.set(
1284                     `native ${type}${length} SampleGrad(Texture2D<${type}${length}>,sampler,float2 location,float2 DDX,float2 DDY)`,
1285                     func => {
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));
1291                         }
1292                     });
1293                 this._map.set(
1294                     `native ${type}${length} SampleGrad(Texture2D<${type}${length}>,sampler,float2 location,float2 DDX,float2 DDY,int2 offset)`,
1295                     func => {
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));
1302                         }
1303                     });
1304                 this._map.set(
1305                     `native ${type}${length} SampleLevel(Texture2D<${type}${length}>,sampler,float2 location,float LOD)`,
1306                     func => {
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));
1310                         }
1311                     });
1312                 this._map.set(
1313                     `native ${type}${length} SampleLevel(Texture2D<${type}${length}>,sampler,float2 location,float LOD,int2 offset)`,
1314                     func => {
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));
1319                         }
1320                     });
1321                 this._map.set(
1322                     `native ${type}4 Gather(Texture2D<${type}${length}>,sampler,float2 location)`,
1323                     func => {
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));
1327                         }
1328                     });
1329                 this._map.set(
1330                     `native ${type}4 Gather(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1331                     func => {
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));
1336                         }
1337                     });
1338                 this._map.set(
1339                     `native ${type}4 GatherRed(Texture2D<${type}${length}>,sampler,float2 location)`,
1340                     func => {
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));
1344                         }
1345                     });
1346                 this._map.set(
1347                     `native ${type}4 GatherRed(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1348                     func => {
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));
1353                         }
1354                     });
1355                 if (length == "2" || length == "3" || length == "4") {
1356                     this._map.set(
1357                         `native ${type}4 GatherGreen(Texture2D<${type}${length}>,sampler,float2 location)`,
1358                         func => {
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));
1362                             }
1363                         });
1364                     this._map.set(
1365                         `native ${type}4 GatherGreen(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1366                         func => {
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));
1371                             }
1372                         });
1373                     if (length == "3" || length == "4") {
1374                         this._map.set(
1375                             `native ${type}4 GatherBlue(Texture2D<${type}${length}>,sampler,float2 location)`,
1376                             func => {
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));
1380                                 }
1381                             });
1382                         this._map.set(
1383                             `native ${type}4 GatherBlue(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1384                             func => {
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));
1389                                 }
1390                             });
1391                         if (length == "4") {
1392                             this._map.set(
1393                                 `native ${type}4 GatherAlpha(Texture2D<${type}${length}>,sampler,float2 location)`,
1394                                 func => {
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));
1398                                     }
1399                                 });
1400                             this._map.set(
1401                                 `native ${type}4 GatherAlpha(Texture2D<${type}${length}>,sampler,float2 location,int2 offset)`,
1402                                 func => {
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));
1407                                     }
1408                                 });
1409                         }
1410                     }
1411                 }
1412                 this._map.set(
1413                     `native ${type}${length} Load(Texture2D<${type}${length}>,int3 location)`,
1414                     func => {
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))));
1417                         }
1418                     });
1419                 this._map.set(
1420                     `native ${type}${length} Load(Texture2D<${type}${length}>,int3 location,int2 offset)`,
1421                     func => {
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))));
1424                         }
1425                     });
1426                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1427                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1428                         for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1429                             this._map.set(
1430                                 `native void GetDimensions(Texture2D<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
1431                                 func => {
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);
1443                                     }
1444                                 });
1445                         }
1446                     }
1447                 }
1448
1449                 this._map.set(
1450                     `native ${type}${length} Sample(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1451                     func => {
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));
1455                         }
1456                     });
1457                 this._map.set(
1458                     `native ${type}${length} Sample(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1459                     func => {
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));
1464                         }
1465                     });
1466                 this._map.set(
1467                     `native ${type}${length} SampleBias(Texture2DArray<${type}${length}>,sampler,float3 location,float Bias)`,
1468                     func => {
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));
1472                         }
1473                     });
1474                 this._map.set(
1475                     `native ${type}${length} SampleBias(Texture2DArray<${type}${length}>,sampler,float3 location,float Bias,int2 offset)`,
1476                     func => {
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));
1481                         }
1482                     });
1483                 this._map.set(
1484                     `native ${type}${length} SampleGrad(Texture2DArray<${type}${length}>,sampler,float3 location,float2 DDX,float2 DDY)`,
1485                     func => {
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));
1491                         }
1492                     });
1493                 this._map.set(
1494                     `native ${type}${length} SampleGrad(Texture2DArray<${type}${length}>,sampler,float3 location,float2 DDX,float2 DDY,int2 offset)`,
1495                     func => {
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));
1502                         }
1503                     });
1504                 this._map.set(
1505                     `native ${type}${length} SampleLevel(Texture2DArray<${type}${length}>,sampler,float3 location,float LOD)`,
1506                     func => {
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));
1510                         }
1511                     });
1512                 this._map.set(
1513                     `native ${type}${length} SampleLevel(Texture2DArray<${type}${length}>,sampler,float3 location,float LOD,int2 offset)`,
1514                     func => {
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));
1519                         }
1520                     });
1521                 this._map.set(
1522                     `native ${type}4 Gather(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1523                     func => {
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));
1527                         }
1528                     });
1529                 this._map.set(
1530                     `native ${type}4 Gather(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1531                     func => {
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));
1536                         }
1537                     });
1538                 this._map.set(
1539                     `native ${type}4 GatherRed(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1540                     func => {
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));
1544                         }
1545                     });
1546                 this._map.set(
1547                     `native ${type}4 GatherRed(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1548                     func => {
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));
1553                         }
1554                     });
1555                 if (length == "2" || length == "3" || length == "4") {
1556                     this._map.set(
1557                         `native ${type}4 GatherGreen(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1558                         func => {
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));
1562                             }
1563                         });
1564                     this._map.set(
1565                         `native ${type}4 GatherGreen(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1566                         func => {
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));
1571                             }
1572                         });
1573                     if (length == "3" || length == "4") {
1574                         this._map.set(
1575                             `native ${type}4 GatherBlue(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1576                             func => {
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));
1580                                 }
1581                             });
1582                         this._map.set(
1583                             `native ${type}4 GatherBlue(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1584                             func => {
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));
1589                                 }
1590                             });
1591                         if (length == "4") {
1592                             this._map.set(
1593                                 `native ${type}4 GatherAlpha(Texture2DArray<${type}${length}>,sampler,float3 location)`,
1594                                 func => {
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));
1598                                     }
1599                                 });
1600                             this._map.set(
1601                                 `native ${type}4 GatherAlpha(Texture2DArray<${type}${length}>,sampler,float3 location,int2 offset)`,
1602                                 func => {
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));
1607                                     }
1608                                 });
1609                         }
1610                     }
1611                 }
1612                 this._map.set(
1613                     `native ${type}${length} Load(Texture2DArray<${type}${length}>,int4 location)`,
1614                     func => {
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))));
1617                         }
1618                     });
1619                 this._map.set(
1620                     `native ${type}${length} Load(Texture2DArray<${type}${length}>,int4 location,int2 offset)`,
1621                     func => {
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))));
1624                         }
1625                     });
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"]) {
1630                                 this._map.set(
1631                                     `native void GetDimensions(Texture2DArray<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Elements,uint* ${addressSpace4} NumberOfLevels)`,
1632                                     func => {
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);
1646                                         }
1647                                     });
1648                             }
1649                         }
1650                     }
1651                 }
1652
1653                 this._map.set(
1654                     `native ${type}${length} Sample(Texture3D<${type}${length}>,sampler,float3 location)`,
1655                     func => {
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));
1659                         }
1660                     });
1661                 this._map.set(
1662                     `native ${type}${length} Sample(Texture3D<${type}${length}>,sampler,float3 location,int3 offset)`,
1663                     func => {
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));
1668                         }
1669                     });
1670                 this._map.set(
1671                     `native ${type}${length} Load(Texture3D<${type}${length}>,int4 location)`,
1672                     func => {
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))));
1675                         }
1676                     });
1677                 this._map.set(
1678                     `native ${type}${length} Load(Texture3D<${type}${length}>,int4 location,int3 offset)`,
1679                     func => {
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))));
1682                         }
1683                     });
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"]) {
1688                                 this._map.set(
1689                                     `native void GetDimensions(Texture3D<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Depth,uint* ${addressSpace4} NumberOfLevels)`,
1690                                     func => {
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);
1704                                         }
1705                                     });
1706                             }
1707                         }
1708                     }
1709                 }
1710
1711                 this._map.set(
1712                     `native ${type}${length} Sample(TextureCube<${type}${length}>,sampler,float3 location)`,
1713                     func => {
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));
1717                         }
1718                     });
1719                 this._map.set(
1720                     `native ${type}${length} SampleBias(TextureCube<${type}${length}>,sampler,float3 location,float Bias)`,
1721                     func => {
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));
1725                         }
1726                     });
1727                 this._map.set(
1728                     `native ${type}${length} SampleGrad(TextureCube<${type}${length}>,sampler,float3 location,float3 DDX,float3 DDY)`,
1729                     func => {
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));
1735                         }
1736                     });
1737                 this._map.set(
1738                     `native ${type}${length} SampleLevel(TextureCube<${type}${length}>,sampler,float3 location,float LOD)`,
1739                     func => {
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));
1743                         }
1744                     });
1745                 this._map.set(
1746                     `native ${type}4 Gather(TextureCube<${type}${length}>,sampler,float3 location)`,
1747                     func => {
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));
1751                         }
1752                     });
1753                 this._map.set(
1754                     `native ${type}4 GatherRed(TextureCube<${type}${length}>,sampler,float3 location)`,
1755                     func => {
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));
1759                         }
1760                     });
1761                 if (length == "2" || length == "3" || length == "4") {
1762                     this._map.set(
1763                         `native ${type}4 GatherGreen(TextureCube<${type}${length}>,sampler,float3 location)`,
1764                         func => {
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));
1768                             }
1769                         });
1770                     if (length == "3" || length == "4") {
1771                         this._map.set(
1772                             `native ${type}4 GatherBlue(TextureCube<${type}${length}>,sampler,float3 location)`,
1773                             func => {
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));
1777                                 }
1778                             });
1779                         if (length == "4") {
1780                             this._map.set(
1781                                 `native ${type}4 GatherAlpha(TextureCube<${type}${length}>,sampler,float3 location)`,
1782                                 func => {
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));
1786                                     }
1787                                 });
1788                         }
1789                     }
1790                 }
1791                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1792                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1793                         for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1794                             this._map.set(
1795                                 `native void GetDimensions(TextureCube<${type}${length}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
1796                                 func => {
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);
1810                                     }
1811                                 });
1812                         }
1813                     }
1814                 }
1815
1816                 for (let addressSpace of ["thread", "threadgroup", "device"]) {
1817                     this._map.set(
1818                         `native void GetDimensions(RWTexture1D<${type}${length}>,uint* ${addressSpace} Width)`,
1819                         func => {
1820                             func.implementation = function([texture, width]) {
1821                                 if (width.loadValue())
1822                                     width.loadValue().copyFrom(EPtr.box(texture.loadValue().width), 1);
1823                             }
1824                         });
1825                     this._map.set(
1826                         `native void GetDimensions(RWTexture1D<${type}${length}>,float* ${addressSpace} Width)`,
1827                         func => {
1828                             func.implementation = function([texture, width]) {
1829                                 if (width.loadValue())
1830                                     width.loadValue().copyFrom(EPtr.box(texture.loadValue().width), 1);
1831                             }
1832                         });
1833                 }
1834                 this._map.set(
1835                     `native ${type}${length} Load(RWTexture1D<${type}${length}>,int location)`,
1836                     func => {
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())));
1839                         }
1840                     });
1841                 this._map.set(
1842                     `native void Store(RWTexture1D<${type}${length}>,${type}${length},uint location)`,
1843                     func => {
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)));
1846                         }
1847                     });
1848
1849                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1850                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1851                         this._map.set(
1852                             `native void GetDimensions(RWTexture1DArray<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Elements)`,
1853                             func => {
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);
1860                                 }
1861                             });
1862                         this._map.set(
1863                             `native void GetDimensions(RWTexture1DArray<${type}${length}>,float* ${addressSpace1} Width,uint* ${addressSpace2} Elements)`,
1864                             func => {
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);
1871                                 }
1872                             });
1873                     }
1874                 }
1875                 this._map.set(
1876                     `native ${type}${length} Load(RWTexture1DArray<${type}${length}>,int2 location)`,
1877                     func => {
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))));
1880                         }
1881                     });
1882                 this._map.set(
1883                     `native void Store(RWTexture1DArray<${type}${length}>,${type}${length},uint2 location)`,
1884                     func => {
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)));
1887                         }
1888                     });
1889
1890                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1891                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1892                         this._map.set(
1893                             `native void GetDimensions(RWTexture2D<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height)`,
1894                             func => {
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);
1901                                 }
1902                             });
1903                         this._map.set(
1904                             `native void GetDimensions(RWTexture2D<${type}${length}>,float* ${addressSpace1} Width,float* ${addressSpace2} Height)`,
1905                             func => {
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);
1912                                 }
1913                             });
1914                     }
1915                 }
1916                 this._map.set(
1917                     `native ${type}${length} Load(RWTexture2D<${type}${length}>,int2 location)`,
1918                     func => {
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))));
1921                         }
1922                     });
1923                 this._map.set(
1924                     `native void Store(RWTexture2D<${type}${length}>,${type}${length},uint2 location)`,
1925                     func => {
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)));
1928                         }
1929                     });
1930
1931                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1932                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1933                         for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1934                             this._map.set(
1935                                 `native void GetDimensions(RWTexture2DArray<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Elements)`,
1936                                 func => {
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);
1945                                     }
1946                                 });
1947                             this._map.set(
1948                                 `native void GetDimensions(RWTexture2DArray<${type}${length}>,float* ${addressSpace1} Width,float* ${addressSpace2} Height,float* ${addressSpace3} Elements)`,
1949                                 func => {
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);
1958                                     }
1959                                 });
1960                         }
1961                     }
1962                 }
1963                 this._map.set(
1964                     `native ${type}${length} Load(RWTexture2DArray<${type}${length}>,int3 location)`,
1965                     func => {
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))));
1968                         }
1969                     });
1970                 this._map.set(
1971                     `native void Store(RWTexture2DArray<${type}${length}>,${type}${length},uint3 location)`,
1972                     func => {
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)));
1975                         }
1976                     });
1977
1978                 for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
1979                     for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
1980                         for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
1981                              this._map.set(
1982                                 `native void GetDimensions(RWTexture3D<${type}${length}>,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Depth)`,
1983                                 func => {
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);
1992                                     }
1993                                 });
1994                             this._map.set(
1995                                 `native void GetDimensions(RWTexture3D<${type}${length}>,float* ${addressSpace1} Width,float* ${addressSpace2} Height,float* ${addressSpace3} Depth)`,
1996                                 func => {
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);
2005                                     }
2006                                 });
2007                         }
2008                     }
2009                 }
2010                 this._map.set(
2011                     `native ${type}${length} Load(RWTexture3D<${type}${length}>,int3 location)`,
2012                     func => {
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))));
2015                         }
2016                     });
2017                 this._map.set(
2018                     `native void Store(RWTexture3D<${type}${length}>,${type}${length},uint3 location)`,
2019                     func => {
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)));
2022                         }
2023                     });
2024             }
2025         }
2026
2027         for (let type of ["half", "float"]) {
2028             this._map.set(
2029                 `native ${type} Sample(TextureDepth2D<${type}>,sampler,float2 location)`,
2030                 func => {
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));
2034                     }
2035                 });
2036             this._map.set(
2037                 `native ${type} Sample(TextureDepth2D<${type}>,sampler,float2 location,int2 offset)`,
2038                 func => {
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));
2043                     }
2044                 });
2045             this._map.set(
2046                 `native ${type} SampleCmp(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue)`,
2047                 func => {
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()));
2051                     }
2052                 });
2053             this._map.set(
2054                 `native ${type} SampleCmp(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue,int2 offset)`,
2055                 func => {
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()));
2060                     }
2061                 });
2062             this._map.set(
2063                 `native ${type} SampleCmpLevelZero(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue)`,
2064                 func => {
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()));
2068                     }
2069                 });
2070             this._map.set(
2071                 `native ${type} SampleCmpLevelZero(TextureDepth2D<${type}>,sampler,float2 location,${type} CompareValue,int2 offset)`,
2072                 func => {
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()));
2077                     }
2078                 });
2079             this._map.set(
2080                 `native ${type} SampleBias(TextureDepth2D<${type}>,sampler,float2 location,float Bias)`,
2081                 func => {
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));
2085                     }
2086                 });
2087             this._map.set(
2088                 `native ${type} SampleBias(TextureDepth2D<${type}>,sampler,float2 location,float Bias,int2 offset)`,
2089                 func => {
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));
2094                     }
2095                 });
2096             this._map.set(
2097                 `native ${type} SampleGrad(TextureDepth2D<${type}>,sampler,float2 location,float2 DDX,float2 DDY)`,
2098                 func => {
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));
2104                     }
2105                 });
2106             this._map.set(
2107                 `native ${type} SampleGrad(TextureDepth2D<${type}>,sampler,float2 location,float2 DDX,float2 DDY,int2 offset)`,
2108                 func => {
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));
2115                     }
2116                 });
2117             this._map.set(
2118                 `native ${type} SampleLevel(TextureDepth2D<${type}>,sampler,float2 location,float LOD)`,
2119                 func => {
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));
2123                     }
2124                 });
2125             this._map.set(
2126                 `native ${type} SampleLevel(TextureDepth2D<${type}>,sampler,float2 location,float LOD,int2 offset)`,
2127                 func => {
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));
2132                     }
2133                 });
2134             this._map.set(
2135                 `native ${type}4 Gather(TextureDepth2D<${type}>,sampler,float2 location)`,
2136                 func => {
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));
2140                     }
2141                 });
2142             this._map.set(
2143                 `native ${type}4 Gather(TextureDepth2D<${type}>,sampler,float2 location,int2 offset)`,
2144                 func => {
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));
2149                     }
2150                 });
2151             this._map.set(
2152                 `native ${type}4 GatherRed(TextureDepth2D<${type}>,sampler,float2 location)`,
2153                 func => {
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));
2157                     }
2158                 });
2159             this._map.set(
2160                 `native ${type}4 GatherRed(TextureDepth2D<${type}>,sampler,float2 location,int2 offset)`,
2161                 func => {
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));
2166                     }
2167                 });
2168             this._map.set(
2169                 `native ${type}4 GatherCmp(TextureDepth2D<${type}>,sampler,float2 location,float compare_value)`,
2170                 func => {
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));
2174                     }
2175                 });
2176             this._map.set(
2177                 `native ${type}4 GatherCmp(TextureDepth2D<${type}>,sampler,float2 location,float compare_value,int2 offset)`,
2178                 func => {
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));
2183                     }
2184                 });
2185             this._map.set(
2186                 `native ${type}4 GatherCmpRed(TextureDepth2D<${type}>,sampler,float2 location,float compare_value)`,
2187                 func => {
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));
2191                     }
2192                 });
2193             this._map.set(
2194                 `native ${type}4 GatherCmpRed(TextureDepth2D<${type}>,sampler,float2 location,float compare_value,int2 offset)`,
2195                 func => {
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));
2200                     }
2201                 });
2202             this._map.set(
2203                 `native ${type} Load(TextureDepth2D<${type}>,int3 location)`,
2204                 func => {
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))));
2207                     }
2208                 });
2209             this._map.set(
2210                 `native ${type} Load(TextureDepth2D<${type}>,int3 location,int2 offset)`,
2211                 func => {
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))));
2214                     }
2215                 });
2216             for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
2217                 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
2218                     for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
2219                         this._map.set(
2220                             `native void GetDimensions(TextureDepth2D<${type}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
2221                             func => {
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);
2233                                 }
2234                             });
2235                     }
2236                 }
2237             }
2238             this._map.set(
2239                 `native ${type} Sample(TextureDepth2DArray<${type}>,sampler,float3 location)`,
2240                 func => {
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));
2244                     }
2245                 });
2246             this._map.set(
2247                 `native ${type} Sample(TextureDepth2DArray<${type}>,sampler,float3 location,int2 offset)`,
2248                 func => {
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));
2253                     }
2254                 });
2255             this._map.set(
2256                 `native ${type} SampleCmp(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue)`,
2257                 func => {
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()));
2261                     }
2262                 });
2263             this._map.set(
2264                 `native ${type} SampleCmp(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue,int2 offset)`,
2265                 func => {
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()));
2270                     }
2271                 });
2272             this._map.set(
2273                 `native ${type} SampleCmpLevelZero(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue)`,
2274                 func => {
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()));
2278                     }
2279                 });
2280             this._map.set(
2281                 `native ${type} SampleCmpLevelZero(TextureDepth2DArray<${type}>,sampler,float3 location,${type} CompareValue,int2 offset)`,
2282                 func => {
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()));
2287                     }
2288                 });
2289             this._map.set(
2290                 `native ${type} SampleBias(TextureDepth2DArray<${type}>,sampler,float3 location,float Bias)`,
2291                 func => {
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));
2295                     }
2296                 });
2297             this._map.set(
2298                 `native ${type} SampleBias(TextureDepth2DArray<${type}>,sampler,float3 location,float Bias,int2 offset)`,
2299                 func => {
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));
2304                     }
2305                 });
2306             this._map.set(
2307                 `native ${type} SampleGrad(TextureDepth2DArray<${type}>,sampler,float3 location,float2 DDX,float2 DDY)`,
2308                 func => {
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));
2314                     }
2315                 });
2316             this._map.set(
2317                 `native ${type} SampleGrad(TextureDepth2DArray<${type}>,sampler,float3 location,float2 DDX,float2 DDY,int2 offset)`,
2318                 func => {
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));
2325                     }
2326                 });
2327             this._map.set(
2328                 `native ${type} SampleLevel(TextureDepth2DArray<${type}>,sampler,float3 location,float LOD)`,
2329                 func => {
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));
2333                     }
2334                 });
2335             this._map.set(
2336                 `native ${type} SampleLevel(TextureDepth2DArray<${type}>,sampler,float3 location,float LOD,int2 offset)`,
2337                 func => {
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));
2342                     }
2343                 });
2344             this._map.set(
2345                 `native ${type}4 Gather(TextureDepth2DArray<${type}>,sampler,float3 location)`,
2346                 func => {
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));
2350                     }
2351                 });
2352             this._map.set(
2353                 `native ${type}4 Gather(TextureDepth2DArray<${type}>,sampler,float3 location,int2 offset)`,
2354                 func => {
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));
2359                     }
2360                 });
2361             this._map.set(
2362                 `native ${type}4 GatherRed(TextureDepth2DArray<${type}>,sampler,float3 location)`,
2363                 func => {
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));
2367                     }
2368                 });
2369             this._map.set(
2370                 `native ${type}4 GatherRed(TextureDepth2DArray<${type}>,sampler,float3 location,int2 offset)`,
2371                 func => {
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));
2376                     }
2377                 });
2378             this._map.set(
2379                 `native ${type}4 GatherCmp(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value)`,
2380                 func => {
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));
2384                     }
2385                 });
2386             this._map.set(
2387                 `native ${type}4 GatherCmp(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value,int2 offset)`,
2388                 func => {
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));
2393                     }
2394                 });
2395             this._map.set(
2396                 `native ${type}4 GatherCmpRed(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value)`,
2397                 func => {
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));
2401                     }
2402                 });
2403             this._map.set(
2404                 `native ${type}4 GatherCmpRed(TextureDepth2DArray<${type}>,sampler,float3 location,float compare_value,int2 offset)`,
2405                 func => {
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));
2410                     }
2411                 });
2412             this._map.set(
2413                 `native ${type} Load(TextureDepth2DArray<${type}>,int4 location)`,
2414                 func => {
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))));
2417                     }
2418                 });
2419             this._map.set(
2420                 `native ${type} Load(TextureDepth2DArray<${type}>,int4 location,int2 offset)`,
2421                 func => {
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))));
2424                     }
2425                 });
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"]) {
2430                             this._map.set(
2431                                 `native void GetDimensions(TextureDepth2DArray<${type}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} Elements,uint* ${addressSpace4} NumberOfLevels)`,
2432                                 func => {
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);
2446                                     }
2447                                 });
2448                         }
2449                     }
2450                 }
2451             }
2452             this._map.set(
2453                 `native ${type} Sample(TextureDepthCube<${type}>,sampler,float3 location)`,
2454                 func => {
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));
2458                     }
2459                 });
2460             this._map.set(
2461                 `native ${type} SampleCmp(TextureDepthCube<${type}>,sampler,float3 location,${type} CompareValue)`,
2462                 func => {
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()));
2466                     }
2467                 });
2468             this._map.set(
2469                 `native ${type} SampleCmpLevelZero(TextureDepthCube<${type}>,sampler,float3 location,${type} CompareValue)`,
2470                 func => {
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()));
2474                     }
2475                 });
2476             this._map.set(
2477                 `native ${type} SampleBias(TextureDepthCube<${type}>,sampler,float3 location,float Bias)`,
2478                 func => {
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));
2482                     }
2483                 });
2484             this._map.set(
2485                 `native ${type} SampleGrad(TextureDepthCube<${type}>,sampler,float3 location,float3 DDX,float3 DDY)`,
2486                 func => {
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));
2492                     }
2493                 });
2494             this._map.set(
2495                 `native ${type} SampleLevel(TextureDepthCube<${type}>,sampler,float3 location,float LOD)`,
2496                 func => {
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));
2500                     }
2501                 });
2502             this._map.set(
2503                 `native ${type}4 Gather(TextureDepthCube<${type}>,sampler,float3 location)`,
2504                 func => {
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));
2508                     }
2509                 });
2510             this._map.set(
2511                 `native ${type}4 GatherRed(TextureDepthCube<${type}>,sampler,float3 location)`,
2512                 func => {
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));
2516                     }
2517                 });
2518             this._map.set(
2519                 `native ${type}4 GatherCmp(TextureDepthCube<${type}>,sampler,float3 location,float compare_value)`,
2520                 func => {
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));
2524                     }
2525                 });
2526             this._map.set(
2527                 `native ${type}4 GatherCmpRed(TextureDepthCube<${type}>,sampler,float3 location,float compare_value)`,
2528                 func => {
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));
2532                     }
2533                 });
2534             for (let addressSpace1 of ["thread", "threadgroup", "device"]) {
2535                 for (let addressSpace2 of ["thread", "threadgroup", "device"]) {
2536                     for (let addressSpace3 of ["thread", "threadgroup", "device"]) {
2537                         this._map.set(
2538                             `native void GetDimensions(TextureDepthCube<${type}>,uint MipLevel,uint* ${addressSpace1} Width,uint* ${addressSpace2} Height,uint* ${addressSpace3} NumberOfLevels)`,
2539                             func => {
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)