d3d: Support depth and stencil in the GE debugger.

But, not with our current depth surfaces.
This commit is contained in:
Unknown W. Brackets 2014-09-14 11:14:56 -07:00
parent fee1ab98ba
commit 2c88935755
3 changed files with 97 additions and 10 deletions

View File

@ -1214,13 +1214,85 @@ namespace DX9 {
}
bool FramebufferManagerDX9::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) {
// TODO: Is this possible?
return false;
u32 fb_address = gstate.getFrameBufRawAddress();
int fb_stride = gstate.FrameBufStride();
u32 z_address = gstate.getDepthBufRawAddress();
int z_stride = gstate.DepthBufStride();
VirtualFramebuffer *vfb = currentRenderVfb_;
if (!vfb) {
vfb = GetVFBAt(fb_address);
}
if (!vfb) {
// If there's no vfb and we're drawing there, must be memory?
buffer = GPUDebugBuffer(Memory::GetPointer(z_address | 0x04000000), z_stride, 512, GPU_DBG_FORMAT_16BIT);
return true;
}
bool success = false;
LPDIRECT3DTEXTURE9 tex = fbo_get_depth_texture(vfb->fbo);
if (tex) {
D3DSURFACE_DESC desc;
D3DLOCKED_RECT locked;
tex->GetLevelDesc(0, &desc);
RECT rect = {0, 0, desc.Width, desc.Height};
HRESULT hr = tex->LockRect(0, &locked, &rect, D3DLOCK_READONLY);
if (SUCCEEDED(hr)) {
GPUDebugBufferFormat fmt = GPU_DBG_FORMAT_24BIT_8X;
int pixelSize = 4;
buffer.Allocate(locked.Pitch / pixelSize, desc.Height, fmt, gstate_c.flipTexture);
memcpy(buffer.GetData(), locked.pBits, locked.Pitch * desc.Height);
success = true;
tex->UnlockRect(0);
}
}
return success;
}
bool FramebufferManagerDX9::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) {
// TODO: Is this possible?
return false;
u32 fb_address = gstate.getFrameBufRawAddress();
int fb_stride = gstate.FrameBufStride();
u32 z_address = gstate.getDepthBufRawAddress();
int z_stride = gstate.DepthBufStride();
VirtualFramebuffer *vfb = currentRenderVfb_;
if (!vfb) {
vfb = GetVFBAt(fb_address);
}
if (!vfb) {
// If there's no vfb and we're drawing there, must be memory?
buffer = GPUDebugBuffer(Memory::GetPointer(z_address | 0x04000000), z_stride, 512, GPU_DBG_FORMAT_16BIT);
return true;
}
bool success = false;
LPDIRECT3DTEXTURE9 tex = fbo_get_depth_texture(vfb->fbo);
if (tex) {
D3DSURFACE_DESC desc;
D3DLOCKED_RECT locked;
tex->GetLevelDesc(0, &desc);
RECT rect = {0, 0, desc.Width, desc.Height};
HRESULT hr = tex->LockRect(0, &locked, &rect, D3DLOCK_READONLY);
if (SUCCEEDED(hr)) {
GPUDebugBufferFormat fmt = GPU_DBG_FORMAT_24X_8BIT;
int pixelSize = 4;
buffer.Allocate(locked.Pitch / pixelSize, desc.Height, fmt, gstate_c.flipTexture);
memcpy(buffer.GetData(), locked.pBits, locked.Pitch * desc.Height);
success = true;
tex->UnlockRect(0);
}
}
return success;
}
} // namespace DX9

View File

@ -11,6 +11,7 @@ struct FBO {
LPDIRECT3DSURFACE9 surf;
LPDIRECT3DSURFACE9 depthstencil;
LPDIRECT3DTEXTURE9 tex;
LPDIRECT3DTEXTURE9 depthstenciltex;
int width;
int height;
@ -36,6 +37,7 @@ void fbo_shutdown() {
FBO * current_fbo = NULL;
#define FOURCC_INTZ ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')))
FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil, FBOColorDepth colorDepth) {
static uint32_t id = 0;
@ -44,6 +46,7 @@ FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil, F
fbo->width = width;
fbo->height = height;
fbo->colorDepth = colorDepth;
fbo->depthstenciltex = nullptr;
HRESULT rtResult = pD3Ddevice->CreateTexture(fbo->width, fbo->height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &fbo->tex, NULL);
if (FAILED(rtResult)) {
@ -58,6 +61,9 @@ FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil, F
ELOG("Failed to create depth buffer");
fbo->surf->Release();
fbo->tex->Release();
if (fbo->depthstenciltex) {
fbo->depthstenciltex->Release();
}
delete fbo;
return NULL;
}
@ -70,13 +76,12 @@ void fbo_destroy(FBO *fbo) {
fbo->tex->Release();
fbo->surf->Release();
fbo->depthstencil->Release();
if (fbo->depthstenciltex) {
fbo->depthstenciltex->Release();
}
delete fbo;
}
void * fbo_get_rtt(FBO *fbo) {
return fbo->tex;
}
void fbo_unbind() {
pD3Ddevice->SetRenderTarget(0, deviceRTsurf);
pD3Ddevice->SetDepthStencilSurface(deviceDSsurf);
@ -97,6 +102,10 @@ LPDIRECT3DTEXTURE9 fbo_get_color_texture(FBO *fbo) {
return fbo->tex;
}
LPDIRECT3DTEXTURE9 fbo_get_depth_texture(FBO *fbo) {
return fbo->depthstenciltex;
}
LPDIRECT3DSURFACE9 fbo_get_color_for_read(FBO *fbo) {
return fbo->surf;
}
@ -109,6 +118,12 @@ void fbo_bind_color_as_texture(FBO *fbo, int color) {
pD3Ddevice->SetTexture(0, fbo->tex);
}
void fbo_bind_depth_as_texture(FBO *fbo) {
if (fbo->depthstenciltex) {
pD3Ddevice->SetTexture(0, fbo->depthstenciltex);
}
}
void fbo_get_dimensions(FBO *fbo, int *w, int *h) {
*w = fbo->width;
*h = fbo->height;

View File

@ -28,6 +28,7 @@ FBO *fbo_create(int width, int height, int num_color_textures, bool z_stencil, F
void fbo_bind_as_render_target(FBO *fbo);
// color must be 0, for now.
void fbo_bind_color_as_texture(FBO *fbo, int color);
void fbo_bind_depth_as_texture(FBO *fbo);
LPDIRECT3DSURFACE9 fbo_get_color_for_read(FBO *fbo);
LPDIRECT3DSURFACE9 fbo_get_color_for_write(FBO *fbo);
void fbo_unbind();
@ -37,8 +38,7 @@ void fbo_resolve(FBO *fbo);
HRESULT fbo_blit_color(FBO *src, const RECT *srcRect, FBO *dst, const RECT *dstRect, D3DTEXTUREFILTERTYPE filter);
LPDIRECT3DTEXTURE9 fbo_get_color_texture(FBO *fbo);
void * fbo_get_rtt(FBO *fbo);
LPDIRECT3DTEXTURE9 fbo_get_depth_texture(FBO *fbo);
// To get default depth and rt surface
void fbo_init();