Skip to content

Commit

Permalink
layer: Refactor log messages on profile loading
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Mar 18, 2024
1 parent f92f6da commit 200c9a8
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 264 deletions.
2 changes: 1 addition & 1 deletion layer/VkLayer_khronos_profiles.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "GLOBAL",
"library_path": "@JSON_LIBRARY_PATH@",
"api_version": "@JSON_API_VERSION@",
"implementation_version": "1.2.0",
"implementation_version": "1.3.0",
"status": "STABLE",
"description": "Khronos Profiles layer",
"introduction": "The Khronos Profiles layer helps test across a wide range of hardware capabilities without requiring a physical copy of every device.",
Expand Down
2 changes: 1 addition & 1 deletion layer/profiles_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "profiles_settings.h"

struct JsonValidator {
JsonValidator(){};
JsonValidator(){}
~JsonValidator();

bool Init();
Expand Down
3 changes: 2 additions & 1 deletion layer/profiles_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ void LogMessage(ProfileLayerSettings *layer_settings, DebugReportBits report, co

char log[STRING_BUFFER];
snprintf(log, STRING_BUFFER, "%s", GetLogPrefix(report));
std::size_t len = std::strlen(log);

va_list list;

va_start(list, message);
vsnprintf(log, STRING_BUFFER, message, list);
vsnprintf(log + len, STRING_BUFFER, message, list);
va_end(list);

if (layer_settings->log.debug_actions & DEBUG_ACTION_STDOUT_BIT) {
Expand Down
7 changes: 6 additions & 1 deletion layer/profiles_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::string format(const char *message, ...) {
std::size_t const STRING_BUFFER(4096);

assert(message != nullptr);
assert(strlen(message) >= 0 && strlen(message) < STRING_BUFFER);
assert(strlen(message) < STRING_BUFFER);

char buffer[STRING_BUFFER];
va_list list;
Expand Down Expand Up @@ -74,6 +74,11 @@ std::string GetString(const std::vector<std::string> &strings) {
return result;
}

bool EndsWith(std::string const &value, std::string const &ending) {
if (ending.size() > value.size()) return false;
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
}

std::string GetUUIDString(const uint8_t deviceUUID[VK_UUID_SIZE]) {
std::string result;

Expand Down
2 changes: 2 additions & 0 deletions layer/profiles_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ std::string format(const char *message, ...);
std::string GetString(const std::vector<std::string> &strings);
std::string GetUUIDString(const uint8_t deviceUUID[VK_UUID_SIZE]);

bool EndsWith(std::string const &value, std::string const &ending);

std::string format_device_support_string(VkFormatFeatureFlags format_features);
std::string format_device_support_string(VkFormatFeatureFlags2 format_features);

Expand Down
17 changes: 14 additions & 3 deletions layer/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ class LayerTests : public VkTestFramework {
TEST_F(LayerTests, TestDesktop2023) {
TEST_DESCRIPTION("Test specifying device extensions to be excluded from being reported by the device");

static const char* profile_file_data = JSON_PROFILES_PATH "VP_LUNARG_desktop_baseline.json";
static const char* profile_dir_data = JSON_PROFILES_PATH;
static const char* profile_name_data = "VP_LUNARG_desktop_baseline_2023";
VkBool32 emulate_portability_data = VK_TRUE;
VkBool32 debug_fail_on_error = VK_FALSE;
const std::vector<const char*> debug_reports = {"DEBUG_REPORT_ERROR_BIT", "DEBUG_REPORT_WARNING_BIT",
"DEBUG_REPORT_NOTIFICATION_BIT", "DEBUG_REPORT_DEBUG_BIT"};

std::vector<VkLayerSettingEXT> settings = {
{kLayerName, kLayerSettingsProfileFile, VK_LAYER_SETTING_TYPE_STRING_EXT, 1, {&profile_file_data}},
{kLayerName, kLayerSettingsProfileDirs, VK_LAYER_SETTING_TYPE_STRING_EXT, 1, {&profile_dir_data}},
{kLayerName, kLayerSettingsProfileName, VK_LAYER_SETTING_TYPE_STRING_EXT, 1, {&profile_name_data}},
{kLayerName, kLayerSettingsEmulatePortability, VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &emulate_portability_data},
{kLayerName, kLayerSettingsDebugFailOnError, VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &debug_fail_on_error}};
{kLayerName, kLayerSettingsDebugFailOnError, VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &debug_fail_on_error},
{kLayerName, kLayerSettingsDebugReports, VK_LAYER_SETTING_TYPE_STRING_EXT, static_cast<uint32_t>(debug_reports.size()), &debug_reports[0]}
};

profiles_test::VulkanInstanceBuilder inst_builder;
VkResult err = inst_builder.init(settings);
Expand All @@ -63,6 +67,13 @@ TEST_F(LayerTests, TestDesktop2023) {
printf("Profile not supported on device, skipping test.\n");
return;
}

VkPhysicalDeviceProperties gpu_props{};
vkGetPhysicalDeviceProperties(gpu, &gpu_props);

ASSERT_EQ(gpu_props.limits.maxImageDimension1D, 16384);
ASSERT_EQ(gpu_props.limits.maxImageDimension2D, 16384);
ASSERT_EQ(gpu_props.limits.maxImageDimension3D, 2048);
}
#endif//__ANDROID__

Expand Down
2 changes: 1 addition & 1 deletion layer/tests/tests_mechanism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ TEST_F(TestsMechanism, default_feature_values) {
const char* default_feature_values_data = "DEFAULT_FEATURE_VALUES_FALSE";
const char* debug_reports_data = "DEBUG_REPORT_MAX_ENUM";

std::vector<VkLayerSettingEXT> settings = {
const std::vector<VkLayerSettingEXT> settings = {
{kLayerName, kLayerSettingsProfileFile, VK_LAYER_SETTING_TYPE_STRING_EXT, 1, &profile_file_data},
{kLayerName, kLayerSettingsProfileName, VK_LAYER_SETTING_TYPE_STRING_EXT, 1, &profile_name_data},
{kLayerName, kLayerSettingsEmulatePortability, VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &emulate_portability_data},
Expand Down
4 changes: 2 additions & 2 deletions library/test/test_api_profile_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ TEST(api_capabilities_object, get_api_version) {
TEST(api_capabilities_object, get_required_profiles) {
Capabilities object;

const VpProfileProperties profileProperties = {VP_LUNARG_DESKTOP_BASELINE_2023_NAME, 1};
const VpProfileProperties profileProperties = {VP_KHR_ROADMAP_2024_NAME, VP_KHR_ROADMAP_2024_SPEC_VERSION};

uint32_t propertyCount = 0;
VkResult result0 = vpGetProfileRequiredProfiles(object.handle, &profileProperties, &propertyCount, nullptr);
EXPECT_EQ(VK_SUCCESS, result0);
EXPECT_TRUE(propertyCount == 2);
EXPECT_TRUE(propertyCount == 1);
}

TEST(api_capabilities_object, get_profile_fallback) {
Expand Down
15 changes: 7 additions & 8 deletions library/test/test_api_reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,27 @@ TEST(api_get_profiles_beta, partial) {
EXPECT_EQ(VP_KHR_ROADMAP_2022_SPEC_VERSION, properties[0].specVersion);
}

TEST(api_get_profile_required_profiles, empty) {
const VpProfileProperties profile = {VP_LUNARG_DESKTOP_BASELINE_2023_NAME, 1};
TEST(api_get_profile_required_profiles, full) {
const VpProfileProperties profile = {VP_KHR_ROADMAP_2024_NAME, VP_KHR_ROADMAP_2024_SPEC_VERSION};

uint32_t count = 0;
VkResult result0 = vpGetProfileRequiredProfiles(&profile, &count, nullptr);
EXPECT_EQ(VK_SUCCESS, result0);
EXPECT_EQ(2, count);
EXPECT_EQ(1, count);

std::vector<VpProfileProperties> data(count);
VkResult result1 = vpGetProfileRequiredProfiles(&profile, &count, &data[0]);
EXPECT_STREQ(VP_LUNARG_MINIMUM_REQUIREMENTS_1_1_NAME, data[0].profileName);
EXPECT_STREQ(VP_LUNARG_MINIMUM_REQUIREMENTS_1_2_NAME, data[1].profileName);
EXPECT_STREQ(VP_KHR_ROADMAP_2022_NAME, data[0].profileName);
EXPECT_EQ(VK_SUCCESS, result1);
EXPECT_EQ(2, count);
EXPECT_EQ(1, count);
}

TEST(api_get_profile_api_version, get) {
const VpProfileProperties profile = {VP_LUNARG_DESKTOP_BASELINE_2023_NAME, 1};
const VpProfileProperties profile = {VP_KHR_ROADMAP_2022_NAME, VP_KHR_ROADMAP_2022_SPEC_VERSION};

uint32_t version = vpGetProfileAPIVersion(&profile);

EXPECT_EQ(VK_MAKE_API_VERSION(0, 1, 2, 148), version);
EXPECT_EQ(VK_MAKE_API_VERSION(0, 1, 3, 204), version);
}

TEST(api_get_profile_device_extension_properties, full) {
Expand Down
8 changes: 4 additions & 4 deletions profiles/VP_LUNARG_desktop_baseline_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema": "profiles-0.8-latest",
"$schema": "profiles-config-latest",
"profiles": {
"VP_LUNARG_desktop_baseline_2022": {
"version": 2,
Expand All @@ -9,7 +9,7 @@
"date": "2023-01-26",
"stage": "STABLE",
"api-version": "1.1.139",
"required-profiles": "VP_LUNARG_minimum_requirements_1_1"
"required-profiles": ""
},
"VP_LUNARG_desktop_baseline_2023": {
"version": 2,
Expand All @@ -19,7 +19,7 @@
"date": "2023-01-30",
"stage": "STABLE",
"api-version": "1.2.148",
"required-profiles": "VP_LUNARG_minimum_requirements_1_1,VP_LUNARG_minimum_requirements_1_2"
"required-profiles": ""
},
"VP_LUNARG_desktop_baseline_2024": {
"version": 1,
Expand All @@ -29,7 +29,7 @@
"date": "2024-02-20",
"stage": "STABLE",
"api-version": "1.2.197",
"required-profiles": "VP_LUNARG_minimum_requirements_1_1,VP_LUNARG_minimum_requirements_1_2"
"required-profiles": ""
}
},
"contributors": {
Expand Down
9 changes: 5 additions & 4 deletions scripts/gen_profiles_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ def apply_json_value(self, profile_name, json_profile_value):
self.description = json_profile_value["description"]
self.date = json_profile_value["date"]
self.stage = json_profile_value["stage"]
if json_profile_value["api-version"] is not None:
if json_profile_value["api-version"]:
self.api_version = self.get_api_version_list(json_profile_value["api-version"])
else:
self.api_version = self.get_api_version(self.input_profile_values, self.merge_mode)
self.required_profiles = json_profile_value["required-profiles"].split(',')
if json_profile_value["required-profiles"]:
self.required_profiles = json_profile_value["required-profiles"].split(',')

def load_jsons(self, input_dir):
if input_dir is not None:
Expand Down Expand Up @@ -960,8 +961,8 @@ def get_profile(self, profile_config, capabilities_key):
json_file = open(args.config, "r")
json_data = json.load(json_file)

if json_data["schema"]:
profile_file.set_schema(json_data["schema"])
if json_data["$schema"]:
profile_file.set_schema(json_data["$schema"])
if json_data["contributors"]:
profile_file.set_contributors(json_data["contributors"])
if json_data["history"]:
Expand Down
Loading

0 comments on commit 200c9a8

Please sign in to comment.