[PATCH vkd3d 4/5] include: Add STATIC_ASSERT() macro.

Józef Kucia joseph.kucia at gmail.com
Thu Nov 8 10:19:31 CST 2018


From: Józef Kucia <jkucia at codeweavers.com>

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 include/private/vkd3d_common.h | 2 ++
 libs/vkd3d-shader/dxbc.c       | 2 +-
 libs/vkd3d-shader/spirv.c      | 6 +++---
 tests/d3d12.c                  | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h
index 2e3873b82440..d097f3d925ef 100644
--- a/include/private/vkd3d_common.h
+++ b/include/private/vkd3d_common.h
@@ -26,6 +26,8 @@
 
 #define DIV_ROUND_UP(a, b) ((a) % (b) == 0 ? (a) / (b) : (a) / (b) + 1)
 
+#define STATIC_ASSERT(e) extern void __VKD3D_STATIC_ASSERT__(int [(e) ? 1 : -1])
+
 static inline size_t align(size_t addr, size_t alignment)
 {
     return (addr + (alignment - 1)) & ~(alignment - 1);
diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c
index eb1729c9bcf2..7b034482a7c6 100644
--- a/libs/vkd3d-shader/dxbc.c
+++ b/libs/vkd3d-shader/dxbc.c
@@ -1788,7 +1788,7 @@ static void read_dword(const char **ptr, DWORD *d)
 
 static void read_float(const char **ptr, float *f)
 {
-    assert(sizeof(float) == sizeof(DWORD)); /* FIXME: use static assert */
+    STATIC_ASSERT(sizeof(float) == sizeof(DWORD));
     read_dword(ptr, (DWORD *)f);
 }
 
diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c
index c9634ed62ca6..1655bf319eae 100644
--- a/libs/vkd3d-shader/spirv.c
+++ b/libs/vkd3d-shader/spirv.c
@@ -6897,10 +6897,10 @@ static void vkd3d_dxbc_compiler_emit_shader_epilogue_function(struct vkd3d_dxbc_
     unsigned int i, count;
     DWORD variable_idx;
 
-    function_id = compiler->epilogue_function_id;
+    STATIC_ASSERT(ARRAY_SIZE(compiler->private_output_variable) == ARRAY_SIZE(param_id));
+    STATIC_ASSERT(ARRAY_SIZE(compiler->private_output_variable) == ARRAY_SIZE(param_type_id));
 
-    assert(ARRAY_SIZE(compiler->private_output_variable) == ARRAY_SIZE(param_id));
-    assert(ARRAY_SIZE(compiler->private_output_variable) == ARRAY_SIZE(param_type_id));
+    function_id = compiler->epilogue_function_id;
 
     void_id = vkd3d_spirv_get_op_type_void(builder);
     type_id = vkd3d_spirv_get_type_id(builder, VKD3D_TYPE_FLOAT, 4);
diff --git a/tests/d3d12.c b/tests/d3d12.c
index b50723b11995..c855e9c42cbb 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -7786,7 +7786,7 @@ static void test_shader_instructions(void)
         },
     };
 
-    assert(sizeof(tests->input) == sizeof(uint_tests->input));
+    STATIC_ASSERT(sizeof(tests->input) == sizeof(uint_tests->input));
 
     memset(&desc, 0, sizeof(desc));
     desc.rt_format = DXGI_FORMAT_R32G32B32A32_FLOAT;
-- 
2.18.1




More information about the wine-devel mailing list