* add a script to run cg compiler on glsl file:
  + handy to check the syntax
  + output the asm of the shader
  - unfortunately don't support latest glsl construct but better than nothing
* really delete resources before context destruction
* wanted to play with opengl3 timer for profiling but not conclusive, just keeping code around for future use


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5278 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2012-06-08 18:14:47 +00:00
parent cb7f27cd76
commit b534fcc1bc
7 changed files with 281 additions and 38 deletions

View File

@ -32,19 +32,6 @@ PWD_old=$PWD
# Go to the script directory
cd `dirname $current_script`
# Setup LD_PRELOAD to work-around issue 1003
SDL_SO=`pwd`/plugins/libpcsx2_SDL.so
if [ -e "$SDL_SO" ]
then
echo "INFO: LD_PRELOAD $SDL_SO"
if [ -n "$LD_PRELOAD" ]
then
LD_PRELOAD="$SDL_SO:$LD_PRELOAD"
else
LD_PRELOAD="$SDL_SO"
fi
fi
# Launch PCSX2
if [ -x pcsx2 ]
then

127
linux_various/validate_glsl.sh Executable file
View File

@ -0,0 +1,127 @@
#!/bin/sh
# copyright (c) 2011 Gregory Hainaut
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
INPUT=0
MACRO=""
ENTRY="-noentry"
TEST=/tmp/test.glsl
GL_VERSION=330
NOFRAG=0
NOVERT=0
# VERT="cgc -oglsl -profile glslv -po version=$GL_VERSION"
# FRAG="cgc -oglsl -profile glslf -po version=$GL_VERSION"
# Uniform buffer not supported on glsl ...
VERT="cgc -oglsl -profile vp40"
FRAG="cgc -oglsl -profile fp40"
######################################################
# Options
######################################################
help()
{
cat <<EOF
Help:
--input <file> : input glsl file (mandatory)
--macro <name> <value> : set a macro. Can be repeated
--entry <name> : set an entry point. Note: print the ASM output of the program
--test_ZZ : test of zzogl glsl file
--test_dx : test of gsdx glsl file
--nofrag : disable fragment processing
--novert : disable vertex processing
EOF
exit
}
while [ -n "$1" ]; do
case $1 in
--help|--h) help;shift 1;;
--input|--i) INPUT=$2; shift 2;;
--macro|--m) MACRO="${MACRO}#define $2 $3\n"; shift 3;;
--entry|--e) ENTRY="-entry $2";shift 2;;
--test_ZZ ) TEST_ZZOGL=1; shift 1;;
--test_dx ) TEST_GSDX=1; shift 1;;
--nofrag) NOFRAG=1; shift 1;;
--novert) NOVERT=1; shift 1;;
--*) echo "ERROR: $1 option does not exists. Use -h for help";exit 1;;
*) break;;
esac
done
if [ "$INPUT" = "0" ] ; then
help
fi
######################################################
# Functions
######################################################
head()
{
\rm -f $TEST
touch $TEST
echo "#version $GL_VERSION\n" >> $TEST
}
tail()
{
cat $INPUT >> $TEST
# Some layout syntax (420) are not supported
# so I remove them (a bit overkill)
#sed -i -e 's/layout(.*)//' $TEST
sed -i -e 's/layout(binding.*)//' $TEST
sed -i -e 's/layout(location.*)//' $TEST
sed -i -e 's/, binding.*)/)/' $TEST
}
vertex_test()
{
head
echo "#define VERTEX_SHADER 1" >> $TEST
echo $MACRO >> $TEST
tail
echo "Vertex check with macro : $MACRO"
$VERT $ENTRY $TEST
echo ""
}
fragment_test()
{
head
echo "#define FRAGMENT_SHADER 1" >> $TEST
echo "$MACRO" >> $TEST
echo "Fragment check with macro : $MACRO"
tail
$FRAG $ENTRY $TEST
echo ""
}
######################################################
# Main
######################################################
if [ "$TEST_ZZOGL" = '1' ] ; then
./test_shader.sh --input $INPUT --novert --m TEST_AEM 1
./test_shader.sh --input $INPUT --novert --m REGION_REPEAT 1
./test_shader.sh --input $INPUT --novert --m EXACT_COLOR 1
./test_shader.sh --input $INPUT --m WRITE_DEPTH 1
./test_shader.sh --input $INPUT
elif [ "$TEST_GSDX" = '1' ] ; then
echo "not yet implemented"
else
if [ "$NOVERT" = '0' ] ; then vertex_test; fi
if [ "$NOFRAG" = '0' ] ; then fragment_test; fi
fi

View File

@ -349,9 +349,9 @@ EXPORT_C_(void) GSclose()
{
FUNCLOG
ZZDestroy();
// Clean shader. Must be done before the context is delete
ZZshExitCleaning();
ZZDestroy();
GLWin.CloseWindow();

View File

@ -0,0 +1,82 @@
/* ZZ Open GL graphics plugin
* Copyright (c)2009-2012 zeydlitz@gmail.com, arcum42@gmail.com, gregory.hainaut@gmail.com
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "Profile_gl3.h"
GPU_Profile GPU_Timer;
void GPU_Profile::dump(bool flush)
{
u32 high_limit;
if (flush) high_limit = 1;
else high_limit = 1000;
while (datas.size() > high_limit) {
ProfileInfo data_start = datas.front();
datas.pop_front();
ProfileInfo data_stop = datas.front();
datas.pop_front();
u32 gpu_time = read_diff_timers(data_start.timer, data_stop.timer);
#ifdef ENABLE_MARKER
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, format("Time %6dus", gpu_time).c_str());
#else
fprintf(stderr, "Frame %d (%d): %6dus\n", data_start.frame, data_start.draw, gpu_time);
#endif
}
}
void GPU_Profile::create_timer()
{
u32 timer = 0;
#ifdef GLSL4_API
glGenQueries(1, &timer);
glQueryCounter(timer, GL_TIMESTAMP);
#endif
datas.push_back(ProfileInfo(timer, frame, draw));
#ifdef ENABLE_MARKER
dump(true);
#endif
}
u32 GPU_Profile::read_diff_timers(u32 start_timer, u32 stop_timer)
{
#ifdef GLSL4_API
if(!start_timer || !stop_timer) return -1;
int stopTimerAvailable = 0;
while (!stopTimerAvailable)
glGetQueryObjectiv(stop_timer, GL_QUERY_RESULT_AVAILABLE, &stopTimerAvailable);
u64 start, stop = 0;
// Note: timers have a precision of the ns, so you need 64 bits value to avoid overflow!
glGetQueryObjectui64v(start_timer, GL_QUERY_RESULT, &start);
glGetQueryObjectui64v(stop_timer, GL_QUERY_RESULT, &stop);
// delete timer
glDeleteQueries(1, &start_timer);
glDeleteQueries(1, &stop_timer);
return (stop-start)/1000;
#else
return 0;
#endif
}

View File

@ -0,0 +1,57 @@
/* ZZ Open GL graphics plugin
* Copyright (c)2009-2012 zeydlitz@gmail.com, arcum42@gmail.com, gregory.hainaut@gmail.com
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "Util.h"
#ifndef _PROFILE_GL3_H_
#define _PROFILE_GL3_H_
#define ENABLE_MARKER // Fire some marker for opengl Debugger (apitrace, gdebugger)
class GPU_Profile {
struct ProfileInfo {
u32 timer;
u32 frame;
u32 draw;
ProfileInfo(u32 timer, u32 frame, u32 draw) : timer(timer), frame(frame), draw(draw) {}
ProfileInfo(u32 timer) : timer(timer), frame(0), draw(0) {}
};
std::list<ProfileInfo> datas;
u32 frame;
u32 draw;
public:
GPU_Profile() : frame(0), draw(0) {
datas.clear();
}
void inc_draw() { draw++;}
void inc_frame() { frame++;}
void create_timer();
u32 read_diff_timers(u32 start_timer, u32 stop_timer);
void dump(bool flush = false);
};
extern GPU_Profile GPU_Timer;
#endif

View File

@ -243,9 +243,7 @@ void ZZshGLEnableProfile() {
// The same function for texture, also to cgGLEnable
void ZZshGLSetTextureParameter(ZZshParameter param, GLuint texobj, const char* name) {
#ifdef ENABLE_MARKER
char* debug = new char[100];
sprintf(debug, "CS: texture %d, param %d", texobj, param);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, format("CS: texture %d, param %d", texobj, param).c_str() );
#endif
g_cs.set_texture(param, texobj);
@ -254,9 +252,7 @@ void ZZshGLSetTextureParameter(ZZshParameter param, GLuint texobj, const char* n
void ZZshGLSetTextureParameter(ZZshShaderLink prog, ZZshParameter param, GLuint texobj, const char* name) {
FRAGMENTSHADER* shader = (FRAGMENTSHADER*)prog.link;
#ifdef ENABLE_MARKER
char* debug = new char[100];
sprintf(debug, "FS(%d):texture %d, param %d", shader->program, texobj, param);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, format("FS(%d):texture %d, param %d", shader->program, texobj, param).c_str() );
#endif
shader->set_texture(param, texobj);
@ -276,9 +272,7 @@ void ZZshSetParameter4fv(ZZshShaderLink& prog, ZZshParameter param, const float*
dirty_vertex_buffer = true;
}
#ifdef ENABLE_MARKER
char* debug = new char[100];
sprintf(debug, "prog: uniform (%s) (%f)", name, *v);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, format("prog: uniform (%s) (%f)", name, *v).c_str() );
#endif
}
@ -286,9 +280,7 @@ void ZZshSetParameter4fv(ZZshParameter param, const float* v, const char* name)
g_cs.ZZshSetParameter4fv(param, v);
dirty_common_buffer = true;
#ifdef ENABLE_MARKER
char* debug = new char[100];
sprintf(debug, "CS: uniform (%s) (%f)", name, *v);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, format("CS: uniform (%s) (%f)", name, *v).c_str() );
#endif
}
@ -380,7 +372,7 @@ void ZZshSetVertexShader(ZZshShaderLink prog) {
if (vs->program != g_current_vs) {
glUseProgramStages(s_pipeline, GL_VERTEX_SHADER_BIT, vs->program);
g_current_ps = vs->program;
g_current_vs = vs->program;
}
}
@ -452,9 +444,7 @@ void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
}
#ifdef ENABLE_MARKER
char* debug = new char[100];
sprintf(debug, "FS(%d): enable texture", ps->program);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, debug);
if (GLEW_GREMEDY_string_marker) glStringMarkerGREMEDY(0, format("FS(%d): enable texture", ps->program).c_str() );
#endif
g_cs.enable_texture();

View File

@ -21,7 +21,7 @@
// divides by z for every pixel, instead of in vertex shader
// fixes kh textures
#extension ARB_texture_rectangle: require
#extension GL_ARB_texture_rectangle: require
#extension GL_ARB_shading_language_420pack: require
#extension GL_ARB_separate_shader_objects : require
@ -565,25 +565,25 @@ half4 ps2FinalColor(half4 col)
#ifdef FRAGMENT_SHADER // This is code only for FRAGMENTS (pixel shader)
#ifdef WRITE_DEPTH
void write_depth_target(vec4 z)
void write_depth_target()
{
FragData1 = z;
FragData1 = PSin.z;
}
#else
void write_depth_target(vec4 z) { }
void write_depth_target() { }
#endif
void RegularPS() {
// whenever outputting depth, make sure to mult by 255/256 and 1
FragData0 = ps2FinalColor(PSin.color);
write_depth_target(PSin.z);
write_depth_target();
}
#define DECL_TEXPS(num, bit) \
void Texture##num##bit##PS() \
{ \
FragData0 = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \
write_depth_target(PSin.z); \
write_depth_target(); \
}
#define DECL_TEXPS_(num) \
@ -605,7 +605,7 @@ void RegularFogPS() {
c.xyz = mix(g_fFogColor.xyz, PSin.color.xyz, vec3(PSin.fog));
c.w = PSin.color.w;
FragData0 = ps2FinalColor(c);
write_depth_target(PSin.z);
write_depth_target();
}
#define DECL_TEXFOGPS(num, bit) \
@ -614,7 +614,7 @@ void TextureFog##num##bit##PS() \
half4 c = ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color); \
c.xyz = mix(g_fFogColor.xyz, c.xyz, vec3(PSin.fog)); \
FragData0 = ps2FinalColor(c); \
write_depth_target(PSin.z); \
write_depth_target(); \
}
#define DECL_TEXFOGPS_(num) \