Title: [242615] trunk
Revision
242615
Author
justin_...@apple.com
Date
2019-03-07 15:03:53 -0800 (Thu, 07 Mar 2019)

Log 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:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (242614 => 242615)


--- trunk/LayoutTests/ChangeLog	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/LayoutTests/ChangeLog	2019-03-07 23:03:53 UTC (rev 242615)
@@ -1,3 +1,15 @@
+2019-03-07  Justin Fan  <justin_...@apple.com>
+
+        [Web GPU] GPUSampler implementation
+        https://bugs.webkit.org/show_bug.cgi?id=195427
+        <rdar://problem/48686011>
+
+        Reviewed by Dean Jackson.
+
+        Update texture-triangle-strip to use a GPUSampler provided through bindings instead of creating one in shader.
+
+        * webgpu/texture-triangle-strip.html:
+
 2019-03-07  Youenn Fablet  <you...@apple.com>
 
         REGRESSION: ( r231040 ) Layout Test http/tests/security/xss-DENIED-xsl-external-entity.xml is a flaky failure

Modified: trunk/LayoutTests/webgpu/texture-triangle-strip.html (242614 => 242615)


--- trunk/LayoutTests/webgpu/texture-triangle-strip.html	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/LayoutTests/webgpu/texture-triangle-strip.html	2019-03-07 23:03:53 UTC (rev 242615)
@@ -10,6 +10,14 @@
 if (window.testRunner)
     testRunner.waitUntilDone();
 
+const positionBufferIndex = 0;
+const texCoordsBufferIndex = 1;
+const positionAttributeNum = 0;
+const texCoordsAttributeNum = 1;
+const bindGroupIndex = 0;
+const textureBindingNum = 0;
+const samplerBindingNum = 1;
+
 const shaderCode = `
 #include <metal_stdlib>
     
@@ -17,8 +25,8 @@
 
 struct VertexIn
 {
-    float4 position [[attribute(0)]];
-    float2 texCoords [[attribute(1)]];
+    float4 position [[attribute(${positionAttributeNum})]];
+    float2 texCoords [[attribute(${texCoordsAttributeNum})]];
 };
 
 struct VertexOut
@@ -35,15 +43,15 @@
     return vOut;
 }
 
-struct Texture
+struct TextureSampler
 {
-    texture2d<float> image [[id(0)]];
+    texture2d<float> t [[id(${textureBindingNum})]];
+    sampler s [[id(${samplerBindingNum})]];
 };
 
-fragment float4 fragment_main(VertexOut v [[stage_in]], const device Texture& t [[buffer(0)]])
+fragment float4 fragment_main(VertexOut v [[stage_in]], const device TextureSampler& args [[buffer(${bindGroupIndex})]])
 {
-    constexpr sampler s(coord::normalized, address::clamp_to_zero, filter::nearest);
-    return t.image.sample(s, v.texCoords);
+    return args.t.sample(args.s, v.texCoords);
 }
 `
 
@@ -51,22 +59,22 @@
     return {
         indexFormat: WebGPUIndexFormat.UINT32,
         attributes: [{
-            shaderLocation: 0,
-            inputSlot: 0,
+            shaderLocation: positionAttributeNum,
+            inputSlot: positionBufferIndex,
             offset: 0,
             format: WebGPUVertexFormat.FLOAT_R32_G32_B32_A32
         }, {
-            shaderLocation: 1,
-            inputSlot: 1,
+            shaderLocation: texCoordsAttributeNum,
+            inputSlot: texCoordsBufferIndex,
             offset: 0,
             format: WebGPUVertexFormat.FLOAT_R32_G32
         }],
         inputs: [{
-            inputSlot: 0,
+            inputSlot: positionBufferIndex,
             stride: 4 * 4,
             stepMode: WebGPUInputStepMode.VERTEX
         }, {
-            inputSlot: 1,
+            inputSlot: texCoordsBufferIndex,
             stride: 4 * 2,
             stepMode: WebGPUInputStepMode.VERTEX
         }]
@@ -80,7 +88,7 @@
     // FIXME: Replace with non-MSL shaders.
     const shaderModule = device.createShaderModule({ code: shaderCode });
 
-    const vertexArray = new Float32Array([
+    const positionArray = new Float32Array([
         // float4 xyzw
         -1, 1, 0, 1,
         -1, -1, 0, 1,
@@ -87,10 +95,10 @@
         1, 1, 0, 1, 
         1, -1, 0, 1
     ]);
-    const vertexBuffer = device.createBuffer({ size: vertexArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
-    vertexBuffer.setSubData(0, vertexArray.buffer);
+    const positionBuffer = device.createBuffer({ size: positionArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
+    positionBuffer.setSubData(0, positionArray.buffer);
 
-    const textureCoordArray = new Float32Array([
+    const texCoordsArray = new Float32Array([
         // float2 texCoords
         0, 0,
         0, 1,
@@ -97,8 +105,8 @@
         1, 0,
         1, 1
     ]);
-    const textureCoordBuffer = device.createBuffer({ size: textureCoordArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
-    textureCoordBuffer.setSubData(0, textureCoordArray.buffer);
+    const textureCoordBuffer = device.createBuffer({ size: texCoordsArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
+    textureCoordBuffer.setSubData(0, texCoordsArray.buffer);
 
     const inputStateDescriptor = createInputStateDescriptor();
 
@@ -143,17 +151,36 @@
     };
     const texture = device.createTexture(textureDescriptor);
 
-    // Bind texture to pipeline
-    const textureBindingNum = 0;
+    // Bind texture and a sampler to pipeline
+    const textureLayoutBinding = { 
+        binding: textureBindingNum, 
+        visibility: GPUShaderStageBit.FRAGMENT, 
+        type: "sampled-texture" 
+    };
+    const samplerLayoutBinding = {
+        binding: samplerBindingNum,
+        visibility: GPUShaderStageBit.FRAGMENT,
+        type: "sampler"
+    };
+
     const bindGroupLayoutDescriptor = {
-        bindings: [{ binding: textureBindingNum, visibility: GPUShaderStageBit.FRAGMENT, type: "sampled-texture" }]
+        bindings: [textureLayoutBinding, samplerLayoutBinding]
     };
     bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
     const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] });
 
+    const textureBinding = { 
+        binding: textureBindingNum, 
+        resource: texture.createDefaultTextureView() 
+    };
+    const samplerBinding = {
+        binding: samplerBindingNum,
+        resource: device.createSampler({ minFilter: "nearest", magFilter: "nearest" })
+    };
+
     const bindGroupDescriptor = {
         layout: bindGroupLayout,
-        bindings: [{ binding: textureBindingNum, resource: texture.createDefaultTextureView() }]
+        bindings: [textureBinding, samplerBinding]
     };
     const bindGroup = device.createBindGroup(bindGroupDescriptor);
 
@@ -176,14 +203,14 @@
     commandBuffer.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
     const passEncoder = beginBasicRenderPass(context, commandBuffer);
     passEncoder.setPipeline(pipeline);
-    passEncoder.setBindGroup(0, bindGroup);
-    passEncoder.setVertexBuffers(0, [vertexBuffer, textureCoordBuffer], [0, 0]);
+    passEncoder.setBindGroup(bindGroupIndex, bindGroup);
+    passEncoder.setVertexBuffers(positionBufferIndex, [positionBuffer, textureCoordBuffer], [0, 0]);
     passEncoder.draw(4, 1, 0, 0);
     passEncoder.endPass();
 
     const queue = device.getQueue();
     queue.submit([commandBuffer]);
-    vertexBuffer.destroy();
+    positionBuffer.destroy();
     textureCoordBuffer.destroy();
     texture.destroy();
     context.present();

Modified: trunk/Source/WebCore/CMakeLists.txt (242614 => 242615)


--- trunk/Source/WebCore/CMakeLists.txt	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/CMakeLists.txt	2019-03-07 23:03:53 UTC (rev 242615)
@@ -473,6 +473,7 @@
     Modules/webgpu/GPULoadOp.idl
     Modules/webgpu/GPUOrigin3D.idl
     Modules/webgpu/GPURequestAdapterOptions.idl
+    Modules/webgpu/GPUSamplerDescriptor.idl
     Modules/webgpu/GPUShaderStageBit.idl
     Modules/webgpu/GPUStoreOp.idl
     Modules/webgpu/GPUTextureDescriptor.idl
@@ -503,6 +504,7 @@
     Modules/webgpu/WebGPURenderPipeline.idl
     Modules/webgpu/WebGPURenderPipelineDescriptor.idl
     Modules/webgpu/WebGPURenderingContext.idl
+    Modules/webgpu/WebGPUSampler.idl
     Modules/webgpu/WebGPUShaderModule.idl
     Modules/webgpu/WebGPUShaderModuleDescriptor.idl
     Modules/webgpu/WebGPUSwapChain.idl

Modified: trunk/Source/WebCore/ChangeLog (242614 => 242615)


--- trunk/Source/WebCore/ChangeLog	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/ChangeLog	2019-03-07 23:03:53 UTC (rev 242615)
@@ -1,3 +1,80 @@
+2019-03-07  Justin Fan  <justin_...@apple.com>
+
+        [Web GPU] GPUSampler implementation
+        https://bugs.webkit.org/show_bug.cgi?id=195427
+        <rdar://problem/48686011>
+
+        Reviewed by Dean Jackson.
+
+        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.
+
 2019-03-07  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r242297.

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (242614 => 242615)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2019-03-07 23:03:53 UTC (rev 242615)
@@ -332,6 +332,7 @@
 $(PROJECT_DIR)/Modules/webgpu/GPULoadOp.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUOrigin3D.idl
 $(PROJECT_DIR)/Modules/webgpu/GPURequestAdapterOptions.idl
+$(PROJECT_DIR)/Modules/webgpu/GPUSamplerDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUShaderStageBit.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUStoreOp.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUTextureDescriptor.idl
@@ -369,6 +370,7 @@
 $(PROJECT_DIR)/Modules/webgpu/WebGPURenderPipeline.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPURenderPipelineDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPURenderingContext.idl
+$(PROJECT_DIR)/Modules/webgpu/WebGPUSampler.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUShaderModule.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUShaderModuleDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/WebGPUShaderStageBit.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (242614 => 242615)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2019-03-07 23:03:53 UTC (rev 242615)
@@ -599,6 +599,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUOrigin3D.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPURequestAdapterOptions.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUSamplerDescriptor.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUSamplerDescriptor.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUShaderStageBit.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUShaderStageBit.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUStoreOp.cpp
@@ -1933,6 +1935,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPURenderPipelineDescriptor.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPURenderingContext.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPURenderingContext.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUSampler.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUSampler.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUShaderModule.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUShaderModule.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSWebGPUShaderModuleDescriptor.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (242614 => 242615)


--- trunk/Source/WebCore/DerivedSources.make	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/DerivedSources.make	2019-03-07 23:03:53 UTC (rev 242615)
@@ -383,6 +383,7 @@
     $(WebCore)/Modules/webgpu/GPULoadOp.idl \
     $(WebCore)/Modules/webgpu/GPUOrigin3D.idl \
     $(WebCore)/Modules/webgpu/GPURequestAdapterOptions.idl \
+    $(WebCore)/Modules/webgpu/GPUSamplerDescriptor.idl \
     $(WebCore)/Modules/webgpu/GPUShaderStageBit.idl \
     $(WebCore)/Modules/webgpu/GPUStoreOp.idl \
     $(WebCore)/Modules/webgpu/GPUTextureDescriptor.idl \
@@ -413,6 +414,7 @@
     $(WebCore)/Modules/webgpu/WebGPURenderPipeline.idl \
     $(WebCore)/Modules/webgpu/WebGPURenderPipelineDescriptor.idl \
     $(WebCore)/Modules/webgpu/WebGPURenderingContext.idl \
+    $(WebCore)/Modules/webgpu/WebGPUSampler.idl \
     $(WebCore)/Modules/webgpu/WebGPUShaderModule.idl \
     $(WebCore)/Modules/webgpu/WebGPUShaderModuleDescriptor.idl \
     $(WebCore)/Modules/webgpu/WebGPUSwapChain.idl \

Copied: trunk/Source/WebCore/Modules/webgpu/GPUSamplerDescriptor.idl (from rev 242614, trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.idl) (0 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/GPUSamplerDescriptor.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/GPUSamplerDescriptor.idl	2019-03-07 23:03:53 UTC (rev 242615)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+
+typedef unsigned long u32;
+
+enum GPUAddressMode {
+    "clamp-to-edge",
+    "repeat",
+    "mirror-repeat",
+    "clamp-to-border-color"
+};
+
+enum GPUFilterMode {
+    "nearest",
+    "linear"
+};
+
+enum GPUBorderColor {
+    "transparent-black",
+    "opaque-black",
+    "opaque-white"
+};
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU
+] dictionary GPUSamplerDescriptor {
+    GPUAddressMode addressModeU = "clampToEdge";
+    GPUAddressMode addressModeV = "clampToEdge";
+    GPUAddressMode addressModeW = "clampToEdge";
+    GPUFilterMode magFilter = "nearest";
+    GPUFilterMode minFilter = "nearest";
+    GPUFilterMode mipmapFilter = "nearest";
+    float lodMinClamp = 0;
+    float lodMaxClamp = 0xffffffff; // TODO: What should this be? Was Number.MAX_VALUE.
+    u32 maxAnisotropy = 1;
+    GPUCompareFunction compareFunction = "never";
+    GPUBorderColor borderColor = "transparentBlack";
+};

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.h (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -28,12 +28,13 @@
 #if ENABLE(WEBGPU)
 
 #include "WebGPUBufferBinding.h"
+#include "WebGPUSampler.h"
 #include "WebGPUTextureView.h"
 #include <wtf/Variant.h>
 
 namespace WebCore {
 
-using WebGPUBindingResource = Variant<RefPtr<WebGPUTextureView>, WebGPUBufferBinding>;
+using WebGPUBindingResource = Variant<RefPtr<WebGPUSampler>, RefPtr<WebGPUTextureView>, WebGPUBufferBinding>;
 
 struct WebGPUBindGroupBinding {
     unsigned long binding;

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.idl (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.idl	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.idl	2019-03-07 23:03:53 UTC (rev 242615)
@@ -25,7 +25,7 @@
 // https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
 
 typedef unsigned long u32;
-typedef (/*WebGPUSampler or */WebGPUTextureView or WebGPUBufferBinding) WebGPUBindingResource;
+typedef (WebGPUSampler or WebGPUTextureView or WebGPUBufferBinding) WebGPUBindingResource;
 
 [
     Conditional=WEBGPU,

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp	2019-03-07 23:03:53 UTC (rev 242615)
@@ -88,7 +88,15 @@
 
         const auto layoutBinding = iterator->value;
 
-        auto bindingResourceVisitor = WTF::makeVisitor([](const RefPtr<WebGPUTextureView>& view) -> Optional<GPUBindingResource> {
+        auto bindingResourceVisitor = WTF::makeVisitor([](const RefPtr<WebGPUSampler>& sampler) -> Optional<GPUBindingResource> {
+            if (!sampler)
+                return WTF::nullopt;
+            auto gpuSampler = sampler->sampler();
+            if (!gpuSampler)
+                return WTF::nullopt;
+
+            return static_cast<GPUBindingResource>(makeRef(*gpuSampler));
+        }, [](const RefPtr<WebGPUTextureView>& view) -> Optional<GPUBindingResource> {
             if (!view)
                 return WTF::nullopt;
             auto texture = view->texture();

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2019-03-07 23:03:53 UTC (rev 242615)
@@ -37,6 +37,8 @@
 #include "GPUCommandBuffer.h"
 #include "GPUPipelineStageDescriptor.h"
 #include "GPURenderPipelineDescriptor.h"
+#include "GPUSampler.h"
+#include "GPUSamplerDescriptor.h"
 #include "GPUShaderModuleDescriptor.h"
 #include "GPUTextureDescriptor.h"
 #include "Logging.h"
@@ -52,6 +54,7 @@
 #include "WebGPUQueue.h"
 #include "WebGPURenderPipeline.h"
 #include "WebGPURenderPipelineDescriptor.h"
+#include "WebGPUSampler.h"
 #include "WebGPUShaderModule.h"
 #include "WebGPUShaderModuleDescriptor.h"
 #include "WebGPUTexture.h"
@@ -84,6 +87,12 @@
     return WebGPUTexture::create(WTFMove(texture));
 }
 
+Ref<WebGPUSampler> WebGPUDevice::createSampler(const GPUSamplerDescriptor& descriptor) const
+{
+    auto sampler = m_device->tryCreateSampler(descriptor);
+    return WebGPUSampler::create(WTFMove(sampler));
+}
+
 Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(const GPUBindGroupLayoutDescriptor& descriptor) const
 {
     auto layout = m_device->tryCreateBindGroupLayout(descriptor);

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -44,11 +44,13 @@
 class WebGPUCommandBuffer;
 class WebGPUPipelineLayout;
 class WebGPURenderPipeline;
+class WebGPUSampler;
 class WebGPUShaderModule;
 class WebGPUTexture;
 
 struct GPUBindGroupLayoutDescriptor;
 struct GPUBufferDescriptor;
+struct GPUSamplerDescriptor;
 struct GPUTextureDescriptor;
 struct WebGPUBindGroupDescriptor;
 struct WebGPUPipelineLayoutDescriptor;
@@ -64,6 +66,7 @@
 
     Ref<WebGPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
     Ref<WebGPUTexture> createTexture(GPUTextureDescriptor&&) const;
+    Ref<WebGPUSampler> createSampler(const GPUSamplerDescriptor&) const;
 
     Ref<WebGPUBindGroupLayout> createBindGroupLayout(const GPUBindGroupLayoutDescriptor&) const;
     Ref<WebGPUPipelineLayout> createPipelineLayout(WebGPUPipelineLayoutDescriptor&&) const;

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl	2019-03-07 23:03:53 UTC (rev 242615)
@@ -33,6 +33,7 @@
 
     WebGPUBuffer createBuffer(GPUBufferDescriptor descriptor);
     WebGPUTexture createTexture(GPUTextureDescriptor descriptor);
+    WebGPUSampler createSampler(GPUSamplerDescriptor descriptor);
 
     WebGPUBindGroupLayout createBindGroupLayout(GPUBindGroupLayoutDescriptor descriptor);
     WebGPUPipelineLayout createPipelineLayout(WebGPUPipelineLayoutDescriptor descriptor);
@@ -50,8 +51,6 @@
     // readonly attribute WebGPUExtensions extensions;
     // readonly attribute WebGPULimits limits;
 
-    // WebGPUSampler createSampler(WebGPUSamplerDescriptor descriptor);
-
     // WebGPUComputePipeline createComputePipeline(WebGPUComputePipelineDescriptor descriptor);
     // WebGPUFence createFence(WebGPUFenceDescriptor descriptor);
 

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.cpp (from rev 242614, trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h) (0 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.cpp	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.cpp	2019-03-07 23:03:53 UTC (rev 242615)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebGPUSampler.h"
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+
+Ref<WebGPUSampler> WebGPUSampler::create(RefPtr<GPUSampler>&& sampler)
+{
+    return adoptRef(*new WebGPUSampler(WTFMove(sampler)));
+}
+
+WebGPUSampler::WebGPUSampler(RefPtr<GPUSampler>&& sampler)
+    : m_sampler(WTFMove(sampler))
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.h (from rev 242614, trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.h) (0 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include "GPUSampler.h"
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class WebGPUSampler : public RefCounted<WebGPUSampler> {
+public:
+    static Ref<WebGPUSampler> create(RefPtr<GPUSampler>&&);
+
+    GPUSampler* sampler() const { return m_sampler.get(); }
+
+private:
+    WebGPUSampler(RefPtr<GPUSampler>&&);
+
+    RefPtr<GPUSampler> m_sampler;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.idl (from rev 242614, trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h) (0 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSampler.idl	2019-03-07 23:03:53 UTC (rev 242615)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU,
+    ImplementationLacksVTable
+] interface WebGPUSampler {
+};

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp	2019-03-07 23:03:53 UTC (rev 242615)
@@ -28,8 +28,6 @@
 
 #if ENABLE(WEBGPU)
 
-#include "GPUTextureFormat.h"
-
 namespace WebCore {
 
 WebGPUSwapChain::~WebGPUSwapChain() = default;

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp	2019-03-07 23:03:53 UTC (rev 242615)
@@ -28,7 +28,7 @@
 
 #if ENABLE(WEBGPU)
 
-#include "WebGPUTextureView.h"
+#include "Logging.h"
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h (242614 => 242615)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -28,7 +28,7 @@
 #if ENABLE(WEBGPU)
 
 #include "GPUTexture.h"
-
+#include "WebGPUTextureView.h"
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
@@ -35,8 +35,6 @@
 
 namespace WebCore {
 
-class WebGPUTextureView;
-
 class WebGPUTexture : public RefCounted<WebGPUTexture> {
 public:
     static Ref<WebGPUTexture> create(RefPtr<GPUTexture>&&);

Modified: trunk/Source/WebCore/Sources.txt (242614 => 242615)


--- trunk/Source/WebCore/Sources.txt	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/Sources.txt	2019-03-07 23:03:53 UTC (rev 242615)
@@ -363,6 +363,7 @@
 Modules/webgpu/WebGPURenderPassDescriptor.cpp
 Modules/webgpu/WebGPURenderPassEncoder.cpp
 Modules/webgpu/WebGPURenderPipeline.cpp
+Modules/webgpu/WebGPUSampler.cpp
 Modules/webgpu/WebGPUShaderModule.cpp
 Modules/webgpu/WebGPUSwapChain.cpp
 Modules/webgpu/WebGPUTexture.cpp
@@ -2782,6 +2783,7 @@
 JSGPULoadOp.cpp
 JSGPUOrigin3D.cpp
 JSGPURequestAdapterOptions.cpp
+JSGPUSamplerDescriptor.cpp
 JSGPUShaderStageBit.cpp
 JSGPUStoreOp.cpp
 JSGPUTextureDescriptor.cpp
@@ -3340,6 +3342,7 @@
 JSWebGPURenderPassEncoder.cpp
 JSWebGPURenderPipeline.cpp
 JSWebGPURenderPipelineDescriptor.cpp
+JSWebGPUSampler.cpp
 JSWebGPUShaderModule.cpp
 JSWebGPUShaderModuleDescriptor.cpp
 JSWebGPUSwapChain.cpp

Modified: trunk/Source/WebCore/SourcesCocoa.txt (242614 => 242615)


--- trunk/Source/WebCore/SourcesCocoa.txt	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2019-03-07 23:03:53 UTC (rev 242615)
@@ -325,6 +325,7 @@
 platform/graphics/gpu/cocoa/GPUQueueMetal.mm
 platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm
 platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm
+platform/graphics/gpu/cocoa/GPUSamplerMetal.mm
 platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm
 platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm
 platform/graphics/gpu/cocoa/GPUTextureMetal.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (242614 => 242615)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-03-07 23:03:53 UTC (rev 242615)
@@ -14105,6 +14105,13 @@
 		D0A20D542092A0A600E0C259 /* WebGLCompressedTextureASTC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLCompressedTextureASTC.h; sourceTree = "<group>"; };
 		D0A20D562092A0A600E0C259 /* WebGLCompressedTextureASTC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebGLCompressedTextureASTC.cpp; sourceTree = "<group>"; };
 		D0A3A7301405A39800FB8ED3 /* ResourceLoaderOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoaderOptions.h; sourceTree = "<group>"; };
+		D0ADB26222309D7600A22935 /* GPUSamplerDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUSamplerDescriptor.h; sourceTree = "<group>"; };
+		D0ADB26322309D7600A22935 /* GPUSamplerDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUSamplerDescriptor.idl; sourceTree = "<group>"; };
+		D0ADB2682230AACB00A22935 /* GPUSampler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUSampler.h; sourceTree = "<group>"; };
+		D0ADB26B2230ACC000A22935 /* GPUSamplerMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUSamplerMetal.mm; sourceTree = "<group>"; };
+		D0ADB26C2230BB8E00A22935 /* WebGPUSampler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUSampler.h; sourceTree = "<group>"; };
+		D0ADB26D2230BB8E00A22935 /* WebGPUSampler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUSampler.cpp; sourceTree = "<group>"; };
+		D0ADB26F2230C1F100A22935 /* WebGPUSampler.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUSampler.idl; sourceTree = "<group>"; };
 		D0B0556609C6700100307E43 /* CreateLinkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateLinkCommand.h; sourceTree = "<group>"; };
 		D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CreateLinkCommand.cpp; sourceTree = "<group>"; };
 		D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutBinding.h; sourceTree = "<group>"; };
@@ -18503,6 +18510,8 @@
 				312FF8B921A4C2EF00EB199D /* GPURenderPipeline.h */,
 				312FF8BC21A4C2F000EB199D /* GPURenderPipelineDescriptor.h */,
 				D06A9A2122026C7A0083C662 /* GPURequestAdapterOptions.h */,
+				D0ADB2682230AACB00A22935 /* GPUSampler.h */,
+				D0ADB26222309D7600A22935 /* GPUSamplerDescriptor.h */,
 				312FF8BB21A4C2F000EB199D /* GPUShaderModule.h */,
 				312FF8C021A4C2F200EB199D /* GPUShaderModuleDescriptor.h */,
 				D08AA032220D0D0B0058C502 /* GPUStoreOp.h */,
@@ -26098,6 +26107,7 @@
 				D0CCA94922299F97006979B6 /* GPUOrigin3D.h */,
 				D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */,
 				D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */,
+				D0ADB26322309D7600A22935 /* GPUSamplerDescriptor.idl */,
 				D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */,
 				D0DE8FB9222E09E200882550 /* GPUShaderStageBit.idl */,
 				D08AA031220D0CE60058C502 /* GPUStoreOp.idl */,
@@ -26168,6 +26178,9 @@
 				D0C419F9218404DA009EC1DE /* WebGPURenderPipeline.idl */,
 				D0C419F22183EFEC009EC1DE /* WebGPURenderPipelineDescriptor.h */,
 				D0C419F32183EFEC009EC1DE /* WebGPURenderPipelineDescriptor.idl */,
+				D0ADB26D2230BB8E00A22935 /* WebGPUSampler.cpp */,
+				D0ADB26C2230BB8E00A22935 /* WebGPUSampler.h */,
+				D0ADB26F2230C1F100A22935 /* WebGPUSampler.idl */,
 				D0615FCD217FE5C6008A48A8 /* WebGPUShaderModule.cpp */,
 				D0615FCC217FE5C6008A48A8 /* WebGPUShaderModule.h */,
 				D0615FCE217FE5C6008A48A8 /* WebGPUShaderModule.idl */,
@@ -26203,6 +26216,7 @@
 				D087CE3921ACA94200BDE174 /* GPUQueueMetal.mm */,
 				D087CE3A21ACA94200BDE174 /* GPURenderPassEncoderMetal.mm */,
 				D087CE3D21ACA94200BDE174 /* GPURenderPipelineMetal.mm */,
+				D0ADB26B2230ACC000A22935 /* GPUSamplerMetal.mm */,
 				D087CE4021ACA94200BDE174 /* GPUShaderModuleMetal.mm */,
 				D087CE3E21ACA94200BDE174 /* GPUSwapChainMetal.mm */,
 				D087CE3F21ACA94200BDE174 /* GPUTextureMetal.mm */,

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (242614 => 242615)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -208,6 +208,7 @@
     macro(WebGPURenderingContext) \
     macro(WebGPURenderPassEncoder) \
     macro(WebGPURenderPipeline) \
+    macro(WebGPUSampler) \
     macro(WebGPUShaderModule) \
     macro(WebGPUSwapChain) \
     macro(WebGPUTexture) \

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupBinding.h (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupBinding.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupBinding.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -28,12 +28,13 @@
 #if ENABLE(WEBGPU)
 
 #include "GPUBufferBinding.h"
+#include "GPUSampler.h"
 #include "GPUTexture.h"
 #include <wtf/Variant.h>
 
 namespace WebCore {
 
-using GPUBindingResource = Variant<Ref<GPUTexture>, GPUBufferBinding>;
+using GPUBindingResource = Variant<Ref<GPUSampler>, Ref<GPUTexture>, GPUBufferBinding>;
 
 struct GPUBindGroupBinding {
     unsigned long binding;

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUBuffer.h (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUBuffer.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUBuffer.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -133,7 +133,7 @@
 
     unsigned long m_byteLength;
     OptionSet<GPUBufferUsage::Flags> m_usage;
-    unsigned m_numScheduledCommandBuffers = 0;
+    unsigned m_numScheduledCommandBuffers { 0 };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUCompareFunction.h (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUCompareFunction.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUCompareFunction.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -40,6 +40,8 @@
     Always
 };
 
+using PlatformCompareFunction = unsigned;
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp	2019-03-07 23:03:53 UTC (rev 242615)
@@ -37,6 +37,8 @@
 #include "GPUPipelineLayoutDescriptor.h"
 #include "GPURenderPipeline.h"
 #include "GPURenderPipelineDescriptor.h"
+#include "GPUSampler.h"
+#include "GPUSamplerDescriptor.h"
 #include "GPUShaderModule.h"
 #include "GPUShaderModuleDescriptor.h"
 #include "GPUTexture.h"
@@ -54,6 +56,11 @@
     return GPUTexture::tryCreate(*this, WTFMove(descriptor));
 }
 
+RefPtr<GPUSampler> GPUDevice::tryCreateSampler(const GPUSamplerDescriptor& descriptor) const
+{
+    return GPUSampler::tryCreate(*this, descriptor);
+}
+
 RefPtr<GPUBindGroupLayout> GPUDevice::tryCreateBindGroupLayout(const GPUBindGroupLayoutDescriptor& descriptor) const
 {
     return GPUBindGroupLayout::tryCreate(*this, descriptor);

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -45,6 +45,7 @@
 class GPUCommandBuffer;
 class GPUPipelineLayout;
 class GPURenderPipeline;
+class GPUSampler;
 class GPUShaderModule;
 class GPUTexture;
 
@@ -53,6 +54,7 @@
 struct GPUPipelineLayoutDescriptor;
 struct GPURenderPipelineDescriptor;
 struct GPURequestAdapterOptions;
+struct GPUSamplerDescriptor;
 struct GPUShaderModuleDescriptor;
 struct GPUTextureDescriptor;
 
@@ -62,6 +64,7 @@
 
     RefPtr<GPUBuffer> tryCreateBuffer(GPUBufferDescriptor&&);
     RefPtr<GPUTexture> tryCreateTexture(GPUTextureDescriptor&&) const;
+    RefPtr<GPUSampler> tryCreateSampler(const GPUSamplerDescriptor&) const;
 
     RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(const GPUBindGroupLayoutDescriptor&) const;
     Ref<GPUPipelineLayout> createPipelineLayout(GPUPipelineLayoutDescriptor&&) const;

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -61,8 +61,9 @@
 
 private:
 #if USE(METAL)
-    void setResourceAsBufferOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned, const char* const);
-    void setResourceAsTextureOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned, const char* const);
+    void setResourceAsBufferOnEncoder(MTLArgumentEncoder *, const GPUBindGroupBinding&, const char* const);
+    void setResourceAsSamplerOnEncoder(MTLArgumentEncoder *, const GPUBindGroupBinding&, const char* const);
+    void setResourceAsTextureOnEncoder(MTLArgumentEncoder *, const GPUBindGroupBinding&, const char* const);
     virtual void useResource(MTLResource *, unsigned) = 0;
 
     // Render command encoder methods.

Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUSampler.h (from rev 242614, trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h) (0 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUSampler.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUSampler.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_PROTOCOL(MTLSamplerState);
+
+namespace WebCore {
+
+class GPUDevice;
+
+struct GPUSamplerDescriptor;
+
+using PlatformSampler = MTLSamplerState;
+using PlatformSamplerSmartPtr = RetainPtr<MTLSamplerState>;
+
+class GPUSampler : public RefCounted<GPUSampler> {
+public:
+    static RefPtr<GPUSampler> tryCreate(const GPUDevice&, const GPUSamplerDescriptor&);
+
+    PlatformSampler* platformSampler() const { return m_platformSampler.get(); }
+
+private:
+    GPUSampler(PlatformSamplerSmartPtr&&);
+
+    PlatformSamplerSmartPtr m_platformSampler;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUSamplerDescriptor.h (from rev 242614, trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupBinding.h) (0 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUSamplerDescriptor.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUSamplerDescriptor.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include "GPUCompareFunction.h"
+
+namespace WebCore {
+
+struct GPUSamplerDescriptor {
+    enum class AddressMode {
+        ClampToEdge,
+        Repeat,
+        MirrorRepeat,
+        ClampToBorderColor,
+    };
+
+    enum class FilterMode {
+        Nearest,
+        Linear,
+    };
+
+    enum class BorderColor {
+        TransparentBlack,
+        OpaqueBlack,
+        OpaqueWhite,
+    };
+
+    AddressMode addressModeU { AddressMode::ClampToEdge };
+    AddressMode addressModeV { AddressMode::ClampToEdge };
+    AddressMode addressModeW { AddressMode::ClampToEdge };
+    FilterMode magFilter { FilterMode::Nearest };
+    FilterMode minFilter { FilterMode::Nearest };
+    FilterMode mipmapFilter { FilterMode::Nearest };
+    float lodMinClamp { 0 };
+    float lodMaxClamp { 0xffffffff };
+    unsigned maxAnisotropy { 1 };
+    GPUCompareFunction compareFunction { GPUCompareFunction::Never };
+    BorderColor borderColor { BorderColor::TransparentBlack };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h	2019-03-07 23:03:53 UTC (rev 242615)
@@ -27,11 +27,13 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPUCompareFunction.h"
 #include "GPUTextureFormat.h"
 
 namespace WebCore {
 
 PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat);
+PlatformCompareFunction platformCompareFunctionForGPUCompareFunction(GPUCompareFunction);
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm	2019-03-07 23:03:53 UTC (rev 242615)
@@ -70,30 +70,37 @@
     END_BLOCK_OBJC_EXCEPTIONS;
 
     // Set each resource on each MTLArgumentEncoder it should be visible on.
-    const auto& bindingsMap = bindGroup.layout().bindingsMap();
-    for (const auto& binding : bindGroup.bindings()) {
-        auto iterator = bindingsMap.find(binding.binding);
-        if (iterator == bindingsMap.end()) {
-            LOG(WebGPU, "%s: GPUBindGroupBinding %lu not found in GPUBindGroupLayout!", functionName, binding.binding);
+    const auto& layoutBindingsMap = bindGroup.layout().bindingsMap();
+    for (const auto& resourceBinding : bindGroup.bindings()) {
+        auto layoutIterator = layoutBindingsMap.find(resourceBinding.binding);
+        if (layoutIterator == layoutBindingsMap.end()) {
+            LOG(WebGPU, "%s: GPUBindGroupBinding %lu not found in GPUBindGroupLayout!", functionName, resourceBinding.binding);
             return;
         }
-        auto bindGroupLayoutBinding = iterator->value;
+        auto layoutBinding = layoutIterator->value;
 
-        switch (bindGroupLayoutBinding.type) {
+        switch (layoutBinding.type) {
         // FIXME: Support more resource types.
         case GPUBindGroupLayoutBinding::BindingType::UniformBuffer:
         case GPUBindGroupLayoutBinding::BindingType::StorageBuffer: {
-            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
-                setResourceAsBufferOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName);
-            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
-                setResourceAsBufferOnEncoder(fragmentArgs.encoder.get(), binding.resource, binding.binding, functionName);
+            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
+                setResourceAsBufferOnEncoder(vertexArgs.encoder.get(), resourceBinding, functionName);
+            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
+                setResourceAsBufferOnEncoder(fragmentArgs.encoder.get(), resourceBinding, functionName);
             break;
         }
+        case GPUBindGroupLayoutBinding::BindingType::Sampler: {
+            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
+                setResourceAsSamplerOnEncoder(vertexArgs.encoder.get(), resourceBinding, functionName);
+            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
+                setResourceAsSamplerOnEncoder(fragmentArgs.encoder.get(), resourceBinding, functionName);
+            break;
+        }
         case GPUBindGroupLayoutBinding::BindingType::SampledTexture: {
-            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
-                setResourceAsTextureOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName);
-            if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
-                setResourceAsTextureOnEncoder(fragmentArgs.encoder.get(), binding.resource, binding.binding, functionName);
+            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Vertex)
+                setResourceAsTextureOnEncoder(vertexArgs.encoder.get(), resourceBinding, functionName);
+            if (layoutBinding.visibility & GPUShaderStageBit::Flags::Fragment)
+                setResourceAsTextureOnEncoder(fragmentArgs.encoder.get(), resourceBinding, functionName);
             break;
         }
         default:
@@ -103,7 +110,7 @@
     }
 }
 
-void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned index, const char* const functionName)
+void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindGroupBinding& binding, const char* const functionName)
 {
 #if LOG_DISABLED
     UNUSED_PARAM(functionName);
@@ -113,12 +120,12 @@
         return;
     }
 
-    if (!WTF::holds_alternative<GPUBufferBinding>(resource)) {
+    if (!WTF::holds_alternative<GPUBufferBinding>(binding.resource)) {
         LOG(WebGPU, "%s: Resource is not a buffer type!", functionName);
         return;
     }
 
-    auto& bufferBinding = WTF::get<GPUBufferBinding>(resource);
+    auto& bufferBinding = WTF::get<GPUBufferBinding>(binding.resource);
     auto& bufferRef = bufferBinding.buffer;
     auto mtlBuffer = bufferRef->platformBuffer();
 
@@ -129,7 +136,7 @@
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    [argumentEncoder setBuffer:mtlBuffer offset:bufferBinding.offset atIndex:index];
+    [argumentEncoder setBuffer:mtlBuffer offset:bufferBinding.offset atIndex:binding.binding];
     useResource(mtlBuffer, bufferRef->isReadOnly() ? MTLResourceUsageRead : MTLResourceUsageRead | MTLResourceUsageWrite);
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -137,7 +144,7 @@
     m_commandBuffer->useBuffer(bufferRef.copyRef());
 }
 
-void GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned index, const char* const functionName)
+void GPUProgrammablePassEncoder::setResourceAsSamplerOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindGroupBinding& binding, const char *const functionName)
 {
 #if LOG_DISABLED
     UNUSED_PARAM(functionName);
@@ -147,12 +154,40 @@
         return;
     }
 
-    if (!WTF::holds_alternative<Ref<GPUTexture>>(resource)) {
-        LOG(WebGPU, "%s: Resource is not a texture type!", functionName);
+    if (!WTF::holds_alternative<Ref<GPUSampler>>(binding.resource)) {
+        LOG(WebGPU, "%s: Resource is not a GPUSampler!", functionName);
         return;
     }
 
-    auto& textureRef = WTF::get<Ref<GPUTexture>>(resource);
+    auto& samplerRef = WTF::get<Ref<GPUSampler>>(binding.resource);
+    auto mtlSampler = samplerRef->platformSampler();
+
+    if (!mtlSampler) {
+        LOG(WebGPU, "%s: Invalid MTLSamplerState in GPUSampler binding!", functionName);
+        return;
+    }
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    [argumentEncoder setSamplerState:mtlSampler atIndex:binding.binding];
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+void GPUProgrammablePassEncoder::setResourceAsTextureOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindGroupBinding& binding, const char* const functionName)
+{
+#if LOG_DISABLED
+    UNUSED_PARAM(functionName);
+#endif
+    if (!argumentEncoder) {
+        LOG(WebGPU, "%s: No argument encoder for requested stage found!", functionName);
+        return;
+    }
+
+    if (!WTF::holds_alternative<Ref<GPUTexture>>(binding.resource)) {
+        LOG(WebGPU, "%s: Resource is not a GPUTextureView!", functionName);
+        return;
+    }
+
+    auto& textureRef = WTF::get<Ref<GPUTexture>>(binding.resource);
     auto mtlTexture = textureRef->platformTexture();
 
     if (!mtlTexture) {
@@ -162,7 +197,7 @@
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    [argumentEncoder setTexture:mtlTexture atIndex:index];
+    [argumentEncoder setTexture:mtlTexture atIndex:binding.binding];
     useResource(mtlTexture, textureRef->isReadOnly() ? MTLResourceUsageRead : MTLResourceUsageRead | MTLResourceUsageWrite);
 
     END_BLOCK_OBJC_EXCEPTIONS;

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm	2019-03-07 23:03:53 UTC (rev 242615)
@@ -29,6 +29,7 @@
 #if ENABLE(WEBGPU)
 
 #import "GPULimits.h"
+#import "GPUUtils.h"
 #import "Logging.h"
 #import "WHLSLVertexBufferIndexCalculator.h"
 #import <Metal/Metal.h>
@@ -37,30 +38,6 @@
 
 namespace WebCore {
 
-static Optional<MTLCompareFunction> validateAndConvertDepthCompareFunctionToMtl(GPUCompareFunction func)
-{
-    switch (func) {
-    case GPUCompareFunction::Never:
-        return MTLCompareFunctionNever;
-    case GPUCompareFunction::Less:
-        return MTLCompareFunctionLess;
-    case GPUCompareFunction::Equal:
-        return MTLCompareFunctionEqual;
-    case GPUCompareFunction::LessEqual:
-        return MTLCompareFunctionLessEqual;
-    case GPUCompareFunction::Greater:
-        return MTLCompareFunctionGreater;
-    case GPUCompareFunction::NotEqual:
-        return MTLCompareFunctionNotEqual;
-    case GPUCompareFunction::GreaterEqual:
-        return MTLCompareFunctionGreaterEqual;
-    case GPUCompareFunction::Always:
-        return MTLCompareFunctionAlways;
-    default:
-        return WTF::nullopt;
-    }
-}
-
 static RetainPtr<MTLDepthStencilState> tryCreateMtlDepthStencilState(const char* const functionName, const GPUDepthStencilStateDescriptor& descriptor, const GPUDevice& device)
 {
 #if LOG_DISABLED
@@ -79,13 +56,8 @@
         return nullptr;
     }
 
-    auto mtlDepthCompare = validateAndConvertDepthCompareFunctionToMtl(descriptor.depthCompare);
-    if (!mtlDepthCompare) {
-        LOG(WebGPU, "%s: Invalid GPUCompareFunction in GPUDepthStencilStateDescriptor!", functionName);
-        return nullptr;
-    }
-
-    [mtlDescriptor setDepthCompareFunction:*mtlDepthCompare];
+    auto mtlDepthCompare = static_cast<MTLCompareFunction>(platformCompareFunctionForGPUCompareFunction(descriptor.depthCompare));
+    [mtlDescriptor setDepthCompareFunction:mtlDepthCompare];
     [mtlDescriptor setDepthWriteEnabled:descriptor.depthWriteEnabled];
 
     // FIXME: Implement back/frontFaceStencil.

Added: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSamplerMetal.mm (0 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSamplerMetal.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSamplerMetal.mm	2019-03-07 23:03:53 UTC (rev 242615)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "GPUSampler.h"
+
+#if ENABLE(WEBGPU)
+
+#import "GPUDevice.h"
+#import "GPUSamplerDescriptor.h"
+#import "GPUUtils.h"
+#import "Logging.h"
+#import <Metal/Metal.h>
+#import <wtf/BlockObjCExceptions.h>
+
+namespace WebCore {
+
+static MTLSamplerAddressMode mtlAddressModeForAddressMode(GPUSamplerDescriptor::AddressMode mode)
+{
+    switch (mode) {
+    case GPUSamplerDescriptor::AddressMode::ClampToEdge:
+        return MTLSamplerAddressModeClampToEdge;
+    case GPUSamplerDescriptor::AddressMode::Repeat:
+        return MTLSamplerAddressModeRepeat;
+    case GPUSamplerDescriptor::AddressMode::MirrorRepeat:
+        return MTLSamplerAddressModeMirrorRepeat;
+    case GPUSamplerDescriptor::AddressMode::ClampToBorderColor:
+        return MTLSamplerAddressModeClampToBorderColor;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+static MTLSamplerBorderColor mtlBorderColorForBorderColor(GPUSamplerDescriptor::BorderColor color)
+{
+    switch (color) {
+    case GPUSamplerDescriptor::BorderColor::TransparentBlack:
+        return MTLSamplerBorderColorTransparentBlack;
+    case GPUSamplerDescriptor::BorderColor::OpaqueBlack:
+        return MTLSamplerBorderColorOpaqueBlack;
+    case GPUSamplerDescriptor::BorderColor::OpaqueWhite:
+        return MTLSamplerBorderColorOpaqueWhite;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+static MTLSamplerMinMagFilter mtlMinMagFilterForFilterMode(GPUSamplerDescriptor::FilterMode mode)
+{
+    switch (mode) {
+    case GPUSamplerDescriptor::FilterMode::Nearest:
+        return MTLSamplerMinMagFilterNearest;
+    case GPUSamplerDescriptor::FilterMode::Linear:
+        return MTLSamplerMinMagFilterLinear;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+static MTLSamplerMipFilter mtlMipFilterForFilterMode(GPUSamplerDescriptor::FilterMode mode)
+{
+    switch (mode) {
+    case GPUSamplerDescriptor::FilterMode::Nearest:
+        return MTLSamplerMipFilterNearest;
+    case GPUSamplerDescriptor::FilterMode::Linear:
+        return MTLSamplerMipFilterLinear;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+static RetainPtr<MTLSamplerState> tryCreateMtlSamplerState(const GPUDevice& device, const GPUSamplerDescriptor& descriptor)
+{
+    if (!device.platformDevice()) {
+        LOG(WebGPU, "GPUSampler::tryCreate(): Invalid GPUDevice!");
+        return nullptr;
+    }
+
+    RetainPtr<MTLSamplerDescriptor> mtlDescriptor;
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    mtlDescriptor = adoptNS([MTLSamplerDescriptor new]);
+    END_BLOCK_OBJC_EXCEPTIONS;
+
+    if (!mtlDescriptor) {
+        LOG(WebGPU, "GPUSampler::tryCreate(): Error creating MTLSamplerDescriptor!");
+        return nullptr;
+    }
+
+    RetainPtr<MTLSamplerState> sampler;
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    [mtlDescriptor setRAddressMode:mtlAddressModeForAddressMode(descriptor.addressModeU)];
+    [mtlDescriptor setSAddressMode:mtlAddressModeForAddressMode(descriptor.addressModeV)];
+    [mtlDescriptor setTAddressMode:mtlAddressModeForAddressMode(descriptor.addressModeW)];
+    [mtlDescriptor setBorderColor:mtlBorderColorForBorderColor(descriptor.borderColor)];
+    [mtlDescriptor setMinFilter:mtlMinMagFilterForFilterMode(descriptor.minFilter)];
+    [mtlDescriptor setMagFilter:mtlMinMagFilterForFilterMode(descriptor.magFilter)];
+    [mtlDescriptor setMipFilter:mtlMipFilterForFilterMode(descriptor.mipmapFilter)];
+    [mtlDescriptor setLodMinClamp:descriptor.lodMinClamp];
+    [mtlDescriptor setLodMaxClamp:descriptor.lodMaxClamp];
+    [mtlDescriptor setMaxAnisotropy:descriptor.maxAnisotropy];
+    [mtlDescriptor setCompareFunction:static_cast<MTLCompareFunction>(platformCompareFunctionForGPUCompareFunction(descriptor.compareFunction))];
+
+    [mtlDescriptor setSupportArgumentBuffers:YES];
+
+    sampler = adoptNS([device.platformDevice() newSamplerStateWithDescriptor:mtlDescriptor.get()]);
+    END_BLOCK_OBJC_EXCEPTIONS;
+
+    if (!sampler)
+        LOG(WebGPU, "GPUSampler::tryCreate(): Error creating MTLSamplerState!");
+
+    return sampler;
+}
+
+RefPtr<GPUSampler> GPUSampler::tryCreate(const GPUDevice& device, const GPUSamplerDescriptor& descriptor)
+{
+    auto sampler = tryCreateMtlSamplerState(device, descriptor);
+    if (!sampler)
+        return nullptr;
+
+    return adoptRef(new GPUSampler(WTFMove(sampler)));
+}
+
+GPUSampler::GPUSampler(RetainPtr<MTLSamplerState>&& sampler)
+    : m_platformSampler(WTFMove(sampler))
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm (242614 => 242615)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm	2019-03-07 23:01:18 UTC (rev 242614)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm	2019-03-07 23:03:53 UTC (rev 242615)
@@ -44,8 +44,34 @@
     case GPUTextureFormat::D32FloatS8Uint:
         return MTLPixelFormatDepth32Float_Stencil8;
     }
+
+    ASSERT_NOT_REACHED();
 }
 
+PlatformCompareFunction platformCompareFunctionForGPUCompareFunction(GPUCompareFunction func)
+{
+    switch (func) {
+    case GPUCompareFunction::Never:
+        return MTLCompareFunctionNever;
+    case GPUCompareFunction::Less:
+        return MTLCompareFunctionLess;
+    case GPUCompareFunction::Equal:
+        return MTLCompareFunctionEqual;
+    case GPUCompareFunction::LessEqual:
+        return MTLCompareFunctionLessEqual;
+    case GPUCompareFunction::Greater:
+        return MTLCompareFunctionGreater;
+    case GPUCompareFunction::NotEqual:
+        return MTLCompareFunctionNotEqual;
+    case GPUCompareFunction::GreaterEqual:
+        return MTLCompareFunctionGreaterEqual;
+    case GPUCompareFunction::Always:
+        return MTLCompareFunctionAlways;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGPU)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to