Skip to content

Commit 3705928

Browse files
committed
[validate_draw] refactor out an is_bit_set function
1 parent 7d15c51 commit 3705928

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

wgpu-core/src/indirect_validation/validate_draw.wgsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ var<storage, read> src: array<u32>;
2525
@group(2) @binding(0)
2626
var<storage, read_write> dst: array<u32>;
2727

28+
fn is_bit_set(data: u32, index: u32) -> bool {
29+
return ((data >> index) & 1u) == 1u;
30+
}
31+
2832
@compute @workgroup_size(64)
2933
fn main(@builtin(global_invocation_id) global_invocation_id: vec3u) {
3034
if global_invocation_id.x >= metadata_range.count { return; }
3135

3236
let metadata = metadata[metadata_range.start + global_invocation_id.x];
3337
var failed = false;
3438

35-
let is_indexed = ((metadata.src_offset >> 31) & 1u) == 1u;
39+
let is_indexed = is_bit_set(metadata.src_offset, 31);
3640
let src_base_offset = ((metadata.src_offset << 2) >> 2);
3741
let dst_base_offset = ((metadata.dst_offset << 2) >> 2);
3842

3943
let first_vertex_or_index = src[src_base_offset + 2];
4044
let vertex_or_index_count = src[src_base_offset + 0];
4145

4246
{
43-
let can_overflow = ((metadata.dst_offset >> 30) & 1u) == 1u;
47+
let can_overflow = is_bit_set(metadata.dst_offset, 30);
4448
let sub_overflows = metadata.vertex_or_index_limit < first_vertex_or_index;
4549
failed |= sub_overflows && !can_overflow;
4650
let vertex_or_index_limit = metadata.vertex_or_index_limit - first_vertex_or_index;
@@ -51,7 +55,7 @@ fn main(@builtin(global_invocation_id) global_invocation_id: vec3u) {
5155
let instance_count = src[src_base_offset + 1];
5256

5357
{
54-
let can_overflow = (metadata.dst_offset >> 31) == 1u;
58+
let can_overflow = is_bit_set(metadata.dst_offset, 31);
5559
let sub_overflows = metadata.instance_limit < first_instance;
5660
failed |= sub_overflows && !can_overflow;
5761
let instance_limit = metadata.instance_limit - first_instance;

0 commit comments

Comments
 (0)