Added debug more code.

Added a check to create a new depth stencil buffer if the render to texture size is bigger than the original depth stencil buffer.
Set depth stencil surface each time the render target is changed (this may or may not help the render to texture bug).
This commit is contained in:
aignacio_sf 2006-01-04 01:36:31 +00:00
parent 80667761b4
commit ac39c20f8e
2 changed files with 192 additions and 92 deletions

View File

@ -66,8 +66,10 @@
#define DEBUG_LRU false #define DEBUG_LRU false
#define DEFAULT_ENABLE_LRU true
#define DEFAULT_ENABLE_DX_MANAGED false
#define DBG_S if (false) {
#define DBG_E }
TypeHandle DXGraphicsStateGuardian9::_type_handle; TypeHandle DXGraphicsStateGuardian9::_type_handle;
@ -529,6 +531,8 @@ do_clear(const RenderBuffer &buffer) {
DWORD main_flags = 0; DWORD main_flags = 0;
DWORD aux_flags = 0; DWORD aux_flags = 0;
DBG_S dxgsg9_cat.error ( ) << "DXGraphicsStateGuardian9::do_clear\n"; DBG_E
//set appropriate flags //set appropriate flags
if (buffer_type & RenderBuffer::T_back) { if (buffer_type & RenderBuffer::T_back) {
main_flags |= D3DCLEAR_TARGET; main_flags |= D3DCLEAR_TARGET;
@ -545,6 +549,9 @@ do_clear(const RenderBuffer &buffer) {
} }
if ((main_flags | aux_flags) != 0) { if ((main_flags | aux_flags) != 0) {
DBG_S dxgsg9_cat.error ( ) << "ccccc DXGraphicsStateGuardian9::really do_clear\n"; DBG_E
HRESULT hr = _d3d_device->Clear(0, NULL, main_flags | aux_flags, _d3dcolor_clear_value, HRESULT hr = _d3d_device->Clear(0, NULL, main_flags | aux_flags, _d3dcolor_clear_value,
_depth_clear_value, (DWORD)_stencil_clear_value); _depth_clear_value, (DWORD)_stencil_clear_value);
if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) { if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) {
@ -593,6 +600,9 @@ do_clear(const RenderBuffer &buffer) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian9:: void DXGraphicsStateGuardian9::
prepare_display_region() { prepare_display_region() {
// DBG_S dxgsg9_cat.error ( ) << "DXGraphicsStateGuardian9::PRE prepare_display_region\n"; DBG_E
if (_current_display_region == (DisplayRegion*)0L) { if (_current_display_region == (DisplayRegion*)0L) {
dxgsg9_cat.error() dxgsg9_cat.error()
<< "Invalid NULL display region in prepare_display_region()\n"; << "Invalid NULL display region in prepare_display_region()\n";
@ -600,9 +610,13 @@ prepare_display_region() {
} else if (_current_display_region != _actual_display_region) { } else if (_current_display_region != _actual_display_region) {
_actual_display_region = _current_display_region; _actual_display_region = _current_display_region;
// DBG_S dxgsg9_cat.error ( ) << "DXGraphicsStateGuardian9::prepare_display_region\n"; DBG_E
int l, u, w, h; int l, u, w, h;
_actual_display_region->get_region_pixels_i(l, u, w, h); _actual_display_region->get_region_pixels_i(l, u, w, h);
DBG_S dxgsg9_cat.error ( ) << "display_region " << l << " " << u << " " << w << " " << h << "\n"; DBG_E
// Create the viewport // Create the viewport
D3DVIEWPORT9 vp = { l, u, w, h, 0.0f, 1.0f }; D3DVIEWPORT9 vp = { l, u, w, h, 0.0f, 1.0f };
HRESULT hr = _d3d_device->SetViewport(&vp); HRESULT hr = _d3d_device->SetViewport(&vp);
@ -701,35 +715,15 @@ prepare_lens() {
bool DXGraphicsStateGuardian9:: bool DXGraphicsStateGuardian9::
begin_frame() { begin_frame() {
DBG_S dxgsg9_cat.error ( ) << "^^^^^^^^^^^ begin_frame \n"; DBG_E
GraphicsStateGuardian::begin_frame();
if (_lru) if (_lru)
{ {
_lru -> begin_frame ( ); _lru -> begin_frame ( );
} }
return GraphicsStateGuardian::begin_frame();
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian9::begin_scene
// Access: Public, Virtual
// Description: Called between begin_frame() and end_frame() to mark
// the beginning of drawing commands for a "scene"
// (usually a particular DisplayRegion) within a frame.
// All 3-D drawing commands, except the clear operation,
// must be enclosed within begin_scene() .. end_scene().
//
// The return value is true if successful (in which case
// the scene will be drawn and end_scene() will be
// called later), or false if unsuccessful (in which
// case nothing will be drawn and end_scene() will not
// be called).
////////////////////////////////////////////////////////////////////
bool DXGraphicsStateGuardian9::
begin_scene() {
if (!GraphicsStateGuardian::begin_scene()) {
return false;
}
HRESULT hr = _d3d_device->BeginScene(); HRESULT hr = _d3d_device->BeginScene();
if (FAILED(hr)) { if (FAILED(hr)) {
@ -753,6 +747,54 @@ begin_scene() {
return true; return true;
} }
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian9::begin_scene
// Access: Public, Virtual
// Description: Called between begin_frame() and end_frame() to mark
// the beginning of drawing commands for a "scene"
// (usually a particular DisplayRegion) within a frame.
// All 3-D drawing commands, except the clear operation,
// must be enclosed within begin_scene() .. end_scene().
//
// The return value is true if successful (in which case
// the scene will be drawn and end_scene() will be
// called later), or false if unsuccessful (in which
// case nothing will be drawn and end_scene() will not
// be called).
////////////////////////////////////////////////////////////////////
bool DXGraphicsStateGuardian9::
begin_scene() {
if (!GraphicsStateGuardian::begin_scene()) {
return false;
}
DBG_S dxgsg9_cat.error ( ) << "DXGraphicsStateGuardian9::begin_scene\n"; DBG_E
/*
HRESULT hr = _d3d_device->BeginScene();
if (FAILED(hr)) {
if (hr == D3DERR_DEVICELOST) {
if (dxgsg9_cat.is_debug()) {
dxgsg9_cat.debug()
<< "BeginScene returns D3DERR_DEVICELOST" << endl;
}
check_cooperative_level();
} else {
dxgsg9_cat.error()
<< "BeginScene failed, unhandled error hr == "
<< D3DERRORSTRING(hr) << endl;
throw_event("panda3d-render-error");
}
return false;
}
*/
return true;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian9::end_scene // Function: DXGraphicsStateGuardian9::end_scene
// Access: Public, Virtual // Access: Public, Virtual
@ -764,6 +806,10 @@ begin_scene() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian9:: void DXGraphicsStateGuardian9::
end_scene() { end_scene() {
DBG_S dxgsg9_cat.error ( ) << "DXGraphicsStateGuardian9::end_scene\n"; DBG_E
/*
HRESULT hr = _d3d_device->EndScene(); HRESULT hr = _d3d_device->EndScene();
if (FAILED(hr)) { if (FAILED(hr)) {
@ -781,6 +827,8 @@ end_scene() {
} }
return; return;
} }
*/
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -793,6 +841,26 @@ end_scene() {
void DXGraphicsStateGuardian9:: void DXGraphicsStateGuardian9::
end_frame() { end_frame() {
DBG_S dxgsg9_cat.error ( ) << "@@@@@@@@@@ end_frame \n"; DBG_E
HRESULT hr = _d3d_device->EndScene();
if (FAILED(hr)) {
if (hr == D3DERR_DEVICELOST) {
if (dxgsg9_cat.is_debug()) {
dxgsg9_cat.debug()
<< "EndScene returns DeviceLost\n";
}
check_cooperative_level();
} else {
dxgsg9_cat.error()
<< "EndScene failed, unhandled error hr == " << D3DERRORSTRING(hr);
throw_event("panda3d-render-error");
}
return;
}
if (_lru) if (_lru)
{ {
int frames; int frames;
@ -3906,6 +3974,9 @@ show_frame() {
return; return;
} }
DBG_S dxgsg9_cat.error ( ) << "- - - - - DXGraphicsStateGuardian9::show_frame\n"; DBG_E
HRESULT hr; HRESULT hr;
if (_swap_chain) { if (_swap_chain) {

View File

@ -23,17 +23,12 @@
// ISSUES: // ISSUES:
// size issues
// texture size must not exeeed the original frame buffer width
// or height due to the size of the original depth/stencil buffer
// render to texure format
// can be specified via the DXGraphicsStateGuardian9 member
// _render_to_texture_d3d_format default = D3DFMT_X8R8G8B8
// should check texture creation with CheckDepthStencilMatch // should check texture creation with CheckDepthStencilMatch
// support copy from texture to ram? // support copy from texture to ram?
// check D3DCAPS2_DYNAMICTEXTURES // check D3DCAPS2_DYNAMICTEXTURES
#define DBG_S if (false) {
#define DBG_E }
#define FL << "\n" << __FILE__ << " " << __LINE__ << "\n" #define FL << "\n" << __FILE__ << " " << __LINE__ << "\n"
TypeHandle wdxGraphicsBuffer9::_type_handle; TypeHandle wdxGraphicsBuffer9::_type_handle;
@ -71,6 +66,7 @@ wdxGraphicsBuffer9(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
wdxGraphicsBuffer9:: wdxGraphicsBuffer9::
~wdxGraphicsBuffer9() { ~wdxGraphicsBuffer9() {
this -> close_buffer ( );
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -88,6 +84,8 @@ begin_frame() {
return false; return false;
} }
DBG_S dxgsg9_cat.error ( ) << "wdxGraphicsBuffer9::begin_frame\n"; DBG_E
DXGraphicsStateGuardian9 *dxgsg; DXGraphicsStateGuardian9 *dxgsg;
DCAST_INTO_R(dxgsg, _gsg, false); DCAST_INTO_R(dxgsg, _gsg, false);
@ -118,6 +116,8 @@ begin_render_texture() {
state = false; state = false;
render_target_index = 0; render_target_index = 0;
DBG_S dxgsg9_cat.error ( ) << "wdxGraphicsBuffer9::begin_render_texture\n"; DBG_E
if (dxgsg -> _d3d_device) { if (dxgsg -> _d3d_device) {
Texture *tex = get_texture(0); Texture *tex = get_texture(0);
tex->set_render_to_texture(true); tex->set_render_to_texture(true);
@ -166,6 +166,13 @@ begin_render_texture() {
hr = dxgsg -> _d3d_device -> SetDepthStencilSurface (this -> _new_z_stencil_surface); hr = dxgsg -> _d3d_device -> SetDepthStencilSurface (this -> _new_z_stencil_surface);
if (SUCCEEDED (hr)) { if (SUCCEEDED (hr)) {
} else {
dxgsg9_cat.error ( ) << "SetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
}
} else {
hr = dxgsg -> _d3d_device -> SetDepthStencilSurface (_z_stencil_buffer);
if (SUCCEEDED (hr)) {
} else { } else {
dxgsg9_cat.error ( ) << "SetDepthStencilSurface " << D3DERRORSTRING(hr) FL; dxgsg9_cat.error ( ) << "SetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
} }
@ -194,13 +201,15 @@ begin_render_texture() {
void wdxGraphicsBuffer9:: void wdxGraphicsBuffer9::
end_render_texture() { end_render_texture() {
if (_gsg != (GraphicsStateGuardian *)NULL) { DBG_S dxgsg9_cat.error ( ) << "wdxGraphicsBuffer9::end_render_texture\n"; DBG_E
DXGraphicsStateGuardian9 *dxgsg; if (_gsg != (GraphicsStateGuardian *)NULL) {
DCAST_INTO_V(dxgsg, _gsg);
if (dxgsg -> _d3d_device) { DXGraphicsStateGuardian9 *dxgsg;
// restore render context DCAST_INTO_V(dxgsg, _gsg);
if (dxgsg -> _d3d_device) {
// restore render context
HRESULT hr; HRESULT hr;
int render_target_index; int render_target_index;
@ -276,17 +285,26 @@ select_cube_map(int cube_map_index) {
hr = direct_3d_cube_texture -> GetCubeMapSurface ( hr = direct_3d_cube_texture -> GetCubeMapSurface (
(D3DCUBEMAP_FACES) _cube_map_index, mipmap_level, &_direct_3d_surface); (D3DCUBEMAP_FACES) _cube_map_index, mipmap_level, &_direct_3d_surface);
if (SUCCEEDED (hr)) { if (SUCCEEDED (hr)) {
hr = dxgsg -> _d3d_device -> SetRenderTarget (render_target_index, hr = dxgsg -> _d3d_device -> SetRenderTarget (render_target_index, _direct_3d_surface);
_direct_3d_surface);
if (SUCCEEDED (hr)) { if (SUCCEEDED (hr)) {
if (this -> _new_z_stencil_surface) { if (this -> _new_z_stencil_surface) {
hr = dxgsg -> _d3d_device -> SetDepthStencilSurface (this -> _new_z_stencil_surface); hr = dxgsg -> _d3d_device -> SetDepthStencilSurface (_new_z_stencil_surface);
if (SUCCEEDED (hr)) {
} else {
dxgsg9_cat.error ( ) << "SetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
}
} else {
hr = dxgsg -> _d3d_device -> SetDepthStencilSurface (_z_stencil_buffer);
if (SUCCEEDED (hr)) { if (SUCCEEDED (hr)) {
} else { } else {
dxgsg9_cat.error ( ) << "SetDepthStencilSurface " << D3DERRORSTRING(hr) FL; dxgsg9_cat.error ( ) << "SetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
} }
} }
DBG_S dxgsg9_cat.error ( ) << "select_cube_map " << _cube_map_index << "\n"; DBG_E
} else { } else {
dxgsg9_cat.error ( ) << "SetRenderTarget " << D3DERRORSTRING(hr) FL; dxgsg9_cat.error ( ) << "SetRenderTarget " << D3DERRORSTRING(hr) FL;
} }
@ -294,7 +312,6 @@ select_cube_map(int cube_map_index) {
dxgsg9_cat.error ( ) << "GetCubeMapSurface " << D3DERRORSTRING(hr) FL; dxgsg9_cat.error ( ) << "GetCubeMapSurface " << D3DERRORSTRING(hr) FL;
} }
} else { } else {
// error: invalid cube map face index
dxgsg9_cat.error ( ) << "Invalid Cube Map Face Index " << _cube_map_index FL; dxgsg9_cat.error ( ) << "Invalid Cube Map Face Index " << _cube_map_index FL;
} }
} }
@ -317,6 +334,8 @@ make_current() {
DCAST_INTO_V(dxgsg, _gsg); DCAST_INTO_V(dxgsg, _gsg);
// do nothing here // do nothing here
DBG_S dxgsg9_cat.error ( ) << "wdxGraphicsBuffer9::make_current\n"; DBG_E
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -420,64 +439,74 @@ open_buffer() {
Texture *tex = get_texture(tex_index); Texture *tex = get_texture(tex_index);
// SET render to texture // render to texture must be set
tex->set_render_to_texture(true); tex->set_render_to_texture(true);
TextureContext *tc = tex->prepare_now(_gsg->get_prepared_objects(), _gsg); TextureContext *tc = tex->prepare_now(_gsg->get_prepared_objects(), _gsg);
if (tc != NULL) { if (tc != NULL) {
HRESULT hr;
IDirect3DSurface9 *_depth_stencil_surface;
_dx_texture_context9 = DCAST (DXTextureContext9, tc); _dx_texture_context9 = DCAST (DXTextureContext9, tc);
// ***** CREATE A DEPTH STENCIL BUFFER IF NEEDED // create a depth stencil buffer if needed
hr = dxgsg -> _d3d_device -> GetDepthStencilSurface (&_depth_stencil_surface);
HRESULT hr; if (SUCCEEDED (hr))
IDirect3DSurface9 *_depth_stencil_surface;
hr = dxgsg -> _d3d_device -> GetDepthStencilSurface (&_depth_stencil_surface);
if (SUCCEEDED (hr))
{
D3DSURFACE_DESC surface_description;
hr = _depth_stencil_surface -> GetDesc (&surface_description);
if (SUCCEEDED (hr))
{
UINT width;
UINT height;
D3DFORMAT format;
D3DMULTISAMPLE_TYPE multisample_type;
DWORD multisample_quality;
BOOL discard;
width = tex -> get_x_size ( );
height = tex -> get_y_size ( );
format = surface_description.Format;
multisample_type = surface_description.MultiSampleType;
multisample_quality = surface_description.MultiSampleQuality;
discard = true;
hr = dxgsg -> _d3d_device -> CreateDepthStencilSurface (
width, height, format, multisample_type, multisample_quality,
discard, &this -> _new_z_stencil_surface, NULL);
if (SUCCEEDED (hr)) {
} else {
dxgsg9_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL;
}
}
else
{
dxgsg9_cat.error ( ) << "GetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
}
_depth_stencil_surface -> Release ( );
}
else
{
dxgsg9_cat.error ( ) << "GetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
}
{ {
D3DSURFACE_DESC surface_description;
// get and copy the current depth stencil's parameters for the new buffer
hr = _depth_stencil_surface -> GetDesc (&surface_description);
if (SUCCEEDED (hr)) {
UINT width;
UINT height;
D3DFORMAT format;
D3DMULTISAMPLE_TYPE multisample_type;
DWORD multisample_quality;
BOOL discard;
width = tex -> get_x_size ( );
height = tex -> get_y_size ( );
DBG_S dxgsg9_cat.error ( ) << "-------------RTT SIZE " << "t width " << width << " t height " << height FL; DBG_E
if (surface_description.Width < width || surface_description.Height < height) {
format = surface_description.Format;
multisample_type = surface_description.MultiSampleType;
multisample_quality = surface_description.MultiSampleQuality;
discard = false;
hr = dxgsg -> _d3d_device -> CreateDepthStencilSurface (
width, height, format, multisample_type, multisample_quality,
discard, &this -> _new_z_stencil_surface, NULL);
if (SUCCEEDED (hr)) {
DBG_S dxgsg9_cat.error ( ) << "-------------OK CreatedDepthStencilSurface " << D3DERRORSTRING(hr) FL; DBG_E
state = true;
} else {
dxgsg9_cat.error ( ) << "CreateDepthStencilSurface " << D3DERRORSTRING(hr) FL;
}
}
else {
// no need to create a separate depth stencil buffer since
// the current depth stencil buffer size is big enough
state = true;
}
}
else {
dxgsg9_cat.error ( ) << "GetDesc " << D3DERRORSTRING(hr) FL;
}
_depth_stencil_surface -> Release ( );
}
else {
dxgsg9_cat.error ( ) << "GetDepthStencilSurface " << D3DERRORSTRING(hr) FL;
}
if (state) {
_is_valid = true; _is_valid = true;
state = true;
} }
} }