TEST(tinybitset_unittest, test_bitset_boundrytest) { Bitset bitset; bool res = bitset.set(-1); EXPECT_EQ(0,res); res = bitset.set(128); EXPECT_EQ(0,res); res = bitset.set(0); EXPECT_EQ(1,res); res = bitset.set(127); EXPECT_EQ(1,res); res = bitset.get(-1); EXPECT_EQ(0,res); res = bitset.get(128); EXPECT_EQ(0,res); res = bitset.get(0); EXPECT_EQ(1,res); res = bitset.get(127); EXPECT_EQ(1,res); }
TEST(tinybitset_unittest, test_bitset_normaltest) { Bitset bitset; bool res; for(int i=0;i<kNormalCaseNum;i++){ bitset.set(kNormalCase[i]); res = bitset.get(kNormalCase[i]); EXPECT_EQ(1,res); res = bitset.empty(); EXPECT_EQ(0,res); } vector<int> bitones = bitset.getbitones(); EXPECT_EQ(kNormalCaseNum,bitones.size()); for(int i=0;i<kNormalCaseNum;i++){ EXPECT_EQ(kNormalCase[i],bitones[i]); } }
static void print_resources(const Compiler &compiler, const char *tag, const SmallVector<Resource> &resources) { fprintf(stderr, "%s\n", tag); fprintf(stderr, "=============\n\n"); bool print_ssbo = !strcmp(tag, "ssbos"); for (auto &res : resources) { auto &type = compiler.get_type(res.type_id); if (print_ssbo && compiler.buffer_is_hlsl_counter_buffer(res.id)) continue; // If we don't have a name, use the fallback for the type instead of the variable // for SSBOs and UBOs since those are the only meaningful names to use externally. // Push constant blocks are still accessed by name and not block name, even though they are technically Blocks. bool is_push_constant = compiler.get_storage_class(res.id) == StorageClassPushConstant; bool is_block = compiler.get_decoration_bitset(type.self).get(DecorationBlock) || compiler.get_decoration_bitset(type.self).get(DecorationBufferBlock); bool is_sized_block = is_block && (compiler.get_storage_class(res.id) == StorageClassUniform || compiler.get_storage_class(res.id) == StorageClassUniformConstant); uint32_t fallback_id = !is_push_constant && is_block ? res.base_type_id : res.id; uint32_t block_size = 0; uint32_t runtime_array_stride = 0; if (is_sized_block) { auto &base_type = compiler.get_type(res.base_type_id); block_size = uint32_t(compiler.get_declared_struct_size(base_type)); runtime_array_stride = uint32_t(compiler.get_declared_struct_size_runtime_array(base_type, 1) - compiler.get_declared_struct_size_runtime_array(base_type, 0)); } Bitset mask; if (print_ssbo) mask = compiler.get_buffer_block_flags(res.id); else mask = compiler.get_decoration_bitset(res.id); string array; for (auto arr : type.array) array = join("[", arr ? convert_to_string(arr) : "", "]") + array; fprintf(stderr, " ID %03u : %s%s", res.id, !res.name.empty() ? res.name.c_str() : compiler.get_fallback_name(fallback_id).c_str(), array.c_str()); if (mask.get(DecorationLocation)) fprintf(stderr, " (Location : %u)", compiler.get_decoration(res.id, DecorationLocation)); if (mask.get(DecorationDescriptorSet)) fprintf(stderr, " (Set : %u)", compiler.get_decoration(res.id, DecorationDescriptorSet)); if (mask.get(DecorationBinding)) fprintf(stderr, " (Binding : %u)", compiler.get_decoration(res.id, DecorationBinding)); if (mask.get(DecorationInputAttachmentIndex)) fprintf(stderr, " (Attachment : %u)", compiler.get_decoration(res.id, DecorationInputAttachmentIndex)); if (mask.get(DecorationNonReadable)) fprintf(stderr, " writeonly"); if (mask.get(DecorationNonWritable)) fprintf(stderr, " readonly"); if (is_sized_block) { fprintf(stderr, " (BlockSize : %u bytes)", block_size); if (runtime_array_stride) fprintf(stderr, " (Unsized array stride: %u bytes)", runtime_array_stride); } uint32_t counter_id = 0; if (print_ssbo && compiler.buffer_get_hlsl_counter_buffer(res.id, counter_id)) fprintf(stderr, " (HLSL counter buffer ID: %u)", counter_id); fprintf(stderr, "\n"); } fprintf(stderr, "=============\n\n"); }