Skip to content

Commit

Permalink
Add render target debug to texture mod tools
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Feb 10, 2017
1 parent 6636e23 commit 6c13baf
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 58 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 9
#define TBF_BUILD 1
#define TBF_BUILD 2
#define TBF_REV 0


Expand Down
10 changes: 10 additions & 0 deletions include/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ namespace tbf
std::unordered_set <uint32_t> pixel_shaders;
std::unordered_set <uint32_t> vertex_shaders;
} extern last_frame;

struct render_target_tracking_s
{
IDirect3DBaseTexture9* tracking_tex;

std::unordered_set <uint32_t> pixel_shaders;
std::unordered_set <uint32_t> vertex_shaders;

bool active;
} extern tracked_rt;
}
}

Expand Down
17 changes: 17 additions & 0 deletions include/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern iSK_Logger* tex_log;
#include <algorithm>

interface ISKTextureD3D9;
struct IDirect3DBaseTexture9;

const int log_level = 0;

Expand Down Expand Up @@ -190,6 +191,14 @@ namespace RenderFix {
ULONG getHitCount (void) { return InterlockedExchangeAdd (&hits, 0UL); }
ULONG getMissCount (void) { return InterlockedExchangeAdd (&misses, 0UL); }

void resetUsedTextures (void);
void applyTexture (IDirect3DBaseTexture9* tex);

std::vector <IDirect3DBaseTexture9 *>
getUsedRenderTargets (void);
void trackRenderTarget (IDirect3DBaseTexture9* rt);
bool isRenderTarget (IDirect3DBaseTexture9* rt);



BOOL isTexturePowerOfTwo (UINT sampler)
Expand All @@ -207,6 +216,14 @@ namespace RenderFix {


private:
struct {
std::unordered_set <IDirect3DBaseTexture9*> render_targets;
} known;

struct {
std::unordered_set <IDirect3DBaseTexture9*> render_targets;
} used;

std::unordered_map <uint32_t, tbf::RenderFix::Texture*> textures;
float time_saved = 0.0f;
LONG64 bytes_saved = 0LL;
Expand Down
172 changes: 125 additions & 47 deletions src/ImGui/mod_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "render.h"
#include "textures.h"

#include <atlbase.h>

void
TBF_DrawFileList (void)
{
Expand Down Expand Up @@ -561,57 +563,45 @@ TBFix_TextureModDlg (void)
ImGui::PopStyleVar (2);
}

#if 0
if (ImGui::CollapsingHeader ("Live Render Target View", ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_DefaultOpen))
{
static LONG last_ht = 256L;
static LONG last_width = 256L;

static std::vector <std::string> list_contents;
static bool list_dirty = false;
static int sel = 0;

extern std::vector <uint32_t> textures_used_last_dump;
extern uint32_t tex_dbg_idx;
extern uint32_t debug_tex_id;

ImGui::BeginChild ("ToolHeadings2", ImVec2 (750, 32), false, ImGuiWindowFlags_AlwaysUseWindowPadding);
static bool list_dirty = true;
static uintptr_t last_sel_ptr = 0;
static int sel = 0;

if (ImGui::Button ("Refresh Targets"))
{
SK_ICommandProcessor& command =
*SK_GetCommandProcessor ();

list_dirty = true;
}

if (ImGui::IsItemHovered ()) ImGui::SetTooltip ("Refreshes the set of texture checksums used in the last frame drawn.");

ImGui::Separator ();
ImGui::EndChild ();
std::vector <IDirect3DBaseTexture9*> render_textures =
tbf::RenderFix::tex_mgr.getUsedRenderTargets ();

if (list_dirty)
{
list_contents.clear ();
sel = tex_dbg_idx;
sel = 0;
int idx = 0;
list_contents.clear ();

for ( auto it : render_textures )
{
char szDesc [16] = { };

sprintf (szDesc, "%px", it);
sprintf (szDesc, "%08x", (uintptr_t)it);

list_contents.push_back (szDesc);

if ((uintptr_t)it == last_sel_ptr)
sel = idx;

++idx;
}
}

ImGui::BeginGroup ();

ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 0.0f);
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.9f, 0.7f, 0.5f, 1.0f));

ImGui::BeginChild ( "Item List",
ImVec2 ( 90, std::max (512L, last_ht) + 128 ),
ImGui::BeginChild ( "Item List2",
ImVec2 ( 90, std::max (512L, last_ht)),
true, ImGuiWindowFlags_AlwaysAutoResize );

if (render_textures.size ())
Expand All @@ -624,35 +614,123 @@ TBFix_TextureModDlg (void)

last_sel = sel;

for ( int line = 0; line < render_textures.size (); line++)
for ( int line = 0; line < render_textures.size (); line++ )
{
if (line == sel)
{
bool selected = true;
ImGui::Selectable (list_contents [line].c_str (), &selected);
D3DSURFACE_DESC desc;

if (sel_changed)
{
ImGui::SetScrollHere (0.5f); // 0.0f:top, 0.5f:center, 1.0f:bottom
sel_changed = false;
}
}
CComPtr <IDirect3DTexture9> pTex = nullptr;

else
if (SUCCEEDED (render_textures [line]->QueryInterface (IID_PPV_ARGS (&pTex))))
{
bool selected = false;

if (ImGui::Selectable (list_contents [line].c_str (), &selected))
if (SUCCEEDED (pTex->GetLevelDesc (0, &desc)))
{
sel_changed = true;
tex_dbg_idx = line;
sel = line;
if (line == sel)
{
bool selected = true;
ImGui::Selectable (list_contents [line].c_str (), &selected);

if (sel_changed)
{
ImGui::SetScrollHere (0.5f); // 0.0f:top, 0.5f:center, 1.0f:bottom
sel_changed = false;
}
}

else
{
bool selected = false;

if (ImGui::Selectable (list_contents [line].c_str (), &selected))
{
sel_changed = true;
sel = line;
last_sel_ptr = (uintptr_t)render_textures [sel];
tbf::RenderFix::tracked_rt.tracking_tex = render_textures [sel];
}
}
}
}
}
}

ImGui::EndChild ();

ImGui::BeginGroup ();

ImGui::PopStyleColor ();
ImGui::PopStyleVar ();

CComPtr <IDirect3DTexture9> pTex = nullptr;

if (render_textures.size ())
render_textures [sel]->QueryInterface (IID_PPV_ARGS (&pTex));

if (pTex != nullptr)
{
D3DSURFACE_DESC desc;

if (SUCCEEDED (pTex->GetLevelDesc (0, &desc)))
{
int shaders = std::max ( tbf::RenderFix::tracked_rt.pixel_shaders.size (),
tbf::RenderFix::tracked_rt.vertex_shaders.size () );

ImGui::SameLine ();

ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.5f, 0.5f, 0.5f, 1.0f));
ImGui::BeginChild ( "Item Selection3",
ImVec2 ( std::max (128L, (LONG)desc.Width / 2 + 24),
std::max (256L, (LONG)desc.Height / 2) + 64 + shaders * 19),
true,
ImGuiWindowFlags_AlwaysAutoResize );

last_width = desc.Width / 2;
last_ht = std::max (256L, (LONG)desc.Height / 2) + 64 + shaders * 19;

extern std::wstring
SK_D3D9_FormatToStr (D3DFORMAT Format, bool include_ordinal = true);


ImGui::Text ( "Dimensions: %lux%lu",
desc.Width, desc.Height/*,
pTex->d3d9_tex->GetLevelCount ()*/ );
ImGui::Text ( "Format: %ws",
SK_D3D9_FormatToStr (desc.Format).c_str () );

ImGui::Separator ();

ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.95f, 0.95f, 0.05f, 1.0f));
ImGui::BeginChildFrame (0, ImVec2 ((float)desc.Width / 2 + 8, (float)desc.Height / 2 + 8), ImGuiWindowFlags_ShowBorders);
ImGui::Image ( pTex,
ImVec2 ((float)desc.Width / 2, (float)desc.Height / 2),
ImVec2 (0,0), ImVec2 (1,1),
ImColor (255,255,255,255), ImColor (255,255,255,128)
);
ImGui::EndChildFrame ();

if (shaders > 0)
{
ImGui::Columns (2);

for ( auto it : tbf::RenderFix::tracked_rt.vertex_shaders ) {
ImGui::Text ("Vertex Shader: %x", it);
}

ImGui::NextColumn ();

for ( auto it : tbf::RenderFix::tracked_rt.pixel_shaders ) {
ImGui::Text ("Pixel Shader: %x", it);
}

ImGui::Columns (1);
}

ImGui::EndChild ();
ImGui::PopStyleColor (2);
}
}

ImGui::EndGroup ();
}
#endif

if (ImGui::CollapsingHeader ("Misc. Settings"))
{
Expand Down
18 changes: 17 additions & 1 deletion src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ D3D9SetVertexShader_Detour (IDirect3DDevice9* This,

////tbf::RenderFix::last_frame.vertex_shaders.insert (vs_checksum);

if (tbf::RenderFix::tracked_rt.active)
tbf::RenderFix::tracked_rt.vertex_shaders.insert (vs_checksum);

return D3D9SetVertexShader_Original (This, pShader);
}

Expand Down Expand Up @@ -451,6 +454,9 @@ D3D9SetPixelShader_Detour (IDirect3DDevice9* This,

////tbf::RenderFix::last_frame.pixel_shaders.insert (ps_checksum);

if (tbf::RenderFix::tracked_rt.active)
tbf::RenderFix::tracked_rt.pixel_shaders.insert (ps_checksum);

return D3D9SetPixelShader_Original (This, pShader);
}

Expand Down Expand Up @@ -700,6 +706,11 @@ D3D9EndFrame_Post (HRESULT hr, IUnknown* device)

hr = SK_EndBufferSwap (hr, device);

tbf::RenderFix::tex_mgr.resetUsedTextures ();
tbf::RenderFix::tracked_rt.active = false;
tbf::RenderFix::tracked_rt.vertex_shaders.clear ();
tbf::RenderFix::tracked_rt.pixel_shaders.clear ();

//if (config.framerate.minimize_latency)
//tbf::FrameRateFix::RenderTick ();

Expand Down Expand Up @@ -1518,6 +1529,8 @@ tbf::RenderFix::Reset ( IDirect3DDevice9 *This,
need_reset.textures = false;
}

tbf::RenderFix::tex_mgr.resetUsedTextures ();

need_reset.graphics = false;

vs_checksums.clear ();
Expand Down Expand Up @@ -1863,4 +1876,7 @@ bool tbf::RenderFix::bink = false;
HMODULE tbf::RenderFix::user32_dll = 0;

tbf::RenderFix::reset_state_s
tbf::RenderFix::need_reset;
tbf::RenderFix::need_reset;

tbf::RenderFix::render_target_tracking_s
tbf::RenderFix::tracked_rt;
Loading

0 comments on commit 6c13baf

Please sign in to comment.