├── .gitignore ├── .gitmodules ├── AutoHDR.rc ├── AutoHDR.sln ├── HDRDll.vcxproj ├── LICENSE ├── README.md ├── debug.cpp ├── debug.h ├── dllmain.cpp ├── framework.h ├── pch.cpp ├── pch.h └── resource.h /.gitignore: -------------------------------------------------------------------------------- 1 | *vcxproj.user 2 | *.addon 3 | *.pdb 4 | .vs/ 5 | .vscode/ 6 | build/ 7 | release/ 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "reshade"] 2 | path = reshade 3 | url = https://github.com/crosire/reshade.git 4 | -------------------------------------------------------------------------------- /AutoHDR.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United Kingdom) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 2024,4,17,0 55 | PRODUCTVERSION 2024,4,17,0 56 | FILEFLAGSMASK 0x3fL 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x40004L 63 | FILETYPE 0x2L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "000004b0" 69 | BEGIN 70 | VALUE "CompanyName", "Lilium" 71 | VALUE "FileDescription", "ReShade AutoHDR" 72 | VALUE "FileVersion", "2024.4.17.0" 73 | VALUE "ProductVersion", "2024.4.17.0" 74 | END 75 | END 76 | BLOCK "VarFileInfo" 77 | BEGIN 78 | VALUE "Translation", 0x0, 1200 79 | END 80 | END 81 | 82 | #endif // English (United Kingdom) resources 83 | ///////////////////////////////////////////////////////////////////////////// 84 | 85 | 86 | 87 | #ifndef APSTUDIO_INVOKED 88 | ///////////////////////////////////////////////////////////////////////////// 89 | // 90 | // Generated from the TEXTINCLUDE 3 resource. 91 | // 92 | 93 | 94 | ///////////////////////////////////////////////////////////////////////////// 95 | #endif // not APSTUDIO_INVOKED 96 | 97 | -------------------------------------------------------------------------------- /AutoHDR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32328.378 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HDRDll", "HDRDll.vcxproj", "{BBC7C93F-451A-4085-9622-91787FF37821}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|64bit = Debug|64bit 11 | Debug|32bit = Debug|32bit 12 | Release|64bit = Release|64bit 13 | Release|32bit = Release|32bit 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {BBC7C93F-451A-4085-9622-91787FF37821}.Debug|64bit.ActiveCfg = Debug|x64 17 | {BBC7C93F-451A-4085-9622-91787FF37821}.Debug|64bit.Build.0 = Debug|x64 18 | {BBC7C93F-451A-4085-9622-91787FF37821}.Debug|32bit.ActiveCfg = Debug|Win32 19 | {BBC7C93F-451A-4085-9622-91787FF37821}.Debug|32bit.Build.0 = Debug|Win32 20 | {BBC7C93F-451A-4085-9622-91787FF37821}.Release|64bit.ActiveCfg = Release|x64 21 | {BBC7C93F-451A-4085-9622-91787FF37821}.Release|64bit.Build.0 = Release|x64 22 | {BBC7C93F-451A-4085-9622-91787FF37821}.Release|32bit.ActiveCfg = Release|Win32 23 | {BBC7C93F-451A-4085-9622-91787FF37821}.Release|32bit.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8FADF784-87FE-4078-BABC-966A9A1FF0E3} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /HDRDll.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {bbc7c93f-451a-4085-9622-91787ff37821} 25 | HDRDll 26 | 10.0 27 | AutoHDR 28 | 29 | 30 | 31 | DynamicLibrary 32 | true 33 | v142 34 | Unicode 35 | 36 | 37 | DynamicLibrary 38 | false 39 | v142 40 | true 41 | Unicode 42 | 43 | 44 | DynamicLibrary 45 | true 46 | Unicode 47 | v142 48 | 49 | 50 | DynamicLibrary 51 | false 52 | true 53 | Unicode 54 | v142 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | true 76 | .addon32 77 | $(ProjectName) 78 | build\$(Platform)\$(Configuration)\Intermediate\ 79 | $(SolutionDir)build\$(Platform)\$(Configuration)\ 80 | 81 | 82 | false 83 | .addon32 84 | $(ProjectName) 85 | build\$(Platform)\$(Configuration)\Intermediate\ 86 | $(SolutionDir)build\$(Platform)\$(Configuration)\ 87 | 88 | 89 | true 90 | $(ProjectName) 91 | .addon64 92 | build\$(Platform)\$(Configuration)\Intermediate\ 93 | $(SolutionDir)build\$(Platform)\$(Configuration)\ 94 | 95 | 96 | false 97 | $(ProjectName) 98 | .addon64 99 | build\$(Platform)\$(Configuration)\Intermediate\ 100 | $(SolutionDir)build\$(Platform)\$(Configuration)\ 101 | 102 | 103 | 104 | Level3 105 | true 106 | WIN32;_DEBUG;HDRDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 107 | true 108 | Use 109 | pch.h 110 | $(SolutionDir)reshade\include;$(SolutionDir)reshade\deps\imgui;%(AdditionalIncludeDirectories) 111 | stdcpp17 112 | 113 | 114 | Windows 115 | true 116 | false 117 | dxgi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 118 | 119 | 120 | 121 | 122 | Level3 123 | true 124 | true 125 | true 126 | WIN32;NDEBUG;HDRDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 127 | true 128 | Use 129 | pch.h 130 | $(SolutionDir)reshade\include;$(SolutionDir)reshade\deps\imgui;%(AdditionalIncludeDirectories) 131 | stdcpp17 132 | 133 | 134 | Windows 135 | true 136 | true 137 | true 138 | false 139 | dxgi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 140 | 141 | 142 | 143 | 144 | Level3 145 | true 146 | _DEBUG;HDRDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 147 | true 148 | Use 149 | pch.h 150 | $(SolutionDir)reshade\include;$(SolutionDir)reshade\deps\imgui;%(AdditionalIncludeDirectories) 151 | stdcpp17 152 | 153 | 154 | Windows 155 | true 156 | false 157 | dxgi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 158 | 159 | 160 | 161 | 162 | Level3 163 | true 164 | true 165 | true 166 | NDEBUG;HDRDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 167 | true 168 | Use 169 | pch.h 170 | $(SolutionDir)reshade\include;$(SolutionDir)reshade\deps\imgui;%(AdditionalIncludeDirectories) 171 | stdcpp17 172 | 173 | 174 | Windows 175 | true 176 | true 177 | true 178 | false 179 | dxgi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | Create 193 | Create 194 | Create 195 | Create 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 MajorPainTheCactus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoHDR (modified) 2 | AutoHDR addon for ReShade v6.0.0 (and later?). 3 | 4 | This modified version adds support for scRGB and removes setting the HDR metadata as it is no longer recommended. 5 | 6 | ***This addon is not safe to use with games that have Anti-Cheat!*** 7 | 8 | ## Installation 9 | - get the latest ReShade version **with full add-on support** from [here](https://reshade.me/#download) and install it for the game of your choice 10 | - download the latest release from [here](https://github.com/EndlesslyFlowering/AutoHDR-ReShade/releases/latest) 11 | - copy depending on the game either `AutoHDR.addon64` or `AutoHDR.addon32` to where the ReShade ini files are in the game folder 12 | - use either inverse tone mapping from my [ReShade HDR Shaders](https://github.com/EndlesslyFlowering/ReShade_HDR_shaders/) or [PumboAutoHDR](https://github.com/Filoppi/PumboAutoHDR/) to convert SDR to HDR (ignore the part about dxvk in "How to use") 13 | - have fun :) 14 | -------------------------------------------------------------------------------- /debug.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "pch.h" 3 | #include "debug.h" 4 | 5 | std::string EnumerateDxgiFormat(const DXGI_FORMAT Format) 6 | { 7 | switch(Format) 8 | { 9 | case DXGI_FORMAT_UNKNOWN: 10 | { 11 | return "DXGI_FORMAT_UNKNOWN"; 12 | } 13 | case DXGI_FORMAT_R32G32B32A32_TYPELESS: 14 | { 15 | return "DXGI_FORMAT_R32G32B32A32_TYPELESS"; 16 | } 17 | case DXGI_FORMAT_R32G32B32A32_FLOAT: 18 | { 19 | return "DXGI_FORMAT_R32G32B32A32_FLOAT"; 20 | } 21 | case DXGI_FORMAT_R32G32B32A32_UINT: 22 | { 23 | return "DXGI_FORMAT_R32G32B32A32_UINT"; 24 | } 25 | case DXGI_FORMAT_R32G32B32A32_SINT: 26 | { 27 | return "DXGI_FORMAT_R32G32B32A32_SINT"; 28 | } 29 | case DXGI_FORMAT_R32G32B32_TYPELESS: 30 | { 31 | return "DXGI_FORMAT_R32G32B32_TYPELESS"; 32 | } 33 | case DXGI_FORMAT_R32G32B32_FLOAT: 34 | { 35 | return "DXGI_FORMAT_R32G32B32_FLOAT"; 36 | } 37 | case DXGI_FORMAT_R32G32B32_UINT: 38 | { 39 | return "DXGI_FORMAT_R32G32B32_UINT"; 40 | } 41 | case DXGI_FORMAT_R32G32B32_SINT: 42 | { 43 | return "DXGI_FORMAT_R32G32B32_SINT"; 44 | } 45 | case DXGI_FORMAT_R16G16B16A16_TYPELESS: 46 | { 47 | return "DXGI_FORMAT_R16G16B16A16_TYPELESS"; 48 | } 49 | case DXGI_FORMAT_R16G16B16A16_FLOAT: 50 | { 51 | return "DXGI_FORMAT_R16G16B16A16_FLOAT"; 52 | } 53 | case DXGI_FORMAT_R16G16B16A16_UNORM: 54 | { 55 | return "DXGI_FORMAT_R16G16B16A16_UNORM"; 56 | } 57 | case DXGI_FORMAT_R16G16B16A16_UINT: 58 | { 59 | return "DXGI_FORMAT_R16G16B16A16_UINT"; 60 | } 61 | case DXGI_FORMAT_R16G16B16A16_SNORM: 62 | { 63 | return "DXGI_FORMAT_R16G16B16A16_SNORM"; 64 | } 65 | case DXGI_FORMAT_R16G16B16A16_SINT: 66 | { 67 | return "DXGI_FORMAT_R16G16B16A16_SINT"; 68 | } 69 | case DXGI_FORMAT_R32G32_TYPELESS: 70 | { 71 | return "DXGI_FORMAT_R32G32_TYPELESS"; 72 | } 73 | case DXGI_FORMAT_R32G32_FLOAT: 74 | { 75 | return "DXGI_FORMAT_R32G32_FLOAT"; 76 | } 77 | case DXGI_FORMAT_R32G32_UINT: 78 | { 79 | return "DXGI_FORMAT_R32G32_UINT"; 80 | } 81 | case DXGI_FORMAT_R32G32_SINT: 82 | { 83 | return "DXGI_FORMAT_R32G32_SINT"; 84 | } 85 | case DXGI_FORMAT_R32G8X24_TYPELESS: 86 | { 87 | return "DXGI_FORMAT_R32G8X24_TYPELESS"; 88 | } 89 | case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: 90 | { 91 | return "DXGI_FORMAT_D32_FLOAT_S8X24_UINT"; 92 | } 93 | case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: 94 | { 95 | return "DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS"; 96 | } 97 | case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: 98 | { 99 | return "DXGI_FORMAT_X32_TYPELESS_G8X24_UINT"; 100 | } 101 | case DXGI_FORMAT_R10G10B10A2_TYPELESS: 102 | { 103 | return "DXGI_FORMAT_R10G10B10A2_TYPELESS"; 104 | } 105 | case DXGI_FORMAT_R10G10B10A2_UNORM: 106 | { 107 | return "DXGI_FORMAT_R10G10B10A2_UNORM"; 108 | } 109 | case DXGI_FORMAT_R10G10B10A2_UINT: 110 | { 111 | return "DXGI_FORMAT_R10G10B10A2_UINT"; 112 | } 113 | case DXGI_FORMAT_R11G11B10_FLOAT: 114 | { 115 | return "DXGI_FORMAT_R11G11B10_FLOAT"; 116 | } 117 | case DXGI_FORMAT_R8G8B8A8_TYPELESS: 118 | { 119 | return "DXGI_FORMAT_R8G8B8A8_TYPELESS"; 120 | } 121 | case DXGI_FORMAT_R8G8B8A8_UNORM: 122 | { 123 | return "DXGI_FORMAT_R8G8B8A8_UNORM"; 124 | } 125 | case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: 126 | { 127 | return "DXGI_FORMAT_R8G8B8A8_UNORM_SRGB"; 128 | } 129 | case DXGI_FORMAT_R8G8B8A8_UINT: 130 | { 131 | return "DXGI_FORMAT_R8G8B8A8_UINT"; 132 | } 133 | case DXGI_FORMAT_R8G8B8A8_SNORM: 134 | { 135 | return "DXGI_FORMAT_R8G8B8A8_SNORM"; 136 | } 137 | case DXGI_FORMAT_R8G8B8A8_SINT: 138 | { 139 | return "DXGI_FORMAT_R8G8B8A8_SINT"; 140 | } 141 | case DXGI_FORMAT_R16G16_TYPELESS: 142 | { 143 | return "DXGI_FORMAT_R16G16_TYPELESS"; 144 | } 145 | case DXGI_FORMAT_R16G16_FLOAT: 146 | { 147 | return "DXGI_FORMAT_R16G16_FLOAT"; 148 | } 149 | case DXGI_FORMAT_R16G16_UNORM: 150 | { 151 | return "DXGI_FORMAT_R16G16_UNORM"; 152 | } 153 | case DXGI_FORMAT_R16G16_UINT: 154 | { 155 | return "DXGI_FORMAT_R16G16_UINT"; 156 | } 157 | case DXGI_FORMAT_R16G16_SNORM: 158 | { 159 | return "DXGI_FORMAT_R16G16_SNORM"; 160 | } 161 | case DXGI_FORMAT_R16G16_SINT: 162 | { 163 | return "DXGI_FORMAT_R16G16_SINT"; 164 | } 165 | case DXGI_FORMAT_R32_TYPELESS: 166 | { 167 | return "DXGI_FORMAT_R32_TYPELESS"; 168 | } 169 | case DXGI_FORMAT_D32_FLOAT: 170 | { 171 | return "DXGI_FORMAT_D32_FLOAT"; 172 | } 173 | case DXGI_FORMAT_R32_FLOAT: 174 | { 175 | return "DXGI_FORMAT_R32_FLOAT"; 176 | } 177 | case DXGI_FORMAT_R32_UINT: 178 | { 179 | return "DXGI_FORMAT_R32_UINT"; 180 | } 181 | case DXGI_FORMAT_R32_SINT: 182 | { 183 | return "DXGI_FORMAT_R32_SINT"; 184 | } 185 | case DXGI_FORMAT_R24G8_TYPELESS: 186 | { 187 | return "DXGI_FORMAT_R24G8_TYPELESS"; 188 | } 189 | case DXGI_FORMAT_D24_UNORM_S8_UINT: 190 | { 191 | return "DXGI_FORMAT_D24_UNORM_S8_UINT"; 192 | } 193 | case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: 194 | { 195 | return "DXGI_FORMAT_R24_UNORM_X8_TYPELESS"; 196 | } 197 | case DXGI_FORMAT_X24_TYPELESS_G8_UINT: 198 | { 199 | return "DXGI_FORMAT_X24_TYPELESS_G8_UINT"; 200 | } 201 | case DXGI_FORMAT_R8G8_TYPELESS: 202 | { 203 | return "DXGI_FORMAT_R8G8_TYPELESS"; 204 | } 205 | case DXGI_FORMAT_R8G8_UNORM: 206 | { 207 | return "DXGI_FORMAT_R8G8_UNORM"; 208 | } 209 | case DXGI_FORMAT_R8G8_UINT: 210 | { 211 | return "DXGI_FORMAT_R8G8_UINT"; 212 | } 213 | case DXGI_FORMAT_R8G8_SNORM: 214 | { 215 | return "DXGI_FORMAT_R8G8_SNORM"; 216 | } 217 | case DXGI_FORMAT_R8G8_SINT: 218 | { 219 | return "DXGI_FORMAT_R8G8_SINT"; 220 | } 221 | case DXGI_FORMAT_R16_TYPELESS: 222 | { 223 | return "DXGI_FORMAT_R16_TYPELESS"; 224 | } 225 | case DXGI_FORMAT_R16_FLOAT: 226 | { 227 | return "DXGI_FORMAT_R16_FLOAT"; 228 | } 229 | case DXGI_FORMAT_D16_UNORM: 230 | { 231 | return "DXGI_FORMAT_D16_UNORM"; 232 | } 233 | case DXGI_FORMAT_R16_UNORM: 234 | { 235 | return "DXGI_FORMAT_R16_UNORM"; 236 | } 237 | case DXGI_FORMAT_R16_UINT: 238 | { 239 | return "DXGI_FORMAT_R16_UINT"; 240 | } 241 | case DXGI_FORMAT_R16_SNORM: 242 | { 243 | return "DXGI_FORMAT_R16_SNORM"; 244 | } 245 | case DXGI_FORMAT_R16_SINT: 246 | { 247 | return "DXGI_FORMAT_R16_SINT"; 248 | } 249 | case DXGI_FORMAT_R8_TYPELESS: 250 | { 251 | return "DXGI_FORMAT_R8_TYPELESS"; 252 | } 253 | case DXGI_FORMAT_R8_UNORM: 254 | { 255 | return "DXGI_FORMAT_R8_UNORM"; 256 | } 257 | case DXGI_FORMAT_R8_UINT: 258 | { 259 | return "DXGI_FORMAT_R8_UINT"; 260 | } 261 | case DXGI_FORMAT_R8_SNORM: 262 | { 263 | return "DXGI_FORMAT_R8_SNORM"; 264 | } 265 | case DXGI_FORMAT_R8_SINT: 266 | { 267 | return "DXGI_FORMAT_R8_SINT"; 268 | } 269 | case DXGI_FORMAT_A8_UNORM: 270 | { 271 | return "DXGI_FORMAT_A8_UNORM"; 272 | } 273 | case DXGI_FORMAT_R1_UNORM: 274 | { 275 | return "DXGI_FORMAT_R1_UNORM"; 276 | } 277 | case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: 278 | { 279 | return "DXGI_FORMAT_R9G9B9E5_SHAREDEXP"; 280 | } 281 | case DXGI_FORMAT_R8G8_B8G8_UNORM: 282 | { 283 | return "DXGI_FORMAT_R8G8_B8G8_UNORM"; 284 | } 285 | case DXGI_FORMAT_G8R8_G8B8_UNORM: 286 | { 287 | return "DXGI_FORMAT_G8R8_G8B8_UNORM"; 288 | } 289 | case DXGI_FORMAT_BC1_TYPELESS: 290 | { 291 | return "DXGI_FORMAT_BC1_TYPELESS"; 292 | } 293 | case DXGI_FORMAT_BC1_UNORM: 294 | { 295 | return "DXGI_FORMAT_BC1_UNORM"; 296 | } 297 | case DXGI_FORMAT_BC1_UNORM_SRGB: 298 | { 299 | return "DXGI_FORMAT_BC1_UNORM_SRGB"; 300 | } 301 | case DXGI_FORMAT_BC2_TYPELESS: 302 | { 303 | return "DXGI_FORMAT_BC2_TYPELESS"; 304 | } 305 | case DXGI_FORMAT_BC2_UNORM: 306 | { 307 | return "DXGI_FORMAT_BC2_UNORM"; 308 | } 309 | case DXGI_FORMAT_BC2_UNORM_SRGB: 310 | { 311 | return "DXGI_FORMAT_BC2_UNORM_SRGB"; 312 | } 313 | case DXGI_FORMAT_BC3_TYPELESS: 314 | { 315 | return "DXGI_FORMAT_BC3_TYPELESS"; 316 | } 317 | case DXGI_FORMAT_BC3_UNORM: 318 | { 319 | return "DXGI_FORMAT_BC3_UNORM"; 320 | } 321 | case DXGI_FORMAT_BC3_UNORM_SRGB: 322 | { 323 | return "DXGI_FORMAT_BC3_UNORM_SRGB"; 324 | } 325 | case DXGI_FORMAT_BC4_TYPELESS: 326 | { 327 | return "DXGI_FORMAT_BC4_TYPELESS"; 328 | } 329 | case DXGI_FORMAT_BC4_UNORM: 330 | { 331 | return "DXGI_FORMAT_BC4_UNORM"; 332 | } 333 | case DXGI_FORMAT_BC4_SNORM: 334 | { 335 | return "DXGI_FORMAT_BC4_SNORM"; 336 | } 337 | case DXGI_FORMAT_BC5_TYPELESS: 338 | { 339 | return "DXGI_FORMAT_BC5_TYPELESS"; 340 | } 341 | case DXGI_FORMAT_BC5_UNORM: 342 | { 343 | return "DXGI_FORMAT_BC5_UNORM"; 344 | } 345 | case DXGI_FORMAT_BC5_SNORM: 346 | { 347 | return "DXGI_FORMAT_BC5_SNORM"; 348 | } 349 | case DXGI_FORMAT_B5G6R5_UNORM: 350 | { 351 | return "DXGI_FORMAT_B5G6R5_UNORM"; 352 | } 353 | case DXGI_FORMAT_B5G5R5A1_UNORM: 354 | { 355 | return "DXGI_FORMAT_B5G5R5A1_UNORM"; 356 | } 357 | case DXGI_FORMAT_B8G8R8A8_UNORM: 358 | { 359 | return "DXGI_FORMAT_B8G8R8A8_UNORM"; 360 | } 361 | case DXGI_FORMAT_B8G8R8X8_UNORM: 362 | { 363 | return "DXGI_FORMAT_B8G8R8X8_UNORM"; 364 | } 365 | case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: 366 | { 367 | return "DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM"; 368 | } 369 | case DXGI_FORMAT_B8G8R8A8_TYPELESS: 370 | { 371 | return "DXGI_FORMAT_B8G8R8A8_TYPELESS"; 372 | } 373 | case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: 374 | { 375 | return "DXGI_FORMAT_B8G8R8A8_UNORM_SRGB"; 376 | } 377 | case DXGI_FORMAT_B8G8R8X8_TYPELESS: 378 | { 379 | return "DXGI_FORMAT_B8G8R8X8_TYPELESS"; 380 | } 381 | case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: 382 | { 383 | return "DXGI_FORMAT_B8G8R8X8_UNORM_SRGB"; 384 | } 385 | case DXGI_FORMAT_BC6H_TYPELESS: 386 | { 387 | return "DXGI_FORMAT_BC6H_TYPELESS"; 388 | } 389 | case DXGI_FORMAT_BC6H_UF16: 390 | { 391 | return "DXGI_FORMAT_BC6H_UF16"; 392 | } 393 | case DXGI_FORMAT_BC6H_SF16: 394 | { 395 | return "DXGI_FORMAT_BC6H_SF16"; 396 | } 397 | case DXGI_FORMAT_BC7_TYPELESS: 398 | { 399 | return "DXGI_FORMAT_BC7_TYPELESS"; 400 | } 401 | case DXGI_FORMAT_BC7_UNORM: 402 | { 403 | return "DXGI_FORMAT_BC7_UNORM"; 404 | } 405 | case DXGI_FORMAT_BC7_UNORM_SRGB: 406 | { 407 | return "DXGI_FORMAT_BC7_UNORM_SRGB"; 408 | } 409 | case DXGI_FORMAT_AYUV: 410 | { 411 | return "DXGI_FORMAT_AYUV"; 412 | } 413 | case DXGI_FORMAT_Y410: 414 | { 415 | return "DXGI_FORMAT_Y410"; 416 | } 417 | case DXGI_FORMAT_Y416: 418 | { 419 | return "DXGI_FORMAT_Y416"; 420 | } 421 | case DXGI_FORMAT_NV12: 422 | { 423 | return "DXGI_FORMAT_NV12"; 424 | } 425 | case DXGI_FORMAT_P010: 426 | { 427 | return "DXGI_FORMAT_P010"; 428 | } 429 | case DXGI_FORMAT_P016: 430 | { 431 | return "DXGI_FORMAT_P016"; 432 | } 433 | case DXGI_FORMAT_420_OPAQUE: 434 | { 435 | return "DXGI_FORMAT_420_OPAQUE"; 436 | } 437 | case DXGI_FORMAT_YUY2: 438 | { 439 | return "DXGI_FORMAT_YUY2"; 440 | } 441 | case DXGI_FORMAT_Y210: 442 | { 443 | return "DXGI_FORMAT_Y210"; 444 | } 445 | case DXGI_FORMAT_Y216: 446 | { 447 | return "DXGI_FORMAT_Y216"; 448 | } 449 | case DXGI_FORMAT_NV11: 450 | { 451 | return "DXGI_FORMAT_NV11"; 452 | } 453 | case DXGI_FORMAT_AI44: 454 | { 455 | return "DXGI_FORMAT_AI44"; 456 | } 457 | case DXGI_FORMAT_IA44: 458 | { 459 | return "DXGI_FORMAT_IA44"; 460 | } 461 | case DXGI_FORMAT_P8: 462 | { 463 | return "DXGI_FORMAT_P8"; 464 | } 465 | case DXGI_FORMAT_A8P8: 466 | { 467 | return "DXGI_FORMAT_A8P8"; 468 | } 469 | case DXGI_FORMAT_B4G4R4A4_UNORM: 470 | { 471 | return "DXGI_FORMAT_B4G4R4A4_UNORM"; 472 | } 473 | case DXGI_FORMAT_P208: 474 | { 475 | return "DXGI_FORMAT_P208"; 476 | } 477 | case DXGI_FORMAT_V208: 478 | { 479 | return "DXGI_FORMAT_V208"; 480 | } 481 | case DXGI_FORMAT_V408: 482 | { 483 | return "DXGI_FORMAT_V408"; 484 | } 485 | case DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE: 486 | { 487 | return "DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE"; 488 | } 489 | case DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE: 490 | { 491 | return "DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE"; 492 | } 493 | default: 494 | { 495 | return "unknown DXGI format"; 496 | } 497 | } 498 | } 499 | 500 | std::string EnumerateDxgiColourSpace(const DXGI_COLOR_SPACE_TYPE ColourSpace) 501 | { 502 | switch(ColourSpace) 503 | { 504 | case DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709: 505 | { 506 | return "DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709"; 507 | } 508 | case DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709: 509 | { 510 | return "DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709"; 511 | } 512 | case DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709: 513 | { 514 | return "DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709"; 515 | } 516 | case DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020: 517 | { 518 | return "DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020"; 519 | } 520 | case DXGI_COLOR_SPACE_RESERVED: 521 | { 522 | return "DXGI_COLOR_SPACE_RESERVED"; 523 | } 524 | case DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601: 525 | { 526 | return "DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601"; 527 | } 528 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601: 529 | { 530 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601"; 531 | } 532 | case DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601: 533 | { 534 | return "DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601"; 535 | } 536 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709: 537 | { 538 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709"; 539 | } 540 | case DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709: 541 | { 542 | return "DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709"; 543 | } 544 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020: 545 | { 546 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020"; 547 | } 548 | case DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020: 549 | { 550 | return "DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020"; 551 | } 552 | case DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020: 553 | { 554 | return "DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020"; 555 | } 556 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020: 557 | { 558 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020"; 559 | } 560 | case DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020: 561 | { 562 | return "DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020"; 563 | } 564 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020: 565 | { 566 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020"; 567 | } 568 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020: 569 | { 570 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020"; 571 | } 572 | case DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020: 573 | { 574 | return "DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020"; 575 | } 576 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020: 577 | { 578 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020"; 579 | } 580 | case DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020: 581 | { 582 | return "DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020"; 583 | } 584 | case DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709: 585 | { 586 | return "DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709"; 587 | } 588 | case DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020: 589 | { 590 | return "DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020"; 591 | } 592 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709: 593 | { 594 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709"; 595 | } 596 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020: 597 | { 598 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020"; 599 | } 600 | case DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020: 601 | { 602 | return "DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020"; 603 | } 604 | case DXGI_COLOR_SPACE_CUSTOM: 605 | { 606 | return "DXGI_COLOR_SPACE_CUSTOM"; 607 | } 608 | default: 609 | { 610 | return "unknown DXGI colour space"; 611 | } 612 | } 613 | } 614 | -------------------------------------------------------------------------------- /debug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | std::string EnumerateDxgiFormat(const DXGI_FORMAT Format); 8 | 9 | std::string EnumerateDxgiColourSpace(const DXGI_COLOR_SPACE_TYPE ColourSpace); 10 | -------------------------------------------------------------------------------- /dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | 3 | #define ImTextureID unsigned long long int 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "debug.h" 18 | 19 | //#define __WINRT__ 20 | 21 | std::unordered_set g_back_buffers; 22 | std::mutex g_mutex; 23 | 24 | bool g_hdr_enable = false; 25 | bool g_use_hdr10 = false; 26 | bool g_hdr_support = false; 27 | bool g_first_csp_change = true; 28 | DXGI_COLOR_SPACE_TYPE g_colour_space = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709; 29 | DXGI_FORMAT g_original_format = DXGI_FORMAT_R10G10B10A2_UNORM; 30 | bool g_is_supported_api = false; 31 | bool g_is_vulkan_api = false; 32 | 33 | reshade::api::device* g_device = nullptr; 34 | reshade::api::effect_runtime* g_runtime = nullptr; 35 | 36 | inline static int dxgi_compute_intersection_area( 37 | int ax1, int ay1, int ax2, int ay2, 38 | int bx1, int by1, int bx2, int by2) 39 | { 40 | return max(0, min(ax2, bx2) - 41 | max(ax1, bx1)) 42 | * max(0, min(ay2, by2) - max(ay1, by1)); 43 | } 44 | 45 | #ifdef __WINRT__ 46 | bool dxgi_check_display_hdr_support(IDXGIFactory2* factory, HWND hwnd) 47 | #else 48 | bool dxgi_check_display_hdr_support(IDXGIFactory1* factory, HWND hwnd) 49 | #endif 50 | { 51 | IDXGIOutput6* output6 = NULL; 52 | IDXGIOutput* best_output = NULL; 53 | IDXGIOutput* current_output = NULL; 54 | IDXGIAdapter* dxgi_adapter = NULL; 55 | UINT i = 0; 56 | bool supported = false; 57 | float best_intersect_area = -1; 58 | 59 | #ifdef __WINRT__ 60 | if (!factory->IsCurrent()) 61 | { 62 | if (FAILED(CreateDXGIFactory2(0, __uuidof(IDXGIFactory2), (void**)&factory))) 63 | { 64 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to create DXGI factory"); 65 | return false; 66 | } 67 | } 68 | 69 | if (FAILED(factory->EnumAdapters(0, &dxgi_adapter))) 70 | { 71 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to enumerate adapters"); 72 | return false; 73 | } 74 | #else 75 | if (!factory->IsCurrent()) 76 | { 77 | if (FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory))) 78 | { 79 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to create DXGI factory"); 80 | return false; 81 | } 82 | } 83 | 84 | if (FAILED(factory->EnumAdapters(0, &dxgi_adapter))) 85 | { 86 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to enumerate adapters"); 87 | return false; 88 | } 89 | #endif 90 | 91 | while (dxgi_adapter->EnumOutputs(i, ¤t_output) 92 | != DXGI_ERROR_NOT_FOUND) 93 | { 94 | RECT r, rect; 95 | DXGI_OUTPUT_DESC desc; 96 | int intersect_area; 97 | int bx1, by1, bx2, by2; 98 | int ax1 = 0; 99 | int ay1 = 0; 100 | int ax2 = 0; 101 | int ay2 = 0; 102 | 103 | if (GetWindowRect(hwnd, &rect)) 104 | { 105 | ax1 = rect.left; 106 | ay1 = rect.top; 107 | ax2 = rect.right; 108 | ay2 = rect.bottom; 109 | } 110 | 111 | /* Get the rectangle bounds of current output */ 112 | if (FAILED(current_output->GetDesc(&desc))) 113 | { 114 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to get DXGI output description"); 115 | goto error; 116 | } 117 | 118 | /* TODO/FIXME - DesktopCoordinates won't work for WinRT */ 119 | r = desc.DesktopCoordinates; 120 | bx1 = r.left; 121 | by1 = r.top; 122 | bx2 = r.right; 123 | by2 = r.bottom; 124 | 125 | /* Compute the intersection */ 126 | intersect_area = dxgi_compute_intersection_area( 127 | ax1, ay1, ax2, ay2, bx1, by1, bx2, by2); 128 | 129 | if (intersect_area > best_intersect_area) 130 | { 131 | best_output = current_output; 132 | best_output->AddRef(); 133 | best_intersect_area = (float)intersect_area; 134 | } 135 | 136 | i++; 137 | } 138 | 139 | if (SUCCEEDED(best_output->QueryInterface(__uuidof(IDXGIOutput6), (void**)&output6))) 140 | { 141 | DXGI_OUTPUT_DESC1 desc1; 142 | if (SUCCEEDED(output6->GetDesc1(&desc1))) 143 | { 144 | supported = (desc1.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020); 145 | 146 | if (supported) 147 | { 148 | reshade::log::message(reshade::log::level::info, "[DXGI]: DXGI Output supports: DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020"); 149 | } 150 | 151 | g_hdr_support = supported; 152 | } 153 | else 154 | { 155 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to get DXGI Output 6 description"); 156 | } 157 | output6->Release(); 158 | } 159 | else 160 | { 161 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to get DXGI Output 6 from best output"); 162 | } 163 | 164 | error: 165 | if(best_output) best_output->Release(); 166 | if(current_output) current_output->Release(); 167 | if(dxgi_adapter) dxgi_adapter->Release(); 168 | 169 | return supported; 170 | } 171 | 172 | void set_reshade_colour_space() 173 | { 174 | if (g_runtime != nullptr) 175 | { 176 | reshade::api::color_space reshade_colour_space; 177 | 178 | switch(g_colour_space) 179 | { 180 | case DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709: 181 | { 182 | reshade_colour_space = reshade::api::color_space::extended_srgb_linear; 183 | } 184 | break; 185 | case DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020: 186 | { 187 | reshade_colour_space = reshade::api::color_space::hdr10_st2084; 188 | } 189 | break; 190 | default: 191 | { 192 | reshade_colour_space = reshade::api::color_space::srgb_nonlinear; 193 | } 194 | break; 195 | } 196 | 197 | std::stringstream log_str; 198 | 199 | log_str << "[ReShade]: ReShade colour space " 200 | << EnumerateDxgiColourSpace(g_colour_space).c_str() 201 | << " set"; 202 | 203 | reshade::log::message(reshade::log::level::info, log_str.str().c_str()); 204 | 205 | g_runtime->set_color_space(reshade_colour_space); 206 | } 207 | } 208 | 209 | void dxgi_swapchain_color_space( 210 | IDXGISwapChain3* swapchain, 211 | DXGI_COLOR_SPACE_TYPE target_colour_space) 212 | { 213 | UINT color_space_support = 0; 214 | 215 | if (FAILED(swapchain->CheckColorSpaceSupport(target_colour_space, &color_space_support))) 216 | { 217 | 218 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to check DXGI swapchain colour space support"); 219 | return; 220 | } 221 | 222 | if((color_space_support & DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT) == DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT) 223 | { 224 | if (FAILED(swapchain->SetColorSpace1(target_colour_space))) 225 | { 226 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to set DXGI swapchain colour space"); 227 | return; 228 | } 229 | 230 | std::stringstream log_str; 231 | 232 | log_str << "[DXGI]: DXGI swapchain colour space " 233 | << EnumerateDxgiColourSpace(target_colour_space).c_str() 234 | << " set"; 235 | 236 | reshade::log::message(reshade::log::level::info, log_str.str().c_str()); 237 | 238 | g_colour_space = target_colour_space; 239 | 240 | set_reshade_colour_space(); 241 | } 242 | else 243 | { 244 | std::stringstream log_str; 245 | 246 | log_str << "[DXGI]: DXGI swapchain colour space " 247 | << EnumerateDxgiColourSpace(target_colour_space).c_str() 248 | << " (" 249 | << color_space_support 250 | << ") not supported"; 251 | 252 | reshade::log::message(reshade::log::level::error, log_str.str().c_str()); 253 | } 254 | } 255 | 256 | static void on_init_device(reshade::api::device* device) 257 | { 258 | //device->create_private_data(); 259 | 260 | g_device = device; 261 | 262 | const reshade::api::device_api device_type = device->get_api(); 263 | 264 | if (device_type == reshade::api::device_api::d3d10 265 | || device_type == reshade::api::device_api::d3d11 266 | || device_type == reshade::api::device_api::d3d12 267 | || device_type == reshade::api::device_api::vulkan) 268 | { 269 | g_is_supported_api = true; 270 | } 271 | else 272 | { 273 | g_is_supported_api = false; 274 | } 275 | 276 | if (device_type == reshade::api::device_api::vulkan) 277 | { 278 | g_is_vulkan_api = true; 279 | } 280 | else 281 | { 282 | g_is_vulkan_api = false; 283 | } 284 | 285 | if (g_is_supported_api) 286 | { 287 | reshade::get_config_value(g_runtime, "HDR", "EnableHDR", g_hdr_enable); 288 | reshade::get_config_value(g_runtime, "HDR", "UseHDR10", g_use_hdr10); 289 | } 290 | } 291 | 292 | static void on_destroy_device(reshade::api::device* device) 293 | { 294 | g_device = nullptr; 295 | 296 | g_is_supported_api = false; 297 | g_is_vulkan_api = false; 298 | } 299 | 300 | //static void init_swapchain(reshade::api::swapchain* swapchain) 301 | //{ 302 | // static int t = 0; ++t; 303 | //} 304 | 305 | static bool on_create_swapchain(reshade::api::device_api api, reshade::api::swapchain_desc& swapchain_desc, void* hwnd) 306 | { 307 | if (g_is_supported_api) 308 | { 309 | swapchain_desc.back_buffer.texture.format = reshade::api::format::r16g16b16a16_float; 310 | 311 | if (g_use_hdr10) 312 | { 313 | swapchain_desc.back_buffer.texture.format = reshade::api::format::r10g10b10a2_unorm; 314 | } 315 | 316 | //swapchain_desc.refresh_rate.numerator = 60; 317 | //swapchain_desc.refresh_rate.denominator = 1; 318 | 319 | if (swapchain_desc.back_buffer_count < 2) 320 | { 321 | swapchain_desc.back_buffer_count = 2; 322 | } 323 | 324 | swapchain_desc.present_mode = static_cast(DXGI_SWAP_EFFECT_FLIP_DISCARD); 325 | swapchain_desc.present_flags |= static_cast(DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING); 326 | } 327 | 328 | return true; 329 | } 330 | 331 | static void on_init_swapchain(reshade::api::swapchain* swapchain, bool resize) 332 | { 333 | if (g_is_supported_api) 334 | { 335 | const std::lock_guard lock(g_mutex); 336 | 337 | reshade::api::device* const device = swapchain->get_device(); 338 | 339 | for (uint32_t i = 0; i < swapchain->get_back_buffer_count(); ++i) 340 | { 341 | const reshade::api::resource buffer = swapchain->get_back_buffer(i); 342 | 343 | g_back_buffers.emplace(buffer.handle); 344 | } 345 | 346 | IDXGISwapChain* native_swapchain = reinterpret_cast(swapchain->get_native()); 347 | ATL::CComPtr swapchain4; 348 | 349 | if (SUCCEEDED(native_swapchain->QueryInterface(__uuidof(IDXGISwapChain4), (void**)&swapchain4))) 350 | { 351 | if (g_hdr_support == false) 352 | { 353 | #ifdef __WINRT__ 354 | IDXGIFactory2* factory = nullptr; 355 | if (FAILED(swapchain4->GetParent(__uuidof(IDXGIFactory2), (void**)&factory))) 356 | { 357 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to get the swap chain's factory 2"); 358 | return; 359 | } 360 | 361 | g_hdr_support = dxgi_check_display_hdr_support(factory, reinterpret_cast(swapchain->get_hwnd())); 362 | #else 363 | IDXGIFactory1* factory = nullptr; 364 | if (FAILED(swapchain4->GetParent(__uuidof(IDXGIFactory1), (void**)&factory))) 365 | { 366 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to get the swap chain's factory 1"); 367 | return; 368 | } 369 | 370 | g_hdr_support = dxgi_check_display_hdr_support(factory, reinterpret_cast(swapchain->get_hwnd())); 371 | 372 | factory->Release(); 373 | #endif // __WINRT__ 374 | } 375 | 376 | if (g_hdr_support == false) 377 | { 378 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed as no HDR support"); 379 | return; 380 | } 381 | 382 | if (g_hdr_enable == true) 383 | { 384 | DXGI_SWAP_CHAIN_DESC1 desc; 385 | if (FAILED(swapchain4->GetDesc1(&desc))) 386 | { 387 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to get swap chain description"); 388 | return; 389 | } 390 | 391 | if (g_first_csp_change) 392 | { 393 | g_original_format = desc.Format; 394 | g_first_csp_change = false; 395 | } 396 | 397 | DXGI_FORMAT new_swapchain_format = DXGI_FORMAT_R16G16B16A16_FLOAT; 398 | DXGI_COLOR_SPACE_TYPE new_colour_space = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709; 399 | 400 | if (g_use_hdr10) 401 | { 402 | new_swapchain_format = DXGI_FORMAT_R10G10B10A2_UNORM; 403 | new_colour_space = DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020; 404 | } 405 | 406 | if (new_swapchain_format != desc.Format 407 | || new_colour_space != g_colour_space) 408 | { 409 | HRESULT hr = swapchain4->ResizeBuffers( 410 | desc.BufferCount, 411 | desc.Width, 412 | desc.Height, 413 | new_swapchain_format, 414 | desc.Flags); 415 | 416 | if (hr == DXGI_ERROR_INVALID_CALL) // Ignore invalid call errors since the device is still in a usable state afterwards 417 | { 418 | std::stringstream log_str; 419 | 420 | log_str << "[DXGI]: Failed to resize swap chain buffers " 421 | << EnumerateDxgiFormat(new_swapchain_format).c_str() 422 | << ": error DXGI_ERROR_INVALID_CALL"; 423 | 424 | reshade::log::message(reshade::log::level::error, log_str.str().c_str()); 425 | } 426 | else if (FAILED(hr)) 427 | { 428 | std::stringstream log_str; 429 | 430 | log_str << "[DXGI]: Failed to resize swap chain buffers " 431 | << EnumerateDxgiFormat(new_swapchain_format).c_str() 432 | << ": error 0x" 433 | << std::hex 434 | << hr; 435 | 436 | reshade::log::message(reshade::log::level::error, log_str.str().c_str()); 437 | return; 438 | } 439 | 440 | std::stringstream log_str; 441 | 442 | log_str << "[DXGI]: swap chain format updated to " 443 | << EnumerateDxgiFormat(new_swapchain_format).c_str(); 444 | 445 | reshade::log::message(reshade::log::level::info, log_str.str().c_str()); 446 | } 447 | 448 | dxgi_swapchain_color_space(swapchain4, new_colour_space); 449 | } 450 | else if (g_hdr_enable == false) 451 | { 452 | DXGI_SWAP_CHAIN_DESC1 desc; 453 | if (FAILED(swapchain4->GetDesc1(&desc))) 454 | { 455 | reshade::log::message(reshade::log::level::error, "[DXGI]: Failed to get swap chain description"); 456 | return; 457 | } 458 | 459 | if (g_first_csp_change) 460 | { 461 | g_original_format = desc.Format; 462 | g_first_csp_change = false; 463 | } 464 | 465 | DXGI_FORMAT new_swapchain_format = g_original_format; 466 | DXGI_COLOR_SPACE_TYPE new_colour_space = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709; 467 | 468 | if (new_swapchain_format != desc.Format 469 | || new_colour_space != g_colour_space) 470 | { 471 | HRESULT hr = swapchain4->ResizeBuffers( 472 | desc.BufferCount, 473 | desc.Width, 474 | desc.Height, 475 | new_swapchain_format, 476 | desc.Flags); 477 | 478 | if (hr == DXGI_ERROR_INVALID_CALL) // Ignore invalid call errors since the device is still in a usable state afterwards 479 | { 480 | std::stringstream log_str; 481 | 482 | log_str << "[DXGI]: Failed to resize swap chain buffers " 483 | << EnumerateDxgiFormat(new_swapchain_format).c_str() 484 | << ": error DXGI_ERROR_INVALID_CALL"; 485 | 486 | reshade::log::message(reshade::log::level::error, log_str.str().c_str()); 487 | } 488 | else if (FAILED(hr)) 489 | { 490 | std::stringstream log_str; 491 | 492 | log_str << "[DXGI]: Failed to resize swap chain buffers " 493 | << EnumerateDxgiFormat(new_swapchain_format).c_str() 494 | << ": error 0x" 495 | << std::hex 496 | << hr; 497 | 498 | reshade::log::message(reshade::log::level::error, log_str.str().c_str()); 499 | } 500 | 501 | std::stringstream log_str; 502 | 503 | log_str << "[DXGI]: swap chain format updated to " 504 | << EnumerateDxgiFormat(new_swapchain_format).c_str(); 505 | 506 | reshade::log::message(reshade::log::level::info, log_str.str().c_str()); 507 | } 508 | 509 | dxgi_swapchain_color_space(swapchain4, new_colour_space); 510 | } 511 | } 512 | } 513 | } 514 | 515 | static void on_destroy_swapchain(reshade::api::swapchain* swapchain, bool resize) 516 | { 517 | if (g_is_supported_api) 518 | { 519 | const std::lock_guard lock(g_mutex); 520 | 521 | reshade::api::device* const device = swapchain->get_device(); 522 | 523 | for (uint32_t i = 0; i < swapchain->get_back_buffer_count(); ++i) 524 | { 525 | const reshade::api::resource buffer = swapchain->get_back_buffer(i); 526 | 527 | g_back_buffers.erase(buffer.handle); 528 | } 529 | } 530 | } 531 | 532 | static bool on_create_resource_view(reshade::api::device* device, reshade::api::resource resource, reshade::api::resource_usage usage_type, reshade::api::resource_view_desc& desc) 533 | { 534 | if (g_is_supported_api) 535 | { 536 | if ((desc.format != reshade::api::format::unknown) && device) 537 | { 538 | bool is_back_buffer = false; 539 | 540 | for (uint64_t back_buffer : g_back_buffers) 541 | { 542 | if (resource == back_buffer) 543 | { 544 | is_back_buffer = true; 545 | } 546 | } 547 | 548 | if (is_back_buffer) 549 | { 550 | const reshade::api::resource_desc texture_desc = device->get_resource_desc(resource); 551 | 552 | if (texture_desc.texture.format == reshade::api::format::r10g10b10a2_unorm) 553 | { 554 | desc.format = reshade::api::format::r10g10b10a2_unorm; 555 | return true; 556 | } 557 | 558 | if (texture_desc.texture.format == reshade::api::format::r16g16b16a16_float) 559 | { 560 | desc.format = reshade::api::format::r16g16b16a16_float; 561 | return true; 562 | } 563 | } 564 | } 565 | } 566 | 567 | return false; 568 | } 569 | 570 | static void draw_settings_overlay(reshade::api::effect_runtime* runtime) 571 | { 572 | if (g_is_supported_api) 573 | { 574 | if (g_hdr_support) 575 | { 576 | if (g_is_vulkan_api) 577 | { 578 | ImGui::TextColored(ImVec4(1.f, 0.3f, 0.3f, 1.f), 579 | "Vulkan API supported is experimental!!" 580 | "\n" "Do not use this with dxvk! Use my dxvk HDR-mod instead!"); 581 | } 582 | 583 | bool hdr_enable_modified = false; 584 | bool hdr_use_hdr10_modified = false; 585 | 586 | hdr_enable_modified |= ImGui::Checkbox("Enable HDR", &g_hdr_enable); 587 | hdr_use_hdr10_modified |= ImGui::Checkbox("Use HDR10 instead of scRGB (needs game restart or chaning the resolution of the game)", &g_use_hdr10); 588 | 589 | if (hdr_enable_modified) 590 | { 591 | reshade::set_config_value(g_runtime, "HDR", "EnableHDR", g_hdr_enable); 592 | } 593 | if (hdr_use_hdr10_modified) 594 | { 595 | reshade::set_config_value(g_runtime, "HDR", "UseHDR10", g_use_hdr10); 596 | } 597 | } 598 | else 599 | { 600 | ImGui::TextUnformatted("HDR support is not enabled. If hardware can support it please go to Windows 'Display Settings' and then turn on 'Use HDR'"); 601 | } 602 | } 603 | else 604 | { 605 | ImGui::TextUnformatted("Unsupported API!"); 606 | } 607 | } 608 | 609 | static void on_init_effect_runtime(reshade::api::effect_runtime* runtime) 610 | { 611 | if (g_is_supported_api) 612 | { 613 | g_runtime = runtime; 614 | 615 | set_reshade_colour_space(); 616 | } 617 | } 618 | 619 | static void on_destroy_effect_runtime(reshade::api::effect_runtime* runtime) 620 | { 621 | if (g_is_supported_api) 622 | { 623 | g_runtime = nullptr; 624 | } 625 | } 626 | 627 | BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) 628 | { 629 | switch (fdwReason) 630 | { 631 | case DLL_PROCESS_ATTACH: 632 | // Call 'reshade::register_addon()' before you call any other function of the ReShade API. 633 | // This will look for the ReShade instance in the current process and initialize the API when found. 634 | if (!reshade::register_addon(hinstDLL)) 635 | return FALSE; 636 | reshade::log::message(reshade::log::level::info, "DLL attached"); 637 | reshade::log::message(reshade::log::level::info, "ReShade addon registered"); 638 | 639 | reshade::register_overlay(nullptr, draw_settings_overlay); 640 | reshade::register_event(&on_create_swapchain); 641 | reshade::register_event(on_init_swapchain); 642 | reshade::register_event(on_destroy_swapchain); 643 | 644 | reshade::register_event(&on_create_resource_view); 645 | 646 | reshade::register_event(on_init_effect_runtime); 647 | reshade::register_event(on_destroy_effect_runtime); 648 | 649 | reshade::register_event(&on_init_device); 650 | reshade::register_event(&on_destroy_device); 651 | 652 | break; 653 | case DLL_PROCESS_DETACH: 654 | reshade::unregister_event(&on_create_swapchain); 655 | reshade::unregister_event(on_init_swapchain); 656 | reshade::unregister_event(on_destroy_swapchain); 657 | 658 | reshade::unregister_event(&on_create_resource_view); 659 | 660 | reshade::unregister_event(on_init_effect_runtime); 661 | reshade::unregister_event(on_destroy_effect_runtime); 662 | 663 | reshade::unregister_event(&on_init_device); 664 | reshade::unregister_event(&on_destroy_device); 665 | 666 | // And finally unregister the add-on from ReShade (this will automatically unregister any events and overlays registered by this add-on too). 667 | reshade::unregister_addon(hinstDLL); 668 | break; 669 | } 670 | return TRUE; 671 | } -------------------------------------------------------------------------------- /framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | // Windows Header Files 5 | #include 6 | -------------------------------------------------------------------------------- /pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: source file corresponding to the pre-compiled header 2 | 3 | #include "pch.h" 4 | 5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed. 6 | -------------------------------------------------------------------------------- /pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: This is a precompiled header file. 2 | // Files listed below are compiled only once, improving build performance for future builds. 3 | // This also affects IntelliSense performance, including code completion and many code browsing features. 4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds. 5 | // Do not add files here that you will be updating frequently as this negates the performance advantage. 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // add headers that you want to pre-compile here 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by AutoHDR.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | --------------------------------------------------------------------------------