Skip to content

Commit

Permalink
Conversion from rgba to rg8unorm should copy correct pixel values
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270558
rdar://123810638

Reviewed by Mike Wyrzykowski.

* LayoutTests/fast/webgpu/conversion-to-rg8unorm-expected.txt: Added.
* LayoutTests/fast/webgpu/conversion-to-rg8unorm.html: Added.
* Source/WebCore/Modules/WebGPU/GPUQueue.cpp:
(WebCore::copyToDestinationFormat):

Canonical link: https://commits.webkit.org/275738@main
  • Loading branch information
achristensen07 committed Mar 6, 2024
1 parent efc0277 commit 4e0d0a1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This test passes if it does not crash.
80 changes: 80 additions & 0 deletions LayoutTests/fast/webgpu/conversion-to-rg8unorm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<script>
if (window.testRunner) { testRunner.dumpAsText(); testRunner.waitUntilDone() }
onload = async () => {
try {
let adapter0 = await navigator.gpu.requestAdapter(
{
}
);

let device0 = await adapter0.requestDevice(
{
label: 'a',
requiredFeatures: [
'depth-clip-control',
'texture-compression-etc2',
'texture-compression-astc',
'indirect-first-instance',
'shader-f16',
'rg11b10ufloat-renderable',
'bgra8unorm-storage'
],
requiredLimits: {
maxVertexAttributes: 23,
maxVertexBufferArrayStride: 46861,
maxStorageTexturesPerShaderStage: 33,
maxBindingsPerBindGroup: 1499,
},
}
);

let canvas0 = document.createElement('canvas');
let imageBitMap0 = await createImageBitmap(canvas0);

let videoFrame1 = new VideoFrame(imageBitMap0, {timestamp: 0});

let texture0 = device0.createTexture(
{
label: 'a',
size: {
width: 373,
depthOrArrayLayers: 1,
},
mipLevelCount: 6,
sampleCount: 1,
format: 'rg8unorm',
usage: GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT,
}
);

device0.queue.copyExternalImageToTexture(
{
source: videoFrame1,
origin: {
x: 2707,
y: 4310,
},
},
{
texture: texture0,
mipLevel: 2591,
origin: [
5319,
466,
9625,
6005,
622
],
aspect: 'stencil-only',
colorSpace: 'srgb',
premultipliedAlpha: true,
},
[
4191
]
);
} catch { }
if (window.testRunner) { testRunner.notifyDone() }
};
</script>
This test passes if it does not crash.
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ static void* copyToDestinationFormat(const uint8_t* rgbaBytes, GPUTextureFormat

case GPUTextureFormat::Rg8unorm: {
uint8_t* data = (uint8_t*)malloc(sizeInBytes / 2);
for (size_t i = 0, i0 = 0; i < sizeInBytes; i += 2, ++i0) {
for (size_t i = 0, i0 = 0; i < sizeInBytes; i += 4, i0 += 2) {
data[i0] = rgbaBytes[i];
data[i0 + 1] = rgbaBytes[i + 1];
}
Expand Down

0 comments on commit 4e0d0a1

Please sign in to comment.