Skip to content

Commit 333980a

Browse files
Refactor into stronger types in public API.
Some fallout where internal functions are using stronger types. Overkill to move everything over to strong types right now, but perhaps move over to it slowly over time.
1 parent 5af8a04 commit 333980a

19 files changed

Lines changed: 576 additions & 388 deletions

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ if (SPIRV_CROSS_CLI)
465465
target_link_libraries(spirv-cross-msl-ycbcr-conversion-test spirv-cross-c)
466466
set_target_properties(spirv-cross-msl-ycbcr-conversion-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
467467

468+
add_executable(spirv-cross-typed-id-test tests-other/typed_id_test.cpp)
469+
target_link_libraries(spirv-cross-typed-id-test spirv-cross-core)
470+
set_target_properties(spirv-cross-typed-id-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
471+
468472
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
469473
target_compile_options(spirv-cross-c-api-test PRIVATE -std=c89 -Wall -Wextra)
470474
endif()
@@ -483,6 +487,8 @@ if (SPIRV_CROSS_CLI)
483487
COMMAND $<TARGET_FILE:spirv-cross-msl-ycbcr-conversion-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_ycbcr_conversion_test.spv)
484488
add_test(NAME spirv-cross-msl-ycbcr-conversion-test-2
485489
COMMAND $<TARGET_FILE:spirv-cross-msl-ycbcr-conversion-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_ycbcr_conversion_test_2.spv)
490+
add_test(NAME spirv-cross-typed-id-test
491+
COMMAND $<TARGET_FILE:spirv-cross-typed-id-test>)
486492
add_test(NAME spirv-cross-test
487493
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel
488494
${spirv-cross-externals}

main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static void print_resources(const Compiler &compiler, const char *tag, const Sma
246246
compiler.get_decoration_bitset(type.self).get(DecorationBufferBlock);
247247
bool is_sized_block = is_block && (compiler.get_storage_class(res.id) == StorageClassUniform ||
248248
compiler.get_storage_class(res.id) == StorageClassUniformConstant);
249-
uint32_t fallback_id = !is_push_constant && is_block ? res.base_type_id : res.id;
249+
ID fallback_id = !is_push_constant && is_block ? ID(res.base_type_id) : ID(res.id);
250250

251251
uint32_t block_size = 0;
252252
uint32_t runtime_array_stride = 0;
@@ -268,7 +268,7 @@ static void print_resources(const Compiler &compiler, const char *tag, const Sma
268268
for (auto arr : type.array)
269269
array = join("[", arr ? convert_to_string(arr) : "", "]") + array;
270270

271-
fprintf(stderr, " ID %03u : %s%s", res.id,
271+
fprintf(stderr, " ID %03u : %s%s", uint32_t(res.id),
272272
!res.name.empty() ? res.name.c_str() : compiler.get_fallback_name(fallback_id).c_str(), array.c_str());
273273

274274
if (mask.get(DecorationLocation))
@@ -442,7 +442,7 @@ static void print_spec_constants(const Compiler &compiler)
442442
fprintf(stderr, "Specialization constants\n");
443443
fprintf(stderr, "==================\n\n");
444444
for (auto &c : spec_constants)
445-
fprintf(stderr, "ID: %u, Spec ID: %u\n", c.id, c.constant_id);
445+
fprintf(stderr, "ID: %u, Spec ID: %u\n", uint32_t(c.id), c.constant_id);
446446
fprintf(stderr, "==================\n\n");
447447
}
448448

spirv_cfg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ uint32_t CFG::find_loop_dominator(uint32_t block_id) const
237237
for (auto &pred : itr->second)
238238
{
239239
auto &pred_block = compiler.get<SPIRBlock>(pred);
240-
if (pred_block.merge == SPIRBlock::MergeLoop && pred_block.merge_block == block_id)
240+
if (pred_block.merge == SPIRBlock::MergeLoop && pred_block.merge_block == ID(block_id))
241241
{
242242
pred_block_id = pred;
243243
ignore_loop_header = true;
244244
break;
245245
}
246-
else if (pred_block.merge == SPIRBlock::MergeSelection && pred_block.next_block == block_id)
246+
else if (pred_block.merge == SPIRBlock::MergeSelection && pred_block.next_block == ID(block_id))
247247
{
248248
pred_block_id = pred;
249249
break;
@@ -268,14 +268,14 @@ uint32_t CFG::find_loop_dominator(uint32_t block_id) const
268268
return block_id;
269269
}
270270

271-
bool CFG::node_terminates_control_flow_in_sub_graph(uint32_t from, uint32_t to) const
271+
bool CFG::node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const
272272
{
273273
// Walk backwards, starting from "to" block.
274274
// Only follow pred edges if they have a 1:1 relationship, or a merge relationship.
275275
// If we cannot find a path to "from", we must assume that to is inside control flow in some way.
276276

277277
auto &from_block = compiler.get<SPIRBlock>(from);
278-
uint32_t ignore_block_id = 0;
278+
BlockID ignore_block_id = 0;
279279
if (from_block.merge == SPIRBlock::MergeLoop)
280280
ignore_block_id = from_block.merge_block;
281281

spirv_cfg.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class CFG
9797

9898
uint32_t find_loop_dominator(uint32_t block) const;
9999

100-
bool node_terminates_control_flow_in_sub_graph(uint32_t from, uint32_t to) const;
100+
bool node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const;
101101

102102
private:
103103
struct VisitOrder

0 commit comments

Comments
 (0)