Added debug code and some formatiing changes.

This commit is contained in:
aignacio_sf 2006-01-25 22:34:09 +00:00
parent e62c1cb763
commit 757c5edae6

View File

@ -47,6 +47,8 @@ CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
_vertex_size = 0; _vertex_size = 0;
_vertex_element_array = 0; _vertex_element_array = 0;
_name = s->get_name ( );
if (header == "//Cg") { if (header == "//Cg") {
// CGcontext is created once during Reset ( ) // CGcontext is created once during Reset ( )
@ -87,13 +89,17 @@ CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
return; return;
} }
this -> _name = s->get_name ( );
// Compile the program. // Compile the program.
try_cg_compile(s, gsg); try_cg_compile(s, gsg);
cerr << _cg_errors; cerr << _cg_errors;
return; return;
} }
if (header == "//hlsl") {
s -> _text.c_str ( );
}
#endif #endif
cerr << s->get_name() << ": unrecognized shader language " << header << "\n"; cerr << s->get_name() << ": unrecognized shader language " << header << "\n";
} }
@ -107,8 +113,7 @@ CLP(ShaderContext)::
~CLP(ShaderContext)() { ~CLP(ShaderContext)() {
release_resources(); release_resources();
if (_vertex_element_array) if (_vertex_element_array) {
{
delete _vertex_element_array; delete _vertex_element_array;
_vertex_element_array = 0; _vertex_element_array = 0;
} }
@ -212,6 +217,14 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
return false; return false;
} }
// DEBUG: output the generated program
DBG_SH3
const char *program;
program = cgGetProgramString (_cg_program[1], CG_COMPILED_PROGRAM);
dxgsg9_cat.debug ( ) << program << "\n";
DBG_E
// The following code is present to work around a bug in the Cg compiler. // The following code is present to work around a bug in the Cg compiler.
// It does not generate correct code for shadow map lookups when using arbfp1. // It does not generate correct code for shadow map lookups when using arbfp1.
// This is a particularly onerous limitation, given that arbfp1 is the only // This is a particularly onerous limitation, given that arbfp1 is the only
@ -304,7 +317,6 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
BOOL paramater_shadowing; BOOL paramater_shadowing;
DWORD assembly_flags; DWORD assembly_flags;
// ?????
paramater_shadowing = FALSE; paramater_shadowing = FALSE;
assembly_flags = 0; assembly_flags = 0;
@ -365,13 +377,11 @@ bind(GSG *gsg) {
// Bind the shaders. // Bind the shaders.
hr = cgD3D9BindProgram(_cg_program[SHADER_type_vert]); hr = cgD3D9BindProgram(_cg_program[SHADER_type_vert]);
if (FAILED (hr)) if (FAILED (hr)) {
{
dxgsg9_cat.error() << "cgD3D9BindProgram vertex shader failed\n"; dxgsg9_cat.error() << "cgD3D9BindProgram vertex shader failed\n";
} }
hr = cgD3D9BindProgram(_cg_program[SHADER_type_frag]); hr = cgD3D9BindProgram(_cg_program[SHADER_type_frag]);
if (FAILED (hr)) if (FAILED (hr)) {
{
dxgsg9_cat.error() << "cgD3D9BindProgram pixel shader failed\n"; dxgsg9_cat.error() << "cgD3D9BindProgram pixel shader failed\n";
} }
@ -382,15 +392,13 @@ bind(GSG *gsg) {
IDirect3DPixelShader9 *pixel_shader; IDirect3DPixelShader9 *pixel_shader;
hr = gsg -> _d3d_device -> GetVertexShader (&vertex_shader); hr = gsg -> _d3d_device -> GetVertexShader (&vertex_shader);
if (FAILED (hr)) if (FAILED (hr)) {
{
dxgsg9_cat.error() dxgsg9_cat.error()
<< "GetVertexShader ( ) failed " << "GetVertexShader ( ) failed "
<< D3DERRORSTRING(hr); << D3DERRORSTRING(hr);
} }
hr = gsg -> _d3d_device -> GetPixelShader (&pixel_shader); hr = gsg -> _d3d_device -> GetPixelShader (&pixel_shader);
if (FAILED (hr)) if (FAILED (hr)) {
{
dxgsg9_cat.error() dxgsg9_cat.error()
<< "GetPixelShader ( ) failed " << "GetPixelShader ( ) failed "
<< D3DERRORSTRING(hr); << D3DERRORSTRING(hr);
@ -557,39 +565,39 @@ p_matrix = &(gsg -> _internal_transform -> get_mat ( ));
} }
DBG_SH4 DBG_SH4
const float *data; const float *data;
data = model_matrix -> get_data ( ); data = model_matrix -> get_data ( );
dxgsg9_cat.debug ( ) << "MODELVIEW MATRIX \n" << dxgsg9_cat.debug ( ) << "MODELVIEW MATRIX \n" <<
data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" << data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" <<
data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" << data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" <<
data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" << data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" <<
data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n"; data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n";
model_matrix = &(gsg -> _external_transform -> get_mat ( )); model_matrix = &(gsg -> _external_transform -> get_mat ( ));
data = model_matrix -> get_data ( ); data = model_matrix -> get_data ( );
dxgsg9_cat.debug ( ) << "EXTERNAL MODELVIEW MATRIX \n" << dxgsg9_cat.debug ( ) << "EXTERNAL MODELVIEW MATRIX \n" <<
data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" << data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" <<
data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" << data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" <<
data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" << data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" <<
data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n"; data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n";
data = projection_matrix -> get_data ( ); data = projection_matrix -> get_data ( );
dxgsg9_cat.debug ( ) << "PROJECTION MATRIX \n" << dxgsg9_cat.debug ( ) << "PROJECTION MATRIX \n" <<
data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" << data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" <<
data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" << data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" <<
data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" << data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" <<
data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n"; data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n";
D3DMATRIX d3d_matrix; D3DMATRIX d3d_matrix;
data = &d3d_matrix._11; data = &d3d_matrix._11;
gsg -> _d3d_device -> GetTransform (D3DTS_WORLDMATRIX(0), &d3d_matrix); gsg -> _d3d_device -> GetTransform (D3DTS_WORLDMATRIX(0), &d3d_matrix);
dxgsg9_cat.debug ( ) << "D3DTS_WORLDMATRIX(0) \n" << dxgsg9_cat.debug ( ) << "D3DTS_WORLDMATRIX(0) \n" <<
data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" << data[ 0] << " " << data[ 1] << " " << data[ 2] << " " << data[ 3] << "\n" <<
data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" << data[ 4] << " " << data[ 5] << " " << data[ 6] << " " << data[ 7] << "\n" <<
data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" << data[ 8] << " " << data[ 9] << " " << data[10] << " " << data[11] << "\n" <<
data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n"; data[12] << " " << data[13] << " " << data[14] << " " << data[15] << "\n";
DBG_E DBG_E
/* /*
@ -641,8 +649,7 @@ gsg -> _d3d_device -> GetTransform (D3DTS_WORLDMATRIX(2), &d3d_matrix);
<< " size " << cgD3D9TypeToSize(cgGetParameterType(p)) << " size " << cgD3D9TypeToSize(cgGetParameterType(p))
<< D3DERRORSTRING(hr); << D3DERRORSTRING(hr);
switch (hr) switch (hr) {
{
case CGD3D9ERR_INVALIDPARAM: case CGD3D9ERR_INVALIDPARAM:
dxgsg9_cat.error() << "CGD3D9ERR_INVALIDPARAM\n"; dxgsg9_cat.error() << "CGD3D9ERR_INVALIDPARAM\n";
break; break;
@ -734,20 +741,50 @@ issue_parameters(GSG *gsg)
data = input->get_vector().get_data(); data = input->get_vector().get_data();
#define TOTAL_VECTORS 32
int start_register;
int total_vectors;
float constant_buffer [TOTAL_VECTORS * 4];
float constant_buffer_result [TOTAL_VECTORS * 4];
start_register = 0;
total_vectors = TOTAL_VECTORS;
DBG_SH3 DBG_SH3
char string [256]; char string [256];
sprintf (string, "%f %f %f %f \n", data [0], data [1], data [2], data [3]); sprintf (string, "%f %f %f %f \n", data [0], data [1], data [2], data [3]);
dxgsg9_cat.debug ( ) << string; dxgsg9_cat.debug ( ) << string;
gsg -> _d3d_device -> GetPixelShaderConstantF (start_register, constant_buffer, total_vectors);
DBG_E DBG_E
HRESULT hr; HRESULT hr;
hr = cgD3D9SetUniform (_cg_fbind[i].parameter, data); hr = cgD3D9SetUniform (_cg_fbind[i].parameter, data);
if (FAILED (hr)) if (FAILED (hr)) {
{
dxgsg9_cat.error() << "cgD3D9SetUniform failed " << D3DERRORSTRING(hr); dxgsg9_cat.error() << "cgD3D9SetUniform failed " << D3DERRORSTRING(hr);
} }
DBG_SH3
gsg -> _d3d_device -> GetPixelShaderConstantF (start_register, constant_buffer_result, total_vectors);
int index;
for (index = 0; index < (total_vectors * 4); index++)
{
if (constant_buffer [index] != constant_buffer_result [index])
{
char string [256];
sprintf (string, "reg %d [%d] %f %f\n", index / 4, index & 0x03, constant_buffer [index], constant_buffer_result [index]);
dxgsg9_cat.debug ( ) << string;
}
}
DBG_E
} }
// Pass in k-float4x4 parameters. // Pass in k-float4x4 parameters.
@ -870,21 +907,22 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
#ifdef HAVE_CGDX9 #ifdef HAVE_CGDX9
if (gsg -> _cg_context) { if (gsg -> _cg_context) {
/* ?????
#ifdef SUPPORT_IMMEDIATE_MODE #ifdef SUPPORT_IMMEDIATE_MODE
/*
if (gsg->_use_sender) { if (gsg->_use_sender) {
cerr << "immediate mode shaders not implemented yet\n"; cerr << "immediate mode shaders not implemented yet\n";
} else return;
#endif // SUPPORT_IMMEDIATE_MODE }
*/ */
#endif // SUPPORT_IMMEDIATE_MODE
// Create and cache a VertexElementArray that does most of the // Create and cache a VertexElementArray that does most of the
// mapping from the vertex shader inputs to a VertexElementArray. // mapping from the vertex shader inputs to a VertexElementArray.
// This can be done since a vertex shader has a well defined input. // This can be done since a vertex shader has a well defined input.
// Later when the vertex buffer is applied the offsets will // Later when the vertex buffer is applied the offsets will
// be properly mapped. // be properly mapped.
if (_vertex_element_array == 0) if (_vertex_element_array == 0) {
{
const GeomVertexArrayData *array_data; const GeomVertexArrayData *array_data;
Geom::NumericType numeric_type; Geom::NumericType numeric_type;
int start, stride, num_values; int start, stride, num_values;
@ -915,8 +953,7 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
} }
} }
} }
if (gsg->_vertex_data->get_array_info(name, array_data, num_values, numeric_type, start, stride)) if (gsg->_vertex_data->get_array_info(name, array_data, num_values, numeric_type, start, stride)) {
{
/* /*
// ORIGINAL OpenGL CODE // ORIGINAL OpenGL CODE
const unsigned char *client_pointer = gsg->setup_array_data(array_data); const unsigned char *client_pointer = gsg->setup_array_data(array_data);
@ -1044,7 +1081,8 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
<< " numeric_type " << numeric_type << " numeric_type " << numeric_type
<< " start " << start << " start " << start
<< " stride " << stride << " stride " << stride
<< "\n"; DBG_E << "\n";
DBG_E
} else { } else {
dxgsg9_cat.error ( ) << "get_array_info ( ) failed\n"; dxgsg9_cat.error ( ) << "get_array_info ( ) failed\n";
@ -1054,14 +1092,12 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
int state; int state;
state = vertex_element_array -> add_end_vertex_element ( ); state = vertex_element_array -> add_end_vertex_element ( );
if (state) if (state) {
{ if (cgD3D9ValidateVertexDeclaration (_cg_program [SHADER_type_vert],
if (cgD3D9ValidateVertexDeclaration (_cg_program [SHADER_type_vert], vertex_element_array -> vertex_element_array) == CG_TRUE) vertex_element_array -> vertex_element_array) == CG_TRUE) {
{
dxgsg9_cat.debug() << "|||||cgD3D9ValidateVertexDeclaration succeeded\n"; dxgsg9_cat.debug() << "|||||cgD3D9ValidateVertexDeclaration succeeded\n";
} }
else else {
{
dxgsg9_cat.error() << "********************************************\n"; dxgsg9_cat.error() << "********************************************\n";
dxgsg9_cat.error() << "***cgD3D9ValidateVertexDeclaration failed***\n"; dxgsg9_cat.error() << "***cgD3D9ValidateVertexDeclaration failed***\n";
dxgsg9_cat.error() << "********************************************\n"; dxgsg9_cat.error() << "********************************************\n";
@ -1073,8 +1109,7 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg)
_vertex_element_array = vertex_element_array; _vertex_element_array = vertex_element_array;
} }
else else {
{
dxgsg9_cat.error ( ) << "VertexElementArray creation failed\n"; dxgsg9_cat.error ( ) << "VertexElementArray creation failed\n";
delete vertex_element_array; delete vertex_element_array;
} }