Skip to content

Commit 2bf2d1e

Browse files
authored
Format code for PR #8448 (#8498)
Automated code formatting for #8448 Co-authored-by: slangbot <[email protected]>
1 parent 5ac16bd commit 2bf2d1e

File tree

6 files changed

+59
-52
lines changed

6 files changed

+59
-52
lines changed

tools/render-test/render-test-main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,8 @@ static SlangResult _innerMain(
15841584
//
15851585
// We also don't want to output the 'Unable to create renderer' error, as this isn't
15861586
// an error.
1587-
SlangResult res = SLANG_E_NOT_AVAILABLE; // Default to not available if device creation fails
1587+
SlangResult res =
1588+
SLANG_E_NOT_AVAILABLE; // Default to not available if device creation fails
15881589
if (!options.onlyStartup)
15891590
{
15901591
fprintf(stderr, "Unable to create renderer %s\n", rendererName.getBuffer());

tools/render-test/slang-test-device-cache.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#include <algorithm>
21
#include "slang-test-device-cache.h"
32

3+
#include <algorithm>
4+
45
// Static member accessor functions (Meyer's singleton pattern)
56
// This ensures proper destruction order - function-local statics are destroyed
67
// in reverse order of first access, avoiding the static destruction order fiasco
@@ -10,7 +11,11 @@ std::mutex& DeviceCache::getMutex()
1011
return instance;
1112
}
1213

13-
std::unordered_map<DeviceCache::DeviceCacheKey, DeviceCache::CachedDevice, DeviceCache::DeviceCacheKeyHash>& DeviceCache::getDeviceCache()
14+
std::unordered_map<
15+
DeviceCache::DeviceCacheKey,
16+
DeviceCache::CachedDevice,
17+
DeviceCache::DeviceCacheKeyHash>&
18+
DeviceCache::getDeviceCache()
1419
{
1520
static std::unordered_map<DeviceCacheKey, CachedDevice, DeviceCacheKeyHash> instance;
1621
return instance;
@@ -24,11 +29,9 @@ uint64_t& DeviceCache::getNextCreationOrder()
2429

2530
bool DeviceCache::DeviceCacheKey::operator==(const DeviceCacheKey& other) const
2631
{
27-
return deviceType == other.deviceType &&
28-
enableValidation == other.enableValidation &&
32+
return deviceType == other.deviceType && enableValidation == other.enableValidation &&
2933
enableRayTracingValidation == other.enableRayTracingValidation &&
30-
profileName == other.profileName &&
31-
requiredFeatures == other.requiredFeatures;
34+
profileName == other.profileName && requiredFeatures == other.requiredFeatures;
3235
}
3336

3437
std::size_t DeviceCache::DeviceCacheKeyHash::operator()(const DeviceCacheKey& key) const
@@ -37,17 +40,17 @@ std::size_t DeviceCache::DeviceCacheKeyHash::operator()(const DeviceCacheKey& ke
3740
std::size_t h2 = std::hash<bool>{}(key.enableValidation);
3841
std::size_t h3 = std::hash<bool>{}(key.enableRayTracingValidation);
3942
std::size_t h4 = std::hash<std::string>{}(key.profileName);
40-
43+
4144
std::size_t h5 = 0;
4245
for (const auto& feature : key.requiredFeatures)
4346
{
4447
h5 ^= std::hash<std::string>{}(feature) + 0x9e3779b9 + (h5 << 6) + (h5 >> 2);
4548
}
46-
49+
4750
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3) ^ (h5 << 4);
4851
}
4952

50-
DeviceCache::CachedDevice::CachedDevice()
53+
DeviceCache::CachedDevice::CachedDevice()
5154
: creationOrder(0)
5255
{
5356
}
@@ -57,11 +60,11 @@ void DeviceCache::evictOldestDeviceIfNeeded()
5760
auto& deviceCache = getDeviceCache();
5861
if (deviceCache.size() < MAX_CACHED_DEVICES)
5962
return;
60-
63+
6164
// Find the oldest device to evict
6265
auto oldestIt = deviceCache.end();
6366
uint64_t oldestCreationOrder = UINT64_MAX;
64-
67+
6568
for (auto it = deviceCache.begin(); it != deviceCache.end(); ++it)
6669
{
6770
if (it->second.creationOrder < oldestCreationOrder)
@@ -70,7 +73,7 @@ void DeviceCache::evictOldestDeviceIfNeeded()
7073
oldestIt = it;
7174
}
7275
}
73-
76+
7477
// Remove the oldest device - ComPtr will handle the actual device release
7578
if (oldestIt != deviceCache.end())
7679
{
@@ -89,49 +92,49 @@ Slang::ComPtr<rhi::IDevice> DeviceCache::acquireDevice(const rhi::DeviceDesc& de
8992
return device;
9093
return nullptr;
9194
}
92-
95+
9396
std::lock_guard<std::mutex> lock(getMutex());
9497
auto& deviceCache = getDeviceCache();
9598
auto& nextCreationOrder = getNextCreationOrder();
96-
99+
97100
// Create cache key
98101
DeviceCacheKey key;
99102
key.deviceType = desc.deviceType;
100103
key.enableValidation = desc.enableValidation;
101104
key.enableRayTracingValidation = desc.enableRayTracingValidation;
102105
key.profileName = desc.slang.targetProfile ? desc.slang.targetProfile : "";
103-
106+
104107
// Add required features to key
105108
for (int i = 0; i < desc.requiredFeatureCount; ++i)
106109
{
107110
key.requiredFeatures.push_back(desc.requiredFeatures[i]);
108111
}
109112
std::sort(key.requiredFeatures.begin(), key.requiredFeatures.end());
110-
113+
111114
// Evict oldest device if we've reached the limit
112115
evictOldestDeviceIfNeeded();
113-
116+
114117
// Check if we have a cached device
115118
auto it = deviceCache.find(key);
116119
if (it != deviceCache.end())
117120
{
118121
// Return the cached device - COM reference counting handles the references
119122
return it->second.device;
120123
}
121-
124+
122125
// Create new device
123126
Slang::ComPtr<rhi::IDevice> device;
124127
auto result = rhi::getRHI()->createDevice(desc, device.writeRef());
125128
if (SLANG_FAILED(result))
126129
{
127130
return nullptr;
128131
}
129-
132+
130133
// Cache the device
131134
CachedDevice& cached = deviceCache[key];
132135
cached.device = device;
133136
cached.creationOrder = nextCreationOrder++;
134-
137+
135138
return device;
136139
}
137140

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#pragma once
22

3-
#include <slang-rhi.h>
43
#include <chrono>
54
#include <mutex>
5+
#include <slang-rhi.h>
6+
#include <string>
67
#include <unordered_map>
78
#include <vector>
8-
#include <string>
99

1010
// Device Cache for preventing NVIDIA Tegra driver state corruption
1111
// This cache reuses Vulkan instances and devices to avoid the VK_ERROR_INCOMPATIBLE_DRIVER
1212
// issue that occurs after ~19 device creation/destruction cycles on Tegra platforms.
13-
// Uses ComPtr for automatic device lifecycle management - devices are released when removed from cache.
13+
// Uses ComPtr for automatic device lifecycle management - devices are released when removed from
14+
// cache.
1415
class DeviceCache
1516
{
1617
public:
@@ -21,33 +22,33 @@ class DeviceCache
2122
bool enableRayTracingValidation;
2223
std::string profileName;
2324
std::vector<std::string> requiredFeatures;
24-
25+
2526
bool operator==(const DeviceCacheKey& other) const;
2627
};
27-
28+
2829
struct DeviceCacheKeyHash
2930
{
3031
std::size_t operator()(const DeviceCacheKey& key) const;
3132
};
32-
33+
3334
struct CachedDevice
3435
{
3536
Slang::ComPtr<rhi::IDevice> device;
3637
uint64_t creationOrder;
37-
38+
3839
CachedDevice();
3940
};
40-
41+
4142
private:
4243
static constexpr int MAX_CACHED_DEVICES = 10;
43-
44+
4445
// Use function-local statics to control destruction order (Meyer's singleton pattern)
4546
static std::mutex& getMutex();
4647
static std::unordered_map<DeviceCacheKey, CachedDevice, DeviceCacheKeyHash>& getDeviceCache();
4748
static uint64_t& getNextCreationOrder();
48-
49+
4950
static void evictOldestDeviceIfNeeded();
50-
51+
5152
public:
5253
static Slang::ComPtr<rhi::IDevice> acquireDevice(const rhi::DeviceDesc& desc);
5354
static void cleanCache();
@@ -58,22 +59,23 @@ class CachedDeviceWrapper
5859
{
5960
private:
6061
Slang::ComPtr<rhi::IDevice> m_device;
61-
62+
6263
public:
6364
CachedDeviceWrapper() = default;
64-
65-
CachedDeviceWrapper(Slang::ComPtr<rhi::IDevice> device) : m_device(device) {}
66-
67-
~CachedDeviceWrapper()
65+
66+
CachedDeviceWrapper(Slang::ComPtr<rhi::IDevice> device)
67+
: m_device(device)
6868
{
6969
}
70-
70+
71+
~CachedDeviceWrapper() {}
72+
7173
// Move constructor
7274
CachedDeviceWrapper(CachedDeviceWrapper&& other) noexcept
7375
: m_device(std::move(other.m_device))
7476
{
7577
}
76-
78+
7779
// Move assignment
7880
CachedDeviceWrapper& operator=(CachedDeviceWrapper&& other) noexcept
7981
{
@@ -83,14 +85,14 @@ class CachedDeviceWrapper
8385
}
8486
return *this;
8587
}
86-
88+
8789
// Delete copy constructor and assignment
8890
CachedDeviceWrapper(const CachedDeviceWrapper&) = delete;
8991
CachedDeviceWrapper& operator=(const CachedDeviceWrapper&) = delete;
90-
92+
9193
rhi::IDevice* get() const { return m_device.get(); }
9294
rhi::IDevice* operator->() const { return m_device.get(); }
9395
operator bool() const { return m_device != nullptr; }
94-
96+
9597
Slang::ComPtr<rhi::IDevice>& getComPtr() { return m_device; }
9698
};

tools/slang-test/slang-test-main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5451,14 +5451,13 @@ SlangResult innerMain(int argc, char** argv)
54515451

54525452
int main(int argc, char** argv)
54535453
{
5454-
// Fallback: run without cleanup if context initialization fails
5455-
SlangResult res = innerMain(argc, argv);
5456-
slang::shutdown();
5457-
Slang::RttiInfo::deallocateAll();
5454+
// Fallback: run without cleanup if context initialization fails
5455+
SlangResult res = innerMain(argc, argv);
5456+
slang::shutdown();
5457+
Slang::RttiInfo::deallocateAll();
54585458

54595459
#ifdef _MSC_VER
5460-
_CrtDumpMemoryLeaks();
5460+
_CrtDumpMemoryLeaks();
54615461
#endif
5462-
return SLANG_SUCCEEDED(res) ? 0 : 1;
5463-
5462+
return SLANG_SUCCEEDED(res) ? 0 : 1;
54645463
}

tools/slang-test/test-context.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ TestContext::InnerMainFunc TestContext::getInnerMainFunc(const String& dirPath,
130130
loader->loadPlatformSharedLibrary(path.begin(), tool.m_sharedLibrary.writeRef())))
131131
{
132132
tool.m_func = (InnerMainFunc)tool.m_sharedLibrary->findFuncByName("innerMain");
133-
tool.m_cleanDeviceCacheFunc = (CleanDeviceCacheFunc)tool.m_sharedLibrary->findFuncByName("cleanDeviceCache");
133+
tool.m_cleanDeviceCacheFunc =
134+
(CleanDeviceCacheFunc)tool.m_sharedLibrary->findFuncByName("cleanDeviceCache");
134135
}
135136

136137
m_sharedLibTools.add(name, tool);
@@ -156,7 +157,8 @@ void TestContext::setInnerMainFunc(const String& name, InnerMainFunc func)
156157
TestContext::CleanDeviceCacheFunc TestContext::getCleanDeviceCacheFunc(const String& name)
157158
{
158159
SharedLibraryTool* tool = m_sharedLibTools.tryGetValue(name);
159-
if (tool) {
160+
if (tool)
161+
{
160162
return tool->m_cleanDeviceCacheFunc;
161163
}
162164

tools/slang-test/test-context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class TestContext
101101
InnerMainFunc getInnerMainFunc(const Slang::String& dirPath, const Slang::String& name);
102102
/// Set the function for the shared library
103103
void setInnerMainFunc(const Slang::String& name, InnerMainFunc func);
104-
104+
105105
/// Get the device cache cleanup function (from shared library)
106106
CleanDeviceCacheFunc getCleanDeviceCacheFunc(const Slang::String& name);
107107

0 commit comments

Comments
 (0)