diff --git a/include/SpecialK/config.h b/include/SpecialK/config.h index 3fb0a1b27..ca70c8ce0 100644 --- a/include/SpecialK/config.h +++ b/include/SpecialK/config.h @@ -926,6 +926,7 @@ struct sk_config_t bool dump = false; bool inject = true; bool cache = true; + bool orig_cache = true;// The initial setting when the game started bool highlight_debug = true; bool injection_keeps_fmt = false; bool generate_mips = false; diff --git a/src/config.cpp b/src/config.cpp index db78da49a..6ebf0531d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -4627,6 +4627,8 @@ auto DeclKeybind = texture.d3d11.inject->load (config.textures.d3d11.inject); texture.res_root->load (config.textures.d3d11.res_root); + SK_RunOnce (config.textures.d3d11.orig_cache = config.textures.d3d11.cache); + texture.d3d11.injection_keeps_format-> load (config.textures.d3d11.injection_keeps_fmt); texture.dump_on_load->load (config.textures.d3d11.dump); diff --git a/src/render/d3d11/d3d11.cpp b/src/render/d3d11/d3d11.cpp index 48d7693e9..0cc689a20 100644 --- a/src/render/d3d11/d3d11.cpp +++ b/src/render/d3d11/d3d11.cpp @@ -1617,9 +1617,6 @@ SK_D3D11_UpdateSubresource_Impl ( early_out = true; } - - static const bool __attempt_to_cache = config.textures.d3d11.cache; - if ( pDstBox != nullptr && ( pDstBox->left >= pDstBox->right || pDstBox->top >= pDstBox->bottom || pDstBox->front >= pDstBox->back ) ) @@ -1652,20 +1649,22 @@ SK_D3D11_UpdateSubresource_Impl ( _Finish (); } - if ( __attempt_to_cache && ( (rdim == D3D11_RESOURCE_DIMENSION_TEXTURE2D) || + if ( config.textures.d3d11.orig_cache && + ( (rdim == D3D11_RESOURCE_DIMENSION_TEXTURE2D) || SK_D3D11_IsStagingCacheable (rdim, pDstResource) ) && DstSubresource == 0 ) { auto& textures = SK_D3D11_Textures; - SK_ComQIPtr pTex (pDstResource); - + SK_ComQIPtr + pTex (pDstResource); if (pTex != nullptr) { - D3D11_TEXTURE2D_DESC desc = { }; - pTex->GetDesc (&desc); + D3D11_TEXTURE2D_DESC + desc = { }; + pTex->GetDesc (&desc); - if (__attempt_to_cache) + if (config.textures.d3d11.orig_cache) { const bool skip = ( (desc.Usage == D3D11_USAGE_STAGING && (! SK_D3D11_IsStagingCacheable (rdim, pDstResource))) || @@ -2042,7 +2041,7 @@ SK_D3D11_CopySubresourceRegion_Impl ( { SK_WRAP_AND_HOOK - // UB: If it's happening, pretend we never saw this... + // UB: If it's happening, pretend we never saw this... if (pDstResource == nullptr || pSrcResource == nullptr) { return; @@ -2120,7 +2119,7 @@ SK_D3D11_CopySubresourceRegion_Impl ( pSrcResource, SrcSubresource, pSrcBox ); }; - bool early_out = + const bool early_out = (! bMustNotIgnore) || SK_D3D11_IgnoreWrappedOrDeferred (bWrapped, bIsDevCtxDeferred, pDevCtx); diff --git a/src/render/d3d11/d3d11_shader.cpp b/src/render/d3d11/d3d11_shader.cpp index 63119eb92..edd635255 100644 --- a/src/render/d3d11/d3d11_shader.cpp +++ b/src/render/d3d11/d3d11_shader.cpp @@ -866,10 +866,10 @@ SK_D3D11_SetShaderResources_Impl ( pDevContext, StartSlot, NumViews, ppShaderResourceViews); }; - bool early_out = shader_base == nullptr || - ( SK_D3D11_IgnoreWrappedOrDeferred (bWrapped, SK_D3D11_IsDevCtxDeferred (pDevContext), - pDevContext) || - (! bMustNotIgnore) ); + bool early_out = (! bMustNotIgnore) || shader_base == nullptr || + SK_D3D11_IgnoreWrappedOrDeferred (bWrapped, + SK_D3D11_IsDevCtxDeferred (pDevContext), + pDevContext); if (early_out) { diff --git a/src/render/d3d11/hooks/d3d11_device.cpp b/src/render/d3d11/hooks/d3d11_device.cpp index 3aa7ed5fd..aecd9a87b 100644 --- a/src/render/d3d11/hooks/d3d11_device.cpp +++ b/src/render/d3d11/hooks/d3d11_device.cpp @@ -1211,6 +1211,8 @@ D3D11Dev_CreateSamplerState_Override D3D11_SAMPLER_DESC new_desc = *pSamplerDesc; + + #pragma region "UglyGameHacksThatShouldNotBeHere" static const bool bShenmue = SK_GetCurrentGameID () == SK_GAME_ID::Shenmue; diff --git a/src/render/d3d11/mod_tools/d3d11_texture_mods.cpp b/src/render/d3d11/mod_tools/d3d11_texture_mods.cpp index 4d033d716..3b1d2ea3d 100644 --- a/src/render/d3d11/mod_tools/d3d11_texture_mods.cpp +++ b/src/render/d3d11/mod_tools/d3d11_texture_mods.cpp @@ -265,6 +265,48 @@ SK_D3D11_LiveTextureView (bool& can_scroll, SK_TLS* pTLS = SK_TLS_Bottom ()) entry.mipmapped = TRUE; non_mipped--; } + + else if (skip) + { + if (DirectX::MakeTypeless (entry.desc.Format) == DXGI_FORMAT_BC7_TYPELESS) + { + SK_ScopedBool decl_tex_scope ( + SK_D3D11_DeclareTexInjectScope (pTLS) + ); + + SK_ComPtr pDev (rb.d3d11.device); + SK_ComPtr pDevCtx (rb.d3d11.immediate_ctx); + DirectX::ScratchImage captured; + if (SUCCEEDED (DirectX::CaptureTexture (pDev, pDevCtx, entry.pTex, captured))) + { + DXGI_FORMAT uncompressed_fmt = + (entry.desc.Format == DXGI_FORMAT_BC7_TYPELESS) ? DXGI_FORMAT_R8G8B8A8_UNORM : + (entry.desc.Format == DXGI_FORMAT_BC7_UNORM) ? DXGI_FORMAT_R8G8B8A8_UNORM : + (entry.desc.Format == DXGI_FORMAT_BC7_UNORM_SRGB) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB + : DXGI_FORMAT_UNKNOWN; + DirectX::ScratchImage converted; + DirectX::Decompress (*captured.GetImage (0,0,0), uncompressed_fmt, converted); + + auto desc = entry.desc; + desc.Format = uncompressed_fmt; + desc.MipLevels = 1; + + auto metadata = + converted.GetMetadata (); + + metadata.mipLevels = 1; + + SK_ComPtr pNewTex; + DirectX::CreateTexture (pDev, converted.GetImages (), 1, metadata, (ID3D11Resource **)&pNewTex.p); + + if (SUCCEEDED (SK_D3D11_MipmapCacheTexture2D (pNewTex, entry.crc32c, pTLS))) + { + entry.mipmapped = TRUE; + non_mipped--; + } + } + } + } } } } @@ -1064,50 +1106,84 @@ SK_D3D11_LiveTextureView (bool& can_scroll, SK_TLS* pTLS = SK_TLS_Bottom ()) switch (entry.desc.Format) { // These formats take an eternity! - case DXGI_FORMAT_BC6H_TYPELESS: + case DXGI_FORMAT_BC6H_TYPELESS: case DXGI_FORMAT_BC6H_UF16: case DXGI_FORMAT_BC6H_SF16: case DXGI_FORMAT_BC7_TYPELESS: case DXGI_FORMAT_BC7_UNORM: case DXGI_FORMAT_BC7_UNORM_SRGB: - ignore = (! bIncludeBC7andBC6H); + ignore = true;//(! bIncludeBC7andBC6H); default: break; } - if (ignore) ImGui::BeginDisabled (); + //if (ignore) ImGui::BeginDisabled (); if (ImGui::Button (" Generate Mipmaps ###GenerateMipmaps")) { SK_ScopedBool decl_tex_scope ( SK_D3D11_DeclareTexInjectScope (pTLS) ); - if (SUCCEEDED (SK_D3D11_MipmapCacheTexture2D (pTex, entry.crc32c, pTLS))) + if (ignore) + { + SK_ComPtr pDevCtx (rb.d3d11.immediate_ctx); + DirectX::ScratchImage captured; + if (SUCCEEDED (DirectX::CaptureTexture (pDev, pDevCtx, pTex, captured))) + { + DXGI_FORMAT uncompressed_fmt = + (entry.desc.Format == DXGI_FORMAT_BC7_TYPELESS) ? DXGI_FORMAT_R8G8B8A8_UNORM : + (entry.desc.Format == DXGI_FORMAT_BC7_UNORM) ? DXGI_FORMAT_R8G8B8A8_UNORM : + (entry.desc.Format == DXGI_FORMAT_BC7_UNORM_SRGB) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB + : DXGI_FORMAT_UNKNOWN; + DirectX::ScratchImage converted; + DirectX::Decompress (*captured.GetImage (0,0,0), uncompressed_fmt, converted); + + auto desc = entry.desc; + desc.Format = uncompressed_fmt; + desc.MipLevels = 1; + + auto metadata = + converted.GetMetadata (); + + metadata.mipLevels = 1; + + SK_ComPtr pNewTex; + DirectX::CreateTexture (pDev, converted.GetImages (), 1, metadata, (ID3D11Resource **)&pNewTex.p); + + if (SUCCEEDED (SK_D3D11_MipmapCacheTexture2D (pNewTex, entry.crc32c, pTLS))) + { + entry.mipmapped = TRUE; + non_mipped--; + } + } + } + + else if (SUCCEEDED (SK_D3D11_MipmapCacheTexture2D (pTex, entry.crc32c, pTLS))) { entry.mipmapped = TRUE; non_mipped--; } } - if (ignore) - { ImGui::EndDisabled (); - if (ImGui::IsItemHovered ()) - { ImGui::BeginTooltip (); - ImGui::TextUnformatted ( - "This operation may take an EXTREMELY long time to complete!!" - ); - ImGui::Separator (); - ImGui::BulletText ( - "Mipmap generation must first Decompress BC7/BC6H textures"); - ImGui::BulletText ( - "Once decompressed, mipmap generation is simple, but..."); - ImGui::BulletText ( - "The mipmapped copy must be recompressed with BC7/BC6H(!!)"); - ImGui::Separator (); - ImGui::TextUnformatted ("\tCompressing BC7/BC6H is SLOW!"); - ImGui::EndTooltip (); - } - } + //if (ignore) + //{ ImGui::EndDisabled (); + // if (ImGui::IsItemHovered ()) + // { ImGui::BeginTooltip (); + // ImGui::TextUnformatted ( + // "This operation may take an EXTREMELY long time to complete!!" + // ); + // ImGui::Separator (); + // ImGui::BulletText ( + // "Mipmap generation must first Decompress BC7/BC6H textures"); + // ImGui::BulletText ( + // "Once decompressed, mipmap generation is simple, but..."); + // ImGui::BulletText ( + // "The mipmapped copy must be recompressed with BC7/BC6H(!!)"); + // ImGui::Separator (); + // ImGui::TextUnformatted ("\tCompressing BC7/BC6H is SLOW!"); + // ImGui::EndTooltip (); + // } + //} } }