Changeset 242615 in webkit


Ignore:
Timestamp:
Mar 7, 2019 3:03:53 PM (5 years ago)
Author:
Justin Fan
Message:

[Web GPU] GPUSampler implementation
https://bugs.webkit.org/show_bug.cgi?id=195427
<rdar://problem/48686011>

Reviewed by Dean Jackson.

Source/WebCore:

Implement ability to create GPUSamplers and use them as pipeline resource bindings.

Test: texture-triangle-strip.html updated.

Add symbols to project:

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Sources.txt:
  • SourcesCocoa.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/WebCoreBuiltinNames.h:

GPUSampler creation:

  • Modules/webgpu/GPUSamplerDescriptor.idl: Added.
  • Modules/webgpu/WebGPUDevice.cpp:

(WebCore::WebGPUDevice::createSampler const): Added.

  • Modules/webgpu/WebGPUDevice.h:
  • Modules/webgpu/WebGPUDevice.idl:
  • Modules/webgpu/WebGPUSampler.cpp: Added.

(WebCore::WebGPUSampler::create):
(WebCore::WebGPUSampler::WebGPUSampler):

  • Modules/webgpu/WebGPUSampler.h: Added.

(WebCore::WebGPUSampler::sampler const):

  • Modules/webgpu/WebGPUSampler.idl: Added.
  • platform/graphics/gpu/GPUDevice.cpp:

(WebCore::GPUDevice::tryCreateSampler const): Added.

  • platform/graphics/gpu/GPUDevice.h:
  • platform/graphics/gpu/GPUSampler.h: Added.

(WebCore::GPUSampler::platformSampler const):

  • platform/graphics/gpu/GPUSamplerDescriptor.h: Added.
  • platform/graphics/gpu/cocoa/GPUSamplerMetal.mm: Added.

(WebCore::mtlAddressModeForAddressMode):
(WebCore::mtlBorderColorForBorderColor):
(WebCore::mtlMinMagFilterForFilterMode):
(WebCore::mtlMipFilterForFilterMode):
(WebCore::tryCreateMtlSamplerState):
(WebCore::GPUSampler::tryCreate):
(WebCore::GPUSampler::GPUSampler):

Move GPUCompareFunction to Utils for shared use.

  • platform/graphics/gpu/GPUCompareFunction.h:
  • platform/graphics/gpu/GPUUtils.h:
  • platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:

(WebCore::tryCreateMtlDepthStencilState):
(WebCore::validateAndConvertDepthCompareFunctionToMtl): Deleted.

  • platform/graphics/gpu/cocoa/GPUUtilsMetal.mm:

(WebCore::platformTextureFormatForGPUTextureFormat):
(WebCore::platformCompareFunctionForGPUCompareFunction):

Expand bind groups to accept GPUSamplers:

  • Modules/webgpu/WebGPUBindGroupBinding.h:
  • Modules/webgpu/WebGPUBindGroupBinding.idl:
  • Modules/webgpu/WebGPUBindGroupDescriptor.cpp:

(WebCore::WebGPUBindGroupDescriptor::asGPUBindGroupDescriptor const):

  • platform/graphics/gpu/GPUBindGroupBinding.h:
  • platform/graphics/gpu/GPUProgrammablePassEncoder.h:
  • platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm:

(WebCore::GPUProgrammablePassEncoder::setBindGroup):
(WebCore::GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder):
(WebCore::GPUProgrammablePassEncoder::setResourceAsSamplerOnEncoder): Added.
(WebCore::GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder):

Misc:

  • Modules/webgpu/WebGPUTexture.cpp: Missing includes.
  • Modules/webgpu/WebGPUTexture.h:
  • Modules/webgpu/WebGPUSwapChain.cpp: Removed extra include.

LayoutTests:

Update texture-triangle-strip to use a GPUSampler provided through bindings instead of creating one in shader.

  • webgpu/texture-triangle-strip.html:
Location:
trunk
Files:
1 added
30 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r242612 r242615  
     12019-03-07  Justin Fan  <justin_fan@apple.com>
     2
     3        [Web GPU] GPUSampler implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=195427
     5        <rdar://problem/48686011>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Update texture-triangle-strip to use a GPUSampler provided through bindings instead of creating one in shader.
     10
     11        * webgpu/texture-triangle-strip.html:
     12
    1132019-03-07  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/webgpu/texture-triangle-strip.html

    r242575 r242615  
    1111    testRunner.waitUntilDone();
    1212
     13const positionBufferIndex = 0;
     14const texCoordsBufferIndex = 1;
     15const positionAttributeNum = 0;
     16const texCoordsAttributeNum = 1;
     17const bindGroupIndex = 0;
     18const textureBindingNum = 0;
     19const samplerBindingNum = 1;
     20
    1321const shaderCode = `
    1422#include <metal_stdlib>
     
    1826struct VertexIn
    1927{
    20     float4 position [[attribute(0)]];
    21     float2 texCoords [[attribute(1)]];
     28    float4 position [[attribute(${positionAttributeNum})]];
     29    float2 texCoords [[attribute(${texCoordsAttributeNum})]];
    2230};
    2331
     
    3644}
    3745
    38 struct Texture
    39 {
    40     texture2d<float> image [[id(0)]];
     46struct TextureSampler
     47{
     48    texture2d<float> t [[id(${textureBindingNum})]];
     49    sampler s [[id(${samplerBindingNum})]];
    4150};
    4251
    43 fragment float4 fragment_main(VertexOut v [[stage_in]], const device Texture& t [[buffer(0)]])
    44 {
    45     constexpr sampler s(coord::normalized, address::clamp_to_zero, filter::nearest);
    46     return t.image.sample(s, v.texCoords);
     52fragment float4 fragment_main(VertexOut v [[stage_in]], const device TextureSampler& args [[buffer(${bindGroupIndex})]])
     53{
     54    return args.t.sample(args.s, v.texCoords);
    4755}
    4856`
     
    5260        indexFormat: WebGPUIndexFormat.UINT32,
    5361        attributes: [{
    54             shaderLocation: 0,
    55             inputSlot: 0,
     62            shaderLocation: positionAttributeNum,
     63            inputSlot: positionBufferIndex,
    5664            offset: 0,
    5765            format: WebGPUVertexFormat.FLOAT_R32_G32_B32_A32
    5866        }, {
    59             shaderLocation: 1,
    60             inputSlot: 1,
     67            shaderLocation: texCoordsAttributeNum,
     68            inputSlot: texCoordsBufferIndex,
    6169            offset: 0,
    6270            format: WebGPUVertexFormat.FLOAT_R32_G32
    6371        }],
    6472        inputs: [{
    65             inputSlot: 0,
     73            inputSlot: positionBufferIndex,
    6674            stride: 4 * 4,
    6775            stepMode: WebGPUInputStepMode.VERTEX
    6876        }, {
    69             inputSlot: 1,
     77            inputSlot: texCoordsBufferIndex,
    7078            stride: 4 * 2,
    7179            stepMode: WebGPUInputStepMode.VERTEX
     
    8189    const shaderModule = device.createShaderModule({ code: shaderCode });
    8290
    83     const vertexArray = new Float32Array([
     91    const positionArray = new Float32Array([
    8492        // float4 xyzw
    8593        -1, 1, 0, 1,
     
    8896        1, -1, 0, 1
    8997    ]);
    90     const vertexBuffer = device.createBuffer({ size: vertexArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
    91     vertexBuffer.setSubData(0, vertexArray.buffer);
    92 
    93     const textureCoordArray = new Float32Array([
     98    const positionBuffer = device.createBuffer({ size: positionArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
     99    positionBuffer.setSubData(0, positionArray.buffer);
     100
     101    const texCoordsArray = new Float32Array([
    94102        // float2 texCoords
    95103        0, 0,
     
    98106        1, 1
    99107    ]);
    100     const textureCoordBuffer = device.createBuffer({ size: textureCoordArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
    101     textureCoordBuffer.setSubData(0, textureCoordArray.buffer);
     108    const textureCoordBuffer = device.createBuffer({ size: texCoordsArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
     109    textureCoordBuffer.setSubData(0, texCoordsArray.buffer);
    102110
    103111    const inputStateDescriptor = createInputStateDescriptor();
     
    144152    const texture = device.createTexture(textureDescriptor);
    145153
    146     // Bind texture to pipeline
    147     const textureBindingNum = 0;
     154    // Bind texture and a sampler to pipeline
     155    const textureLayoutBinding = {
     156        binding: textureBindingNum,
     157        visibility: GPUShaderStageBit.FRAGMENT,
     158        type: "sampled-texture"
     159    };
     160    const samplerLayoutBinding = {
     161        binding: samplerBindingNum,
     162        visibility: GPUShaderStageBit.FRAGMENT,
     163        type: "sampler"
     164    };
     165
    148166    const bindGroupLayoutDescriptor = {
    149         bindings: [{ binding: textureBindingNum, visibility: GPUShaderStageBit.FRAGMENT, type: "sampled-texture" }]
     167        bindings: [textureLayoutBinding, samplerLayoutBinding]
    150168    };
    151169    bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
    152170    const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] });
    153171
     172    const textureBinding = {
     173        binding: textureBindingNum,
     174        resource: texture.createDefaultTextureView()
     175    };
     176    const samplerBinding = {
     177        binding: samplerBindingNum,
     178        resource: device.createSampler({ minFilter: "nearest", magFilter: "nearest" })
     179    };
     180
    154181    const bindGroupDescriptor = {
    155182        layout: bindGroupLayout,
    156         bindings: [{ binding: textureBindingNum, resource: texture.createDefaultTextureView() }]
     183        bindings: [textureBinding, samplerBinding]
    157184    };
    158185    const bindGroup = device.createBindGroup(bindGroupDescriptor);
     
    177204    const passEncoder = beginBasicRenderPass(context, commandBuffer);
    178205    passEncoder.setPipeline(pipeline);
    179     passEncoder.setBindGroup(0, bindGroup);
    180     passEncoder.setVertexBuffers(0, [vertexBuffer, textureCoordBuffer], [0, 0]);
     206    passEncoder.setBindGroup(bindGroupIndex, bindGroup);
     207    passEncoder.setVertexBuffers(positionBufferIndex, [positionBuffer, textureCoordBuffer], [0, 0]);
    181208    passEncoder.draw(4, 1, 0, 0);
    182209    passEncoder.endPass();
     
    184211    const queue = device.getQueue();
    185212    queue.submit([commandBuffer]);
    186     vertexBuffer.destroy();
     213    positionBuffer.destroy();
    187214    textureCoordBuffer.destroy();
    188215    texture.destroy();
  • trunk/Source/WebCore/CMakeLists.txt

    r242575 r242615  
    474474    Modules/webgpu/GPUOrigin3D.idl
    475475    Modules/webgpu/GPURequestAdapterOptions.idl
     476    Modules/webgpu/GPUSamplerDescriptor.idl
    476477    Modules/webgpu/GPUShaderStageBit.idl
    477478    Modules/webgpu/GPUStoreOp.idl
     
    504505    Modules/webgpu/WebGPURenderPipelineDescriptor.idl
    505506    Modules/webgpu/WebGPURenderingContext.idl
     507    Modules/webgpu/WebGPUSampler.idl
    506508    Modules/webgpu/WebGPUShaderModule.idl
    507509    Modules/webgpu/WebGPUShaderModuleDescriptor.idl
  • trunk/Source/WebCore/ChangeLog

    r242609 r242615  
     12019-03-07  Justin Fan  <justin_fan@apple.com>
     2
     3        [Web GPU] GPUSampler implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=195427
     5        <rdar://problem/48686011>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Implement ability to create GPUSamplers and use them as pipeline resource bindings.
     10
     11        Test: texture-triangle-strip.html updated.
     12
     13        Add symbols to project:
     14        * CMakeLists.txt:
     15        * DerivedSources-input.xcfilelist:
     16        * DerivedSources-output.xcfilelist:
     17        * DerivedSources.make:
     18        * Sources.txt:
     19        * SourcesCocoa.txt:
     20        * WebCore.xcodeproj/project.pbxproj:
     21        * bindings/js/WebCoreBuiltinNames.h:
     22
     23        GPUSampler creation:
     24        * Modules/webgpu/GPUSamplerDescriptor.idl: Added.
     25        * Modules/webgpu/WebGPUDevice.cpp:
     26        (WebCore::WebGPUDevice::createSampler const): Added.
     27        * Modules/webgpu/WebGPUDevice.h:
     28        * Modules/webgpu/WebGPUDevice.idl:
     29        * Modules/webgpu/WebGPUSampler.cpp: Added.
     30        (WebCore::WebGPUSampler::create):
     31        (WebCore::WebGPUSampler::WebGPUSampler):
     32        * Modules/webgpu/WebGPUSampler.h: Added.
     33        (WebCore::WebGPUSampler::sampler const):
     34        * Modules/webgpu/WebGPUSampler.idl: Added.
     35        * platform/graphics/gpu/GPUDevice.cpp:
     36        (WebCore::GPUDevice::tryCreateSampler const): Added.
     37        * platform/graphics/gpu/GPUDevice.h:
     38        * platform/graphics/gpu/GPUSampler.h: Added.
     39        (WebCore::GPUSampler::platformSampler const):
     40        * platform/graphics/gpu/GPUSamplerDescriptor.h: Added.
     41        * platform/graphics/gpu/cocoa/GPUSamplerMetal.mm: Added.
     42        (WebCore::mtlAddressModeForAddressMode):
     43        (WebCore::mtlBorderColorForBorderColor):
     44        (WebCore::mtlMinMagFilterForFilterMode):
     45        (WebCore::mtlMipFilterForFilterMode):
     46        (WebCore::tryCreateMtlSamplerState):
     47        (WebCore::GPUSampler::tryCreate):
     48        (WebCore::GPUSampler::GPUSampler):
     49
     50        Move GPUCompareFunction to Utils for shared use.
     51        * platform/graphics/gpu/GPUCompareFunction.h:
     52        * platform/graphics/gpu/GPUUtils.h:
     53        * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
     54        (WebCore::tryCreateMtlDepthStencilState):
     55        (WebCore::validateAndConvertDepthCompareFunctionToMtl): Deleted.
     56        * platform/graphics/gpu/cocoa/GPUUtilsMetal.mm:
     57        (WebCore::platformTextureFormatForGPUTextureFormat):
     58        (WebCore::platformCompareFunctionForGPUCompareFunction):
     59
     60        Expand bind groups to accept GPUSamplers:
     61        * Modules/webgpu/WebGPUBindGroupBinding.h:
     62        * Modules/webgpu/WebGPUBindGroupBinding.idl:
     63        * Modules/webgpu/WebGPUBindGroupDescriptor.cpp:
     64        (WebCore::WebGPUBindGroupDescriptor::asGPUBindGroupDescriptor const):
     65        * platform/graphics/gpu/GPUBindGroupBinding.h:
     66        * platform/graphics/gpu/GPUProgrammablePassEncoder.h:
     67        * platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm:
     68        (WebCore::GPUProgrammablePassEncoder::setBindGroup):
     69        (WebCore::GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder):
     70        (WebCore::GPUProgrammablePassEncoder::setResourceAsSamplerOnEncoder): Added.
     71        (WebCore::GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder):
     72
     73        Misc:
     74        * Modules/webgpu/WebGPUTexture.cpp: Missing includes.
     75        * Modules/webgpu/WebGPUTexture.h:
     76        * Modules/webgpu/WebGPUSwapChain.cpp: Removed extra include.
     77
    1782019-03-07  Commit Queue  <commit-queue@webkit.org>
    279
  • trunk/Source/WebCore/DerivedSources-input.xcfilelist

    r242575 r242615  
    333333$(PROJECT_DIR)/Modules/webgpu/GPUOrigin3D.idl
    334334$(PROJECT_DIR)/Modules/webgpu/GPURequestAdapterOptions.idl
     335$(PROJECT_DIR)/Modules/webgpu/GPUSamplerDescriptor.idl
    335336$(PROJECT_DIR)/Modules/webgpu/GPUShaderStageBit.idl
    336337$(PROJECT_DIR)/Modules/webgpu/GPUStoreOp.idl
     
    370371$(PROJECT_DIR)/Modules/webgpu/WebGPURenderPipelineDescriptor.idl
    371372$(PROJECT_DIR)/Modules/webgpu/WebGPURenderingContext.idl
     373$(PROJECT_DIR)/Modules/webgpu/WebGPUSampler.idl
    372374$(PROJECT_DIR)/Modules/webgpu/WebGPUShaderModule.idl
    373375$(PROJECT_DIR)/Modules/webgpu/WebGPUShaderModuleDescriptor.idl
  • trunk/Source/WebCore/DerivedSources-output.xcfilelist

    r242575 r242615  
    600600$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.cpp
    601601$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.h
     602$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUSamplerDescriptor.cpp
     603$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUSamplerDescriptor.h
    602604$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUShaderStageBit.cpp
    603605$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUShaderStageBit.h
     
    19341936$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPURenderingContext.cpp
    19351937$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPURenderingContext.h
     1938$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUSampler.cpp
     1939$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUSampler.h
    19361940$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUShaderModule.cpp
    19371941$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUShaderModule.h
  • trunk/Source/WebCore/DerivedSources.make

    r242575 r242615  
    384384    $(WebCore)/Modules/webgpu/GPUOrigin3D.idl \
    385385    $(WebCore)/Modules/webgpu/GPURequestAdapterOptions.idl \
     386    $(WebCore)/Modules/webgpu/GPUSamplerDescriptor.idl \
    386387    $(WebCore)/Modules/webgpu/GPUShaderStageBit.idl \
    387388    $(WebCore)/Modules/webgpu/GPUStoreOp.idl \
     
    414415    $(WebCore)/Modules/webgpu/WebGPURenderPipelineDescriptor.idl \
    415416    $(WebCore)/Modules/webgpu/WebGPURenderingContext.idl \
     417    $(WebCore)/Modules/webgpu/WebGPUSampler.idl \
    416418    $(WebCore)/Modules/webgpu/WebGPUShaderModule.idl \
    417419    $(WebCore)/Modules/webgpu/WebGPUShaderModuleDescriptor.idl \
  • trunk/Source/WebCore/Modules/webgpu/GPUSamplerDescriptor.idl

    r242614 r242615  
    2626
    2727typedef unsigned long u32;
    28 typedef (/*WebGPUSampler or */WebGPUTextureView or WebGPUBufferBinding) WebGPUBindingResource;
     28
     29enum GPUAddressMode {
     30    "clamp-to-edge",
     31    "repeat",
     32    "mirror-repeat",
     33    "clamp-to-border-color"
     34};
     35
     36enum GPUFilterMode {
     37    "nearest",
     38    "linear"
     39};
     40
     41enum GPUBorderColor {
     42    "transparent-black",
     43    "opaque-black",
     44    "opaque-white"
     45};
    2946
    3047[
    3148    Conditional=WEBGPU,
    3249    EnabledAtRuntime=WebGPU
    33 ] dictionary WebGPUBindGroupBinding {
    34     u32 binding;
    35     WebGPUBindingResource resource;
     50] dictionary GPUSamplerDescriptor {
     51    GPUAddressMode addressModeU = "clampToEdge";
     52    GPUAddressMode addressModeV = "clampToEdge";
     53    GPUAddressMode addressModeW = "clampToEdge";
     54    GPUFilterMode magFilter = "nearest";
     55    GPUFilterMode minFilter = "nearest";
     56    GPUFilterMode mipmapFilter = "nearest";
     57    float lodMinClamp = 0;
     58    float lodMaxClamp = 0xffffffff; // TODO: What should this be? Was Number.MAX_VALUE.
     59    u32 maxAnisotropy = 1;
     60    GPUCompareFunction compareFunction = "never";
     61    GPUBorderColor borderColor = "transparentBlack";
    3662};
  • trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.h

    r239837 r242615  
    2929
    3030#include "WebGPUBufferBinding.h"
     31#include "WebGPUSampler.h"
    3132#include "WebGPUTextureView.h"
    3233#include <wtf/Variant.h>
     
    3435namespace WebCore {
    3536
    36 using WebGPUBindingResource = Variant<RefPtr<WebGPUTextureView>, WebGPUBufferBinding>;
     37using WebGPUBindingResource = Variant<RefPtr<WebGPUSampler>, RefPtr<WebGPUTextureView>, WebGPUBufferBinding>;
    3738
    3839struct WebGPUBindGroupBinding {
  • trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.idl

    r239837 r242615  
    2626
    2727typedef unsigned long u32;
    28 typedef (/*WebGPUSampler or */WebGPUTextureView or WebGPUBufferBinding) WebGPUBindingResource;
     28typedef (WebGPUSampler or WebGPUTextureView or WebGPUBufferBinding) WebGPUBindingResource;
    2929
    3030[
  • trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp

    r242575 r242615  
    8989        const auto layoutBinding = iterator->value;
    9090
    91         auto bindingResourceVisitor = WTF::makeVisitor([](const RefPtr<WebGPUTextureView>& view) -> Optional<GPUBindingResource> {
     91        auto bindingResourceVisitor = WTF::makeVisitor([](const RefPtr<WebGPUSampler>& sampler) -> Optional<GPUBindingResource> {
     92            if (!sampler)
     93                return WTF::nullopt;
     94            auto gpuSampler = sampler->sampler();
     95            if (!gpuSampler)
     96                return WTF::nullopt;
     97
     98            return static_cast<GPUBindingResource>(makeRef(*gpuSampler));
     99        }, [](const RefPtr<WebGPUTextureView>& view) -> Optional<GPUBindingResource> {
    92100            if (!view)
    93101                return WTF::nullopt;
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp

    r242575 r242615  
    3838#include "GPUPipelineStageDescriptor.h"
    3939#include "GPURenderPipelineDescriptor.h"
     40#include "GPUSampler.h"
     41#include "GPUSamplerDescriptor.h"
    4042#include "GPUShaderModuleDescriptor.h"
    4143#include "GPUTextureDescriptor.h"
     
    5355#include "WebGPURenderPipeline.h"
    5456#include "WebGPURenderPipelineDescriptor.h"
     57#include "WebGPUSampler.h"
    5558#include "WebGPUShaderModule.h"
    5659#include "WebGPUShaderModuleDescriptor.h"
     
    8386    auto texture = m_device->tryCreateTexture(WTFMove(descriptor));
    8487    return WebGPUTexture::create(WTFMove(texture));
     88}
     89
     90Ref<WebGPUSampler> WebGPUDevice::createSampler(const GPUSamplerDescriptor& descriptor) const
     91{
     92    auto sampler = m_device->tryCreateSampler(descriptor);
     93    return WebGPUSampler::create(WTFMove(sampler));
    8594}
    8695
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h

    r242575 r242615  
    4545class WebGPUPipelineLayout;
    4646class WebGPURenderPipeline;
     47class WebGPUSampler;
    4748class WebGPUShaderModule;
    4849class WebGPUTexture;
     
    5051struct GPUBindGroupLayoutDescriptor;
    5152struct GPUBufferDescriptor;
     53struct GPUSamplerDescriptor;
    5254struct GPUTextureDescriptor;
    5355struct WebGPUBindGroupDescriptor;
     
    6567    Ref<WebGPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
    6668    Ref<WebGPUTexture> createTexture(GPUTextureDescriptor&&) const;
     69    Ref<WebGPUSampler> createSampler(const GPUSamplerDescriptor&) const;
    6770
    6871    Ref<WebGPUBindGroupLayout> createBindGroupLayout(const GPUBindGroupLayoutDescriptor&) const;
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl

    r242575 r242615  
    3434    WebGPUBuffer createBuffer(GPUBufferDescriptor descriptor);
    3535    WebGPUTexture createTexture(GPUTextureDescriptor descriptor);
     36    WebGPUSampler createSampler(GPUSamplerDescriptor descriptor);
    3637
    3738    WebGPUBindGroupLayout createBindGroupLayout(GPUBindGroupLayoutDescriptor descriptor);
     
    5152    // readonly attribute WebGPULimits limits;
    5253
    53     // WebGPUSampler createSampler(WebGPUSamplerDescriptor descriptor);
    54 
    5554    // WebGPUComputePipeline createComputePipeline(WebGPUComputePipelineDescriptor descriptor);
    5655    // WebGPUFence createFence(WebGPUFenceDescriptor descriptor);
  • trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.cpp

    r242614 r242615  
    2424 */
    2525
    26 #pragma once
     26#include "config.h"
     27#include "WebGPUSampler.h"
    2728
    2829#if ENABLE(WEBGPU)
    2930
    30 #include "GPUTextureFormat.h"
    31 
    3231namespace WebCore {
    3332
    34 PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat);
     33Ref<WebGPUSampler> WebGPUSampler::create(RefPtr<GPUSampler>&& sampler)
     34{
     35    return adoptRef(*new WebGPUSampler(WTFMove(sampler)));
     36}
     37
     38WebGPUSampler::WebGPUSampler(RefPtr<GPUSampler>&& sampler)
     39    : m_sampler(WTFMove(sampler))
     40{
     41}
    3542
    3643} // namespace WebCore
  • trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.h

    r242614 r242615  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "WebGPUBufferBinding.h"
    31 #include "WebGPUTextureView.h"
    32 #include <wtf/Variant.h>
     30#include "GPUSampler.h"
     31#include <wtf/RefCounted.h>
     32#include <wtf/RefPtr.h>
    3333
    3434namespace WebCore {
    3535
    36 using WebGPUBindingResource = Variant<RefPtr<WebGPUTextureView>, WebGPUBufferBinding>;
     36class WebGPUSampler : public RefCounted<WebGPUSampler> {
     37public:
     38    static Ref<WebGPUSampler> create(RefPtr<GPUSampler>&&);
    3739
    38 struct WebGPUBindGroupBinding {
    39     unsigned long binding;
    40     WebGPUBindingResource resource;
     40    GPUSampler* sampler() const { return m_sampler.get(); }
     41
     42private:
     43    WebGPUSampler(RefPtr<GPUSampler>&&);
     44
     45    RefPtr<GPUSampler> m_sampler;
    4146};
    4247
  • trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.idl

    r242614 r242615  
    2323 * THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
     25// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
    2526
    26 #pragma once
    27 
    28 #if ENABLE(WEBGPU)
    29 
    30 #include "GPUTextureFormat.h"
    31 
    32 namespace WebCore {
    33 
    34 PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat);
    35 
    36 } // namespace WebCore
    37 
    38 #endif // ENABLE(WEBGPU)
     27[
     28    Conditional=WEBGPU,
     29    EnabledAtRuntime=WebGPU,
     30    ImplementationLacksVTable
     31] interface WebGPUSampler {
     32};
  • trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp

    r241048 r242615  
    2828
    2929#if ENABLE(WEBGPU)
    30 
    31 #include "GPUTextureFormat.h"
    3230
    3331namespace WebCore {
  • trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp

    r242575 r242615  
    2929#if ENABLE(WEBGPU)
    3030
    31 #include "WebGPUTextureView.h"
     31#include "Logging.h"
    3232
    3333namespace WebCore {
  • trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h

    r242575 r242615  
    2929
    3030#include "GPUTexture.h"
    31 
     31#include "WebGPUTextureView.h"
    3232#include <wtf/RefCounted.h>
    3333#include <wtf/RefPtr.h>
     
    3535
    3636namespace WebCore {
    37 
    38 class WebGPUTextureView;
    3937
    4038class WebGPUTexture : public RefCounted<WebGPUTexture> {
  • trunk/Source/WebCore/Sources.txt

    r242599 r242615  
    364364Modules/webgpu/WebGPURenderPassEncoder.cpp
    365365Modules/webgpu/WebGPURenderPipeline.cpp
     366Modules/webgpu/WebGPUSampler.cpp
    366367Modules/webgpu/WebGPUShaderModule.cpp
    367368Modules/webgpu/WebGPUSwapChain.cpp
     
    27832784JSGPUOrigin3D.cpp
    27842785JSGPURequestAdapterOptions.cpp
     2786JSGPUSamplerDescriptor.cpp
    27852787JSGPUShaderStageBit.cpp
    27862788JSGPUStoreOp.cpp
     
    33413343JSWebGPURenderPipeline.cpp
    33423344JSWebGPURenderPipelineDescriptor.cpp
     3345JSWebGPUSampler.cpp
    33433346JSWebGPUShaderModule.cpp
    33443347JSWebGPUShaderModuleDescriptor.cpp
  • trunk/Source/WebCore/SourcesCocoa.txt

    r242359 r242615  
    326326platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm
    327327platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm
     328platform/graphics/gpu/cocoa/GPUSamplerMetal.mm
    328329platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm
    329330platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r242599 r242615  
    1410614106                D0A20D562092A0A600E0C259 /* WebGLCompressedTextureASTC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebGLCompressedTextureASTC.cpp; sourceTree = "<group>"; };
    1410714107                D0A3A7301405A39800FB8ED3 /* ResourceLoaderOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoaderOptions.h; sourceTree = "<group>"; };
     14108                D0ADB26222309D7600A22935 /* GPUSamplerDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUSamplerDescriptor.h; sourceTree = "<group>"; };
     14109                D0ADB26322309D7600A22935 /* GPUSamplerDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUSamplerDescriptor.idl; sourceTree = "<group>"; };
     14110                D0ADB2682230AACB00A22935 /* GPUSampler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUSampler.h; sourceTree = "<group>"; };
     14111                D0ADB26B2230ACC000A22935 /* GPUSamplerMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUSamplerMetal.mm; sourceTree = "<group>"; };
     14112                D0ADB26C2230BB8E00A22935 /* WebGPUSampler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUSampler.h; sourceTree = "<group>"; };
     14113                D0ADB26D2230BB8E00A22935 /* WebGPUSampler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUSampler.cpp; sourceTree = "<group>"; };
     14114                D0ADB26F2230C1F100A22935 /* WebGPUSampler.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUSampler.idl; sourceTree = "<group>"; };
    1410814115                D0B0556609C6700100307E43 /* CreateLinkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateLinkCommand.h; sourceTree = "<group>"; };
    1410914116                D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CreateLinkCommand.cpp; sourceTree = "<group>"; };
     
    1850418511                                312FF8BC21A4C2F000EB199D /* GPURenderPipelineDescriptor.h */,
    1850518512                                D06A9A2122026C7A0083C662 /* GPURequestAdapterOptions.h */,
     18513                                D0ADB2682230AACB00A22935 /* GPUSampler.h */,
     18514                                D0ADB26222309D7600A22935 /* GPUSamplerDescriptor.h */,
    1850618515                                312FF8BB21A4C2F000EB199D /* GPUShaderModule.h */,
    1850718516                                312FF8C021A4C2F200EB199D /* GPUShaderModuleDescriptor.h */,
     
    2609926108                                D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */,
    2610026109                                D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */,
     26110                                D0ADB26322309D7600A22935 /* GPUSamplerDescriptor.idl */,
    2610126111                                D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */,
    2610226112                                D0DE8FB9222E09E200882550 /* GPUShaderStageBit.idl */,
     
    2616926179                                D0C419F22183EFEC009EC1DE /* WebGPURenderPipelineDescriptor.h */,
    2617026180                                D0C419F32183EFEC009EC1DE /* WebGPURenderPipelineDescriptor.idl */,
     26181                                D0ADB26D2230BB8E00A22935 /* WebGPUSampler.cpp */,
     26182                                D0ADB26C2230BB8E00A22935 /* WebGPUSampler.h */,
     26183                                D0ADB26F2230C1F100A22935 /* WebGPUSampler.idl */,
    2617126184                                D0615FCD217FE5C6008A48A8 /* WebGPUShaderModule.cpp */,
    2617226185                                D0615FCC217FE5C6008A48A8 /* WebGPUShaderModule.h */,
     
    2620426217                                D087CE3A21ACA94200BDE174 /* GPURenderPassEncoderMetal.mm */,
    2620526218                                D087CE3D21ACA94200BDE174 /* GPURenderPipelineMetal.mm */,
     26219                                D0ADB26B2230ACC000A22935 /* GPUSamplerMetal.mm */,
    2620626220                                D087CE4021ACA94200BDE174 /* GPUShaderModuleMetal.mm */,
    2620726221                                D087CE3E21ACA94200BDE174 /* GPUSwapChainMetal.mm */,
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r242575 r242615  
    209209    macro(WebGPURenderPassEncoder) \
    210210    macro(WebGPURenderPipeline) \
     211    macro(WebGPUSampler) \
    211212    macro(WebGPUShaderModule) \
    212213    macro(WebGPUSwapChain) \
  • trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupBinding.h

    r239837 r242615  
    2929
    3030#include "GPUBufferBinding.h"
     31#include "GPUSampler.h"
    3132#include "GPUTexture.h"
    3233#include <wtf/Variant.h>
     
    3435namespace WebCore {
    3536
    36 using GPUBindingResource = Variant<Ref<GPUTexture>, GPUBufferBinding>;
     37using GPUBindingResource = Variant<Ref<GPUSampler>, Ref<GPUTexture>, GPUBufferBinding>;
    3738
    3839struct GPUBindGroupBinding {
  • trunk/Source/WebCore/platform/graphics/gpu/GPUBuffer.h

    r242404 r242615  
    134134    unsigned long m_byteLength;
    135135    OptionSet<GPUBufferUsage::Flags> m_usage;
    136     unsigned m_numScheduledCommandBuffers = 0;
     136    unsigned m_numScheduledCommandBuffers { 0 };
    137137};
    138138
  • trunk/Source/WebCore/platform/graphics/gpu/GPUCompareFunction.h

    r240748 r242615  
    4141};
    4242
     43using PlatformCompareFunction = unsigned;
     44
    4345} // namespace WebCore
    4446
  • trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp

    r242575 r242615  
    3838#include "GPURenderPipeline.h"
    3939#include "GPURenderPipelineDescriptor.h"
     40#include "GPUSampler.h"
     41#include "GPUSamplerDescriptor.h"
    4042#include "GPUShaderModule.h"
    4143#include "GPUShaderModuleDescriptor.h"
     
    5355{
    5456    return GPUTexture::tryCreate(*this, WTFMove(descriptor));
     57}
     58
     59RefPtr<GPUSampler> GPUDevice::tryCreateSampler(const GPUSamplerDescriptor& descriptor) const
     60{
     61    return GPUSampler::tryCreate(*this, descriptor);
    5562}
    5663
  • trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h

    r242575 r242615  
    4646class GPUPipelineLayout;
    4747class GPURenderPipeline;
     48class GPUSampler;
    4849class GPUShaderModule;
    4950class GPUTexture;
     
    5455struct GPURenderPipelineDescriptor;
    5556struct GPURequestAdapterOptions;
     57struct GPUSamplerDescriptor;
    5658struct GPUShaderModuleDescriptor;
    5759struct GPUTextureDescriptor;
     
    6365    RefPtr<GPUBuffer> tryCreateBuffer(GPUBufferDescriptor&&);
    6466    RefPtr<GPUTexture> tryCreateTexture(GPUTextureDescriptor&&) const;
     67    RefPtr<GPUSampler> tryCreateSampler(const GPUSamplerDescriptor&) const;
    6568
    6669    RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(const GPUBindGroupLayoutDescriptor&) const;
  • trunk/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h

    r242575 r242615  
    6262private:
    6363#if USE(METAL)
    64     void setResourceAsBufferOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned, const char* const);
    65     void setResourceAsTextureOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned, const char* const);
     64    void setResourceAsBufferOnEncoder(MTLArgumentEncoder *, const GPUBindGroupBinding&, const char* const);
     65    void setResourceAsSamplerOnEncoder(MTLArgumentEncoder *, const GPUBindGroupBinding&, const char* const);
     66    void setResourceAsTextureOnEncoder(MTLArgumentEncoder *, const GPUBindGroupBinding&, const char* const);
    6667    virtual void useResource(MTLResource *, unsigned) = 0;
    6768
  • trunk/Source/WebCore/platform/graphics/gpu/GPUSampler.h

    r242614 r242615  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "GPUTexture.h"
    31 
    3230#include <wtf/RefCounted.h>
    3331#include <wtf/RefPtr.h>
    34 #include <wtf/Vector.h>
     32#include <wtf/RetainPtr.h>
     33
     34OBJC_PROTOCOL(MTLSamplerState);
    3535
    3636namespace WebCore {
    3737
    38 class WebGPUTextureView;
     38class GPUDevice;
    3939
    40 class WebGPUTexture : public RefCounted<WebGPUTexture> {
     40struct GPUSamplerDescriptor;
     41
     42using PlatformSampler = MTLSamplerState;
     43using PlatformSamplerSmartPtr = RetainPtr<MTLSamplerState>;
     44
     45class GPUSampler : public RefCounted<GPUSampler> {
    4146public:
    42     static Ref<WebGPUTexture> create(RefPtr<GPUTexture>&&);
     47    static RefPtr<GPUSampler> tryCreate(const GPUDevice&, const GPUSamplerDescriptor&);
    4348
    44     RefPtr<GPUTexture> texture() const { return m_texture; }
    45 
    46     Ref<WebGPUTextureView> createDefaultTextureView();
    47     void destroy();
     49    PlatformSampler* platformSampler() const { return m_platformSampler.get(); }
    4850
    4951private:
    50     explicit WebGPUTexture(RefPtr<GPUTexture>&&);
     52    GPUSampler(PlatformSamplerSmartPtr&&);
    5153
    52     RefPtr<GPUTexture> m_texture;
    53     Vector<Ref<WebGPUTextureView>> m_textureViews;
     54    PlatformSamplerSmartPtr m_platformSampler;
    5455};
    5556
  • trunk/Source/WebCore/platform/graphics/gpu/GPUSamplerDescriptor.h

    r242614 r242615  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "WebGPUBufferBinding.h"
    31 #include "WebGPUTextureView.h"
    32 #include <wtf/Variant.h>
     30#include "GPUCompareFunction.h"
    3331
    3432namespace WebCore {
    3533
    36 using WebGPUBindingResource = Variant<RefPtr<WebGPUTextureView>, WebGPUBufferBinding>;
     34struct GPUSamplerDescriptor {
     35    enum class AddressMode {
     36        ClampToEdge,
     37        Repeat,
     38        MirrorRepeat,
     39        ClampToBorderColor,
     40    };
    3741
    38 struct WebGPUBindGroupBinding {
    39     unsigned long binding;
    40     WebGPUBindingResource resource;
     42    enum class FilterMode {
     43        Nearest,
     44        Linear,
     45    };
     46
     47    enum class BorderColor {
     48        TransparentBlack,
     49        OpaqueBlack,
     50        OpaqueWhite,
     51    };
     52
     53    AddressMode addressModeU { AddressMode::ClampToEdge };
     54    AddressMode addressModeV { AddressMode::ClampToEdge };
     55    AddressMode addressModeW { AddressMode::ClampToEdge };
     56    FilterMode magFilter { FilterMode::Nearest };
     57    FilterMode minFilter { FilterMode::Nearest };
     58    FilterMode mipmapFilter { FilterMode::Nearest };
     59    float lodMinClamp { 0 };
     60    float lodMaxClamp { 0xffffffff };
     61    unsigned maxAnisotropy { 1 };
     62    GPUCompareFunction compareFunction { GPUCompareFunction::Never };
     63    BorderColor borderColor { BorderColor::TransparentBlack };
    4164};
    4265
  • trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h

    r241181 r242615  
    2828#if ENABLE(WEBGPU)
    2929
     30#include "GPUCompareFunction.h"
    3031#include "GPUTextureFormat.h"
    3132
     
    3334
    3435PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat);
     36PlatformCompareFunction platformCompareFunctionForGPUCompareFunction(GPUCompareFunction);
    3537
    3638} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm

    r242575 r242615  
    7171
    7272    // Set each resource on each MTLArgumentEncoder it should be visible on.
    73     const auto& bindingsMap = bindGroup.layout().bindingsMap();
    74     for (const auto& binding : bindGroup.bindings()) {
    75         auto iterator = bindingsMap.find(binding.binding);
    76         if (iterator == bindingsMap.end()) {
    77             LOG(WebGPU, "%s: GPUBindGroupBinding %lu not found in GPUBindGroupLayout!", functionName, binding.binding);
     73    const auto& layoutBindingsMap = bindGroup.layout().bindingsMap();
     74    for (const auto& resourceBinding : bindGroup.bindings()) {
     75        auto layoutIterator = layoutBindingsMap.find(resourceBinding.binding);
     76        if (layoutIterator == layoutBindingsMap.end()) {
     77            LOG(WebGPU, "%s: GPUBindGroupBinding %lu not found in GPUBindGroupLayout!", functionName, resourceBinding.binding);
    7878            return;
    7979        }
    80         auto bindGroupLayoutBinding = iterator->value;
    81 
    82         switch (bindGroupLayoutBinding.type) {
     80        auto layoutBinding = layoutIterator->value;
     81
     82        switch (layoutBinding.type) {
    8383        // FIXME: Support more resource types.
    8484        case GPUBindGroupLayoutBinding::BindingType::UniformBuffer:
    8585        case GPUBindGroupLayoutBinding::BindingType::StorageBuffer: {
    86             if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
    87                 setResourceAsBufferOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName);
    88             if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
    89                 setResourceAsBufferOnEncoder(fragmentArgs.encoder.get(), binding.resource, binding.binding, functionName);
     86            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
     87                setResourceAsBufferOnEncoder(vertexArgs.encoder.get(), resourceBinding, functionName);
     88            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
     89                setResourceAsBufferOnEncoder(fragmentArgs.encoder.get(), resourceBinding, functionName);
    9090            break;
    9191        }
     92        case GPUBindGroupLayoutBinding::BindingType::Sampler: {
     93            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
     94                setResourceAsSamplerOnEncoder(vertexArgs.encoder.get(), resourceBinding, functionName);
     95            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
     96                setResourceAsSamplerOnEncoder(fragmentArgs.encoder.get(), resourceBinding, functionName);
     97            break;
     98        }
    9299        case GPUBindGroupLayoutBinding::BindingType::SampledTexture: {
    93             if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
    94                 setResourceAsTextureOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName);
    95             if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
    96                 setResourceAsTextureOnEncoder(fragmentArgs.encoder.get(), binding.resource, binding.binding, functionName);
     100            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
     101                setResourceAsTextureOnEncoder(vertexArgs.encoder.get(), resourceBinding, functionName);
     102            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
     103                setResourceAsTextureOnEncoder(fragmentArgs.encoder.get(), resourceBinding, functionName);
    97104            break;
    98105        }
     
    104111}
    105112
    106 void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned index, const char* const functionName)
     113void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindGroupBinding& binding, const char* const functionName)
    107114{
    108115#if LOG_DISABLED
     
    114121    }
    115122
    116     if (!WTF::holds_alternative<GPUBufferBinding>(resource)) {
     123    if (!WTF::holds_alternative<GPUBufferBinding>(binding.resource)) {
    117124        LOG(WebGPU, "%s: Resource is not a buffer type!", functionName);
    118125        return;
    119126    }
    120127
    121     auto& bufferBinding = WTF::get<GPUBufferBinding>(resource);
     128    auto& bufferBinding = WTF::get<GPUBufferBinding>(binding.resource);
    122129    auto& bufferRef = bufferBinding.buffer;
    123130    auto mtlBuffer = bufferRef->platformBuffer();
     
    130137    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    131138
    132     [argumentEncoder setBuffer:mtlBuffer offset:bufferBinding.offset atIndex:index];
     139    [argumentEncoder setBuffer:mtlBuffer offset:bufferBinding.offset atIndex:binding.binding];
    133140    useResource(mtlBuffer, bufferRef->isReadOnly() ? MTLResourceUsageRead : MTLResourceUsageRead | MTLResourceUsageWrite);
    134141
     
    138145}
    139146
    140 void GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned index, const char* const functionName)
     147void GPUProgrammablePassEncoder::setResourceAsSamplerOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindGroupBinding& binding, const char *const functionName)
    141148{
    142149#if LOG_DISABLED
     
    148155    }
    149156
    150     if (!WTF::holds_alternative<Ref<GPUTexture>>(resource)) {
    151         LOG(WebGPU, "%s: Resource is not a texture type!", functionName);
    152         return;
    153     }
    154 
    155     auto& textureRef = WTF::get<Ref<GPUTexture>>(resource);
     157    if (!WTF::holds_alternative<Ref<GPUSampler>>(binding.resource)) {
     158        LOG(WebGPU, "%s: Resource is not a GPUSampler!", functionName);
     159        return;
     160    }
     161
     162    auto& samplerRef = WTF::get<Ref<GPUSampler>>(binding.resource);
     163    auto mtlSampler = samplerRef->platformSampler();
     164
     165    if (!mtlSampler) {
     166        LOG(WebGPU, "%s: Invalid MTLSamplerState in GPUSampler binding!", functionName);
     167        return;
     168    }
     169
     170    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     171    [argumentEncoder setSamplerState:mtlSampler atIndex:binding.binding];
     172    END_BLOCK_OBJC_EXCEPTIONS;
     173}
     174
     175void GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindGroupBinding& binding, const char* const functionName)
     176{
     177#if LOG_DISABLED
     178    UNUSED_PARAM(functionName);
     179#endif
     180    if (!argumentEncoder) {
     181        LOG(WebGPU, "%s: No argument encoder for requested stage found!", functionName);
     182        return;
     183    }
     184
     185    if (!WTF::holds_alternative<Ref<GPUTexture>>(binding.resource)) {
     186        LOG(WebGPU, "%s: Resource is not a GPUTextureView!", functionName);
     187        return;
     188    }
     189
     190    auto& textureRef = WTF::get<Ref<GPUTexture>>(binding.resource);
    156191    auto mtlTexture = textureRef->platformTexture();
    157192
     
    163198    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    164199
    165     [argumentEncoder setTexture:mtlTexture atIndex:index];
     200    [argumentEncoder setTexture:mtlTexture atIndex:binding.binding];
    166201    useResource(mtlTexture, textureRef->isReadOnly() ? MTLResourceUsageRead : MTLResourceUsageRead | MTLResourceUsageWrite);
    167202
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm

    r241310 r242615  
    3030
    3131#import "GPULimits.h"
     32#import "GPUUtils.h"
    3233#import "Logging.h"
    3334#import "WHLSLVertexBufferIndexCalculator.h"
     
    3839namespace WebCore {
    3940
    40 static Optional<MTLCompareFunction> validateAndConvertDepthCompareFunctionToMtl(GPUCompareFunction func)
    41 {
    42     switch (func) {
    43     case GPUCompareFunction::Never:
    44         return MTLCompareFunctionNever;
    45     case GPUCompareFunction::Less:
    46         return MTLCompareFunctionLess;
    47     case GPUCompareFunction::Equal:
    48         return MTLCompareFunctionEqual;
    49     case GPUCompareFunction::LessEqual:
    50         return MTLCompareFunctionLessEqual;
    51     case GPUCompareFunction::Greater:
    52         return MTLCompareFunctionGreater;
    53     case GPUCompareFunction::NotEqual:
    54         return MTLCompareFunctionNotEqual;
    55     case GPUCompareFunction::GreaterEqual:
    56         return MTLCompareFunctionGreaterEqual;
    57     case GPUCompareFunction::Always:
    58         return MTLCompareFunctionAlways;
    59     default:
    60         return WTF::nullopt;
    61     }
    62 }
    63 
    6441static RetainPtr<MTLDepthStencilState> tryCreateMtlDepthStencilState(const char* const functionName, const GPUDepthStencilStateDescriptor& descriptor, const GPUDevice& device)
    6542{
     
    8057    }
    8158
    82     auto mtlDepthCompare = validateAndConvertDepthCompareFunctionToMtl(descriptor.depthCompare);
    83     if (!mtlDepthCompare) {
    84         LOG(WebGPU, "%s: Invalid GPUCompareFunction in GPUDepthStencilStateDescriptor!", functionName);
    85         return nullptr;
    86     }
    87 
    88     [mtlDescriptor setDepthCompareFunction:*mtlDepthCompare];
     59    auto mtlDepthCompare = static_cast<MTLCompareFunction>(platformCompareFunctionForGPUCompareFunction(descriptor.depthCompare));
     60    [mtlDescriptor setDepthCompareFunction:mtlDepthCompare];
    8961    [mtlDescriptor setDepthWriteEnabled:descriptor.depthWriteEnabled];
    9062
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm

    r241181 r242615  
    4545        return MTLPixelFormatDepth32Float_Stencil8;
    4646    }
     47
     48    ASSERT_NOT_REACHED();
     49}
     50
     51PlatformCompareFunction platformCompareFunctionForGPUCompareFunction(GPUCompareFunction func)
     52{
     53    switch (func) {
     54    case GPUCompareFunction::Never:
     55        return MTLCompareFunctionNever;
     56    case GPUCompareFunction::Less:
     57        return MTLCompareFunctionLess;
     58    case GPUCompareFunction::Equal:
     59        return MTLCompareFunctionEqual;
     60    case GPUCompareFunction::LessEqual:
     61        return MTLCompareFunctionLessEqual;
     62    case GPUCompareFunction::Greater:
     63        return MTLCompareFunctionGreater;
     64    case GPUCompareFunction::NotEqual:
     65        return MTLCompareFunctionNotEqual;
     66    case GPUCompareFunction::GreaterEqual:
     67        return MTLCompareFunctionGreaterEqual;
     68    case GPUCompareFunction::Always:
     69        return MTLCompareFunctionAlways;
     70    }
     71
     72    ASSERT_NOT_REACHED();
    4773}
    4874
Note: See TracChangeset for help on using the changeset viewer.