Skip to content

Commit

Permalink
[WebGPU] Device::hasFeature() and Adapter::hasFeature() only check th…
Browse files Browse the repository at this point in the history
…at list is not empty

https://bugs.webkit.org/show_bug.cgi?id=274664
<radar://128671215>

Reviewed by Tadeu Zagallo.

std::find here was incorrect, we can use contains() instead however.

* LayoutTests/TestExpectations:
* LayoutTests/fast/webgpu/regression/repro_274664-expected.txt: Added.
* LayoutTests/fast/webgpu/regression/repro_274664.html: Added.
* LayoutTests/fast/webgpu/regression/repro_274664b-expected.txt: Added.
* LayoutTests/fast/webgpu/regression/repro_274664b.html: Added.
* LayoutTests/fast/webgpu/regression/repro_274664c-expected.txt: Added.
* LayoutTests/fast/webgpu/regression/repro_274664c.html: Added.
Add regression test.

* Source/WebGPU/WebGPU/Adapter.mm:
(WebGPU::Adapter::hasFeature):
* Source/WebGPU/WebGPU/Device.mm:
(WebGPU::Device::hasFeature const):

Canonical link: https://commits.webkit.org/279293@main
  • Loading branch information
mwyrzykowski committed May 24, 2024
1 parent fc1a727 commit 862497b
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 2 deletions.
3 changes: 3 additions & 0 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,9 @@ webkit.org/b/139639 [ Debug ] cssom/non-subpixel-scroll-top-left-values.html [ S
[ Debug ] fast/workers/worker-cloneport.html [ Slow ]
[ Debug ] fast/webgpu/present-without-compute-pipeline.html [ Slow ]
[ Debug ] fast/webgpu/multidimensional-texture-bounds.html [ Slow ]

fast/webgpu/regression [ Pass ]

[ Debug ] fast/webgpu/fuzz-272863.html [ Skip ]
[ Release ] fast/webgpu/fuzz-272863.html [ Pass Failure Timeout ]
[ Debug ] fast/webgpu/fuzz-272903.html [ Skip ]
Expand Down
7 changes: 7 additions & 0 deletions LayoutTests/fast/webgpu/regression/repro_274664-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONSOLE MESSAGE: rg11b10ufloat
CONSOLE MESSAGE: createTexture: descriptor.usage & WGPUTextureUsage_RenderAttachment && !isRenderableFormat(descriptor.format, *this)
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
19 changes: 19 additions & 0 deletions LayoutTests/fast/webgpu/regression/repro_274664.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
globalThis.testRunner?.waitUntilDone();
const log = console.debug;

onload = async () => {
let adapter = await navigator.gpu.requestAdapter({});
let device = await adapter.requestDevice({requiredFeatures: ['depth32float-stencil8']});
device.pushErrorScope('validation');
let texture = device.createTexture({format: 'rg11b10ufloat', size: [1, 1, 1], usage: GPUTextureUsage.RENDER_ATTACHMENT});
log(texture.format);
let error = await device.popErrorScope();
if (error) {
log(error.message);
} else {
log(`no validation error`);
}
globalThis.testRunner?.notifyDone();
};
</script>
7 changes: 7 additions & 0 deletions LayoutTests/fast/webgpu/regression/repro_274664b-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONSOLE MESSAGE: rg11b10ufloat
CONSOLE MESSAGE: createTexture: descriptor.usage & WGPUTextureUsage_RenderAttachment && !isRenderableFormat(descriptor.format, *this)
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
19 changes: 19 additions & 0 deletions LayoutTests/fast/webgpu/regression/repro_274664b.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
globalThis.testRunner?.waitUntilDone();
const log = console.debug;

onload = async () => {
let adapter = await navigator.gpu.requestAdapter({});
let device = await adapter.requestDevice({});
device.pushErrorScope('validation');
let texture = device.createTexture({format: 'rg11b10ufloat', size: [1, 1, 1], usage: GPUTextureUsage.RENDER_ATTACHMENT});
log(texture.format);
let error = await device.popErrorScope();
if (error) {
log(error.message);
} else {
log(`no validation error`);
}
globalThis.testRunner?.notifyDone();
};
</script>
7 changes: 7 additions & 0 deletions LayoutTests/fast/webgpu/regression/repro_274664c-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONSOLE MESSAGE: rg11b10ufloat
CONSOLE MESSAGE: no validation error
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
19 changes: 19 additions & 0 deletions LayoutTests/fast/webgpu/regression/repro_274664c.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
globalThis.testRunner?.waitUntilDone();
const log = console.debug;

onload = async () => {
let adapter = await navigator.gpu.requestAdapter({});
let device = await adapter.requestDevice({requiredFeatures: ['rg11b10ufloat-renderable']});
device.pushErrorScope('validation');
let texture = device.createTexture({format: 'rg11b10ufloat', size: [1, 1, 1], usage: GPUTextureUsage.RENDER_ATTACHMENT});
log(texture.format);
let error = await device.popErrorScope();
if (error) {
log(error.message);
} else {
log(`no validation error`);
}
globalThis.testRunner?.notifyDone();
};
</script>
2 changes: 1 addition & 1 deletion Source/WebGPU/WebGPU/Adapter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

bool Adapter::hasFeature(WGPUFeatureName feature)
{
return std::find(m_capabilities.features.begin(), m_capabilities.features.end(), feature);
return m_capabilities.features.contains(feature);
}

void Adapter::requestDevice(const WGPUDeviceDescriptor& descriptor, CompletionHandler<void(WGPURequestDeviceStatus, Ref<Device>&&, String&&)>&& callback)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebGPU/WebGPU/Device.mm
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static void setOwnerWithIdentity(id<MTLResourceSPI> resource, auto webProcessID)

bool Device::hasFeature(WGPUFeatureName feature) const
{
return std::find(m_capabilities.features.begin(), m_capabilities.features.end(), feature);
return m_capabilities.features.contains(feature);
}

auto Device::currentErrorScope(WGPUErrorFilter type) -> ErrorScope*
Expand Down

0 comments on commit 862497b

Please sign in to comment.