@@ -1011,7 +1011,7 @@ bool reshade::runtime::load_effect(const std::filesystem::path &source_file, con
1011
1011
}
1012
1012
1013
1013
bool source_cached = false ; std::string source;
1014
- if (!effect.preprocessed && (preprocess_required || (source_cached = load_effect_cache (source_file, source_hash, source)) == false ))
1014
+ if (!effect.preprocessed && (preprocess_required || (source_cached = load_effect_cache (source_file. stem (). u8string () + ' - ' + std::to_string (_renderer_id) + ' - ' + std::to_string ( source_hash), " i " , source)) == false ))
1015
1015
{
1016
1016
reshadefx::preprocessor pp;
1017
1017
pp.add_macro_definition (" __RESHADE__" , std::to_string (VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_REVISION));
@@ -1064,7 +1064,7 @@ bool reshade::runtime::load_effect(const std::filesystem::path &source_file, con
1064
1064
if (effect.preprocessed )
1065
1065
{
1066
1066
source = std::move (pp.output ());
1067
- source_cached = save_effect_cache (source_file, source_hash, source);
1067
+ source_cached = save_effect_cache (source_file. stem (). u8string () + ' - ' + std::to_string (_renderer_id) + ' - ' + std::to_string ( source_hash), " i " , source);
1068
1068
1069
1069
// Keep track of used preprocessor definitions (so they can be displayed in the overlay)
1070
1070
effect.definitions .clear ();
@@ -1387,7 +1387,7 @@ bool reshade::runtime::create_effect(size_t effect_index)
1387
1387
}
1388
1388
1389
1389
// Compile shader modules
1390
- std::unordered_map<std::string, std::vector< char > > entry_points;
1390
+ std::unordered_map<std::string, std::string > entry_points;
1391
1391
1392
1392
for (const reshadefx::entry_point &entry_point : effect.module .entry_points )
1393
1393
{
@@ -1496,42 +1496,38 @@ bool reshade::runtime::create_effect(size_t effect_index)
1496
1496
}
1497
1497
else if (_renderer_id & 0x10000 )
1498
1498
{
1499
- std::string source = " #version 430\n " ;
1500
- source += " #define ENTRY_POINT_" + entry_point.name + " 1\n " ;
1499
+ cso = " #version 430\n #define ENTRY_POINT_" + entry_point.name + " 1\n " ;
1501
1500
1502
1501
if (type == api::shader_stage::vertex)
1503
1502
{
1504
1503
// OpenGL does not allow using 'discard' in the vertex shader profile
1505
- source += " #define discard\n " ;
1504
+ cso += " #define discard\n " ;
1506
1505
// 'dFdx', 'dFdx' and 'fwidth' too are only available in fragment shaders
1507
- source += " #define dFdx(x) x\n " ;
1508
- source += " #define dFdy(y) y\n " ;
1509
- source += " #define fwidth(p) p\n " ;
1506
+ cso += " #define dFdx(x) x\n " ;
1507
+ cso += " #define dFdy(y) y\n " ;
1508
+ cso += " #define fwidth(p) p\n " ;
1510
1509
}
1511
1510
if (type != api::shader_stage::compute)
1512
1511
{
1513
1512
// OpenGL does not allow using 'shared' in vertex/fragment shader profile
1514
- source += " #define shared\n " ;
1515
- source += " #define atomicAdd(a, b) a\n " ;
1516
- source += " #define atomicAnd(a, b) a\n " ;
1517
- source += " #define atomicOr(a, b) a\n " ;
1518
- source += " #define atomicXor(a, b) a\n " ;
1519
- source += " #define atomicMin(a, b) a\n " ;
1520
- source += " #define atomicMax(a, b) a\n " ;
1521
- source += " #define atomicExchange(a, b) a\n " ;
1522
- source += " #define atomicCompSwap(a, b, c) a\n " ;
1513
+ cso += " #define shared\n " ;
1514
+ cso += " #define atomicAdd(a, b) a\n " ;
1515
+ cso += " #define atomicAnd(a, b) a\n " ;
1516
+ cso += " #define atomicOr(a, b) a\n " ;
1517
+ cso += " #define atomicXor(a, b) a\n " ;
1518
+ cso += " #define atomicMin(a, b) a\n " ;
1519
+ cso += " #define atomicMax(a, b) a\n " ;
1520
+ cso += " #define atomicExchange(a, b) a\n " ;
1521
+ cso += " #define atomicCompSwap(a, b, c) a\n " ;
1523
1522
// Barrier intrinsics are only available in compute shaders
1524
- source += " #define barrier()\n " ;
1525
- source += " #define memoryBarrier()\n " ;
1526
- source += " #define groupMemoryBarrier()\n " ;
1523
+ cso += " #define barrier()\n " ;
1524
+ cso += " #define memoryBarrier()\n " ;
1525
+ cso += " #define groupMemoryBarrier()\n " ;
1527
1526
}
1528
1527
1529
- source += " #line 1 0\n " ; // Reset line number, so it matches what is shown when viewing the generated code
1530
- source += effect.preamble ;
1531
- source += effect.module .hlsl ;
1532
-
1533
- cso.resize (source.size ());
1534
- std::memcpy (cso.data (), source.data (), cso.size ());
1528
+ cso += " #line 1 0\n " ; // Reset line number, so it matches what is shown when viewing the generated code
1529
+ cso += effect.preamble ;
1530
+ cso += effect.module .hlsl ;
1535
1531
}
1536
1532
else
1537
1533
{
@@ -1617,8 +1613,11 @@ bool reshade::runtime::create_effect(size_t effect_index)
1617
1613
attributes += " profile=" + profile + ' ;' ;
1618
1614
attributes += " flags=" + std::to_string (compile_flags) + ' ;' ;
1619
1615
1620
- const size_t hash = std::hash<std::string_view>()(attributes) ^ std::hash<std::string_view>()(hlsl);
1621
- if (!load_effect_cache (effect.source_file , entry_point.name , hash, cso, effect.assembly [entry_point.name ]))
1616
+ const std::string cache_id =
1617
+ effect.source_file .stem ().u8string () + ' -' + entry_point.name + ' -' + std::to_string (_renderer_id) + ' -' +
1618
+ std::to_string (std::hash<std::string_view>()(attributes) ^ std::hash<std::string_view>()(hlsl));
1619
+
1620
+ if (load_effect_cache (cache_id, " cso" , cso) == false )
1622
1621
{
1623
1622
com_ptr<ID3DBlob> d3d_compiled, d3d_errors;
1624
1623
const HRESULT hr = D3DCompile (
@@ -1676,10 +1675,16 @@ bool reshade::runtime::create_effect(size_t effect_index)
1676
1675
cso.resize (d3d_compiled->GetBufferSize ());
1677
1676
std::memcpy (cso.data (), d3d_compiled->GetBufferPointer (), cso.size ());
1678
1677
1678
+ save_effect_cache (cache_id, " cso" , cso);
1679
+ }
1680
+
1681
+ std::string &assembly = effect.assembly [entry_point.name ];
1682
+ if (load_effect_cache (cache_id, " asm" , assembly) == false )
1683
+ {
1679
1684
if (com_ptr<ID3DBlob> d3d_disassembled; SUCCEEDED (D3DDisassemble (cso.data (), cso.size (), 0 , nullptr , &d3d_disassembled)))
1680
- effect. assembly [entry_point. name ] .assign (static_cast <const char *>(d3d_disassembled->GetBufferPointer ()), d3d_disassembled->GetBufferSize () - 1 );
1685
+ assembly.assign (static_cast <const char *>(d3d_disassembled->GetBufferPointer ()), d3d_disassembled->GetBufferSize () - 1 );
1681
1686
1682
- save_effect_cache (effect. source_file , entry_point. name , hash, cso, effect. assembly [entry_point. name ] );
1687
+ save_effect_cache (cache_id, " asm " , assembly);
1683
1688
}
1684
1689
}
1685
1690
}
@@ -2707,13 +2712,13 @@ void reshade::runtime::destroy_effects()
2707
2712
_textures_loaded = false ;
2708
2713
}
2709
2714
2710
- bool reshade::runtime::load_effect_cache (const std::filesystem::path &source_file , const size_t hash , std::string &source) const
2715
+ bool reshade::runtime::load_effect_cache (const std::string &id , const std::string &type , std::string &source) const
2711
2716
{
2712
2717
if (_no_effect_cache)
2713
2718
return false ;
2714
2719
2715
2720
std::filesystem::path path = g_reshade_base_path / _intermediate_cache_path;
2716
- path /= std::filesystem::u8path (" reshade-" + source_file. stem (). u8string () + ' - ' + std::to_string (_renderer_id) + ' - ' + std::to_string (hash) + " .i " );
2721
+ path /= std::filesystem::u8path (" reshade-" + id + ' . ' + type );
2717
2722
2718
2723
{ const HANDLE file = CreateFileW (path.c_str (), FILE_GENERIC_READ, FILE_SHARE_READ, nullptr , OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr );
2719
2724
if (file == INVALID_HANDLE_VALUE)
@@ -2725,47 +2730,13 @@ bool reshade::runtime::load_effect_cache(const std::filesystem::path &source_fil
2725
2730
return result != FALSE ;
2726
2731
}
2727
2732
}
2728
- bool reshade::runtime::load_effect_cache (const std::filesystem::path &source_file , const std::string &entry_point , const size_t hash, std::vector< char > &cso, std:: string &dasm ) const
2733
+ bool reshade::runtime::save_effect_cache (const std::string &id , const std::string &type , const std::string &source ) const
2729
2734
{
2730
2735
if (_no_effect_cache)
2731
2736
return false ;
2732
2737
2733
2738
std::filesystem::path path = g_reshade_base_path / _intermediate_cache_path;
2734
- path /= std::filesystem::u8path (" reshade-" + source_file.stem ().u8string () + ' -' + entry_point + ' -' + std::to_string (_renderer_id) + ' -' + std::to_string (hash) + " .cso" );
2735
-
2736
- { const HANDLE file = CreateFileW (path.c_str (), FILE_GENERIC_READ, FILE_SHARE_READ, nullptr , OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr );
2737
- if (file == INVALID_HANDLE_VALUE)
2738
- return false ;
2739
- DWORD size = GetFileSize (file, nullptr );
2740
- cso.resize (size);
2741
- const BOOL result = ReadFile (file, cso.data (), size, &size, nullptr );
2742
- CloseHandle (file);
2743
- if (result == FALSE )
2744
- return false ;
2745
- }
2746
-
2747
- path.replace_extension (L" .asm" );
2748
-
2749
- { const HANDLE file = CreateFileW (path.c_str (), FILE_GENERIC_READ, FILE_SHARE_READ, nullptr , OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr );
2750
- if (file == INVALID_HANDLE_VALUE)
2751
- return false ;
2752
- DWORD size = GetFileSize (file, nullptr );
2753
- dasm.resize (size);
2754
- const BOOL result = ReadFile (file, dasm.data (), size, &size, nullptr );
2755
- CloseHandle (file);
2756
- if (result == FALSE )
2757
- return false ;
2758
- }
2759
-
2760
- return true ;
2761
- }
2762
- bool reshade::runtime::save_effect_cache (const std::filesystem::path &source_file, const size_t hash, const std::string &source) const
2763
- {
2764
- if (_no_effect_cache)
2765
- return false ;
2766
-
2767
- std::filesystem::path path = g_reshade_base_path / _intermediate_cache_path;
2768
- path /= std::filesystem::u8path (" reshade-" + source_file.stem ().u8string () + ' -' + std::to_string (_renderer_id) + ' -' + std::to_string (hash) + " .i" );
2739
+ path /= std::filesystem::u8path (" reshade-" + id + ' .' + type);
2769
2740
2770
2741
{ const HANDLE file = CreateFileW (path.c_str (), FILE_GENERIC_WRITE, FILE_SHARE_READ, nullptr , CREATE_NEW, FILE_ATTRIBUTE_ARCHIVE | FILE_FLAG_SEQUENTIAL_SCAN, nullptr );
2771
2742
if (file == INVALID_HANDLE_VALUE)
@@ -2776,39 +2747,6 @@ bool reshade::runtime::save_effect_cache(const std::filesystem::path &source_fil
2776
2747
return result != FALSE ;
2777
2748
}
2778
2749
}
2779
- bool reshade::runtime::save_effect_cache (const std::filesystem::path &source_file, const std::string &entry_point, const size_t hash, const std::vector<char > &cso, const std::string &dasm) const
2780
- {
2781
- if (_no_effect_cache)
2782
- return false ;
2783
-
2784
- std::filesystem::path path = g_reshade_base_path / _intermediate_cache_path;
2785
- path /= std::filesystem::u8path (" reshade-" + source_file.stem ().u8string () + ' -' + entry_point + ' -' + std::to_string (_renderer_id) + ' -' + std::to_string (hash) + " .cso" );
2786
-
2787
- { const HANDLE file = CreateFileW (path.c_str (), FILE_GENERIC_WRITE, FILE_SHARE_READ, nullptr , CREATE_NEW, FILE_FLAG_SEQUENTIAL_SCAN, nullptr );
2788
- if (file == INVALID_HANDLE_VALUE)
2789
- return false ;
2790
- DWORD size = static_cast <DWORD>(cso.size ());
2791
- const BOOL result = WriteFile (file, cso.data (), size, &size, nullptr );
2792
- CloseHandle (file);
2793
- if (result == FALSE )
2794
- return false ;
2795
- }
2796
-
2797
- path.replace_extension (L" .asm" );
2798
-
2799
- { const HANDLE file = CreateFileW (path.c_str (), FILE_GENERIC_WRITE, FILE_SHARE_READ, nullptr , CREATE_NEW, FILE_ATTRIBUTE_ARCHIVE | FILE_FLAG_SEQUENTIAL_SCAN, nullptr );
2800
- if (file == INVALID_HANDLE_VALUE)
2801
- return false ;
2802
- DWORD size = static_cast <DWORD>(dasm.size ());
2803
- const BOOL result = WriteFile (file, dasm.c_str (), size, &size, NULL );
2804
- CloseHandle (file);
2805
- if (result == FALSE )
2806
- return false ;
2807
- }
2808
-
2809
- return true ;
2810
- }
2811
-
2812
2750
void reshade::runtime::clear_effect_cache ()
2813
2751
{
2814
2752
// Find all cached effect files and delete them
0 commit comments