Changeset 246631 in webkit


Ignore:
Timestamp:
Jun 20, 2019 2:40:41 AM (5 years ago)
Author:
mmaxfield@apple.com
Message:

[WHLSL] Hook up common texture functions
https://bugs.webkit.org/show_bug.cgi?id=198704
<rdar://problem/51668841>

Reviewed by Saam Barati.

Source/WebCore:

This patch adds the Metal implementation of the Sample(), Load(), and GetDimensions()
texture functions. The implementation simply performs string concatenation to produce the
correct results, and adds many new native functions to the standard library.

We can't zero-fill texture types or sampler types, so this patch forbids default
constructors for those types. It also forbids those types to exist within arrays, array
references, or pointers, becuase an out-of-bounds access may cause us to try to zero-fill
them.

Tests: webgpu/whlsl-textures-getdimensions.html

webgpu/whlsl-textures-load.html
webgpu/whlsl-textures-sample.html

  • Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h: Add some more introspection functions

so we can generate the necessary Metal functions for the appropriate texture types.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isAtomic const):
(WebCore::WHLSL::AST::NativeTypeDeclaration::isTextureArray const):
(WebCore::WHLSL::AST::NativeTypeDeclaration::isDepthTexture const):
(WebCore::WHLSL::AST::NativeTypeDeclaration::isWritableTexture const):
(WebCore::WHLSL::AST::NativeTypeDeclaration::textureDimension const):
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsTextureArray):
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsDepthTexture):
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsWritableTexture):
(WebCore::WHLSL::AST::NativeTypeDeclaration::setTextureDimension):
(WebCore::WHLSL::AST::NativeTypeDeclaration::isAtom const): Deleted.

  • Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp: Native types can be passed into

entry points, too.
(WebCore::WHLSL::Metal::EntryPointScaffolding::resourceHelperTypes):

  • Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp: Entry points that return void don't need a

semantic.
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):

  • Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp: Implement the functions.

(WebCore::WHLSL::Metal::vectorLength):
(WebCore::WHLSL::Metal::vectorInnerType):
(WebCore::WHLSL::Metal::vectorSuffix):
(WebCore::WHLSL::Metal::writeNativeFunction):

  • Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp: Textures come in two flavors: sample-able

and read/write-able. Make sure we produce the correct Metal types for them.
(WebCore::WHLSL::Metal::writeNativeType):

  • Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp: We can't auto-initialize textures and

samplers. Therefore, this function needs to be able to fail.
(WebCore::WHLSL::AutoInitialize::visit):
(WebCore::WHLSL::autoInitializeVariables):

  • Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h:
  • Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp: We can't auto-initialize textures, so users

shouldn't be able to either.
(WebCore::WHLSL::checkDuplicateFunctions):

  • Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp: Added. Make sure textures and samplers can't

exist inside arrays, array references, or pointers. This is because out-of-bounds accesses may cause
us to attempt to zero-fill the inner type, but we can't zero-fill textures and samplers.
(WebCore::WHLSL::TextureReferencesChecker::TextureReferencesChecker):
(WebCore::WHLSL::Searcher::Searcher):
(WebCore::WHLSL::Searcher::found const):
(WebCore::WHLSL::Searcher::visit):
(WebCore::WHLSL::TextureReferencesChecker::containsTextureOrSampler):
(WebCore::WHLSL::TextureReferencesChecker::visit):
(WebCore::WHLSL::checkTextureReferences):

  • Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h.
  • Modules/webgpu/WHLSL/WHLSLChecker.cpp:
  • Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp: Record more detailed information about texture types,

so we can emit correct Metal code.
(WebCore::WHLSL::Intrinsics::addFullTexture):
(WebCore::WHLSL::Intrinsics::addDepthTexture):

  • Modules/webgpu/WHLSL/WHLSLIntrinsics.h:

(WebCore::WHLSL::Intrinsics::WTF_ARRAY_LENGTH):

  • Modules/webgpu/WHLSL/WHLSLNameResolver.cpp: Nested NameResolvers need to propagate their error. Also,

native functions with named arguments shouldn't be adding their arguments to the global scope.
(WebCore::WHLSL::NameResolver::visit):

  • Modules/webgpu/WHLSL/WHLSLNameResolver.h:
  • Modules/webgpu/WHLSL/WHLSLPrepare.cpp:

(WebCore::WHLSL::prepareShared):

  • Modules/webgpu/WHLSL/WHLSLProgram.h:

(WebCore::WHLSL::Program::intrinsics const):

  • Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp:
  • Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt: Metal doesn't have writable depth textures.
  • Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp:
  • Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: Don't generate default constructors for textures

or samplers.
(WebCore::WHLSL::synthesizeConstructors):

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/gpu/GPUTexture.h: Make texture usages more clear.

(WebCore::GPUTexture::isSampled const):
(WebCore::GPUTexture::isStorage const):

  • platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm: Ditto.

(WebCore::GPUBindGroup::tryCreate):

  • platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm: Ditto.

(WebCore::GPUProgrammablePassEncoder::setBindGroup):

  • platform/graphics/gpu/cocoa/GPUTextureMetal.mm: Ditto.

(WebCore::mtlTextureUsageForGPUTextureUsageFlags):

LayoutTests:

Make the text tests play better with js-test-pre.js.

  • webgpu/whlsl-buffer-length.html:
  • webgpu/whlsl-compute-expected.txt:
  • webgpu/whlsl-compute.html:
  • webgpu/whlsl-duplicate-types-should-not-produce-duplicate-ctors.html:
  • webgpu/whlsl-null-dereference-expected.txt:
  • webgpu/whlsl-null-dereference.html:
  • webgpu/whlsl-oob-access-expected.txt:
  • webgpu/whlsl-oob-access.html:
  • webgpu/whlsl-textures-getdimensions-expected.txt: Added.
  • webgpu/whlsl-textures-getdimensions.html: Copied from LayoutTests/webgpu/whlsl-buffer-length.html.
  • webgpu/whlsl-textures-load-expected.html: Added.
  • webgpu/whlsl-textures-load.html: Added.
  • webgpu/whlsl-textures-sample-expected.html: Added.
  • webgpu/whlsl-textures-sample.html: Added.
Location:
trunk
Files:
6 added
37 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246629 r246631  
     12019-06-19  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [WHLSL] Hook up common texture functions
     4        https://bugs.webkit.org/show_bug.cgi?id=198704
     5        <rdar://problem/51668841>
     6
     7        Reviewed by Saam Barati.
     8
     9        Make the text tests play better with js-test-pre.js.
     10
     11        * webgpu/whlsl-buffer-length.html:
     12        * webgpu/whlsl-compute-expected.txt:
     13        * webgpu/whlsl-compute.html:
     14        * webgpu/whlsl-duplicate-types-should-not-produce-duplicate-ctors.html:
     15        * webgpu/whlsl-null-dereference-expected.txt:
     16        * webgpu/whlsl-null-dereference.html:
     17        * webgpu/whlsl-oob-access-expected.txt:
     18        * webgpu/whlsl-oob-access.html:
     19        * webgpu/whlsl-textures-getdimensions-expected.txt: Added.
     20        * webgpu/whlsl-textures-getdimensions.html: Copied from LayoutTests/webgpu/whlsl-buffer-length.html.
     21        * webgpu/whlsl-textures-load-expected.html: Added.
     22        * webgpu/whlsl-textures-load.html: Added.
     23        * webgpu/whlsl-textures-sample-expected.html: Added.
     24        * webgpu/whlsl-textures-sample.html: Added.
     25
    1262019-06-19  Rob Buis  <rbuis@igalia.com>
    227
  • trunk/LayoutTests/webgpu/whlsl-buffer-length-expected.txt

    r246515 r246631  
     1PASS resultUint32Array[0] is 1337
    12PASS successfullyParsed is true
    23
    34TEST COMPLETE
    4 PASS resultUint32Array[0] is 1337
    55
  • trunk/LayoutTests/webgpu/whlsl-buffer-length.html

    r246515 r246631  
    6060    resultsBuffer.unmap();
    6161}
    62 if (window.testRunner)
    63     testRunner.waitUntilDone();
     62window.jsTestIsAsync = true;
    6463window.addEventListener("load", function() {
    6564    start().then(function() {
    66         if (window.testRunner)
    67             testRunner.notifyDone();
     65        finishJSTest();
    6866    }, function() {
    69         if (window.testRunner)
    70             testRunner.notifyDone();
     67        finishJSTest();
    7168    });
    7269});
  • trunk/LayoutTests/webgpu/whlsl-compute-expected.txt

    r246427 r246631  
    1 PASS successfullyParsed is true
    2 
    3 TEST COMPLETE
    41PASS resultsFloat32Array[0] is 2
    52PASS resultsFloat32Array[1] is 4
     
    107PASS resultsFloat32Array[6] is 7
    118PASS resultsFloat32Array[7] is 8
     9PASS successfullyParsed is true
    1210
     11TEST COMPLETE
     12
  • trunk/LayoutTests/webgpu/whlsl-compute.html

    r246515 r246631  
    7474    resultsBuffer.unmap();
    7575}
    76 if (window.testRunner)
    77     testRunner.waitUntilDone();
     76window.jsTestIsAsync = true;
    7877window.addEventListener("load", function() {
    7978    start().then(function() {
    80         if (window.testRunner)
    81             testRunner.notifyDone();
     79        finishJSTest();
    8280    }, function() {
    83         if (window.testRunner)
    84             testRunner.notifyDone();
     81        finishJSTest();
    8582    });
    8683});
  • trunk/LayoutTests/webgpu/whlsl-duplicate-types-should-not-produce-duplicate-ctors-expected.txt

    r246550 r246631  
    1 PASS successfullyParsed is true
    2 
    3 TEST COMPLETE
    41PASS resultsFloat32Array[0] is 2
    52PASS resultsFloat32Array[1] is 4
     
    107PASS resultsFloat32Array[6] is 7
    118PASS resultsFloat32Array[7] is 8
     9PASS successfullyParsed is true
    1210
     11TEST COMPLETE
     12
  • trunk/LayoutTests/webgpu/whlsl-duplicate-types-should-not-produce-duplicate-ctors.html

    r246550 r246631  
    9595    resultsBuffer.unmap();
    9696}
    97 if (window.testRunner)
    98     testRunner.waitUntilDone();
     97window.jsTestIsAsync = true;
    9998window.addEventListener("load", function() {
    10099    start().then(function() {
    101         if (window.testRunner)
    102             testRunner.notifyDone();
     100        finishJSTest();
    103101    }, function() {
    104         if (window.testRunner)
    105             testRunner.notifyDone();
     102        finishJSTest();
    106103    });
    107104});
  • trunk/LayoutTests/webgpu/whlsl-null-dereference-expected.txt

    r246438 r246631  
    1 PASS successfullyParsed is true
    2 
    3 TEST COMPLETE
    41PASS resultsFloat32Array[0] is 2
    52PASS resultsFloat32Array[1] is 4
     
    107PASS resultsFloat32Array[6] is 7
    118PASS resultsFloat32Array[7] is 8
     9PASS successfullyParsed is true
    1210
     11TEST COMPLETE
     12
  • trunk/LayoutTests/webgpu/whlsl-null-dereference.html

    r246515 r246631  
    110110    resultsBuffer.unmap();
    111111}
    112 if (window.testRunner)
    113     testRunner.waitUntilDone();
     112window.jsTestIsAsync = true;
    114113window.addEventListener("load", function() {
    115114    start().then(function() {
    116         if (window.testRunner)
    117             testRunner.notifyDone();
     115        finishJSTest();
    118116    }, function() {
    119         if (window.testRunner)
    120             testRunner.notifyDone();
     117        finishJSTest();
    121118    });
    122119});
  • trunk/LayoutTests/webgpu/whlsl-oob-access-expected.txt

    r246438 r246631  
    1 PASS successfullyParsed is true
    2 
    3 TEST COMPLETE
    41PASS resultsFloat32Array[0] is 2
    52PASS resultsFloat32Array[1] is 4
     
    107PASS resultsFloat32Array[6] is 7
    118PASS resultsFloat32Array[7] is 8
     9PASS successfullyParsed is true
    1210
     11TEST COMPLETE
     12
  • trunk/LayoutTests/webgpu/whlsl-oob-access.html

    r246515 r246631  
    7777    resultsBuffer.unmap();
    7878}
    79 if (window.testRunner)
    80     testRunner.waitUntilDone();
     79window.jsTestIsAsync = true;
    8180window.addEventListener("load", function() {
    8281    start().then(function() {
    83         if (window.testRunner)
    84             testRunner.notifyDone();
     82        finishJSTest();
    8583    }, function() {
    86         if (window.testRunner)
    87             testRunner.notifyDone();
     84        finishJSTest();
    8885    });
    8986});
  • trunk/LayoutTests/webgpu/whlsl-textures-getdimensions.html

    r246630 r246631  
    88const shaderSource = `
    99[numthreads(1, 1, 1)]
    10 compute void computeShader(device uint[] buffer : register(u0), float3 threadID : SV_DispatchThreadID) {
    11     buffer[0] = buffer.length;
     10compute void computeShader(Texture2D<float4> theTexture : register(t0), device uint[] theBuffer : register(u1)) {
     11    uint width;
     12    uint height;
     13    uint numberOfLevels;
     14    GetDimensions(theTexture, 0, &width, &height, &numberOfLevels);
     15    theBuffer[0] = width;
     16    theBuffer[1] = height;
     17    theBuffer[2] = numberOfLevels;
    1218}
    1319`;
    14 let resultUint32Array;
     20let resultsUint32Array;
    1521async function start() {
    1622    const adapter = await navigator.gpu.requestAdapter();
     
    2026    const computeStage = {module: shaderModule, entryPoint: "computeShader"};
    2127
    22     const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "storage-buffer"}]};
     28    const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "sampled-texture"}, {binding: 1, visibility: 7, type: "storage-buffer"}]};
    2329    const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
    2430    const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
     
    2834    const computePipeline = device.createComputePipeline(computePipelineDescriptor);
    2935
    30     const size = Uint32Array.BYTES_PER_ELEMENT * 1337;
     36    const textureDescriptor = {size: {width: 2, height: 2, depth: 1}, format: "rgba8unorm", usage: GPUTextureUsage.SAMPLED};
     37    const texture = device.createTexture(textureDescriptor);
     38    const textureView = texture.createDefaultView();
    3139
    32     const bufferDescriptor = {size, usage: GPUBufferUsage.MAP_WRITE | GPUBufferUsage.TRANSFER_SRC};
    33     const buffer = device.createBuffer(bufferDescriptor);
    34     const bufferArrayBuffer = await buffer.mapWriteAsync();
    35     const bufferUint32Array = new Uint32Array(bufferArrayBuffer);
    36     bufferUint32Array[0] = 0;
    37     buffer.unmap();
    38 
    39     const resultsBufferDescriptor = {size, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.TRANSFER_DST | GPUBufferUsage.MAP_READ};
     40    const resultsBufferDescriptor = {size: Uint32Array.BYTES_PER_ELEMENT * 3, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.MAP_READ};
    4041    const resultsBuffer = device.createBuffer(resultsBufferDescriptor);
    4142
    42     const bufferBinding = {buffer: resultsBuffer, size};
    43     const bindGroupBinding = {binding: 0, resource: bufferBinding};
    44     const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]};
     43    const bufferBinding = {buffer: resultsBuffer, size: Uint32Array.BYTES_PER_ELEMENT * 3};
     44    const bindGroupBindings = [{binding: 0, resource: textureView}, {binding: 1, resource: bufferBinding}];
     45    const bindGroupDescriptor = {layout: bindGroupLayout, bindings: bindGroupBindings};
    4546    const bindGroup = device.createBindGroup(bindGroupDescriptor);
    4647
    4748    const commandEncoder = device.createCommandEncoder(); // {}
    48     commandEncoder.copyBufferToBuffer(buffer, 0, resultsBuffer, 0, 1 * Uint32Array.BYTES_PER_ELEMENT);
    4949    const computePassEncoder = commandEncoder.beginComputePass();
    5050    computePassEncoder.setPipeline(computePipeline);
     
    5656
    5757    const resultsArrayBuffer = await resultsBuffer.mapReadAsync();
    58     resultUint32Array = new Uint32Array(resultsArrayBuffer);
    59     shouldBe("resultUint32Array[0]", "1337");
     58    resultsUint32Array = new Uint32Array(resultsArrayBuffer);
     59    shouldBe("resultsUint32Array[0]", "2");
     60    shouldBe("resultsUint32Array[1]", "2");
     61    shouldBe("resultsUint32Array[2]", "1");
    6062    resultsBuffer.unmap();
    6163}
    62 if (window.testRunner)
    63     testRunner.waitUntilDone();
     64window.jsTestIsAsync = true;
    6465window.addEventListener("load", function() {
    6566    start().then(function() {
    66         if (window.testRunner)
    67             testRunner.notifyDone();
    68     }, function() {
    69         if (window.testRunner)
    70             testRunner.notifyDone();
     67        finishJSTest();
     68    }, function(e) {
     69        finishJSTest();
    7170    });
    7271});
  • trunk/Source/WebCore/ChangeLog

    r246628 r246631  
     12019-06-19  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [WHLSL] Hook up common texture functions
     4        https://bugs.webkit.org/show_bug.cgi?id=198704
     5        <rdar://problem/51668841>
     6
     7        Reviewed by Saam Barati.
     8
     9        This patch adds the Metal implementation of the Sample(), Load(), and GetDimensions()
     10        texture functions. The implementation simply performs string concatenation to produce the
     11        correct results, and adds many new native functions to the standard library.
     12
     13        We can't zero-fill texture types or sampler types, so this patch forbids default
     14        constructors for those types. It also forbids those types to exist within arrays, array
     15        references, or pointers, becuase an out-of-bounds access may cause us to try to zero-fill
     16        them.
     17
     18        Tests: webgpu/whlsl-textures-getdimensions.html
     19               webgpu/whlsl-textures-load.html
     20               webgpu/whlsl-textures-sample.html
     21
     22        * Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h: Add some more introspection functions
     23        so we can generate the necessary Metal functions for the appropriate texture types.
     24        (WebCore::WHLSL::AST::NativeTypeDeclaration::isAtomic const):
     25        (WebCore::WHLSL::AST::NativeTypeDeclaration::isTextureArray const):
     26        (WebCore::WHLSL::AST::NativeTypeDeclaration::isDepthTexture const):
     27        (WebCore::WHLSL::AST::NativeTypeDeclaration::isWritableTexture const):
     28        (WebCore::WHLSL::AST::NativeTypeDeclaration::textureDimension const):
     29        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsTextureArray):
     30        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsDepthTexture):
     31        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsWritableTexture):
     32        (WebCore::WHLSL::AST::NativeTypeDeclaration::setTextureDimension):
     33        (WebCore::WHLSL::AST::NativeTypeDeclaration::isAtom const): Deleted.
     34        * Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp: Native types can be passed into
     35        entry points, too.
     36        (WebCore::WHLSL::Metal::EntryPointScaffolding::resourceHelperTypes):
     37        * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp: Entry points that return void don't need a
     38        semantic.
     39        (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
     40        * Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp: Implement the functions.
     41        (WebCore::WHLSL::Metal::vectorLength):
     42        (WebCore::WHLSL::Metal::vectorInnerType):
     43        (WebCore::WHLSL::Metal::vectorSuffix):
     44        (WebCore::WHLSL::Metal::writeNativeFunction):
     45        * Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp: Textures come in two flavors: sample-able
     46        and read/write-able. Make sure we produce the correct Metal types for them.
     47        (WebCore::WHLSL::Metal::writeNativeType):
     48        * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp: We can't auto-initialize textures and
     49        samplers. Therefore, this function needs to be able to fail.
     50        (WebCore::WHLSL::AutoInitialize::visit):
     51        (WebCore::WHLSL::autoInitializeVariables):
     52        * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h:
     53        * Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp: We can't auto-initialize textures, so users
     54        shouldn't be able to either.
     55        (WebCore::WHLSL::checkDuplicateFunctions):
     56        * Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp: Added. Make sure textures and samplers can't
     57        exist inside arrays, array references, or pointers. This is because out-of-bounds accesses may cause
     58        us to attempt to zero-fill the inner type, but we can't zero-fill textures and samplers.
     59        (WebCore::WHLSL::TextureReferencesChecker::TextureReferencesChecker):
     60        (WebCore::WHLSL::Searcher::Searcher):
     61        (WebCore::WHLSL::Searcher::found const):
     62        (WebCore::WHLSL::Searcher::visit):
     63        (WebCore::WHLSL::TextureReferencesChecker::containsTextureOrSampler):
     64        (WebCore::WHLSL::TextureReferencesChecker::visit):
     65        (WebCore::WHLSL::checkTextureReferences):
     66        * Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h.
     67        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
     68        * Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp: Record more detailed information about texture types,
     69        so we can emit correct Metal code.
     70        (WebCore::WHLSL::Intrinsics::addFullTexture):
     71        (WebCore::WHLSL::Intrinsics::addDepthTexture):
     72        * Modules/webgpu/WHLSL/WHLSLIntrinsics.h:
     73        (WebCore::WHLSL::Intrinsics::WTF_ARRAY_LENGTH):
     74        * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp: Nested NameResolvers need to propagate their error. Also,
     75        native functions with named arguments shouldn't be adding their arguments to the global scope.
     76        (WebCore::WHLSL::NameResolver::visit):
     77        * Modules/webgpu/WHLSL/WHLSLNameResolver.h:
     78        * Modules/webgpu/WHLSL/WHLSLPrepare.cpp:
     79        (WebCore::WHLSL::prepareShared):
     80        * Modules/webgpu/WHLSL/WHLSLProgram.h:
     81        (WebCore::WHLSL::Program::intrinsics const):
     82        * Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp:
     83        * Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt: Metal doesn't have writable depth textures.
     84        * Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp:
     85        * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: Don't generate default constructors for textures
     86        or samplers.
     87        (WebCore::WHLSL::synthesizeConstructors):
     88        * Sources.txt:
     89        * WebCore.xcodeproj/project.pbxproj:
     90        * platform/graphics/gpu/GPUTexture.h: Make texture usages more clear.
     91        (WebCore::GPUTexture::isSampled const):
     92        (WebCore::GPUTexture::isStorage const):
     93        * platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm: Ditto.
     94        (WebCore::GPUBindGroup::tryCreate):
     95        * platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm: Ditto.
     96        (WebCore::GPUProgrammablePassEncoder::setBindGroup):
     97        * platform/graphics/gpu/cocoa/GPUTextureMetal.mm: Ditto.
     98        (WebCore::mtlTextureUsageForGPUTextureUsageFlags):
     99
    11002019-06-19  Justin Fan  <justin_fan@apple.com>
    2101
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h

    r246490 r246631  
    6060    bool isNumber() const { return m_isNumber; }
    6161    bool isFloating() const { return m_isFloating; }
    62     bool isAtom() const { return m_isAtomic; }
     62    bool isAtomic() const { return m_isAtomic; }
    6363    bool isVector() const { return m_isVector; }
    6464    bool isMatrix() const { return m_isMatrix; }
     65    bool isOpaqueType() const { return m_isOpaqueType; }
    6566    bool isTexture() const { return m_isTexture; }
     67    bool isTextureArray() const { return m_isTextureArray; }
     68    bool isDepthTexture() const { return m_isDepthTexture; }
     69    bool isWritableTexture() const { return m_isWritableTexture; }
     70    uint textureDimension() const { return m_textureDimension; }
    6671    bool isSigned() const { return m_isSigned; }
    6772    const std::function<bool(int)>& canRepresentInteger() const { return m_canRepresentInteger; }
     
    7984    void setIsVector() { m_isVector = true; }
    8085    void setIsMatrix() { m_isMatrix = true; }
     86    void setIsOpaqueType() { m_isOpaqueType = true; }
    8187    void setIsTexture() { m_isTexture = true; }
     88    void setIsTextureArray() { m_isTextureArray = true; }
     89    void setIsDepthTexture() { m_isDepthTexture = true; }
     90    void setIsWritableTexture() { m_isWritableTexture = true; }
     91    void setTextureDimension(uint textureDimension) { m_textureDimension = textureDimension; }
    8292    void setIsSigned() { m_isSigned = true; }
    8393    void setCanRepresentInteger(std::function<bool(int)>&& canRepresent) { m_canRepresentInteger = WTFMove(canRepresent); }
     
    98108    std::function<int64_t(unsigned)> m_formatValueFromUnsignedInteger;
    99109    std::function<void(const std::function<bool(int64_t)>&)> m_iterateAllValues;
     110    uint m_textureDimension { 0 };
    100111    bool m_isInt { false };
    101112    bool m_isNumber { false };
     
    104115    bool m_isVector { false };
    105116    bool m_isMatrix { false };
     117    bool m_isOpaqueType { false };
    106118    bool m_isTexture { false };
     119    bool m_isTextureArray { false };
     120    bool m_isDepthTexture { false };
     121    bool m_isWritableTexture { false };
    107122    bool m_isSigned { false };
    108123};
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp

    r246628 r246631  
    150150            if (iterator == m_resourceMap.end())
    151151                continue;
    152             auto& unnamedType = *m_entryPointItems.inputs[iterator->value].unnamedType;
    153             auto& referenceType = downcast<AST::ReferenceType>(unnamedType);
    154             auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType());
    155             auto addressSpace = toString(referenceType.addressSpace());
    156             auto elementName = m_namedBindGroups[i].namedBindings[j].elementName;
    157             auto index = m_namedBindGroups[i].namedBindings[j].index;
    158             structItems.append(std::make_pair(index, makeString("    ", addressSpace, " ", mangledTypeName, "* ", elementName, " [[id(", index, ")]];\n")));
    159             if (auto lengthInformation = m_namedBindGroups[i].namedBindings[j].lengthInformation)
    160                 structItems.append(std::make_pair(lengthInformation->index, makeString("uint2 ", lengthInformation->elementName, " [[id(", lengthInformation->index, ")]];")));
     152            auto& type = m_entryPointItems.inputs[iterator->value].unnamedType->unifyNode();
     153            if (is<AST::UnnamedType>(type) && is<AST::ReferenceType>(downcast<AST::UnnamedType>(type))) {
     154                auto& referenceType = downcast<AST::ReferenceType>(downcast<AST::UnnamedType>(type));
     155                auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType());
     156                auto addressSpace = toString(referenceType.addressSpace());
     157                auto elementName = m_namedBindGroups[i].namedBindings[j].elementName;
     158                auto index = m_namedBindGroups[i].namedBindings[j].index;
     159                structItems.append(std::make_pair(index, makeString(addressSpace, " ", mangledTypeName, "* ", elementName, " [[id(", index, ")]];")));
     160                if (auto lengthInformation = m_namedBindGroups[i].namedBindings[j].lengthInformation)
     161                    structItems.append(std::make_pair(lengthInformation->index, makeString("uint2 ", lengthInformation->elementName, " [[id(", lengthInformation->index, ")]];")));
     162            } else if (is<AST::NamedType>(type) && is<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(type))) {
     163                auto& namedType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(type));
     164                auto mangledTypeName = m_typeNamer.mangledNameForType(namedType);
     165                auto elementName = m_namedBindGroups[i].namedBindings[j].elementName;
     166                auto index = m_namedBindGroups[i].namedBindings[j].index;
     167                structItems.append(std::make_pair(index, makeString(mangledTypeName, ' ', elementName, " [[id(", index, ")]];")));
     168            }
    161169        }
    162170        std::sort(structItems.begin(), structItems.end(), [](const std::pair<unsigned, String>& left, const std::pair<unsigned, String>& right) {
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp

    r246579 r246631  
    559559    ASSERT(iterator != m_functionMapping.end());
    560560    auto variableName = generateNextVariableName();
    561     m_stringBuilder.append(makeString(m_typeNamer.mangledNameForType(callExpression.resolvedType()), ' ', variableName, " = ", iterator->value, '('));
     561    if (!matches(callExpression.resolvedType(), m_intrinsics.voidType()))
     562        m_stringBuilder.append(makeString(m_typeNamer.mangledNameForType(callExpression.resolvedType()), ' ', variableName, " = "));
     563    m_stringBuilder.append(makeString(iterator->value, '('));
    562564    for (size_t i = 0; i < argumentNames.size(); ++i) {
    563565        if (i)
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp

    r246579 r246631  
    8282}
    8383
     84static int vectorLength(AST::NativeTypeDeclaration& nativeTypeDeclaration)
     85{
     86    int vectorLength = 1;
     87    if (!nativeTypeDeclaration.typeArguments().isEmpty()) {
     88        ASSERT(nativeTypeDeclaration.typeArguments().size() == 2);
     89        ASSERT(WTF::holds_alternative<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1]));
     90        vectorLength = WTF::get<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1]).integerLiteral().value();
     91    }
     92    return vectorLength;
     93}
     94
     95static AST::NamedType& vectorInnerType(AST::NativeTypeDeclaration& nativeTypeDeclaration)
     96{
     97    if (nativeTypeDeclaration.typeArguments().isEmpty())
     98        return nativeTypeDeclaration;
     99
     100    ASSERT(nativeTypeDeclaration.typeArguments().size() == 2);
     101    ASSERT(WTF::holds_alternative<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0]));
     102    return WTF::get<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0])->resolvedType();
     103}
     104
     105static const char* vectorSuffix(int vectorLength)
     106{
     107    switch (vectorLength) {
     108    case 1:
     109        return "";
     110    case 2:
     111        return "2";
     112    case 3:
     113        return "3";
     114    default:
     115        ASSERT(vectorLength == 4);
     116        return "4";
     117    }
     118}
     119
    84120String writeNativeFunction(AST::NativeFunctionDeclaration& nativeFunctionDeclaration, String& outputFunctionName, Intrinsics& intrinsics, TypeNamer& typeNamer, const char* memsetZeroFunctionName)
    85121{
     
    103139            if (is<AST::NativeTypeDeclaration>(parameterNamedType)) {
    104140                auto& parameterNativeTypeDeclaration = downcast<AST::NativeTypeDeclaration>(parameterNamedType);
    105                 if (parameterNativeTypeDeclaration.isAtom()) {
     141                if (parameterNativeTypeDeclaration.isAtomic()) {
    106142                    stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, '(', metalParameterName, " x) {\n"));
    107143                    stringBuilder.append("    return atomic_load_explicit(&x, memory_order_relaxed);\n");
     
    390426
    391427    if (nativeFunctionDeclaration.name() == "Sample") {
    392         // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195813 Implement this
    393         notImplemented();
     428        ASSERT(nativeFunctionDeclaration.parameters().size() == 3 || nativeFunctionDeclaration.parameters().size() == 4);
     429       
     430        auto& textureType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[0]->type()->unifyNode()));
     431        auto& locationType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[2]->type()->unifyNode()));
     432        auto locationVectorLength = vectorLength(locationType);
     433        auto& returnType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.type().unifyNode()));
     434        auto returnVectorLength = vectorLength(returnType);
     435
     436        auto metalParameter1Name = typeNamer.mangledNameForType(textureType);
     437        auto metalParameter2Name = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[1]->type());
     438        auto metalParameter3Name = typeNamer.mangledNameForType(locationType);
     439        String metalParameter4Name;
     440        if (nativeFunctionDeclaration.parameters().size() == 4)
     441            metalParameter4Name = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[3]->type());
     442        auto metalReturnName = typeNamer.mangledNameForType(returnType);
     443        stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, '(', metalParameter1Name, " theTexture, ", metalParameter2Name, " theSampler, ", metalParameter3Name, " location"));
     444        if (!metalParameter4Name.isNull())
     445            stringBuilder.append(makeString(", ", metalParameter4Name, " offset"));
     446        stringBuilder.append(") {\n");
     447        stringBuilder.append("    return theTexture.sample(theSampler, ");
     448        if (textureType.isTextureArray()) {
     449            ASSERT(locationVectorLength > 1);
     450            stringBuilder.append(makeString("location.", "xyzw"_str.substring(0, locationVectorLength - 1), ", location.", "xyzw"_str.substring(locationVectorLength - 1, 1)));
     451        } else
     452            stringBuilder.append("location");
     453        if (!metalParameter4Name.isNull())
     454            stringBuilder.append(", offset");
     455        stringBuilder.append(")");
     456        if (!textureType.isDepthTexture())
     457            stringBuilder.append(makeString(".", "xyzw"_str.substring(0, returnVectorLength)));
     458        stringBuilder.append(";\n");
     459        stringBuilder.append("}\n");
     460        return stringBuilder.toString();
    394461    }
    395462
    396463    if (nativeFunctionDeclaration.name() == "Load") {
    397         // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195813 Implement this
    398         notImplemented();
     464        ASSERT(nativeFunctionDeclaration.parameters().size() == 2);
     465       
     466        auto& textureType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[0]->type()->unifyNode()));
     467        auto& locationType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[1]->type()->unifyNode()));
     468        auto locationVectorLength = vectorLength(locationType);
     469        auto& returnType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.type().unifyNode()));
     470        auto returnVectorLength = vectorLength(returnType);
     471
     472        auto metalParameter1Name = typeNamer.mangledNameForType(textureType);
     473        auto metalParameter2Name = typeNamer.mangledNameForType(locationType);
     474        auto metalReturnName = typeNamer.mangledNameForType(returnType);
     475        stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, '(', metalParameter1Name, " theTexture, ", metalParameter2Name, " location) {\n"));
     476        if (textureType.isTextureArray()) {
     477            ASSERT(locationVectorLength > 1);
     478            String dimensions[] = { "width"_str, "height"_str, "depth"_str };
     479            for (int i = 0; i < locationVectorLength - 1; ++i) {
     480                auto suffix = "xyzw"_str.substring(i, 1);
     481                stringBuilder.append(makeString("    if (location.", suffix, " < 0 || static_cast<uint32_t>(location.", suffix, ") >= theTexture.get_", dimensions[i], "()) return ", metalReturnName, "(0);\n"));
     482            }
     483            auto suffix = "xyzw"_str.substring(locationVectorLength - 1, 1);
     484            stringBuilder.append(makeString("    if (location.", suffix, " < 0 || static_cast<uint32_t>(location.", suffix, ") >= theTexture.get_array_size()) return ", metalReturnName, "(0);\n"));
     485        } else {
     486            if (locationVectorLength == 1)
     487                stringBuilder.append(makeString("    if (location < 0 || static_cast<uint32_t>(location) >= theTexture.get_width()) return ", metalReturnName, "(0);\n"));
     488            else {
     489                stringBuilder.append(makeString("    if (location.x < 0 || static_cast<uint32_t>(location.x) >= theTexture.get_width()) return ", metalReturnName, "(0);\n"));
     490                stringBuilder.append(makeString("    if (location.y < 0 || static_cast<uint32_t>(location.y) >= theTexture.get_height()) return ", metalReturnName, "(0);\n"));
     491                if (locationVectorLength >= 3)
     492                    stringBuilder.append(makeString("    if (location.z < 0 || static_cast<uint32_t>(location.z) >= theTexture.get_depth()) return ", metalReturnName, "(0);\n"));
     493            }
     494        }
     495        stringBuilder.append("    return theTexture.read(");
     496        if (textureType.isTextureArray()) {
     497            ASSERT(locationVectorLength > 1);
     498            stringBuilder.append(makeString("uint", vectorSuffix(locationVectorLength - 1), "(location.", "xyzw"_str.substring(0, locationVectorLength - 1), "), uint(location.", "xyzw"_str.substring(locationVectorLength - 1, 1), ")"));
     499        } else
     500            stringBuilder.append(makeString("uint", vectorSuffix(locationVectorLength), "(location)"));
     501        stringBuilder.append(")");
     502        if (!textureType.isDepthTexture())
     503            stringBuilder.append(makeString(".", "xyzw"_str.substring(0, returnVectorLength)));
     504        stringBuilder.append(";\n");
     505        stringBuilder.append("}\n");
     506        return stringBuilder.toString();
    399507    }
    400508
    401509    if (nativeFunctionDeclaration.name() == "GetDimensions") {
    402         // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195813 Implement this
    403         notImplemented();
     510        auto& textureType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[0]->type()->unifyNode()));
     511
     512        size_t index = 1;
     513        if (!textureType.isWritableTexture() && textureType.textureDimension() != 1)
     514            ++index;
     515        auto widthTypeName = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[index]->type());
     516        ++index;
     517        String heightTypeName;
     518        if (textureType.textureDimension() >= 2) {
     519            heightTypeName = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[index]->type());
     520            ++index;
     521        }
     522        String depthTypeName;
     523        if (textureType.textureDimension() >= 3) {
     524            depthTypeName = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[index]->type());
     525            ++index;
     526        }
     527        String elementsTypeName;
     528        if (textureType.isTextureArray()) {
     529            elementsTypeName = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[index]->type());
     530            ++index;
     531        }
     532        String numberOfLevelsTypeName;
     533        if (!textureType.isWritableTexture()) {
     534            numberOfLevelsTypeName = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[index]->type());
     535            ++index;
     536        }
     537        ASSERT(index == nativeFunctionDeclaration.parameters().size());
     538
     539        auto metalParameter1Name = typeNamer.mangledNameForType(textureType);
     540        stringBuilder.append(makeString("void ", outputFunctionName, '(', metalParameter1Name, " theTexture"));
     541        if (!textureType.isWritableTexture() && textureType.textureDimension() != 1)
     542            stringBuilder.append(", uint mipLevel");
     543        stringBuilder.append(makeString(", ", widthTypeName, " width"));
     544        if (!heightTypeName.isNull())
     545            stringBuilder.append(makeString(", ", heightTypeName, " height"));
     546        if (!depthTypeName.isNull())
     547            stringBuilder.append(makeString(", ", depthTypeName, " depth"));
     548        if (!elementsTypeName.isNull())
     549            stringBuilder.append(makeString(", ", elementsTypeName, " elements"));
     550        if (!numberOfLevelsTypeName.isNull())
     551            stringBuilder.append(makeString(", ", numberOfLevelsTypeName, " numberOfLevels"));
     552        stringBuilder.append(") {\n");
     553        stringBuilder.append("    if (width)\n");
     554        stringBuilder.append("        *width = theTexture.get_width(");
     555        if (!textureType.isWritableTexture() && textureType.textureDimension() != 1)
     556            stringBuilder.append("mipLevel");
     557        stringBuilder.append(");\n");
     558        if (!heightTypeName.isNull()) {
     559            stringBuilder.append("    if (height)\n");
     560            stringBuilder.append("        *height = theTexture.get_height(");
     561            if (!textureType.isWritableTexture() && textureType.textureDimension() != 1)
     562                stringBuilder.append("mipLevel");
     563            stringBuilder.append(");\n");
     564        }
     565        if (!depthTypeName.isNull()) {
     566            stringBuilder.append("    if (depth)\n");
     567            stringBuilder.append("        *depth = theTexture.get_depth(");
     568            if (!textureType.isWritableTexture() && textureType.textureDimension() != 1)
     569                stringBuilder.append("mipLevel");
     570            stringBuilder.append(");\n");
     571        }
     572        if (!elementsTypeName.isNull()) {
     573            stringBuilder.append("    if (elements)\n");
     574            stringBuilder.append("        *elements = theTexture.get_array_size();\n");
     575        }
     576        if (!numberOfLevelsTypeName.isNull()) {
     577            stringBuilder.append("    if (numberOfLevels)\n");
     578            stringBuilder.append("        *numberOfLevels = theTexture.get_num_mip_levels();\n");
     579        }
     580        stringBuilder.append("}\n");
     581        return stringBuilder.toString();
    404582    }
    405583
     
    440618
    441619    if (nativeFunctionDeclaration.name() == "Store") {
    442         // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195813 Implement this
    443         notImplemented();
     620        ASSERT(nativeFunctionDeclaration.parameters().size() == 3);
     621       
     622        auto& textureType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[0]->type()->unifyNode()));
     623        auto& itemType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[1]->type()->unifyNode()));
     624        auto& itemVectorInnerType = vectorInnerType(itemType);
     625        auto itemVectorLength = vectorLength(itemType);
     626        auto& locationType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[2]->type()->unifyNode()));
     627        auto locationVectorLength = vectorLength(locationType);
     628
     629        auto metalParameter1Name = typeNamer.mangledNameForType(textureType);
     630        auto metalParameter2Name = typeNamer.mangledNameForType(itemType);
     631        auto metalParameter3Name = typeNamer.mangledNameForType(locationType);
     632        auto metalInnerTypeName = typeNamer.mangledNameForType(itemVectorInnerType);
     633        stringBuilder.append(makeString("void ", outputFunctionName, '(', metalParameter1Name, " theTexture, ", metalParameter2Name, " item, ", metalParameter3Name, " location) {\n"));
     634        if (textureType.isTextureArray()) {
     635            ASSERT(locationVectorLength > 1);
     636            String dimensions[] = { "width"_str, "height"_str, "depth"_str };
     637            for (int i = 0; i < locationVectorLength - 1; ++i) {
     638                auto suffix = "xyzw"_str.substring(i, 1);
     639                stringBuilder.append(makeString("    if (location.", suffix, " >= theTexture.get_", dimensions[i], "()) return;\n"));
     640            }
     641            auto suffix = "xyzw"_str.substring(locationVectorLength - 1, 1);
     642            stringBuilder.append(makeString("    if (location.", suffix, " >= theTexture.get_array_size()) return;\n"));
     643        } else {
     644            if (locationVectorLength == 1)
     645                stringBuilder.append(makeString("    if (location >= theTexture.get_width()) return;\n"));
     646            else {
     647                stringBuilder.append(makeString("    if (location.x >= theTexture.get_width()) return;\n"));
     648                stringBuilder.append(makeString("    if (location.y >= theTexture.get_height()) return;\n"));
     649                if (locationVectorLength >= 3)
     650                    stringBuilder.append(makeString("    if (location.z >= theTexture.get_depth()) return;\n"));
     651            }
     652        }
     653        stringBuilder.append(makeString("    theTexture.write(vec<", metalInnerTypeName, ", 4>(item"));
     654        for (int i = 0; i < 4 - itemVectorLength; ++i)
     655            stringBuilder.append(", 0");
     656        stringBuilder.append("), ");
     657        if (textureType.isTextureArray()) {
     658            ASSERT(locationVectorLength > 1);
     659            stringBuilder.append(makeString("uint", vectorSuffix(locationVectorLength - 1), "(location.", "xyzw"_str.substring(0, locationVectorLength - 1), "), uint(location.", "xyzw"_str.substring(locationVectorLength - 1, 1), ")"));
     660        } else
     661            stringBuilder.append(makeString("uint", vectorSuffix(locationVectorLength), "(location)"));
     662        stringBuilder.append(");\n");
     663        stringBuilder.append("}\n");
     664        return stringBuilder.toString();
    444665    }
    445666
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp

    r246428 r246631  
    181181        if (nativeTypeDeclaration.name() == "TextureDepth2D")
    182182            return "depth2d"_str;
    183         if (nativeTypeDeclaration.name() == "RWTextureDepth2D")
    184             return "depth2d"_str;
    185183        if (nativeTypeDeclaration.name() == "TextureDepth2DArray")
    186             return "depth2d_array"_str;
    187         if (nativeTypeDeclaration.name() == "RWTextureDepth2DArray")
    188184            return "depth2d_array"_str;
    189185        ASSERT(nativeTypeDeclaration.name() == "TextureDepthCube");
     
    240236        return "float"_str;
    241237    })();
    242     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195813 Specify the second template argument to Metal texture types.
    243     return makeString(prefix, '<', innerType, '>');
     238    auto isReadWrite = nativeTypeDeclaration.name() == "RWTexture1D"
     239        || nativeTypeDeclaration.name() == "RWTexture1DArray"
     240        || nativeTypeDeclaration.name() == "RWTexture2D"
     241        || nativeTypeDeclaration.name() == "RWTexture2DArray"
     242        || nativeTypeDeclaration.name() == "RWTexture3D";
     243    return makeString(prefix, '<', innerType, ", ", isReadWrite ? "access::read_write" : "access::sample", '>');
    244244}
    245245
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp

    r246273 r246631  
    7676        Vector<std::reference_wrapper<ResolvingType>> argumentTypes;
    7777        auto* function = resolveFunctionOverload(*callExpression->overloads(), argumentTypes, type);
    78         RELEASE_ASSERT(function);
     78        if (!function) {
     79            setError();
     80            return;
     81        }
    7982        callExpression->setFunction(*function);
    8083
     
    8689};
    8790
    88 void autoInitializeVariables(Program& program)
     91bool autoInitializeVariables(Program& program)
    8992{
    9093    AutoInitialize autoInitialize(program.nameContext());
    9194    autoInitialize.Visitor::visit(program);
     95    return !autoInitialize.error();
    9296}
    9397
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.h

    r246273 r246631  
    3434class Program;
    3535
    36 void autoInitializeVariables(Program&);
     36bool autoInitializeVariables(Program&);
    3737
    3838}
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp

    r246439 r246631  
    142142            && matches(*function.parameters()[0]->type(), *function.parameters()[1]->type()))
    143143            return false;
     144        else if (function.isCast() && function.parameters().isEmpty()) {
     145            auto& unifyNode = function.type().unifyNode();
     146            if (is<AST::NamedType>(unifyNode) && is<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(unifyNode))) {
     147                auto& nativeTypeDeclaration = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(unifyNode));
     148                if (nativeTypeDeclaration.isOpaqueType())
     149                    return false;
     150            }
     151        }
    144152
    145153        return true;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.h

    r246630 r246631  
    3434class Program;
    3535
    36 void autoInitializeVariables(Program&);
     36bool checkTextureReferences(Program&);
    3737
    3838}
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp

    r246625 r246631  
    453453    }
    454454
    455     ~Checker() = default;
     455    virtual ~Checker() = default;
    456456
    457457    void visit(Program&) override;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp

    r246428 r246631  
    273273        nativeTypeDeclaration.setIsAtomic();
    274274        m_atomicUintType = &nativeTypeDeclaration;
    275     } else if (nativeTypeDeclaration.name() == "sampler")
     275    } else if (nativeTypeDeclaration.name() == "sampler") {
    276276        m_samplerType = &nativeTypeDeclaration;
     277        nativeTypeDeclaration.setIsOpaqueType();
     278    }
    277279    else
    278280        ASSERT_NOT_REACHED();
     
    370372    ASSERT(innerTypeIndex != WTF_ARRAY_LENGTH(m_textureInnerTypeNames));
    371373    nativeTypeDeclaration.setIsTexture();
     374    nativeTypeDeclaration.setIsOpaqueType();
     375    if (nativeTypeDeclaration.name() == "Texture1DArray" || nativeTypeDeclaration.name() == "RWTexture1DArray" || nativeTypeDeclaration.name() == "Texture2DArray" || nativeTypeDeclaration.name() == "RWTexture2DArray")
     376        nativeTypeDeclaration.setIsTextureArray();
     377    if (nativeTypeDeclaration.name() == "RWTexture1D" || nativeTypeDeclaration.name() == "RWTexture2D" || nativeTypeDeclaration.name() == "RWTexture3D" || nativeTypeDeclaration.name() == "RWTexture1DArray" || nativeTypeDeclaration.name() == "RWTexture2DArray")
     378        nativeTypeDeclaration.setIsWritableTexture();
     379    if (nativeTypeDeclaration.name() == "Texture1D" || nativeTypeDeclaration.name() == "RWTexture1D" || nativeTypeDeclaration.name() == "Texture1DArray" || nativeTypeDeclaration.name() == "RWTexture1DArray")
     380        nativeTypeDeclaration.setTextureDimension(1);
     381    if (nativeTypeDeclaration.name() == "Texture2D" || nativeTypeDeclaration.name() == "RWTexture2D" || nativeTypeDeclaration.name() == "TextureCube" || nativeTypeDeclaration.name() == "Texture2DArray" || nativeTypeDeclaration.name() == "RWTexture2DArray")
     382        nativeTypeDeclaration.setTextureDimension(2);
     383    if (nativeTypeDeclaration.name() == "Texture3D" || nativeTypeDeclaration.name() == "RWTexture3D")
     384        nativeTypeDeclaration.setTextureDimension(3);
    372385    m_fullTextures[textureTypeIndex][innerTypeIndex][vectorLength - 1] = &nativeTypeDeclaration;
    373386    return true;
     
    379392    if (nativeTypeDeclaration.name() == "TextureDepth2D")
    380393        texture = m_textureDepth2D;
    381     else if (nativeTypeDeclaration.name() == "RWTextureDepth2D")
    382         texture = m_rwTextureDepth2D;
    383394    else if (nativeTypeDeclaration.name() == "TextureDepth2DArray")
    384395        texture = m_textureDepth2DArray;
    385     else if (nativeTypeDeclaration.name() == "RWTextureDepth2DArray")
    386         texture = m_rwTextureDepth2DArray;
    387396    else {
    388397        ASSERT(nativeTypeDeclaration.name() == "TextureDepthCube");
     
    392401    ASSERT(innerTypeIndex != WTF_ARRAY_LENGTH(m_depthTextureInnerTypes));
    393402    nativeTypeDeclaration.setIsTexture();
     403    nativeTypeDeclaration.setIsOpaqueType();
     404    if (texture == m_textureDepth2DArray)
     405        nativeTypeDeclaration.setIsTextureArray();
     406    nativeTypeDeclaration.setTextureDimension(2);
     407    nativeTypeDeclaration.setIsDepthTexture();
    394408    texture[innerTypeIndex] = &nativeTypeDeclaration;
    395409}
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h

    r246428 r246631  
    264264    AST::NativeTypeDeclaration* m_matrixFloat[3][3] {{ 0 }};
    265265
    266     static constexpr const char* m_textureTypeNames[] = { "Texture1D", "RWTexture1D", "Texture1DArray", "RWTexture1DArray", "Texture2D", "RWTexture2D", "Texture2DArray", "RWTexture2DArray", "Texture3D", "RWTexture3D", "TextureCube" };
     266    static constexpr const char* m_textureTypeNames[] = { "Texture1D", "RWTexture1D", "Texture2D", "RWTexture2D", "Texture3D", "RWTexture3D", "TextureCube", "Texture1DArray", "RWTexture1DArray", "Texture2DArray", "RWTexture2DArray" };
    267267
    268268    static constexpr const char* m_textureInnerTypeNames[] = { "uchar", "ushort",  "uint", "char", "short", "int", "half", "float" };
     
    273273
    274274    AST::NativeTypeDeclaration* m_textureDepth2D[WTF_ARRAY_LENGTH(m_depthTextureInnerTypes)] { 0 };
    275     AST::NativeTypeDeclaration* m_rwTextureDepth2D[WTF_ARRAY_LENGTH(m_depthTextureInnerTypes)] { 0 };
    276275    AST::NativeTypeDeclaration* m_textureDepth2DArray[WTF_ARRAY_LENGTH(m_depthTextureInnerTypes)] { 0 };
    277     AST::NativeTypeDeclaration* m_rwTextureDepth2DArray[WTF_ARRAY_LENGTH(m_depthTextureInnerTypes)] { 0 };
    278276    AST::NativeTypeDeclaration* m_textureDepthCube[WTF_ARRAY_LENGTH(m_depthTextureInnerTypes)] { 0 };
    279277
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp

    r246550 r246631  
    5959NameResolver::NameResolver(NameResolver& parentResolver, NameContext& nameContext)
    6060    : m_nameContext(nameContext)
     61    , m_parentNameResolver(&parentResolver)
    6162{
    6263    m_isResolvingCalls = parentResolver.m_isResolvingCalls;
    6364    setCurrentFunctionDefinition(parentResolver.m_currentFunction);
     65}
     66
     67NameResolver::~NameResolver()
     68{
     69    if (error() && m_parentNameResolver)
     70        m_parentNameResolver->setError();
    6471}
    6572
     
    117124    NameResolver newNameResolver(*this, nameContext);
    118125    newNameResolver.checkErrorAndVisit(ifStatement.body());
    119     if (ifStatement.elseBody()) {
     126    if (newNameResolver.error())
     127        setError();
     128    else if (ifStatement.elseBody()) {
    120129        NameContext nameContext(&m_nameContext);
    121130        NameResolver newNameResolver(*this, nameContext);
     
    259268}
    260269
     270void NameResolver::visit(AST::NativeFunctionDeclaration& nativeFunctionDeclaration)
     271{
     272    NameContext newNameContext(&m_nameContext);
     273    NameResolver newNameResolver(newNameContext);
     274    newNameResolver.Visitor::visit(nativeFunctionDeclaration);
     275}
     276
    261277// FIXME: https://bugs.webkit.org/show_bug.cgi?id=198167 Make sure all the names have been resolved.
    262278
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h

    r246550 r246631  
    4343    NameResolver(NameResolver&, NameContext&);
    4444
    45     virtual ~NameResolver() = default;
     45    virtual ~NameResolver();
    4646
    4747    void visit(AST::FunctionDefinition&) override;
     
    5555
    5656private:
     57    void visit(AST::NativeFunctionDeclaration&) override;
    5758    void visit(AST::TypeReference&) override;
    5859    void visit(AST::Block&) override;
     
    7273    HashSet<AST::TypeReference*> m_typeReferences;
    7374    AST::FunctionDefinition* m_currentFunction { nullptr };
     75    NameResolver* m_parentNameResolver { nullptr };
    7476    bool m_isResolvingCalls { false };
    7577};
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp

    r246550 r246631  
    3232#include "WHLSLAutoInitializeVariables.h"
    3333#include "WHLSLCheckDuplicateFunctions.h"
     34#include "WHLSLCheckTextureReferences.h"
    3435#include "WHLSLChecker.h"
    3536#include "WHLSLComputeDimensions.h"
     
    134135
    135136    checkLiteralTypes(program);
    136     autoInitializeVariables(program);
     137    RUN_PASS(checkTextureReferences, program);
     138    RUN_PASS(autoInitializeVariables, program);
    137139    resolveProperties(program);
    138140    findHighZombies(program);
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h

    r240020 r246631  
    8787    NameContext& nameContext() { return m_nameContext; }
    8888    Intrinsics& intrinsics() { return m_intrinsics; }
     89    const Intrinsics& intrinsics() const { return m_intrinsics; }
    8990    Vector<UniqueRef<AST::TypeDefinition>>& typeDefinitions() { return m_typeDefinitions; }
    9091    Vector<UniqueRef<AST::StructureDefinition>>& structureDefinitions() { return m_structureDefinitions; }
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp

    r245680 r246631  
    4242class RecursiveTypeChecker : public Visitor {
    4343public:
    44     ~RecursiveTypeChecker() = default;
     44    virtual ~RecursiveTypeChecker() = default;
    4545
    4646    void visit(AST::TypeDefinition&) override;
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt

    r246579 r246631  
    130130native typedef Texture1D<float3>;
    131131native typedef Texture1D<float4>;
    132 native typedef RWTexture1D<ushort>;
    133 native typedef RWTexture1D<ushort2>;
    134 native typedef RWTexture1D<ushort3>;
    135 native typedef RWTexture1D<ushort4>;
    136 native typedef RWTexture1D<uint>;
    137 native typedef RWTexture1D<uint2>;
    138 native typedef RWTexture1D<uint3>;
    139 native typedef RWTexture1D<uint4>;
    140 native typedef RWTexture1D<short>;
    141 native typedef RWTexture1D<short2>;
    142 native typedef RWTexture1D<short3>;
    143 native typedef RWTexture1D<short4>;
    144 native typedef RWTexture1D<int>;
    145 native typedef RWTexture1D<int2>;
    146 native typedef RWTexture1D<int3>;
    147 native typedef RWTexture1D<int4>;
    148 native typedef RWTexture1D<half>;
    149 native typedef RWTexture1D<half2>;
    150 native typedef RWTexture1D<half3>;
    151 native typedef RWTexture1D<half4>;
    152 native typedef RWTexture1D<float>;
    153 native typedef RWTexture1D<float2>;
    154 native typedef RWTexture1D<float3>;
    155 native typedef RWTexture1D<float4>;
    156132native typedef Texture1DArray<ushort>;
    157133native typedef Texture1DArray<ushort2>;
     
    178154native typedef Texture1DArray<float3>;
    179155native typedef Texture1DArray<float4>;
    180 native typedef RWTexture1DArray<ushort>;
    181 native typedef RWTexture1DArray<ushort2>;
    182 native typedef RWTexture1DArray<ushort3>;
    183 native typedef RWTexture1DArray<ushort4>;
    184 native typedef RWTexture1DArray<uint>;
    185 native typedef RWTexture1DArray<uint2>;
    186 native typedef RWTexture1DArray<uint3>;
    187 native typedef RWTexture1DArray<uint4>;
    188 native typedef RWTexture1DArray<short>;
    189 native typedef RWTexture1DArray<short2>;
    190 native typedef RWTexture1DArray<short3>;
    191 native typedef RWTexture1DArray<short4>;
    192 native typedef RWTexture1DArray<int>;
    193 native typedef RWTexture1DArray<int2>;
    194 native typedef RWTexture1DArray<int3>;
    195 native typedef RWTexture1DArray<int4>;
    196 native typedef RWTexture1DArray<half>;
    197 native typedef RWTexture1DArray<half2>;
    198 native typedef RWTexture1DArray<half3>;
    199 native typedef RWTexture1DArray<half4>;
    200 native typedef RWTexture1DArray<float>;
    201 native typedef RWTexture1DArray<float2>;
    202 native typedef RWTexture1DArray<float3>;
    203 native typedef RWTexture1DArray<float4>;
    204156native typedef Texture2D<ushort>;
    205157native typedef Texture2D<ushort2>;
     
    226178native typedef Texture2D<float3>;
    227179native typedef Texture2D<float4>;
    228 native typedef RWTexture2D<ushort>;
    229 native typedef RWTexture2D<ushort2>;
    230 native typedef RWTexture2D<ushort3>;
    231 native typedef RWTexture2D<ushort4>;
    232 native typedef RWTexture2D<uint>;
    233 native typedef RWTexture2D<uint2>;
    234 native typedef RWTexture2D<uint3>;
    235 native typedef RWTexture2D<uint4>;
    236 native typedef RWTexture2D<short>;
    237 native typedef RWTexture2D<short2>;
    238 native typedef RWTexture2D<short3>;
    239 native typedef RWTexture2D<short4>;
    240 native typedef RWTexture2D<int>;
    241 native typedef RWTexture2D<int2>;
    242 native typedef RWTexture2D<int3>;
    243 native typedef RWTexture2D<int4>;
    244 native typedef RWTexture2D<half>;
    245 native typedef RWTexture2D<half2>;
    246 native typedef RWTexture2D<half3>;
    247 native typedef RWTexture2D<half4>;
    248 native typedef RWTexture2D<float>;
    249 native typedef RWTexture2D<float2>;
    250 native typedef RWTexture2D<float3>;
    251 native typedef RWTexture2D<float4>;
    252180native typedef Texture2DArray<ushort>;
    253181native typedef Texture2DArray<ushort2>;
     
    274202native typedef Texture2DArray<float3>;
    275203native typedef Texture2DArray<float4>;
    276 native typedef RWTexture2DArray<ushort>;
    277 native typedef RWTexture2DArray<ushort2>;
    278 native typedef RWTexture2DArray<ushort3>;
    279 native typedef RWTexture2DArray<ushort4>;
    280 native typedef RWTexture2DArray<uint>;
    281 native typedef RWTexture2DArray<uint2>;
    282 native typedef RWTexture2DArray<uint3>;
    283 native typedef RWTexture2DArray<uint4>;
    284 native typedef RWTexture2DArray<short>;
    285 native typedef RWTexture2DArray<short2>;
    286 native typedef RWTexture2DArray<short3>;
    287 native typedef RWTexture2DArray<short4>;
    288 native typedef RWTexture2DArray<int>;
    289 native typedef RWTexture2DArray<int2>;
    290 native typedef RWTexture2DArray<int3>;
    291 native typedef RWTexture2DArray<int4>;
    292 native typedef RWTexture2DArray<half>;
    293 native typedef RWTexture2DArray<half2>;
    294 native typedef RWTexture2DArray<half3>;
    295 native typedef RWTexture2DArray<half4>;
    296 native typedef RWTexture2DArray<float>;
    297 native typedef RWTexture2DArray<float2>;
    298 native typedef RWTexture2DArray<float3>;
    299 native typedef RWTexture2DArray<float4>;
    300204native typedef Texture3D<ushort>;
    301205native typedef Texture3D<ushort2>;
     
    322226native typedef Texture3D<float3>;
    323227native typedef Texture3D<float4>;
    324 native typedef RWTexture3D<ushort>;
    325 native typedef RWTexture3D<ushort2>;
    326 native typedef RWTexture3D<ushort3>;
    327 native typedef RWTexture3D<ushort4>;
    328 native typedef RWTexture3D<uint>;
    329 native typedef RWTexture3D<uint2>;
    330 native typedef RWTexture3D<uint3>;
    331 native typedef RWTexture3D<uint4>;
    332 native typedef RWTexture3D<short>;
    333 native typedef RWTexture3D<short2>;
    334 native typedef RWTexture3D<short3>;
    335 native typedef RWTexture3D<short4>;
    336 native typedef RWTexture3D<int>;
    337 native typedef RWTexture3D<int2>;
    338 native typedef RWTexture3D<int3>;
    339 native typedef RWTexture3D<int4>;
    340 native typedef RWTexture3D<half>;
    341 native typedef RWTexture3D<half2>;
    342 native typedef RWTexture3D<half3>;
    343 native typedef RWTexture3D<half4>;
    344 native typedef RWTexture3D<float>;
    345 native typedef RWTexture3D<float2>;
    346 native typedef RWTexture3D<float3>;
    347 native typedef RWTexture3D<float4>;
    348228native typedef TextureCube<ushort>;
    349229native typedef TextureCube<ushort2>;
     
    371251native typedef TextureCube<float4>;
    372252native typedef TextureDepth2D<float>;
    373 native typedef RWTextureDepth2D<float>;
    374253native typedef TextureDepth2DArray<float>;
    375 native typedef RWTextureDepth2DArray<float>;
    376254native typedef TextureDepthCube<float>;
    377255
     
    849727}
    850728
     729operator float2(float x, float y) {
     730    float2 result;
     731    result.x = x;
     732    result.y = y;
     733    return result;
     734}
     735
     736operator int3(int x, int y, int z) {
     737    int3 result;
     738    result.x = x;
     739    result.y = y;
     740    result.z = z;
     741    return result;
     742}
     743
     744operator int2(int x, int y) {
     745    int2 result;
     746    result.x = x;
     747    result.y = y;
     748    return result;
     749}
     750
     751operator uint2(uint x, uint y) {
     752    uint2 result;
     753    result.x = x;
     754    result.y = y;
     755    return result;
     756}
     757
     758native ushort Sample(Texture1D<ushort>, sampler, float location);
     759native ushort Sample(Texture1DArray<ushort>, sampler, float2 location);
     760native ushort Sample(Texture2D<ushort>, sampler, float2 location);
     761native ushort Sample(Texture2D<ushort>, sampler, float2 location, int2 offset);
     762native ushort Sample(Texture2DArray<ushort>, sampler, float3 location);
     763native ushort Sample(Texture2DArray<ushort>, sampler, float3 location, int2 offset);
     764native ushort Sample(Texture3D<ushort>, sampler, float3 location);
     765native ushort Sample(Texture3D<ushort>, sampler, float3 location, int3 offset);
     766native ushort Sample(TextureCube<ushort>, sampler, float3 location);
     767native ushort2 Sample(Texture1D<ushort2>, sampler, float location);
     768native ushort2 Sample(Texture1DArray<ushort2>, sampler, float2 location);
     769native ushort2 Sample(Texture2D<ushort2>, sampler, float2 location);
     770native ushort2 Sample(Texture2D<ushort2>, sampler, float2 location, int2 offset);
     771native ushort2 Sample(Texture2DArray<ushort2>, sampler, float3 location);
     772native ushort2 Sample(Texture2DArray<ushort2>, sampler, float3 location, int2 offset);
     773native ushort2 Sample(Texture3D<ushort2>, sampler, float3 location);
     774native ushort2 Sample(Texture3D<ushort2>, sampler, float3 location, int3 offset);
     775native ushort2 Sample(TextureCube<ushort2>, sampler, float3 location);
     776native ushort3 Sample(Texture1D<ushort3>, sampler, float location);
     777native ushort3 Sample(Texture1DArray<ushort3>, sampler, float2 location);
     778native ushort3 Sample(Texture2D<ushort3>, sampler, float2 location);
     779native ushort3 Sample(Texture2D<ushort3>, sampler, float2 location, int2 offset);
     780native ushort3 Sample(Texture2DArray<ushort3>, sampler, float3 location);
     781native ushort3 Sample(Texture2DArray<ushort3>, sampler, float3 location, int2 offset);
     782native ushort3 Sample(Texture3D<ushort3>, sampler, float3 location);
     783native ushort3 Sample(Texture3D<ushort3>, sampler, float3 location, int3 offset);
     784native ushort3 Sample(TextureCube<ushort3>, sampler, float3 location);
     785native ushort4 Sample(Texture1D<ushort4>, sampler, float location);
     786native ushort4 Sample(Texture1DArray<ushort4>, sampler, float2 location);
     787native ushort4 Sample(Texture2D<ushort4>, sampler, float2 location);
     788native ushort4 Sample(Texture2D<ushort4>, sampler, float2 location, int2 offset);
     789native ushort4 Sample(Texture2DArray<ushort4>, sampler, float3 location);
     790native ushort4 Sample(Texture2DArray<ushort4>, sampler, float3 location, int2 offset);
     791native ushort4 Sample(Texture3D<ushort4>, sampler, float3 location);
     792native ushort4 Sample(Texture3D<ushort4>, sampler, float3 location, int3 offset);
     793native ushort4 Sample(TextureCube<ushort4>, sampler, float3 location);
     794native uint Sample(Texture1D<uint>, sampler, float location);
     795native uint Sample(Texture1DArray<uint>, sampler, float2 location);
     796native uint Sample(Texture2D<uint>, sampler, float2 location);
     797native uint Sample(Texture2D<uint>, sampler, float2 location, int2 offset);
     798native uint Sample(Texture2DArray<uint>, sampler, float3 location);
     799native uint Sample(Texture2DArray<uint>, sampler, float3 location, int2 offset);
     800native uint Sample(Texture3D<uint>, sampler, float3 location);
     801native uint Sample(Texture3D<uint>, sampler, float3 location, int3 offset);
     802native uint Sample(TextureCube<uint>, sampler, float3 location);
     803native uint2 Sample(Texture1D<uint2>, sampler, float location);
     804native uint2 Sample(Texture1DArray<uint2>, sampler, float2 location);
     805native uint2 Sample(Texture2D<uint2>, sampler, float2 location);
     806native uint2 Sample(Texture2D<uint2>, sampler, float2 location, int2 offset);
     807native uint2 Sample(Texture2DArray<uint2>, sampler, float3 location);
     808native uint2 Sample(Texture2DArray<uint2>, sampler, float3 location, int2 offset);
     809native uint2 Sample(Texture3D<uint2>, sampler, float3 location);
     810native uint2 Sample(Texture3D<uint2>, sampler, float3 location, int3 offset);
     811native uint2 Sample(TextureCube<uint2>, sampler, float3 location);
     812native uint3 Sample(Texture1D<uint3>, sampler, float location);
     813native uint3 Sample(Texture1DArray<uint3>, sampler, float2 location);
     814native uint3 Sample(Texture2D<uint3>, sampler, float2 location);
     815native uint3 Sample(Texture2D<uint3>, sampler, float2 location, int2 offset);
     816native uint3 Sample(Texture2DArray<uint3>, sampler, float3 location);
     817native uint3 Sample(Texture2DArray<uint3>, sampler, float3 location, int2 offset);
     818native uint3 Sample(Texture3D<uint3>, sampler, float3 location);
     819native uint3 Sample(Texture3D<uint3>, sampler, float3 location, int3 offset);
     820native uint3 Sample(TextureCube<uint3>, sampler, float3 location);
     821native uint4 Sample(Texture1D<uint4>, sampler, float location);
     822native uint4 Sample(Texture1DArray<uint4>, sampler, float2 location);
     823native uint4 Sample(Texture2D<uint4>, sampler, float2 location);
     824native uint4 Sample(Texture2D<uint4>, sampler, float2 location, int2 offset);
     825native uint4 Sample(Texture2DArray<uint4>, sampler, float3 location);
     826native uint4 Sample(Texture2DArray<uint4>, sampler, float3 location, int2 offset);
     827native uint4 Sample(Texture3D<uint4>, sampler, float3 location);
     828native uint4 Sample(Texture3D<uint4>, sampler, float3 location, int3 offset);
     829native uint4 Sample(TextureCube<uint4>, sampler, float3 location);
     830native short Sample(Texture1D<short>, sampler, float location);
     831native short Sample(Texture1DArray<short>, sampler, float2 location);
     832native short Sample(Texture2D<short>, sampler, float2 location);
     833native short Sample(Texture2D<short>, sampler, float2 location, int2 offset);
     834native short Sample(Texture2DArray<short>, sampler, float3 location);
     835native short Sample(Texture2DArray<short>, sampler, float3 location, int2 offset);
     836native short Sample(Texture3D<short>, sampler, float3 location);
     837native short Sample(Texture3D<short>, sampler, float3 location, int3 offset);
     838native short Sample(TextureCube<short>, sampler, float3 location);
     839native short2 Sample(Texture1D<short2>, sampler, float location);
     840native short2 Sample(Texture1DArray<short2>, sampler, float2 location);
     841native short2 Sample(Texture2D<short2>, sampler, float2 location);
     842native short2 Sample(Texture2D<short2>, sampler, float2 location, int2 offset);
     843native short2 Sample(Texture2DArray<short2>, sampler, float3 location);
     844native short2 Sample(Texture2DArray<short2>, sampler, float3 location, int2 offset);
     845native short2 Sample(Texture3D<short2>, sampler, float3 location);
     846native short2 Sample(Texture3D<short2>, sampler, float3 location, int3 offset);
     847native short2 Sample(TextureCube<short2>, sampler, float3 location);
     848native short3 Sample(Texture1D<short3>, sampler, float location);
     849native short3 Sample(Texture1DArray<short3>, sampler, float2 location);
     850native short3 Sample(Texture2D<short3>, sampler, float2 location);
     851native short3 Sample(Texture2D<short3>, sampler, float2 location, int2 offset);
     852native short3 Sample(Texture2DArray<short3>, sampler, float3 location);
     853native short3 Sample(Texture2DArray<short3>, sampler, float3 location, int2 offset);
     854native short3 Sample(Texture3D<short3>, sampler, float3 location);
     855native short3 Sample(Texture3D<short3>, sampler, float3 location, int3 offset);
     856native short3 Sample(TextureCube<short3>, sampler, float3 location);
     857native short4 Sample(Texture1D<short4>, sampler, float location);
     858native short4 Sample(Texture1DArray<short4>, sampler, float2 location);
     859native short4 Sample(Texture2D<short4>, sampler, float2 location);
     860native short4 Sample(Texture2D<short4>, sampler, float2 location, int2 offset);
     861native short4 Sample(Texture2DArray<short4>, sampler, float3 location);
     862native short4 Sample(Texture2DArray<short4>, sampler, float3 location, int2 offset);
     863native short4 Sample(Texture3D<short4>, sampler, float3 location);
     864native short4 Sample(Texture3D<short4>, sampler, float3 location, int3 offset);
     865native short4 Sample(TextureCube<short4>, sampler, float3 location);
     866native int Sample(Texture1D<int>, sampler, float location);
     867native int Sample(Texture1DArray<int>, sampler, float2 location);
     868native int Sample(Texture2D<int>, sampler, float2 location);
     869native int Sample(Texture2D<int>, sampler, float2 location, int2 offset);
     870native int Sample(Texture2DArray<int>, sampler, float3 location);
     871native int Sample(Texture2DArray<int>, sampler, float3 location, int2 offset);
     872native int Sample(Texture3D<int>, sampler, float3 location);
     873native int Sample(Texture3D<int>, sampler, float3 location, int3 offset);
     874native int Sample(TextureCube<int>, sampler, float3 location);
     875native int2 Sample(Texture1D<int2>, sampler, float location);
     876native int2 Sample(Texture1DArray<int2>, sampler, float2 location);
     877native int2 Sample(Texture2D<int2>, sampler, float2 location);
     878native int2 Sample(Texture2D<int2>, sampler, float2 location, int2 offset);
     879native int2 Sample(Texture2DArray<int2>, sampler, float3 location);
     880native int2 Sample(Texture2DArray<int2>, sampler, float3 location, int2 offset);
     881native int2 Sample(Texture3D<int2>, sampler, float3 location);
     882native int2 Sample(Texture3D<int2>, sampler, float3 location, int3 offset);
     883native int2 Sample(TextureCube<int2>, sampler, float3 location);
     884native int3 Sample(Texture1D<int3>, sampler, float location);
     885native int3 Sample(Texture1DArray<int3>, sampler, float2 location);
     886native int3 Sample(Texture2D<int3>, sampler, float2 location);
     887native int3 Sample(Texture2D<int3>, sampler, float2 location, int2 offset);
     888native int3 Sample(Texture2DArray<int3>, sampler, float3 location);
     889native int3 Sample(Texture2DArray<int3>, sampler, float3 location, int2 offset);
     890native int3 Sample(Texture3D<int3>, sampler, float3 location);
     891native int3 Sample(Texture3D<int3>, sampler, float3 location, int3 offset);
     892native int3 Sample(TextureCube<int3>, sampler, float3 location);
     893native int4 Sample(Texture1D<int4>, sampler, float location);
     894native int4 Sample(Texture1DArray<int4>, sampler, float2 location);
     895native int4 Sample(Texture2D<int4>, sampler, float2 location);
     896native int4 Sample(Texture2D<int4>, sampler, float2 location, int2 offset);
     897native int4 Sample(Texture2DArray<int4>, sampler, float3 location);
     898native int4 Sample(Texture2DArray<int4>, sampler, float3 location, int2 offset);
     899native int4 Sample(Texture3D<int4>, sampler, float3 location);
     900native int4 Sample(Texture3D<int4>, sampler, float3 location, int3 offset);
     901native int4 Sample(TextureCube<int4>, sampler, float3 location);
     902native half Sample(Texture1D<half>, sampler, float location);
     903native half Sample(Texture1DArray<half>, sampler, float2 location);
     904native half Sample(Texture2D<half>, sampler, float2 location);
     905native half Sample(Texture2D<half>, sampler, float2 location, int2 offset);
     906native half Sample(Texture2DArray<half>, sampler, float3 location);
     907native half Sample(Texture2DArray<half>, sampler, float3 location, int2 offset);
     908native half Sample(Texture3D<half>, sampler, float3 location);
     909native half Sample(Texture3D<half>, sampler, float3 location, int3 offset);
     910native half Sample(TextureCube<half>, sampler, float3 location);
     911native half2 Sample(Texture1D<half2>, sampler, float location);
     912native half2 Sample(Texture1DArray<half2>, sampler, float2 location);
     913native half2 Sample(Texture2D<half2>, sampler, float2 location);
     914native half2 Sample(Texture2D<half2>, sampler, float2 location, int2 offset);
     915native half2 Sample(Texture2DArray<half2>, sampler, float3 location);
     916native half2 Sample(Texture2DArray<half2>, sampler, float3 location, int2 offset);
     917native half2 Sample(Texture3D<half2>, sampler, float3 location);
     918native half2 Sample(Texture3D<half2>, sampler, float3 location, int3 offset);
     919native half2 Sample(TextureCube<half2>, sampler, float3 location);
     920native half3 Sample(Texture1D<half3>, sampler, float location);
     921native half3 Sample(Texture1DArray<half3>, sampler, float2 location);
     922native half3 Sample(Texture2D<half3>, sampler, float2 location);
     923native half3 Sample(Texture2D<half3>, sampler, float2 location, int2 offset);
     924native half3 Sample(Texture2DArray<half3>, sampler, float3 location);
     925native half3 Sample(Texture2DArray<half3>, sampler, float3 location, int2 offset);
     926native half3 Sample(Texture3D<half3>, sampler, float3 location);
     927native half3 Sample(Texture3D<half3>, sampler, float3 location, int3 offset);
     928native half3 Sample(TextureCube<half3>, sampler, float3 location);
     929native half4 Sample(Texture1D<half4>, sampler, float location);
     930native half4 Sample(Texture1DArray<half4>, sampler, float2 location);
     931native half4 Sample(Texture2D<half4>, sampler, float2 location);
     932native half4 Sample(Texture2D<half4>, sampler, float2 location, int2 offset);
     933native half4 Sample(Texture2DArray<half4>, sampler, float3 location);
     934native half4 Sample(Texture2DArray<half4>, sampler, float3 location, int2 offset);
     935native half4 Sample(Texture3D<half4>, sampler, float3 location);
     936native half4 Sample(Texture3D<half4>, sampler, float3 location, int3 offset);
     937native half4 Sample(TextureCube<half4>, sampler, float3 location);
     938native float Sample(Texture1D<float>, sampler, float location);
     939native float Sample(Texture1DArray<float>, sampler, float2 location);
     940native float Sample(Texture2D<float>, sampler, float2 location);
     941native float Sample(Texture2D<float>, sampler, float2 location, int2 offset);
     942native float Sample(Texture2DArray<float>, sampler, float3 location);
     943native float Sample(Texture2DArray<float>, sampler, float3 location, int2 offset);
     944native float Sample(Texture3D<float>, sampler, float3 location);
     945native float Sample(Texture3D<float>, sampler, float3 location, int3 offset);
     946native float Sample(TextureCube<float>, sampler, float3 location);
     947native float2 Sample(Texture1D<float2>, sampler, float location);
     948native float2 Sample(Texture1DArray<float2>, sampler, float2 location);
     949native float2 Sample(Texture2D<float2>, sampler, float2 location);
     950native float2 Sample(Texture2D<float2>, sampler, float2 location, int2 offset);
     951native float2 Sample(Texture2DArray<float2>, sampler, float3 location);
     952native float2 Sample(Texture2DArray<float2>, sampler, float3 location, int2 offset);
     953native float2 Sample(Texture3D<float2>, sampler, float3 location);
     954native float2 Sample(Texture3D<float2>, sampler, float3 location, int3 offset);
     955native float2 Sample(TextureCube<float2>, sampler, float3 location);
     956native float3 Sample(Texture1D<float3>, sampler, float location);
     957native float3 Sample(Texture1DArray<float3>, sampler, float2 location);
     958native float3 Sample(Texture2D<float3>, sampler, float2 location);
     959native float3 Sample(Texture2D<float3>, sampler, float2 location, int2 offset);
     960native float3 Sample(Texture2DArray<float3>, sampler, float3 location);
     961native float3 Sample(Texture2DArray<float3>, sampler, float3 location, int2 offset);
     962native float3 Sample(Texture3D<float3>, sampler, float3 location);
     963native float3 Sample(Texture3D<float3>, sampler, float3 location, int3 offset);
     964native float3 Sample(TextureCube<float3>, sampler, float3 location);
     965native float4 Sample(Texture1D<float4>, sampler, float location);
     966native float4 Sample(Texture1DArray<float4>, sampler, float2 location);
     967native float4 Sample(Texture2D<float4>, sampler, float2 location);
     968native float4 Sample(Texture2D<float4>, sampler, float2 location, int2 offset);
     969native float4 Sample(Texture2DArray<float4>, sampler, float3 location);
     970native float4 Sample(Texture2DArray<float4>, sampler, float3 location, int2 offset);
     971native float4 Sample(Texture3D<float4>, sampler, float3 location);
     972native float4 Sample(Texture3D<float4>, sampler, float3 location, int3 offset);
     973native float4 Sample(TextureCube<float4>, sampler, float3 location);
     974native float Sample(TextureDepth2D<float>, sampler, float2 location);
     975native float Sample(TextureDepth2D<float>, sampler, float2 location, int2 offset);
     976native float Sample(TextureDepth2DArray<float>, sampler, float3 location);
     977native float Sample(TextureDepth2DArray<float>, sampler, float3 location, int2 offset);
     978native float Sample(TextureDepthCube<float>, sampler, float3 location);
     979
     980native ushort Load(Texture1D<ushort>, int location);
     981native ushort Load(Texture1DArray<ushort>, int2 location);
     982native ushort Load(Texture2D<ushort>, int2 location);
     983native ushort Load(Texture2DArray<ushort>, int3 location);
     984native ushort Load(Texture3D<ushort>, int3 location);
     985native ushort2 Load(Texture1D<ushort2>, int location);
     986native ushort2 Load(Texture1DArray<ushort2>, int2 location);
     987native ushort2 Load(Texture2D<ushort2>, int2 location);
     988native ushort2 Load(Texture2DArray<ushort2>, int3 location);
     989native ushort2 Load(Texture3D<ushort2>, int3 location);
     990native ushort3 Load(Texture1D<ushort3>, int location);
     991native ushort3 Load(Texture1DArray<ushort3>, int2 location);
     992native ushort3 Load(Texture2D<ushort3>, int2 location);
     993native ushort3 Load(Texture2DArray<ushort3>, int3 location);
     994native ushort3 Load(Texture3D<ushort3>, int3 location);
     995native ushort4 Load(Texture1D<ushort4>, int location);
     996native ushort4 Load(Texture1DArray<ushort4>, int2 location);
     997native ushort4 Load(Texture2D<ushort4>, int2 location);
     998native ushort4 Load(Texture2DArray<ushort4>, int3 location);
     999native ushort4 Load(Texture3D<ushort4>, int3 location);
     1000native uint Load(Texture1D<uint>, int location);
     1001native uint Load(Texture1DArray<uint>, int2 location);
     1002native uint Load(Texture2D<uint>, int2 location);
     1003native uint Load(Texture2DArray<uint>, int3 location);
     1004native uint Load(Texture3D<uint>, int3 location);
     1005native uint2 Load(Texture1D<uint2>, int location);
     1006native uint2 Load(Texture1DArray<uint2>, int2 location);
     1007native uint2 Load(Texture2D<uint2>, int2 location);
     1008native uint2 Load(Texture2DArray<uint2>, int3 location);
     1009native uint2 Load(Texture3D<uint2>, int3 location);
     1010native uint3 Load(Texture1D<uint3>, int location);
     1011native uint3 Load(Texture1DArray<uint3>, int2 location);
     1012native uint3 Load(Texture2D<uint3>, int2 location);
     1013native uint3 Load(Texture2DArray<uint3>, int3 location);
     1014native uint3 Load(Texture3D<uint3>, int3 location);
     1015native uint4 Load(Texture1D<uint4>, int location);
     1016native uint4 Load(Texture1DArray<uint4>, int2 location);
     1017native uint4 Load(Texture2D<uint4>, int2 location);
     1018native uint4 Load(Texture2DArray<uint4>, int3 location);
     1019native uint4 Load(Texture3D<uint4>, int3 location);
     1020native short Load(Texture1D<short>, int location);
     1021native short Load(Texture1DArray<short>, int2 location);
     1022native short Load(Texture2D<short>, int2 location);
     1023native short Load(Texture2DArray<short>, int3 location);
     1024native short Load(Texture3D<short>, int3 location);
     1025native short2 Load(Texture1D<short2>, int location);
     1026native short2 Load(Texture1DArray<short2>, int2 location);
     1027native short2 Load(Texture2D<short2>, int2 location);
     1028native short2 Load(Texture2DArray<short2>, int3 location);
     1029native short2 Load(Texture3D<short2>, int3 location);
     1030native short3 Load(Texture1D<short3>, int location);
     1031native short3 Load(Texture1DArray<short3>, int2 location);
     1032native short3 Load(Texture2D<short3>, int2 location);
     1033native short3 Load(Texture2DArray<short3>, int3 location);
     1034native short3 Load(Texture3D<short3>, int3 location);
     1035native short4 Load(Texture1D<short4>, int location);
     1036native short4 Load(Texture1DArray<short4>, int2 location);
     1037native short4 Load(Texture2D<short4>, int2 location);
     1038native short4 Load(Texture2DArray<short4>, int3 location);
     1039native short4 Load(Texture3D<short4>, int3 location);
     1040native int Load(Texture1D<int>, int location);
     1041native int Load(Texture1DArray<int>, int2 location);
     1042native int Load(Texture2D<int>, int2 location);
     1043native int Load(Texture2DArray<int>, int3 location);
     1044native int Load(Texture3D<int>, int3 location);
     1045native int2 Load(Texture1D<int2>, int location);
     1046native int2 Load(Texture1DArray<int2>, int2 location);
     1047native int2 Load(Texture2D<int2>, int2 location);
     1048native int2 Load(Texture2DArray<int2>, int3 location);
     1049native int2 Load(Texture3D<int2>, int3 location);
     1050native int3 Load(Texture1D<int3>, int location);
     1051native int3 Load(Texture1DArray<int3>, int2 location);
     1052native int3 Load(Texture2D<int3>, int2 location);
     1053native int3 Load(Texture2DArray<int3>, int3 location);
     1054native int3 Load(Texture3D<int3>, int3 location);
     1055native int4 Load(Texture1D<int4>, int location);
     1056native int4 Load(Texture1DArray<int4>, int2 location);
     1057native int4 Load(Texture2D<int4>, int2 location);
     1058native int4 Load(Texture2DArray<int4>, int3 location);
     1059native int4 Load(Texture3D<int4>, int3 location);
     1060native half Load(Texture1D<half>, int location);
     1061native half Load(Texture1DArray<half>, int2 location);
     1062native half Load(Texture2D<half>, int2 location);
     1063native half Load(Texture2DArray<half>, int3 location);
     1064native half Load(Texture3D<half>, int3 location);
     1065native half2 Load(Texture1D<half2>, int location);
     1066native half2 Load(Texture1DArray<half2>, int2 location);
     1067native half2 Load(Texture2D<half2>, int2 location);
     1068native half2 Load(Texture2DArray<half2>, int3 location);
     1069native half2 Load(Texture3D<half2>, int3 location);
     1070native half3 Load(Texture1D<half3>, int location);
     1071native half3 Load(Texture1DArray<half3>, int2 location);
     1072native half3 Load(Texture2D<half3>, int2 location);
     1073native half3 Load(Texture2DArray<half3>, int3 location);
     1074native half3 Load(Texture3D<half3>, int3 location);
     1075native half4 Load(Texture1D<half4>, int location);
     1076native half4 Load(Texture1DArray<half4>, int2 location);
     1077native half4 Load(Texture2D<half4>, int2 location);
     1078native half4 Load(Texture2DArray<half4>, int3 location);
     1079native half4 Load(Texture3D<half4>, int3 location);
     1080native float Load(Texture1D<float>, int location);
     1081native float Load(Texture1DArray<float>, int2 location);
     1082native float Load(Texture2D<float>, int2 location);
     1083native float Load(Texture2DArray<float>, int3 location);
     1084native float Load(Texture3D<float>, int3 location);
     1085native float2 Load(Texture1D<float2>, int location);
     1086native float2 Load(Texture1DArray<float2>, int2 location);
     1087native float2 Load(Texture2D<float2>, int2 location);
     1088native float2 Load(Texture2DArray<float2>, int3 location);
     1089native float2 Load(Texture3D<float2>, int3 location);
     1090native float3 Load(Texture1D<float3>, int location);
     1091native float3 Load(Texture1DArray<float3>, int2 location);
     1092native float3 Load(Texture2D<float3>, int2 location);
     1093native float3 Load(Texture2DArray<float3>, int3 location);
     1094native float3 Load(Texture3D<float3>, int3 location);
     1095native float4 Load(Texture1D<float4>, int location);
     1096native float4 Load(Texture1DArray<float4>, int2 location);
     1097native float4 Load(Texture2D<float4>, int2 location);
     1098native float4 Load(Texture2DArray<float4>, int3 location);
     1099native float4 Load(Texture3D<float4>, int3 location);
     1100native float Load(TextureDepth2D<float>, int2 location);
     1101native float Load(TextureDepth2DArray<float>, int3 location);
     1102
     1103native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, thread uint* Height, thread uint* NumberOfLevels);
     1104native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, thread uint* Height, device uint* NumberOfLevels);
     1105native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, thread uint* Height, threadgroup uint* NumberOfLevels);
     1106native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, device uint* Height, thread uint* NumberOfLevels);
     1107native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, device uint* Height, device uint* NumberOfLevels);
     1108native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, device uint* Height, threadgroup uint* NumberOfLevels);
     1109native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, threadgroup uint* Height, thread uint* NumberOfLevels);
     1110native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, threadgroup uint* Height, device uint* NumberOfLevels);
     1111native void GetDimensions(Texture2D<float4>, uint MipLevel, thread uint* Width, threadgroup uint* Height, threadgroup uint* NumberOfLevels);
     1112native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, thread uint* Height, thread uint* NumberOfLevels);
     1113native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, thread uint* Height, device uint* NumberOfLevels);
     1114native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, thread uint* Height, threadgroup uint* NumberOfLevels);
     1115native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, device uint* Height, thread uint* NumberOfLevels);
     1116native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, device uint* Height, device uint* NumberOfLevels);
     1117native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, device uint* Height, threadgroup uint* NumberOfLevels);
     1118native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, threadgroup uint* Height, thread uint* NumberOfLevels);
     1119native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, threadgroup uint* Height, device uint* NumberOfLevels);
     1120native void GetDimensions(Texture2D<float4>, uint MipLevel, device uint* Width, threadgroup uint* Height, threadgroup uint* NumberOfLevels);
     1121native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, thread uint* Height, thread uint* NumberOfLevels);
     1122native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, thread uint* Height, device uint* NumberOfLevels);
     1123native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, thread uint* Height, threadgroup uint* NumberOfLevels);
     1124native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, device uint* Height, thread uint* NumberOfLevels);
     1125native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, device uint* Height, device uint* NumberOfLevels);
     1126native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, device uint* Height, threadgroup uint* NumberOfLevels);
     1127native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, threadgroup uint* Height, thread uint* NumberOfLevels);
     1128native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, threadgroup uint* Height, device uint* NumberOfLevels);
     1129native void GetDimensions(Texture2D<float4>, uint MipLevel, threadgroup uint* Width, threadgroup uint* Height, threadgroup uint* NumberOfLevels);
     1130
    8511131// FIXME: https://bugs.webkit.org/show_bug.cgi?id=192890 Insert the rest of the standard library once the parser is fast enough
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp

    r245680 r246631  
    4040class FindArrayTypes : public Visitor {
    4141public:
    42     ~FindArrayTypes() = default;
     42    virtual ~FindArrayTypes() = default;
    4343
    4444    void visit(AST::ArrayType& arrayType) override
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp

    r246550 r246631  
    8383class FindAllTypes : public Visitor {
    8484public:
    85     ~FindAllTypes() = default;
     85    virtual ~FindAllTypes() = default;
    8686
    8787    void visit(AST::PointerType& pointerType) override
     
    172172        if (matches(namedType, program.intrinsics().voidType()))
    173173            continue;
    174         if (is<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType)) && downcast<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType)).isAtom())
     174        if (is<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType)) && downcast<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType)).isAtomic())
    175175            continue;
    176176
     
    181181        program.append(WTFMove(copyConstructor));
    182182
     183        if (is<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType))) {
     184            auto& nativeTypeDeclaration = downcast<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType));
     185            if (nativeTypeDeclaration.isOpaqueType())
     186                continue;
     187        }
    183188        AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(Lexer::Token(namedType.get().origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(namedType.get().origin()), namedType.get()), "operator cast"_str, AST::VariableDeclarations(), WTF::nullopt, isOperator));
    184189        if (!program.append(WTFMove(defaultConstructor)))
  • trunk/Source/WebCore/Sources.txt

    r246540 r246631  
    313313Modules/webgpu/WHLSL/WHLSLLexer.cpp
    314314Modules/webgpu/WHLSL/WHLSLParser.cpp
     315Modules/webgpu/WHLSL/WHLSLCheckTextureReferences.cpp
    315316Modules/webgpu/WHLSL/WHLSLChecker.cpp
    316317Modules/webgpu/WHLSL/WHLSLGatherEntryPointItems.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r246611 r246631  
    63846384                1C24EEA71C72A7B40080F8FC /* JSFontFaceSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSFontFaceSet.h; path = DerivedSources/WebCore/JSFontFaceSet.h; sourceTree = BUILT_PRODUCTS_DIR; };
    63856385                1C2649790D7E248A00BD10F2 /* DocumentLoaderMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentLoaderMac.cpp; sourceTree = "<group>"; };
     6386                1C281C6D22B87B9800691C00 /* WHLSLCheckTextureReferences.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLCheckTextureReferences.cpp; sourceTree = "<group>"; };
     6387                1C281C6E22B87B9800691C00 /* WHLSLCheckTextureReferences.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLCheckTextureReferences.h; sourceTree = "<group>"; };
    63866388                1C3249101C6D6A3B007EDB32 /* FontVariantBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontVariantBuilder.cpp; sourceTree = "<group>"; };
    63876389                1C33277121CF0BE1000DC9F2 /* WHLSLNamedType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLNamedType.h; sourceTree = "<group>"; };
     
    2548225484                                1C840B9B21EC400900D0500D /* WHLSLChecker.cpp */,
    2548325485                                1C840B9721EC400700D0500D /* WHLSLChecker.h */,
     25486                                1C281C6D22B87B9800691C00 /* WHLSLCheckTextureReferences.cpp */,
     25487                                1C281C6E22B87B9800691C00 /* WHLSLCheckTextureReferences.h */,
    2548425488                                1C86CA4B22AA19FF001BF961 /* WHLSLComputeDimensions.cpp */,
    2548525489                                1C86CA4C22AA19FF001BF961 /* WHLSLComputeDimensions.h */,
  • trunk/Source/WebCore/platform/graphics/gpu/GPUTexture.h

    r242575 r246631  
    5555    bool isOutputAttachment() const { return m_usage.contains(GPUTextureUsage::Flags::OutputAttachment); }
    5656    bool isReadOnly() const { return m_usage.containsAny({ GPUTextureUsage::Flags::TransferSource, GPUTextureUsage::Flags::Sampled }); }
     57    bool isSampled() const { return m_usage.contains(GPUTextureUsage::Flags::Sampled); }
     58    bool isStorage() const { return m_usage.contains(GPUTextureUsage::Flags::Storage); }
    5759
    5860    RefPtr<GPUTexture> tryCreateDefaultTextureView();
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm

    r246394 r246631  
    217217                return false;
    218218            if (isForVertex)
    219                 setSamplerOnEncoder(vertexEncoder, samplerState, index);
     219                setSamplerOnEncoder(vertexEncoder, samplerState, layoutBinding.internalName);
    220220            if (isForFragment)
    221                 setSamplerOnEncoder(fragmentEncoder, samplerState, index);
     221                setSamplerOnEncoder(fragmentEncoder, samplerState, layoutBinding.internalName);
    222222            if (isForCompute)
    223                 setSamplerOnEncoder(computeEncoder, samplerState, index);
     223                setSamplerOnEncoder(computeEncoder, samplerState, layoutBinding.internalName);
    224224            return true;
    225225        }, [&](GPUBindGroupLayout::SampledTexture&) -> bool {
     
    228228                return false;
    229229            if (isForVertex)
    230                 setTextureOnEncoder(vertexEncoder, textureResource->platformTexture(), index);
     230                setTextureOnEncoder(vertexEncoder, textureResource->platformTexture(), layoutBinding.internalName);
    231231            if (isForFragment)
    232                 setTextureOnEncoder(fragmentEncoder, textureResource->platformTexture(), index);
     232                setTextureOnEncoder(fragmentEncoder, textureResource->platformTexture(), layoutBinding.internalName);
    233233            if (isForCompute)
    234                 setTextureOnEncoder(computeEncoder, textureResource->platformTexture(), index);
     234                setTextureOnEncoder(computeEncoder, textureResource->platformTexture(), layoutBinding.internalName);
    235235            boundTextures.append(textureResource.releaseNonNull());
    236236            return true;
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm

    r243627 r246631  
    6464
    6565    for (auto& bufferRef : bindGroup.boundBuffers()) {
    66         useResource(bufferRef->platformBuffer(), bufferRef->isReadOnly() ? MTLResourceUsageRead : MTLResourceUsageRead | MTLResourceUsageWrite);
     66        MTLResourceUsage usage = 0;
     67        if (bufferRef->isUniform()) {
     68            ASSERT(!bufferRef->isStorage());
     69            usage = MTLResourceUsageRead;
     70        } else if (bufferRef->isStorage()) {
     71            ASSERT(!bufferRef->isUniform());
     72            usage = MTLResourceUsageRead | MTLResourceUsageWrite;
     73        }
     74        useResource(bufferRef->platformBuffer(), usage);
    6775        m_commandBuffer->useBuffer(bufferRef.copyRef());
    6876    }
    6977    for (auto& textureRef : bindGroup.boundTextures()) {
    70         useResource(textureRef->platformTexture(), textureRef->isReadOnly() ? MTLResourceUsageRead : MTLResourceUsageRead | MTLResourceUsageWrite);
     78        MTLResourceUsage usage = 0;
     79        if (textureRef->isSampled()) {
     80            ASSERT(!textureRef->isStorage());
     81            usage = MTLResourceUsageRead | MTLResourceUsageSample;
     82        } else if (textureRef->isStorage()) {
     83            ASSERT(!textureRef->isSampled());
     84            usage = MTLResourceUsageRead | MTLResourceUsageWrite;
     85        }
     86        useResource(textureRef->platformTexture(), usage);
    7187        m_commandBuffer->useTexture(textureRef.copyRef());
    7288    }
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm

    r243636 r246631  
    6060    UNUSED_PARAM(functionName);
    6161#endif
     62
    6263    if (flags.containsAny({ GPUTextureUsage::Flags::TransferSource, GPUTextureUsage::Flags::Sampled }) && (flags & GPUTextureUsage::Flags::Storage)) {
    6364        LOG(WebGPU, "%s: Texture cannot have both STORAGE and a read-only usage!", functionName);
     
    6566    }
    6667
    67     if (flags & GPUTextureUsage::Flags::OutputAttachment) {
    68         if (flags.containsAny({ GPUTextureUsage::Flags::Storage, GPUTextureUsage::Flags::Sampled })) {
    69             LOG(WebGPU, "%s: Texture cannot have OUTPUT_ATTACHMENT usage with STORAGE or SAMPLED usages!", functionName);
    70             return WTF::nullopt;
    71         }
    72 
    73         return MTLTextureUsageRenderTarget | MTLTextureUsagePixelFormatView;
    74     }
    75 
    76     if (flags & GPUTextureUsage::Flags::Storage)
    77         return MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView;
    78 
    79     if (flags & GPUTextureUsage::Flags::Sampled)
    80         return MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView;
    81 
    82     return MTLTextureUsageUnknown;
     68    if (flags & GPUTextureUsage::Flags::OutputAttachment && flags.containsAny({ GPUTextureUsage::Flags::Storage, GPUTextureUsage::Flags::Sampled })) {
     69        LOG(WebGPU, "%s: Texture cannot have OUTPUT_ATTACHMENT usage with STORAGE or SAMPLED usages!", functionName);
     70        return WTF::nullopt;
     71    }
     72
     73    MTLTextureUsage result = MTLTextureUsagePixelFormatView;
     74    if (flags.contains(GPUTextureUsage::Flags::OutputAttachment))
     75        result |= MTLTextureUsageRenderTarget;
     76    if (flags.containsAny({ GPUTextureUsage::Flags::Storage, GPUTextureUsage::Flags::Sampled }))
     77        result |= MTLTextureUsageShaderRead;
     78    if (flags.contains(GPUTextureUsage::Flags::Storage))
     79        result |= MTLTextureUsageShaderWrite;
     80
     81    return result;
    8382}
    8483
Note: See TracChangeset for help on using the changeset viewer.