Skip to content

Commit cb5714e

Browse files
committed
loader_test: major update redux
1 parent 235e712 commit cb5714e

18 files changed

Lines changed: 1456 additions & 1344 deletions

src/api_layers/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/api_layer_platform_defines.h ${CMAKE_
3131

3232
# Basics for api_dump API Layer
3333

34+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
35+
set(LAYER_LIB_NAME "XrApiLayer_api_dump")
36+
else()
37+
set(LAYER_LIB_NAME "libXrApiLayer_api_dump")
38+
endif()
3439
gen_xr_layer_json(
3540
${CMAKE_CURRENT_BINARY_DIR}/XrApiLayer_api_dump.json
3641
LUNARG_api_dump
37-
libXrApiLayer_api_dump${CMAKE_SHARED_MODULE_SUFFIX}
42+
${LAYER_LIB_NAME}${CMAKE_SHARED_MODULE_SUFFIX}
3843
1
3944
"API Layer to record api calls as they occur"
4045
""
@@ -96,10 +101,15 @@ endif()
96101

97102
# Basics for core_validation API Layer
98103

104+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
105+
set(LAYER_LIB_NAME "XrApiLayer_core_validation")
106+
else()
107+
set(LAYER_LIB_NAME "libXrApiLayer_core_validation")
108+
endif()
99109
gen_xr_layer_json(
100110
${CMAKE_CURRENT_BINARY_DIR}/XrApiLayer_core_validation.json
101111
LUNARG_core_validation
102-
libXrApiLayer_core_validation${CMAKE_SHARED_MODULE_SUFFIX}
112+
${LAYER_LIB_NAME}${CMAKE_SHARED_MODULE_SUFFIX}
103113
1
104114
"API Layer to perform validation of api calls and parameters as they occur"
105115
""

src/api_layers/api_dump.cpp

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// limitations under the License.
1616
//
1717
// Author: Mark Young <marky@lunarg.com>
18+
// Author: Dave Houlton <daveh@lunarg.com>
1819
//
1920

2021
#include "hex_and_handles.h"
@@ -469,62 +470,50 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
469470
contents.emplace_back("XrResult", "xrCreateInstance", "");
470471
contents.emplace_back("const XrInstanceCreateInfo*", "info", PointerToHexString(info));
471472
if (nullptr != info) {
472-
std::string prefix = "info->";
473+
std::string info_prefix = "info->";
473474
contents.emplace_back("XrStructureType", "info->type", std::to_string(info->type));
474-
std::string next_prefix = prefix;
475+
std::string next_prefix = info_prefix;
475476
next_prefix += "next";
476477
// Decode the next chain if it exists
477478
if (!ApiDumpDecodeNextChain(nullptr, info->next, next_prefix, contents)) {
478479
throw std::invalid_argument("Invalid Operation");
479480
}
480-
std::string flags_prefix = prefix;
481+
std::string flags_prefix = info_prefix;
481482
flags_prefix += "createFlags";
482483
contents.emplace_back("XrInstanceCreateFlags", flags_prefix, std::to_string(info->createFlags));
483-
std::string applicationinfo_prefix = prefix;
484+
std::string applicationinfo_prefix = info_prefix;
484485
applicationinfo_prefix += "applicationInfo";
485486
if (!ApiDumpOutputXrStruct(nullptr, &info->applicationInfo, applicationinfo_prefix, "XrApplicationInfo", true,
486487
contents)) {
487488
throw std::invalid_argument("Invalid Operation");
488489
}
489-
std::string enabledapilayercount_prefix = prefix;
490+
std::string enabledapilayercount_prefix = info_prefix;
490491
enabledapilayercount_prefix += "enabledApiLayerCount";
491492
std::ostringstream oss_enabledApiLayerCount;
492493
oss_enabledApiLayerCount << "0x" << std::hex << (info->enabledApiLayerCount);
493494
contents.emplace_back("uint32_t", enabledapilayercount_prefix, oss_enabledApiLayerCount.str());
494-
std::string enabledapilayernames_prefix = prefix;
495+
std::string enabledapilayernames_prefix = info_prefix;
495496
enabledapilayernames_prefix += "enabledApiLayerNames";
496497
std::ostringstream oss_enabledApiLayerNames_array;
497498
oss_enabledApiLayerNames_array << "0x" << std::hex << (info->enabledApiLayerNames);
498499
contents.emplace_back("const char* const*", enabledapilayernames_prefix, oss_enabledApiLayerNames_array.str());
499-
for (uint32_t info_enabledapilayernames_inc = 0; info_enabledapilayernames_inc < info->enabledApiLayerCount;
500-
++info_enabledapilayernames_inc) {
501-
std::string enabledapilayernames_array_prefix = enabledapilayernames_prefix;
502-
enabledapilayernames_array_prefix += "[";
503-
enabledapilayernames_array_prefix += std::to_string(info_enabledapilayernames_inc);
504-
enabledapilayernames_array_prefix += "]";
505-
std::ostringstream oss_enabledApiLayerNames;
506-
oss_enabledApiLayerNames << "0x" << std::hex << (*info->enabledApiLayerNames[info_enabledapilayernames_inc]);
507-
contents.emplace_back("const char* const*", enabledapilayernames_array_prefix, oss_enabledApiLayerNames.str());
500+
for (uint32_t i = 0; i < info->enabledApiLayerCount; ++i) {
501+
std::string prefix = enabledapilayernames_prefix + "[" + std::to_string(i) + "]";
502+
contents.emplace_back("const char* const*", prefix, info->enabledApiLayerNames[i]);
508503
}
509-
std::string enabledextensioncount_prefix = prefix;
504+
std::string enabledextensioncount_prefix = info_prefix;
510505
enabledextensioncount_prefix += "enabledExtensionCount";
511506
std::ostringstream oss_enabledExtensionCount;
512507
oss_enabledExtensionCount << "0x" << std::hex << (info->enabledExtensionCount);
513508
contents.emplace_back("uint32_t", enabledextensioncount_prefix, oss_enabledExtensionCount.str());
514-
std::string enabledextensionnames_prefix = prefix;
509+
std::string enabledextensionnames_prefix = info_prefix;
515510
enabledextensionnames_prefix += "enabledExtensionNames";
516511
std::ostringstream oss_enabledExtensionNames_array;
517512
oss_enabledExtensionNames_array << "0x" << std::hex << (info->enabledExtensionNames);
518513
contents.emplace_back("const char* const*", enabledextensionnames_prefix, oss_enabledExtensionNames_array.str());
519-
for (uint32_t info_enabledextensionnames_inc = 0; info_enabledextensionnames_inc < info->enabledExtensionCount;
520-
++info_enabledextensionnames_inc) {
521-
std::string enabledextensionnames_array_prefix = enabledextensionnames_prefix;
522-
enabledextensionnames_array_prefix += "[";
523-
enabledextensionnames_array_prefix += std::to_string(info_enabledextensionnames_inc);
524-
enabledextensionnames_array_prefix += "]";
525-
std::ostringstream oss_enabledExtensionNames;
526-
oss_enabledExtensionNames << "0x" << std::hex << (*info->enabledExtensionNames[info_enabledextensionnames_inc]);
527-
contents.emplace_back("const char* const*", enabledextensionnames_array_prefix, oss_enabledExtensionNames.str());
514+
for (uint32_t ii = 0; ii < info->enabledExtensionCount; ++ii) {
515+
std::string prefix = enabledextensionnames_prefix + "[" + std::to_string(ii) + "]";
516+
contents.emplace_back("const char* const*", prefix, info->enabledExtensionNames[ii]);
528517
}
529518
}
530519

src/common/filesystem_utils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,12 @@ bool FileSysUtilsParsePathList(std::string& path_list, std::vector<std::string>&
223223
}
224224

225225
bool FileSysUtilsFindFilesInPath(const std::string& path, std::vector<std::string>& files) {
226+
// Append "\\*" to file name to list folder contents. This appears to contradict the
227+
// MS documentation and example code, but verified empirically
228+
std::string starred_path = path + DIRECTORY_SYMBOL + "*";
229+
226230
WIN32_FIND_DATAW file_data;
227-
HANDLE file_handle = FindFirstFileW(utf8_to_wide(path).c_str(), &file_data);
231+
HANDLE file_handle = FindFirstFileW(utf8_to_wide(starred_path).c_str(), &file_data);
228232
if (file_handle != INVALID_HANDLE_VALUE) {
229233
do {
230234
if (!(file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {

src/common/object_info.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// limitations under the License.
1717
//
1818
// Author: Mark Young <marky@lunarg.com>, Ryan Pavlik <ryan.pavlik@collabora.com>
19+
// Author: Dave Houlton <daveh@lunarg.com>
1920
//
2021

2122
#include "object_info.h"
@@ -32,6 +33,8 @@
3233
#include <string>
3334
#include <vector>
3435

36+
#include "memory.h"
37+
3538
std::string XrSdkLogObjectInfo::ToString() const {
3639
std::ostringstream oss;
3740
oss << Uint64ToHexString(handle);
@@ -238,44 +241,45 @@ NamesAndLabels DebugUtilsData::PopulateNamesAndLabels(std::vector<XrSdkLogObject
238241
return {objects, labels};
239242
}
240243

241-
AugmentedCallbackData DebugUtilsData::AugmentCallbackData(
242-
const XrDebugUtilsMessengerCallbackDataEXT& provided_callback_data) const {
243-
AugmentedCallbackData ret{provided_callback_data};
244-
if (object_info_.Empty() || provided_callback_data.objectCount == 0) {
245-
return ret;
244+
void DebugUtilsData::WrapCallbackData(AugmentedCallbackData* aug_data,
245+
const XrDebugUtilsMessengerCallbackDataEXT* callback_data) const {
246+
// If there's nothing to add, just retun the original data as the augmented copy
247+
aug_data->exported_data = callback_data;
248+
if (object_info_.Empty() || callback_data->objectCount == 0) {
249+
return;
246250
}
247-
bool obj_name_found = false;
248-
for (uint32_t obj = 0; obj < provided_callback_data.objectCount; ++obj) {
249-
auto& current_obj = provided_callback_data.objects[obj];
250-
if (!obj_name_found) {
251-
auto lookup = object_info_.LookUpStoredObjectInfo(current_obj.objectHandle, current_obj.objectType);
252-
if (lookup != nullptr) {
253-
obj_name_found = true;
254-
}
255-
}
256251

257-
// If this is a session, see if there are any labels associated with it for us to add
258-
// to the callback content.
252+
// Inspect each of the callback objects
253+
bool name_found = false;
254+
for (uint32_t obj = 0; obj < callback_data->objectCount; ++obj) {
255+
auto& current_obj = callback_data->objects[obj];
256+
name_found |= (nullptr != object_info_.LookUpStoredObjectInfo(current_obj.objectHandle, current_obj.objectType));
257+
258+
// If this is a session, record any labels associated with it
259259
if (XR_OBJECT_TYPE_SESSION == current_obj.objectType) {
260260
XrSession session = TreatIntegerAsHandle<XrSession>(current_obj.objectHandle);
261-
LookUpSessionLabels(session, ret.labels);
261+
LookUpSessionLabels(session, aug_data->labels);
262262
}
263263
}
264264

265-
if (!obj_name_found && ret.labels.empty()) {
266-
// nothing to add to the data
267-
return ret;
265+
// If we found nothing to add, return the original data
266+
if (!name_found && aug_data->labels.empty()) {
267+
return;
268268
}
269269

270-
// If a name or a label has been found, we should update it in a new version of the callback data
271-
ret.new_objects.assign(provided_callback_data.objects, provided_callback_data.objects + provided_callback_data.objectCount);
270+
// Found additional data - modify an internal copy and return that as the exported data
271+
memcpy(&aug_data->modified_data, callback_data, sizeof(XrDebugUtilsMessengerCallbackDataEXT));
272+
aug_data->new_objects.assign(callback_data->objects, callback_data->objects + callback_data->objectCount);
272273

273-
for (auto& obj : ret.new_objects) {
274+
// Record (overwrite) the names of all incoming objects provided in our internal list
275+
for (auto& obj : aug_data->new_objects) {
274276
object_info_.LookUpObjectName(obj);
275277
}
276-
ret.temporary_callback_data.objects = ret.new_objects.data();
277-
ret.temporary_callback_data.sessionLabelCount = static_cast<uint32_t>(ret.labels.size());
278-
ret.temporary_callback_data.sessionLabels = ret.labels.empty() ? nullptr : ret.labels.data();
279-
ret.callback_data_to_use = &ret.temporary_callback_data;
280-
return ret;
278+
279+
// Update local copy & point export to it
280+
aug_data->modified_data.objects = aug_data->new_objects.data();
281+
aug_data->modified_data.sessionLabelCount = static_cast<uint32_t>(aug_data->labels.size());
282+
aug_data->modified_data.sessionLabels = aug_data->labels.empty() ? nullptr : aug_data->labels.data();
283+
aug_data->exported_data = &aug_data->modified_data;
284+
return;
281285
}

src/common/object_info.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,12 @@ struct NamesAndLabels {
181181
};
182182

183183
struct AugmentedCallbackData {
184-
explicit AugmentedCallbackData(const XrDebugUtilsMessengerCallbackDataEXT& data_to_use)
185-
: temporary_callback_data(data_to_use), callback_data_to_use(&data_to_use) {}
186184
std::vector<XrDebugUtilsLabelEXT> labels;
187-
XrDebugUtilsMessengerCallbackDataEXT temporary_callback_data;
188185
std::vector<XrDebugUtilsObjectNameInfoEXT> new_objects;
189-
190-
const XrDebugUtilsMessengerCallbackDataEXT* callback_data_to_use;
186+
XrDebugUtilsMessengerCallbackDataEXT modified_data;
187+
const XrDebugUtilsMessengerCallbackDataEXT* exported_data;
191188
};
189+
192190
/// Tracks all the data (handle names and session labels) required to fully augment XR_EXT_debug_utils-related calls.
193191
class DebugUtilsData {
194192
public:
@@ -225,7 +223,8 @@ class DebugUtilsData {
225223
/// Given the collection of objects, populate their names and list of labels
226224
NamesAndLabels PopulateNamesAndLabels(std::vector<XrSdkLogObjectInfo> objects) const;
227225

228-
AugmentedCallbackData AugmentCallbackData(const XrDebugUtilsMessengerCallbackDataEXT& provided_callback_data) const;
226+
void WrapCallbackData(AugmentedCallbackData* aug_data,
227+
const XrDebugUtilsMessengerCallbackDataEXT* provided_callback_data) const;
229228

230229
private:
231230
void RemoveIndividualLabel(XrSdkSessionLabelList& label_vec);

src/common/platform_utils.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2017-2019 The Khronos Group Inc.
2-
// Copyright (c) 2017 Valve Corporation
3-
// Copyright (c) 2017 LunarG, Inc.
2+
// Copyright (c) 2017-2019 Valve Corporation
3+
// Copyright (c) 2017-2019 LunarG, Inc.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
// limitations under the License.
1616
//
1717
// Author: Mark Young <marky@lunarg.com>
18+
// Author: Dave Houlton <daveh@lunarg.com>
1819
//
1920

2021
#pragma once
@@ -28,6 +29,20 @@
2829
#include <iostream>
2930
#endif
3031

32+
// OpenXR paths and registry key locations
33+
#define OPENXR_RELATIVE_PATH "openxr/"
34+
#define OPENXR_IMPLICIT_API_LAYER_RELATIVE_PATH "/api_layers/implicit.d"
35+
#define OPENXR_EXPLICIT_API_LAYER_RELATIVE_PATH "/api_layers/explicit.d"
36+
#ifdef XR_OS_WINDOWS
37+
#define OPENXR_REGISTRY_LOCATION "SOFTWARE\\Khronos\\OpenXR\\"
38+
#define OPENXR_IMPLICIT_API_LAYER_REGISTRY_LOCATION "\\ApiLayers\\Implicit"
39+
#define OPENXR_EXPLICIT_API_LAYER_REGISTRY_LOCATION "\\ApiLayers\\Explicit"
40+
#endif
41+
42+
// OpenXR Loader environment variables of interest
43+
#define OPENXR_RUNTIME_JSON_ENV_VAR "XR_RUNTIME_JSON"
44+
#define OPENXR_API_LAYER_PATH_ENV_VAR "XR_API_LAYER_PATH"
45+
3146
// This is a CMake generated file with #defines for any functions/includes
3247
// that it found present and build-time configuration.
3348
// If you don't have this file, on non-Windows you'll need to define

0 commit comments

Comments
 (0)