From 46fca3f9f4a9b47b32e9dfbacda0f3d19536c02c Mon Sep 17 00:00:00 2001
From: Henri Verbeet <hverbeet@codeweavers.com>
Date: Wed, 17 Apr 2024 13:12:13 +0200
Subject: [PATCH] vkd3d-common: Introduce VKD3D_BITMAP_SIZE.

---
 include/private/vkd3d_common.h | 2 ++
 libs/vkd3d-shader/d3dbc.c      | 2 +-
 libs/vkd3d-shader/dxil.c       | 2 +-
 libs/vkd3d-shader/ir.c         | 3 +--
 tests/shader_runner.h          | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h
index c03ac72e70..de6878a4b4 100644
--- a/include/private/vkd3d_common.h
+++ b/include/private/vkd3d_common.h
@@ -340,6 +340,8 @@ static inline int vkd3d_u32_compare(uint32_t x, uint32_t y)
     return (x > y) - (x < y);
 }
 
+#define VKD3D_BITMAP_SIZE(x) (((x) + 0x1f) >> 5)
+
 static inline bool bitmap_clear(uint32_t *map, unsigned int idx)
 {
     return map[idx >> 5] &= ~(1u << (idx & 0x1f));
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c
index f7160f1233..55d9ecf707 100644
--- a/libs/vkd3d-shader/d3dbc.c
+++ b/libs/vkd3d-shader/d3dbc.c
@@ -216,7 +216,7 @@ struct vkd3d_shader_sm1_parser
     struct vkd3d_shader_parser p;
 
 #define MAX_CONSTANT_COUNT 8192
-    uint32_t constant_def_mask[3][MAX_CONSTANT_COUNT / 32];
+    uint32_t constant_def_mask[3][VKD3D_BITMAP_SIZE(MAX_CONSTANT_COUNT)];
 };
 
 /* This table is not order or position dependent. */
diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c
index d07d5adee7..6a1fb6bddb 100644
--- a/libs/vkd3d-shader/dxil.c
+++ b/libs/vkd3d-shader/dxil.c
@@ -805,7 +805,7 @@ struct sm6_parser
     struct vkd3d_shader_dst_param *output_params;
     struct vkd3d_shader_dst_param *input_params;
     struct vkd3d_shader_dst_param *patch_constant_params;
-    uint32_t io_regs_declared[(VKD3DSPR_COUNT + 0x1f) / 0x20];
+    uint32_t io_regs_declared[VKD3D_BITMAP_SIZE(VKD3DSPR_COUNT)];
 
     struct sm6_function *functions;
     size_t function_count;
diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c
index 552de31150..59b74c065d 100644
--- a/libs/vkd3d-shader/ir.c
+++ b/libs/vkd3d-shader/ir.c
@@ -2917,8 +2917,7 @@ static enum vkd3d_result vsir_block_init(struct vsir_block *block, unsigned int
     if (block_count > SIZE_MAX - (sizeof(*block->dominates) * CHAR_BIT - 1))
         return VKD3D_ERROR_OUT_OF_MEMORY;
 
-    block_count = align(block_count, sizeof(*block->dominates) * CHAR_BIT);
-    byte_count = block_count / CHAR_BIT;
+    byte_count = VKD3D_BITMAP_SIZE(block_count) * sizeof(*block->dominates);
 
     assert(label);
     memset(block, 0, sizeof(*block));
diff --git a/tests/shader_runner.h b/tests/shader_runner.h
index ef0b753b34..5f061fa7dc 100644
--- a/tests/shader_runner.h
+++ b/tests/shader_runner.h
@@ -177,7 +177,7 @@ struct shader_runner
 
     struct resource *resources[MAX_RESOURCES];
     size_t resource_count;
-    uint32_t failed_resources[RESOURCE_TYPE_VERTEX_BUFFER + 1][(MAX_RESOURCES + 0x1f) / 0x20];
+    uint32_t failed_resources[RESOURCE_TYPE_VERTEX_BUFFER + 1][VKD3D_BITMAP_SIZE(MAX_RESOURCES)];
     unsigned int failed_resource_count;
 
     struct sampler samplers[MAX_SAMPLERS];
-- 
GitLab