Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,15 @@
<ItemGroup>
<ClInclude Include="dlss\DLSS.h" />
<ClInclude Include="fsr\FSR.h" />
<ClInclude Include="includes\callbacks.h" />
<ClInclude Include="includes\cbuffers.h" />
<ClInclude Include="includes\com_ptr.h" />
<ClInclude Include="includes\debug.h" />
<ClInclude Include="includes\game.h" />
<ClInclude Include="includes\globals.h" />
<ClInclude Include="includes\hash.h" />
<ClInclude Include="includes\instance_data.h" />
<ClInclude Include="includes\managed_resources.h" />
<ClInclude Include="includes\overlay_log.h" />
<ClInclude Include="includes\math.h" />
<ClInclude Include="includes\matrix.h" />
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,11 @@
<ClInclude Include="includes\overlay_log.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="includes\callbacks.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="includes\managed_resources.h">
<Filter>Includes</Filter>
</ClInclude>
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions Source/Core/core.hpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#pragma once

// "_DEBUG" might already be defined in debug?
// Setting it to 0 causes the compiler to still assume it as defined and that thus we are in debug mode (don't change this manually).
#ifndef NDEBUG
#define _DEBUG 1

Check warning on line 6 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:6:9 [cppcoreguidelines-macro-usage]

macro '_DEBUG' used to declare a constant; consider using a 'constexpr' constant

Check warning on line 6 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:6:9 [bugprone-reserved-identifier]

declaration uses identifier '_DEBUG', which is a reserved identifier
#endif // !NDEBUG

// Enable when you are developing shaders or code (not debugging, there's "NDEBUG" for that).
// This brings out the development tools, allowing you to trace draw calls and a lot more stuff.
#ifndef DEVELOPMENT
#define DEVELOPMENT 0

Check warning on line 12 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:12:9 [cppcoreguidelines-macro-usage]

macro 'DEVELOPMENT' used to declare a constant; consider using a 'constexpr' constant
#endif // DEVELOPMENT
// Enable when you are testing shaders or code (e.g. to dump the shaders, logging warnings, etc etc).
// This is not mutually exclusive with "DEVELOPMENT", but it should be a sub-set of it.
// If neither of these are true, then we are in "shipping" mode, with code meant to be used by the final user.
#ifndef TEST
#define TEST 0

Check warning on line 18 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:18:9 [cppcoreguidelines-macro-usage]

macro 'TEST' used to declare a constant; consider using a 'constexpr' constant
#endif // TEST

#define LOG_VERBOSE ((DEVELOPMENT || TEST) && 0)

// Disables loading the ReShade Addon code (useful to test the mod without any ReShade dependencies (e.g. optionally "Prey"))
#define DISABLE_RESHADE 0

Check warning on line 24 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:24:9 [cppcoreguidelines-macro-usage]

macro 'DISABLE_RESHADE' used to declare a constant; consider using a 'constexpr' constant

#pragma comment(lib, "Gdi32.lib") // For "SetDeviceGammaRamp"
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "Dxva2.lib") // For "SetMonitorBrightness"

#define _USE_MATH_DEFINES

Check warning on line 30 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:30:9 [bugprone-reserved-identifier]

declaration uses identifier '_USE_MATH_DEFINES', which is a reserved identifier

#ifdef _WIN32
#define ImTextureID ImU64
#endif

#include <d3d11.h>

Check failure on line 36 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:36:10 [clang-diagnostic-error]

'd3d11.h' file not found
#include <d3d11_4.h>
#include <dxgi.h>
#include <dxgi1_6.h>
Expand All @@ -42,12 +42,12 @@

#include <cstdio>
#include <filesystem>
#include <fstream>

Check warning on line 45 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:45:1 [misc-include-cleaner]

included header fstream is not used directly
#include <shared_mutex>
#include <string>
#include <map>

Check warning on line 48 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:48:1 [misc-include-cleaner]

included header map is not used directly
#include <unordered_map>

Check warning on line 49 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:49:1 [misc-include-cleaner]

included header unordered_map is not used directly
#include <unordered_set>

Check warning on line 50 in Source/Core/core.hpp

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/core.hpp:50:1 [misc-include-cleaner]

included header unordered_set is not used directly
#include <set>
#include <vector>
#include <semaphore>
Expand Down Expand Up @@ -2570,6 +2570,12 @@
}
#endif // ENABLE_SR

// Execute all Luma callbacks.
for (const auto& callback : LumaCallbacks::on_destroy_device)
{
callback.second();
}

device->destroy_private_data<DeviceData>();
}

Expand Down Expand Up @@ -2959,6 +2965,12 @@
// TODO: put code to track all recently created resources and late upgraded them if the size/aspect ratio now matches the swapchain (some games resize the swapchain after resources, so in that case we should handle indirect upgrades like this)
}

// Execute all Luma callbacks.
for (const auto& callback : LumaCallbacks::on_init_swapchain)
{
callback.second();
}

game->OnInitSwapchain(swapchain);
}

Expand Down
20 changes: 20 additions & 0 deletions Source/Core/includes/callbacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <vector>

Check failure on line 3 in Source/Core/includes/callbacks.h

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/includes/callbacks.h:3:10 [clang-diagnostic-error]

'vector' file not found
#include <functional>

// struct cause maybe we want to make some members private in future
//
// So far std::unoredered_map may be the best solution for this.
// std::unordered_set could be better, but it won't work with std::function.
// std::vector could be too much manual management for the user (developer)?
//
// Signal user that callback was executed?
struct LumaCallbacks final
{
// Executed after swapchain resize and after swapchain creation.
static inline std::unordered_map<uint32_t, std::function<void()>> on_init_swapchain;

// Executed before device is destroyed.
static inline std::unordered_map<uint32_t, std::function<void()>> on_destroy_device;
};
8 changes: 6 additions & 2 deletions Source/Core/includes/instance_data.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

#include <algorithm>

Check failure on line 3 in Source/Core/includes/instance_data.h

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/includes/instance_data.h:3:10 [clang-diagnostic-error]

'algorithm' file not found
Expand All @@ -16,6 +16,8 @@
#include <utility>
#include <vector>

#include "managed_resources.h"

// Forward declarations
struct GameDeviceData;

Expand Down Expand Up @@ -90,7 +92,7 @@
AppendCommandList,
ResetCommmandList,
FlushCommandList,
Custom, // Custom draw call for custom passes we added/replaced
Custom, // Custom draw call for custom passes we added/replaced
};

TraceDrawCallType type = TraceDrawCallType::Shader;
Expand Down Expand Up @@ -583,6 +585,8 @@
buffers.push_back(luma_ui_data.get());
return buffers;
}

ManagedResources managed_resources;
};

struct __declspec(uuid("c5805458-2c02-4ebf-b139-38b85118d971")) SwapchainData
Expand All @@ -595,5 +599,5 @@
std::vector<com_ptr<ID3D11RenderTargetView>> display_composition_rtvs;

// Whether the original SDR (vanilla) swapchain was linear space (e.g. sRGB formats)
bool vanilla_was_linear_space = false;
bool vanilla_was_linear_space = false;
};
46 changes: 46 additions & 0 deletions Source/Core/includes/managed_resources.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include <d3d11_4.h>

Check failure on line 3 in Source/Core/includes/managed_resources.h

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/includes/managed_resources.h:3:10 [clang-diagnostic-error]

'd3d11_4.h' file not found
#include <unordered_map>
#include <vector>
#include "com_ptr.h"

struct ManagedResources
{
// Key should be result of CompileTimeStringHash()!
// Example usage: shader_resource_views[CompileTimeStringHash("scene")] = srv_scene;
// Example usage: shader_resource_views["scene"_h] = srv_scene;
std::unordered_map<uint32_t, ComPtr<ID3D11ShaderResourceView>> shader_resource_views;
std::unordered_map<uint32_t, ComPtr<ID3D11RenderTargetView>> render_target_views;
std::unordered_map<uint32_t, ComPtr<ID3D11UnorderedAccessView>> unordered_access_views;
std::unordered_map<uint32_t, ComPtr<ID3D11DepthStencilView>> depth_stencil_views;
std::unordered_map<uint32_t, ComPtr<ID3D11Resource>> resources;
std::unordered_map<uint32_t, ComPtr<ID3D11Buffer>> buffers;
std::unordered_map<uint32_t, ComPtr<ID3D11Texture1D>> textures_1d;
std::unordered_map<uint32_t, ComPtr<ID3D11Texture2D>> textures_2d;
std::unordered_map<uint32_t, ComPtr<ID3D11Texture3D>> textures_3d;
std::unordered_map<uint32_t, ComPtr<ID3D11InputLayout>> input_layouts;
std::unordered_map<uint32_t, ComPtr<ID3D11RasterizerState>> rasterizers;
std::unordered_map<uint32_t, ComPtr<ID3D11SamplerState>> samplers;
std::unordered_map<uint32_t, ComPtr<ID3D11BlendState>> blends;
std::unordered_map<uint32_t, ComPtr<ID3D11DepthStencilState>> depth_stencils;
std::unordered_map<uint32_t, ComPtr<ID3D11VertexShader>> vertex_shaders;
std::unordered_map<uint32_t, ComPtr<ID3D11ComputeShader>> compute_shaders;
std::unordered_map<uint32_t, ComPtr<ID3D11PixelShader>> pixel_shaders;
std::unordered_map<uint32_t, ComPtr<ID3D11DomainShader>> domain_shaders;
std::unordered_map<uint32_t, ComPtr<ID3D11GeometryShader>> geometry_shaders;
std::unordered_map<uint32_t, ComPtr<ID3D11HullShader>> hull_shaders;
};

// TODO: Move this somewhere else.
inline void ResetCOMArray(auto& array)
{
for (auto*& ptr : array)
{
if (ptr)
{
ptr->Release();
ptr = nullptr;
}
}
}
7 changes: 7 additions & 0 deletions Source/Core/includes/math.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

// Needs to be defined before anybody else includes "cmath"
Expand All @@ -5,7 +5,7 @@
#define _USE_MATH_DEFINES
#endif

#include <cmath>

Check failure on line 8 in Source/Core/includes/math.h

View workflow job for this annotation

GitHub Actions / Run linter

Source/Core/includes/math.h:8:10 [clang-diagnostic-error]

'cmath' file not found
#include <array>
#include <limits>
#include <algorithm>
Expand Down Expand Up @@ -182,6 +182,13 @@
return hash;
}

// User-defined literal for CompileTimeStringHash.
// Usage: `"some_string"_h`, this is equivalent to `CompileTimeStringHash("some_string")`.
consteval uint32_t operator"" _h(const char* str, size_t len)
{
return CompileTimeStringHash(str);
}

uint32_t FindNextUniqueNumberInRange(uint32_t value, uint32_t min_value, uint32_t max_value, std::unordered_set<uint32_t> excluded_values)
{
assert(value >= min_value && value <= max_value);
Expand Down
Loading
Loading