Skip to content

Commit 1440604

Browse files
jpr42charles-lunarg
authored andcommitted
Address feedback
1 parent e91fda6 commit 1440604

6 files changed

Lines changed: 33 additions & 37 deletions

File tree

loader/asm_offset.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,10 @@ int main(int argc, char **argv) {
171171
}
172172
}
173173
// NOLINTEND(cert-err33-c)
174+
if (ferror(file)) {
175+
fclose(file);
176+
fprintf(stderr, "Error: failed to write gen_defines.asm\n");
177+
return 1;
178+
}
174179
return fclose(file);
175180
}

loader/dev_ext_trampoline.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ VKAPI_ATTR void VKAPI_CALL vkdev_ext248(VkDevice device) ASM_NAME("vkdev_ext248"
286286
VKAPI_ATTR void VKAPI_CALL vkdev_ext249(VkDevice device) ASM_NAME("vkdev_ext249");
287287

288288
void *loader_get_dev_ext_trampoline(uint32_t index) {
289-
// NOLINTNEXTLINE(bugprone-switch-missing-default-case) - falls through to the return NULL below
290289
switch (index) {
291290
#define CASE_HANDLE(num) case num: return vkdev_ext##num
292291
CASE_HANDLE(0);
@@ -539,7 +538,6 @@ void *loader_get_dev_ext_trampoline(uint32_t index) {
539538
CASE_HANDLE(247);
540539
CASE_HANDLE(248);
541540
CASE_HANDLE(249);
541+
default: return NULL;
542542
}
543-
544-
return NULL;
545543
}

loader/loader.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5815,24 +5815,23 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance(const VkInstanceCreateI
58155815

58165816
struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance;
58175817
if (NULL == ptr_instance) {
5818-
loader_log(ptr_instance, VULKAN_LOADER_WARN_BIT, 0,
5818+
loader_log(NULL, VULKAN_LOADER_ERROR_BIT, 0,
58195819
"terminator_CreateInstance: Loader instance pointer null encountered. Possibly set by active layer. (Policy "
58205820
"#LLP_LAYER_21)");
5821+
abort();
58215822
} else if (LOADER_MAGIC_NUMBER != ptr_instance->magic) {
5822-
loader_log(ptr_instance, VULKAN_LOADER_WARN_BIT, 0,
5823+
loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT, 0,
58235824
"terminator_CreateInstance: Instance pointer (%p) has invalid MAGIC value 0x%08" PRIx64
58245825
". Instance value possibly "
58255826
"corrupted by active layer (Policy #LLP_LAYER_21). ",
58265827
ptr_instance, ptr_instance->magic);
5828+
abort();
58275829
}
58285830

58295831
// Save the application version if it has been modified - layers sometimes needs features in newer API versions than
58305832
// what the application requested, and thus will increase the instance version to a level that suites their needs.
58315833
if (pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->apiVersion) {
58325834
loader_api_version altered_version = loader_make_version(pCreateInfo->pApplicationInfo->apiVersion);
5833-
// per LLP_LAYER_21 (docs/LoaderLayerInterface.md), a layer that clobbers pInstance before calling down is
5834-
// documented to crash the loader; this is not recoverable here.
5835-
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
58365835
if (altered_version.major != ptr_instance->app_api_version.major ||
58375836
altered_version.minor != ptr_instance->app_api_version.minor) {
58385837
ptr_instance->app_api_version = altered_version;
@@ -5867,14 +5866,12 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance(const VkInstanceCreateI
58675866
} else {
58685867
for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) {
58695868
if (!strcmp(pCreateInfo->ppEnabledExtensionNames[j], VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
5870-
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference) - see LLP_LAYER_21 note above
58715869
ptr_instance->supports_get_dev_prop_2 = true;
58725870
break;
58735871
}
58745872
}
58755873
}
58765874

5877-
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference) - see LLP_LAYER_21 note above
58785875
for (uint32_t i = 0; i < ptr_instance->icd_tramp_list.count; i++) {
58795876
icd_term = loader_icd_add(ptr_instance, &ptr_instance->icd_tramp_list.scanned_list[i]);
58805877
if (NULL == icd_term) {
@@ -6230,21 +6227,20 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(VkPhysicalDevice physical
62306227
VkDeviceGroupDeviceCreateInfo *caller_dgci = NULL;
62316228

62326229
if (NULL == dev) {
6233-
loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
6230+
loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
62346231
"terminator_CreateDevice: Loader device pointer null encountered. Possibly set by active layer. (Policy "
62356232
"#LLP_LAYER_22)");
6233+
abort();
62366234
} else if (DEVICE_DISP_TABLE_MAGIC_NUMBER != dev->loader_dispatch.core_dispatch.magic) {
6237-
loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
6235+
loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
62386236
"terminator_CreateDevice: Device pointer (%p) has invalid MAGIC value 0x%08" PRIx64
62396237
". The expected value is "
62406238
"0x10ADED040410ADED. Device value possibly "
62416239
"corrupted by active layer (Policy #LLP_LAYER_22). ",
62426240
dev, dev->loader_dispatch.core_dispatch.magic);
6241+
abort();
62436242
}
62446243

6245-
// per LLP_LAYER_22 (docs/LoaderLayerInterface.md), a layer that clobbers pDevice before calling down is
6246-
// documented to crash the loader; this is not recoverable here.
6247-
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
62486244
dev->phys_dev_term = phys_dev_term;
62496245

62506246
icd_exts.list = NULL;

loader/loader_environment.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -519,36 +519,32 @@ VkResult loader_add_environment_layers(struct loader_instance *inst, const char
519519
continue;
520520
}
521521

522-
// We found a layer we're interested in, but has it been disabled...
523-
bool adding;
522+
// A layer matching the enable filter is force-enabled even if it also matches the disable filter - this mirrors
523+
// VK_INSTANCE_LAYERS, which VK_LOADER_LAYERS_ENABLE is a generalization of, and which overrides disables.
524+
// Also make sure the layer isn't already in the output_list, skip adding it if it is.
525+
bool force_enabled = check_name_matches_filter_environment_var(source_prop->info.layerName, &filters->enable_filter) &&
526+
!loader_find_layer_name_in_list(source_prop->info.layerName, target_list);
527+
524528
bool is_implicit = (0 == (source_prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER));
525529
bool disabled_by_type =
526530
(is_implicit) ? (filters->disable_filter.disable_all_implicit) : (filters->disable_filter.disable_all_explicit);
527-
if ((filters->disable_filter.disable_all || disabled_by_type ||
531+
if (!force_enabled &&
532+
(filters->disable_filter.disable_all || disabled_by_type ||
528533
check_name_matches_filter_environment_var(source_prop->info.layerName, &filters->disable_filter.additional_filters)) &&
529534
!check_name_matches_filter_environment_var(source_prop->info.layerName, &filters->allow_filter)) {
530535
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
531536
"Layer \"%s\" ignored because it has been disabled by env var \'%s\'", source_prop->info.layerName,
532537
VK_LAYERS_DISABLE_ENV_VAR);
538+
continue;
533539
}
534540

535-
// Whether a layer is force-enabled only depends on the check below - the disable check above exists purely to log
536-
// why a layer was skipped, since a layer is only ever added by this function via VK_LOADER_LAYERS_ENABLE.
537-
// Also make sure the layer isn't already in the output_list, skip adding it if it is.
538-
if (check_name_matches_filter_environment_var(source_prop->info.layerName, &filters->enable_filter) &&
539-
!loader_find_layer_name_in_list(source_prop->info.layerName, target_list)) {
540-
adding = true;
541-
// Only way is_substring is true is if there are enable variables. If that's the case, and we're past the
542-
// above, we should indicate that it was forced on in this way.
543-
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
544-
"Layer \"%s\" forced enabled due to env var \'%s\'", source_prop->info.layerName, VK_LAYERS_ENABLE_ENV_VAR);
545-
} else {
546-
adding = false;
547-
}
548-
549-
if (!adding) {
541+
if (!force_enabled) {
550542
continue;
551543
}
544+
// Only way is_substring is true is if there are enable variables. If that's the case, and we're past the
545+
// above, we should indicate that it was forced on in this way.
546+
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Layer \"%s\" forced enabled due to env var \'%s\'",
547+
source_prop->info.layerName, VK_LAYERS_ENABLE_ENV_VAR);
552548

553549
// If not a meta-layer, simply add it.
554550
if (0 == (source_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) {

loader/phys_dev_ext.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ VKAPI_ATTR void VKAPI_CALL vkPhysDevExtTermin249(VkPhysicalDevice) ASM_NAME("vkP
549549

550550

551551
void *loader_get_phys_dev_ext_tramp(uint32_t index) {
552-
// NOLINTNEXTLINE(bugprone-switch-missing-default-case) - falls through to the return NULL below
553552
switch (index) {
554553
#define TRAMP_CASE_HANDLE(num) case num: return vkPhysDevExtTramp##num
555554
TRAMP_CASE_HANDLE(0);
@@ -802,12 +801,11 @@ void *loader_get_phys_dev_ext_tramp(uint32_t index) {
802801
TRAMP_CASE_HANDLE(247);
803802
TRAMP_CASE_HANDLE(248);
804803
TRAMP_CASE_HANDLE(249);
804+
default: return NULL;
805805
}
806-
return NULL;
807806
}
808807

809808
void *loader_get_phys_dev_ext_termin(uint32_t index) {
810-
// NOLINTNEXTLINE(bugprone-switch-missing-default-case) - falls through to the return NULL below
811809
switch (index) {
812810
#define TERM_CASE_HANDLE(num) case num: return vkPhysDevExtTermin##num
813811
TERM_CASE_HANDLE(0);
@@ -1060,6 +1058,6 @@ void *loader_get_phys_dev_ext_termin(uint32_t index) {
10601058
TERM_CASE_HANDLE(247);
10611059
TERM_CASE_HANDLE(248);
10621060
TERM_CASE_HANDLE(249);
1061+
default: return NULL;
10631062
}
1064-
return NULL;
10651063
}

tests/loader_layer_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,6 +4191,9 @@ TEST(TestLayers, EnvironLayerEnableDisableExplicitLayer) {
41914191
ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Insert instance layer", explicit_layer_name_3));
41924192
ASSERT_TRUE(env.debug_log.find_prefix_then_postfix(explicit_layer_name_3, "forced enabled due to env var"));
41934193
ASSERT_FALSE(env.debug_log.find_prefix_then_postfix(explicit_layer_name_3, "disabled because name matches filter of env var"));
4194+
// layer_3 also matches VK_LOADER_LAYERS_DISABLE ("*Second*"), but VK_LOADER_LAYERS_ENABLE overrides it - it should not
4195+
// also log that it was ignored as disabled.
4196+
ASSERT_FALSE(env.debug_log.find_prefix_then_postfix(explicit_layer_name_3, "ignored because it has been disabled"));
41944197

41954198
// Disable all but enable 2
41964199
// ------------------------------------------

0 commit comments

Comments
 (0)