Skip to content

Commit

Permalink
layer: Improve API consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Aug 8, 2023
1 parent 430013c commit b259aae
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 288 deletions.
6 changes: 3 additions & 3 deletions include/vulkan/layer/vk_layer_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ void vlGetLayerSettingValues(VlLayerSettingSet layerSettingSet,
const char *pSettingName, std::vector<std::string> &settingValues);

void vlGetLayerSettingValue(VlLayerSettingSet layerSettingSet,
const char *pSettingName, VkFrameset &settingValue);
const char *pSettingName, VkFramesetEXT &settingValue);

void vlGetLayerSettingValues(VlLayerSettingSet layerSettingSet,
const char *pSettingName, std::vector<VkFrameset> &settingValues);
void vlGetLayerSettingValues(VlLayerSettingSet layerSettingSet, const char *pSettingName,
std::vector<VkFramesetEXT> &settingValues);

// Required by vk_safe_struct
typedef std::pair<uint32_t, uint32_t> VlCustomSTypeInfo;
Expand Down
65 changes: 18 additions & 47 deletions include/vulkan/layer/vk_layer_settings_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,19 @@ extern "C" {
// Mark Lobodzinski
//
// Description
// This extension provides the VkLayerSettingsEXT struct that can be included in the pNext chain of the
// VkInstanceCreateInfo structure passed as the pCreateInfo parameter of vkCreateInstance
// The structure contains an array of VkLayerSettingValueEXT structures that define layer specific settings
// The extension also provides the vkEnumerateInstanceLayerSettingsEXT and vkEnumerateInstanceLayerSettingOptionEXT
// commands, useful for enumerating all layer settings and their possible values, respectively.
// This extension provides a mechanism for configuring programmatically through
// the Vulkan API the behavior of layers.
//
// This extension provides the [VkLayerSettingsCreateInfoEXT] struct that can be
// included in the [pNext] chain of the [VkInstanceCreateInfo]
// structure passed as the [pCreateInfo] parameter of [vkCreateInstance].
//
// The structure contains an array of [VkLayerSettingEXT] structure
// values that configure specific features of layers.
//
// Note
// The VK_EXT_layer_settings extension subsumes all the functionality provided in the [VK_EXT_validation_flags] extension
// The [VK_EXT_layer_settings] extension subsumes all the functionality provided in the [VK_EXT_validation_flags] extension
// and the [VK_EXT_validation_features] extension.
//
// New Commands
// vkEnumerateInstanceLayerSettingsEXT
// vkEnumerateInstanceLayerSettingOptionEXT
//
// New Structures
// array_int32
// array_int64
// array_float
// array_bool
// array_char
// VkLayerSettingValueEXT
// VkLayerSettingDescriptionEXT
// VkLayerSettingOptionEXT
// Extending VkInstanceCreateInfo :
// VkLayerSettingsEXT
//
// New Unions
// VkLayerSettingValueDataEXT
//
// New Enums
// VkLayerSettingValueTypeEXT

#define VK_EXT_layer_settings 1
#define VK_EXT_LAYER_SETTINGS_SPEC_VERSION 1
Expand All @@ -82,40 +64,29 @@ extern "C" {
#define VK_STRUCTURE_TYPE_LAYER_SETTINGS_EXT ((VkStructureType)(VK_STRUCTURE_TYPE_MAX_ENUM - 43))

typedef enum VkLayerSettingTypeEXT {
VK_LAYER_SETTING_TYPE_BOOL_EXT = 0,
VK_LAYER_SETTING_TYPE_BOOL32_EXT = 0,
VK_LAYER_SETTING_TYPE_INT32_EXT,
VK_LAYER_SETTING_TYPE_INT64_EXT,
VK_LAYER_SETTING_TYPE_UINT32_EXT,
VK_LAYER_SETTING_TYPE_UINT64_EXT,
VK_LAYER_SETTING_TYPE_FLOAT_EXT,
VK_LAYER_SETTING_TYPE_DOUBLE_EXT,
VK_LAYER_SETTING_TYPE_FRAMESET_EXT,
VK_LAYER_SETTING_TYPE_STRING_EXT
VK_LAYER_SETTING_TYPE_FLOAT32_EXT,
VK_LAYER_SETTING_TYPE_FLOAT64_EXT,
VK_LAYER_SETTING_TYPE_STRING_EXT,
VK_LAYER_SETTING_TYPE_FRAMESET_EXT
} VkLayerSettingTypeEXT;

typedef struct VkFrameset {
typedef struct VkFramesetEXT {
uint32_t first;
uint32_t count;
uint32_t step;
} VkFrameset;
} VkFramesetEXT;

typedef struct VkLayerSettingEXT {
const char *pLayerName;
const char *pSettingName;
VkLayerSettingTypeEXT type;
uint32_t count;
union {
const void *value;
const VkBool32 *asBool32;
const int32_t *asInt32;
const int64_t *asInt64;
const uint32_t *asUint32;
const uint64_t *asUint64;
const float *asFloat;
const double *asDouble;
const VkFrameset *asFrameset;
const char **asString;
};
const void *pValues;
} VkLayerSettingEXT;

typedef struct VkLayerSettingsCreateInfoEXT {
Expand Down
14 changes: 7 additions & 7 deletions src/layer/layer_settings_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ std::string LayerSettings::FindSettingsFile() {
LSTATUS err = RegOpenKeyEx(hives[hive_index], "Software\\Khronos\\Vulkan\\Settings", 0, KEY_READ, &key);
if (err == ERROR_SUCCESS) {
char name[2048];
DWORD i = 0, name_size, type, value, value_size;
DWORD i = 0, name_size, type, pValues, value_size;
while (ERROR_SUCCESS == RegEnumValue(key, i++, name, &(name_size = sizeof(name)), nullptr, &type,
reinterpret_cast<LPBYTE>(&value), &(value_size = sizeof(value)))) {
reinterpret_cast<LPBYTE>(&pValues), &(value_size = sizeof(pValues)))) {
// Check if the registry entry is a dword with a value of zero
if (type != REG_DWORD || value != 0) {
if (type != REG_DWORD || pValues != 0) {
continue;
}

Expand Down Expand Up @@ -315,16 +315,16 @@ std::string LayerSettings::GetFileSetting(const char *pSettingName) {
}
}

void LayerSettings::SetFileSetting(const char *pSettingName, const std::string &value) {
void LayerSettings::SetFileSetting(const char *pSettingName, const std::string &pValues) {
assert(pSettingName != nullptr);

this->setting_file_values.insert({pSettingName, value});
this->setting_file_values.insert({pSettingName, pValues});
}

const LayerSetting *LayerSettings::GetAPISetting(const char *pSettingName) {
const VkLayerSettingEXT *LayerSettings::GetAPISetting(const char *pSettingName) {
assert(pSettingName != nullptr);

return reinterpret_cast<const LayerSetting *>(this->FindLayerSettingValue(pSettingName));
return reinterpret_cast<const VkLayerSettingEXT *>(this->FindLayerSettingValue(pSettingName));
}

} // namespace vl
22 changes: 2 additions & 20 deletions src/layer/layer_settings_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@
#include <map>

namespace vl {
struct LayerSetting {
const char *pLayerName;
const char *pSettingName;
VkLayerSettingTypeEXT type;
uint32_t count;
union {
const VkBool32 *asBool32;
const int32_t *asInt32;
const int64_t *asInt64;
const uint32_t *asUint32;
const uint64_t *asUint64;
const float *asFloat;
const double *asDouble;
const VkFrameset *asFrameset;
const char **asString;
};
};

class LayerSettings {
public:
LayerSettings(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pCreateInfo,
Expand All @@ -49,9 +31,9 @@ namespace vl {

std::string GetFileSetting(const char *pSettingName);

void SetFileSetting(const char *pSettingName, const std::string& value);
void SetFileSetting(const char *pSettingName, const std::string& pValues);

const LayerSetting *GetAPISetting(const char *pSettingName);
const VkLayerSettingEXT *GetAPISetting(const char *pSettingName);

void Log(const char *pSettingName, const char *pMessage);

Expand Down
12 changes: 6 additions & 6 deletions src/layer/layer_settings_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

namespace vl {

std::vector<std::string> Split(const std::string &value, char delimiter) {
std::vector<std::string> Split(const std::string &pValues, char delimiter) {
std::vector<std::string> result;

std::string parse = value;
std::string parse = pValues;

std::size_t start = 0;
std::size_t end = parse.find(delimiter);
Expand Down Expand Up @@ -198,10 +198,10 @@ int64_t ToInt64(const std::string &token) {
return int_id;
}

VkFrameset ToFrameSet(const std::string &s) {
VkFramesetEXT ToFrameSet(const std::string &s) {
assert(IsFrameSets(s));

VkFrameset frameset{0, 1, 1};
VkFramesetEXT frameset{0, 1, 1};

const std::vector<std::string> &frameset_split = vl::Split(s, '-');
if (frameset_split.size() >= 1) {
Expand All @@ -217,10 +217,10 @@ VkFrameset ToFrameSet(const std::string &s) {
return frameset;
}

std::vector<VkFrameset> ToFrameSets(const std::string &s) {
std::vector<VkFramesetEXT> ToFrameSets(const std::string &s) {
std::vector<std::string> tokens = Split(s, FindDelimiter(s));

std::vector<VkFrameset> results;
std::vector<VkFramesetEXT> results;
results.resize(tokens.size());
for (std::size_t i = 0, n = tokens.size(); i < n; ++i) {
results[i] = ToFrameSet(tokens[i]);
Expand Down
6 changes: 3 additions & 3 deletions src/layer/layer_settings_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace vl {
const void *next);

std::vector<std::string> Split(
const std::string &value, char delimiter);
const std::string &pValues, char delimiter);

enum TrimMode {
TRIM_NONE,
Expand Down Expand Up @@ -62,9 +62,9 @@ namespace vl {

bool IsFrameSets(const std::string &s);

VkFrameset ToFrameSet(const std::string &s);
VkFramesetEXT ToFrameSet(const std::string &s);

std::vector<VkFrameset> ToFrameSets(const std::string &s);
std::vector<VkFramesetEXT> ToFrameSets(const std::string &s);

bool IsInteger(const std::string &s);

Expand Down
Loading

0 comments on commit b259aae

Please sign in to comment.