@@ -299,6 +299,10 @@ HRESULT WINAPI hk_D3D11CreateDeviceAndSwapChain(
299299 pAdapter->GetDesc (&adapterDesc);
300300 globals::state->SetAdapterDescription (adapterDesc.Description );
301301
302+ if (globals::shaderCache->IsHdrRendering ()) {
303+ pSwapChainDesc->BufferDesc .Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
304+ }
305+
302306 if (!REL::Module::IsVR ()) {
303307 pSwapChainDesc->SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
304308
@@ -452,6 +456,18 @@ HRESULT WINAPI hk_D3D11CreateDeviceAndSwapChain(
452456 streamline->PostDevice ();
453457 }
454458
459+ if (*ppSwapChain && globals::shaderCache->IsHdrRendering ()) {
460+ IDXGISwapChain4* swapChain4 = nullptr ;
461+ if (SUCCEEDED ((*ppSwapChain)->QueryInterface (IID_PPV_ARGS (&swapChain4)))) {
462+ // Traditionally color space would be set to HDR10 equivalent, however as we do no tonemapping in-engine,
463+ // we use scRGB as the format and thus Rec. 709 primaries
464+ //
465+ // Tonemapping is performed either by the compositor or other system components into PQ
466+ swapChain4->SetColorSpace1 (DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709);
467+ swapChain4->Release ();
468+ }
469+ }
470+
455471 return ret;
456472}
457473
@@ -563,9 +579,96 @@ namespace Hooks
563579 {
564580 static void thunk (RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
565581 {
582+ if (globals::shaderCache->IsHdrRendering ()) {
583+ a_properties->format = RE::BSGraphics::Format::kR16G16B16A16_FLOAT ;
584+ }
585+ globals::state->ModifyRenderTarget (a_target, a_properties);
586+ func (This, a_target, a_properties);
587+ }
588+ static inline REL::Relocation<decltype (thunk)> func;
589+ };
590+
591+ struct CreateRenderTarget_ImagespaceTempCopy
592+ {
593+ static void thunk (RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
594+ {
595+ if (globals::shaderCache->IsHdrRendering ()) {
596+ a_properties->format = RE::BSGraphics::Format::kR16G16B16A16_FLOAT ;
597+ }
598+ globals::state->ModifyRenderTarget (a_target, a_properties);
599+ func (This, a_target, a_properties);
600+ }
601+
602+ static inline REL::Relocation<decltype (thunk)> func;
603+ };
604+
605+ struct CreateRenderTarget_ImagespaceTempCopy2
606+ {
607+ static void thunk (RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
608+ {
609+ if (globals::shaderCache->IsHdrRendering ()) {
610+ a_properties->format = RE::BSGraphics::Format::kR16G16B16A16_FLOAT ;
611+ }
612+ globals::state->ModifyRenderTarget (a_target, a_properties);
613+ func (This, a_target, a_properties);
614+ }
615+
616+ static inline REL::Relocation<decltype (thunk)> func;
617+ };
618+
619+ struct CreateRenderTarget_LDRBlurSwap
620+ {
621+ static void thunk (RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
622+ {
623+ if (globals::shaderCache->IsHdrRendering ()) {
624+ a_properties->format = RE::BSGraphics::Format::kR16G16B16A16_FLOAT ;
625+ }
626+ globals::state->ModifyRenderTarget (a_target, a_properties);
627+ func (This, a_target, a_properties);
628+ }
629+
630+ static inline REL::Relocation<decltype (thunk)> func;
631+ };
632+
633+ struct CreateRenderTarget_LDRDownsample
634+ {
635+ static void thunk (RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
636+ {
637+ if (globals::shaderCache->IsHdrRendering ()) {
638+ a_properties->format = RE::BSGraphics::Format::kR16G16B16A16_FLOAT ;
639+ }
640+ globals::state->ModifyRenderTarget (a_target, a_properties);
641+ func (This, a_target, a_properties);
642+ }
643+
644+ static inline REL::Relocation<decltype (thunk)> func;
645+ };
646+
647+ struct CreateRenderTarget_TemporalAAAccumulation0
648+ {
649+ static void thunk (RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
650+ {
651+ if (globals::shaderCache->IsHdrRendering ()) {
652+ a_properties->format = RE::BSGraphics::Format::kR16G16B16A16_FLOAT ;
653+ }
654+ globals::state->ModifyRenderTarget (a_target, a_properties);
655+ func (This, a_target, a_properties);
656+ }
657+
658+ static inline REL::Relocation<decltype (thunk)> func;
659+ };
660+
661+ struct CreateRenderTarget_TemporalAAAccumulation1
662+ {
663+ static void thunk (RE::BSGraphics::Renderer* This, RE::RENDER_TARGETS::RENDER_TARGET a_target, RE::BSGraphics::RenderTargetProperties* a_properties)
664+ {
665+ if (globals::shaderCache->IsHdrRendering ()) {
666+ a_properties->format = RE::BSGraphics::Format::kR16G16B16A16_FLOAT ;
667+ }
566668 globals::state->ModifyRenderTarget (a_target, a_properties);
567669 func (This, a_target, a_properties);
568670 }
671+
569672 static inline REL::Relocation<decltype (thunk)> func;
570673 };
571674
@@ -958,6 +1061,12 @@ namespace Hooks
9581061
9591062 logger::info (" Hooking BSShaderRenderTargets::Create::CreateRenderTarget(s)" );
9601063 stl::write_thunk_call<CreateRenderTarget_Main>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0x3F0 , 0x3F3 , 0x548 ));
1064+ stl::write_thunk_call<CreateRenderTarget_ImagespaceTempCopy>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0x62F , 0x62E ));
1065+ stl::write_thunk_call<CreateRenderTarget_ImagespaceTempCopy2>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0x642 , 0x641 ));
1066+ stl::write_thunk_call<CreateRenderTarget_LDRBlurSwap>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0x529 , 0x528 ));
1067+ stl::write_thunk_call<CreateRenderTarget_LDRDownsample>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0xB2E , 0xB2E ));
1068+ stl::write_thunk_call<CreateRenderTarget_TemporalAAAccumulation0>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0xE68 , 0xE6A ));
1069+ stl::write_thunk_call<CreateRenderTarget_TemporalAAAccumulation1>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0xE7E , 0xE80 ));
9611070 stl::write_thunk_call<CreateRenderTarget_Normals>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0x458 , 0x45B , 0x5B0 ));
9621071 stl::write_thunk_call<CreateRenderTarget_NormalsSwap>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0x46B , 0x46E , 0x5C3 ));
9631072 stl::write_thunk_call<CreateRenderTarget_Snow>(REL::RelocationID (100458 , 107175 ).address () + REL::Relocate (0x406 , 0x409 , 0x55e ));
0 commit comments