Skip to content

Commit

Permalink
Cherry-pick 5612088. rdar://123810931
Browse files Browse the repository at this point in the history
    [WebGPU] getBindGroupLayout should return a non-null possibly-invalid layout
    https://bugs.webkit.org/show_bug.cgi?id=270469
    rdar://123810931

    Reviewed by Mike Wyrzykowski.

    * LayoutTests/fast/webgpu/bind-group-layout-invalid-expected.txt: Added.
    * LayoutTests/fast/webgpu/bind-group-layout-invalid.html: Added.
    * Source/WebGPU/WebGPU/ComputePipeline.h:
    * Source/WebGPU/WebGPU/ComputePipeline.mm:
    (WebGPU::ComputePipeline::getBindGroupLayout):
    * Source/WebGPU/WebGPU/RenderPipeline.h:
    * Source/WebGPU/WebGPU/RenderPipeline.mm:
    (WebGPU::RenderPipeline::getBindGroupLayout):

    Canonical link: https://commits.webkit.org/275664@main
  • Loading branch information
achristensen07 authored and Mohsin Qureshi committed Mar 7, 2024
1 parent a16448c commit 6b33ac2
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This test passes if it does not crash.
171 changes: 171 additions & 0 deletions LayoutTests/fast/webgpu/bind-group-layout-invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<script>
if (window.testRunner) { testRunner.waitUntilDone(); testRunner.dumpAsText() }
const log = globalThis.$vm?.print ?? console.log;

onload = async () => {
try {
adapter1 = await navigator.gpu.requestAdapter( { } );
let promise3 = adapter1.requestDevice(
{
label: 'a',
requiredFeatures: [
'depth-clip-control',
'depth32float-stencil8',
'texture-compression-etc2',
'texture-compression-astc',
'indirect-first-instance',
'shader-f16',
'rg11b10ufloat-renderable',
'bgra8unorm-storage'
],
requiredLimits: {
maxVertexAttributes: 22,
maxVertexBufferArrayStride: 60002,
maxStorageTexturesPerShaderStage: 36,
maxBindingsPerBindGroup: 9205,
},
}
);


let device1 = await promise3;

let pipelineLayout2 = device1.createPipelineLayout(
{
label: 'a',
bindGroupLayouts: [
],
}
);

let shaderModule4 = device1.createShaderModule(
{
label: 'a',
code: `@group(1) @binding(121)
var<storage, read_write> __dynamicOffset2: array<u32>;
@group(1) @binding(632)
var<storage, read_write> field5: array<u32>;
@group(0) @binding(632)
var<storage, read_write> __DynamicOffsets0: array<u32>;
@group(2) @binding(523)
var<storage, read_write> global4: array<u32>;
@group(1) @binding(351)
var<storage, read_write> __DynamicOffsets1: array<u32>;
@group(2) @binding(623)
var<storage, read_write> type4: array<u32>;
@group(0) @binding(121)
var<storage, read_write> __ArgumentBuffer_2: array<u32>;
@group(2) @binding(559)
var<storage, read_write> function3: array<u32>;
@compute @workgroup_size(7, 1, 1)
fn compute0(@builtin(global_invocation_id) global_id : vec3<u32>, @builtin(local_invocation_id) local_id : vec3<u32>) {
var x: u32 = 0;
loop {
function3[x] = global_id.x;
x += 1;
__DynamicOffsets1[global_id.y-global_id.x] = __dynamicOffset2[x];
if (x > 2 * arrayLength(&field5)) {
break;
}
}
}
@compute @workgroup_size(8, 1, 4)
fn compute1(@builtin(global_invocation_id) global_id : vec3<u32>, @builtin(local_invocation_id) local_id : vec3<u32>) {
__dynamicOffset2[global_id.x*local_id.x] = u32(function3[global_id.x*local_id.x]);
}
struct S {
@location(0) out0: vec4<f32>,
@location(1) out1: vec4<f32>,
}
struct S2 {
@location(0) out0: vec4<f32>,
out1: vec4<f32>,
}
struct S3 {
@location(0) out0: vec4<f32>,
out1: S4,
}
struct S4 {
@location(1) out2: vec4<f32>,
@location(2) out3: vec4<f32>,
}
@fragment
fn fragment0(@builtin(position) coord_in: vec4<f32>) -> @location(123) i32 {
return i32();
}
@fragment
fn fragment1(@builtin(position) coord_in: vec4<f32>) -> @location(0) vec4<f32> {
return vec4<f32>(coord_in.x, coord_in.y, 0.0, 1.0);
}
@fragment
fn fragment2(@builtin(position) coord_in: vec4<f32>) -> S {
}
@fragment
fn fragment3(@builtin(position) coord_in: vec4<f32>) -> S {
return S();
}
@fragment
fn fragment4(@builtin(position) coord_in: vec4<f32>) -> S2 {
return S2();
}
@fragment
fn fragment5(x: S3) -> S3 {
return x;
}
@vertex
fn vertex0() -> @builtin(position) vec4<f32> {
return vec4<f32>(0.0, 0.0, 0.0, 1.0);
}
@vertex
fn vertex1(@builtin(vertex_index) v_index: u32, @builtin(instance_index) i_index: u32,) -> @builtin(position) vec4<f32> {
return vec4<f32>(f32(v_index), f32(i_index), 0.0, 1.0);
}
@vertex
fn vertex2(@builtin(vertex_index) v_index: u32, @builtin(instance_index) i_index: u32,) -> S {
}
@vertex
fn vertex3(@builtin(vertex_index) v_index: u32, @builtin(instance_index) i_index: u32,) -> S {
return S();
}
`,
sourceMap: {},
hints: {},
}
);

let pipeline6 = device1.createComputePipeline(
{
label: 'a',
layout: pipelineLayout2,
compute: {
module: shaderModule4,
entryPoint: 'compute0',
constants: {},
},
}
);

let bindGroupLayout11 = pipeline6.getBindGroupLayout(
75
);

bindGroupLayout11.label = '\u0afc';
} catch { }
if (window.testRunner) { testRunner.notifyDone() }
};
</script>
This test passes if it does not crash.
2 changes: 1 addition & 1 deletion Source/WebGPU/WebGPU/ComputePipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ComputePipeline : public WGPUComputePipelineImpl, public RefCounted<Comput

~ComputePipeline();

RefPtr<BindGroupLayout> getBindGroupLayout(uint32_t groupIndex);
Ref<BindGroupLayout> getBindGroupLayout(uint32_t groupIndex);
void setLabel(String&&);

bool isValid() const { return m_computePipelineState; }
Expand Down
8 changes: 4 additions & 4 deletions Source/WebGPU/WebGPU/ComputePipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ static MTLSize metalSize(auto workgroupSize, const HashMap<String, WGSL::Constan

ComputePipeline::~ComputePipeline() = default;

RefPtr<BindGroupLayout> ComputePipeline::getBindGroupLayout(uint32_t groupIndex)
Ref<BindGroupLayout> ComputePipeline::getBindGroupLayout(uint32_t groupIndex)
{
if (!isValid()) {
m_device->generateAValidationError("getBindGroupLayout: ComputePipeline is invalid"_s);
m_pipelineLayout->makeInvalid();
return nullptr;
return BindGroupLayout::createInvalid(m_device);
}

if (groupIndex >= m_pipelineLayout->numberOfBindGroupLayouts()) {
m_device->generateAValidationError("getBindGroupLayout: groupIndex is out of range"_s);
m_pipelineLayout->makeInvalid();
return nullptr;
return BindGroupLayout::createInvalid(m_device);
}

return &m_pipelineLayout->bindGroupLayout(groupIndex);
return m_pipelineLayout->bindGroupLayout(groupIndex);
}

void ComputePipeline::setLabel(String&&)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebGPU/WebGPU/RenderPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class RenderPipeline : public WGPURenderPipelineImpl, public RefCounted<RenderPi

~RenderPipeline();

RefPtr<BindGroupLayout> getBindGroupLayout(uint32_t groupIndex);
Ref<BindGroupLayout> getBindGroupLayout(uint32_t groupIndex);
void setLabel(String&&);

bool isValid() const { return m_renderPipelineState; }
Expand Down
8 changes: 4 additions & 4 deletions Source/WebGPU/WebGPU/RenderPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1584,21 +1584,21 @@ static uint32_t componentsForDataType(MTLDataType dataType)

RenderPipeline::~RenderPipeline() = default;

RefPtr<BindGroupLayout> RenderPipeline::getBindGroupLayout(uint32_t groupIndex)
Ref<BindGroupLayout> RenderPipeline::getBindGroupLayout(uint32_t groupIndex)
{
if (!isValid()) {
m_device->generateAValidationError("getBindGroupLayout: RenderPipeline is invalid"_s);
m_pipelineLayout->makeInvalid();
return nullptr;
return BindGroupLayout::createInvalid(m_device);
}

if (groupIndex >= m_pipelineLayout->numberOfBindGroupLayouts()) {
m_device->generateAValidationError("getBindGroupLayout: groupIndex is out of range"_s);
m_pipelineLayout->makeInvalid();
return nullptr;
return BindGroupLayout::createInvalid(m_device);
}

return &m_pipelineLayout->bindGroupLayout(groupIndex);
return m_pipelineLayout->bindGroupLayout(groupIndex);
}

void RenderPipeline::setLabel(String&&)
Expand Down

0 comments on commit 6b33ac2

Please sign in to comment.