Commit c7780791 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Introduce a function to compile ARB vertex/fragment programs.

parent 8063d4cf
......@@ -38,6 +38,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
WINE_DECLARE_DEBUG_CHANNEL(d3d_constants);
WINE_DECLARE_DEBUG_CHANNEL(d3d);
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
static BOOL shader_is_pshader_version(enum wined3d_shader_type type)
{
......@@ -3279,11 +3280,40 @@ static void shader_hw_call(const struct wined3d_shader_instruction *ins)
shader_addline(buffer, "CAL l%u;\n", ins->src[0].reg.idx[0].offset);
}
static BOOL shader_arb_compile(const struct wined3d_gl_info *gl_info, GLenum target, const char *src)
{
GLint native, pos;
GL_EXTCALL(glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(src), src));
checkGLcall("glProgramStringARB()");
if (FIXME_ON(d3d_shader))
{
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if (pos != -1)
{
FIXME_(d3d_shader)("Program error at position %d: %s\n\n", pos,
debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(src);
return FALSE;
}
}
if (WARN_ON(d3d_perf))
{
GL_EXTCALL(glGetProgramivARB(target, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
checkGLcall("glGetProgramivARB()");
if (!native)
WARN_(d3d_perf)("Program exceeds native resource limits.\n");
}
return TRUE;
}
/* Context activation is done by the caller. */
static GLuint create_arb_blt_vertex_program(const struct wined3d_gl_info *gl_info)
{
GLuint program_id = 0;
GLint pos;
static const char blt_vprogram[] =
"!!ARBvp1.0\n"
......@@ -3295,25 +3325,7 @@ static GLuint create_arb_blt_vertex_program(const struct wined3d_gl_info *gl_inf
GL_EXTCALL(glGenProgramsARB(1, &program_id));
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, program_id));
GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(blt_vprogram), blt_vprogram));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if (pos != -1)
{
FIXME("Vertex program error at position %d: %s\n\n", pos,
debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(blt_vprogram);
}
else
{
GLint native;
GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
checkGLcall("glGetProgramivARB()");
if (!native) WARN("Program exceeds native resource limits.\n");
}
shader_arb_compile(gl_info, GL_VERTEX_PROGRAM_ARB, blt_vprogram);
return program_id;
}
......@@ -3324,7 +3336,6 @@ static GLuint create_arb_blt_fragment_program(const struct wined3d_gl_info *gl_i
{
GLuint program_id = 0;
const char *fprogram;
GLint pos;
static const char * const blt_fprograms_full[WINED3D_GL_RES_TYPE_COUNT] =
{
......@@ -3400,24 +3411,7 @@ static GLuint create_arb_blt_fragment_program(const struct wined3d_gl_info *gl_i
GL_EXTCALL(glGenProgramsARB(1, &program_id));
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, program_id));
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(fprogram), fprogram));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if (pos != -1)
{
FIXME("Fragment program error at position %d: %s\n\n", pos,
debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(fprogram);
}
else
{
GLint native;
GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
checkGLcall("glGetProgramivARB()");
if (!native) WARN("Program exceeds native resource limits.\n");
}
shader_arb_compile(gl_info, GL_FRAGMENT_PROGRAM_ARB, fprogram);
return program_id;
}
......@@ -3585,7 +3579,6 @@ static GLuint shader_arb_generate_pshader(const struct wined3d_shader *shader,
BOOL dcl_td = FALSE;
BOOL want_nv_prog = FALSE;
struct arb_pshader_private *shader_priv = shader->backend_data;
GLint errPos;
DWORD map;
BOOL custom_linear_fog = FALSE;
......@@ -3894,27 +3887,8 @@ static GLuint shader_arb_generate_pshader(const struct wined3d_shader *shader,
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, retval));
TRACE("Created hw pixel shader, prg=%d\n", retval);
/* Create the program and check for errors */
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
buffer->content_size, buffer->buffer));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
if (errPos != -1)
{
FIXME("HW PixelShader Error at position %d: %s\n\n",
errPos, debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(buffer->buffer);
retval = 0;
}
else
{
GLint native;
GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
checkGLcall("glGetProgramivARB()");
if (!native) WARN("Program exceeds native resource limits.\n");
}
if (!shader_arb_compile(gl_info, GL_FRAGMENT_PROGRAM_ARB, buffer->buffer))
return 0;
return retval;
}
......@@ -4200,7 +4174,6 @@ static GLuint shader_arb_generate_vshader(const struct wined3d_shader *shader,
DWORD next_local = 0;
struct shader_arb_ctx_priv priv_ctx;
unsigned int i;
GLint errPos;
memset(&priv_ctx, 0, sizeof(priv_ctx));
priv_ctx.cur_vs_args = args;
......@@ -4320,27 +4293,8 @@ static GLuint shader_arb_generate_vshader(const struct wined3d_shader *shader,
GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ret));
TRACE("Created hw vertex shader, prg=%d\n", ret);
/* Create the program and check for errors */
GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
buffer->content_size, buffer->buffer));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
if (errPos != -1)
{
FIXME("HW VertexShader Error at position %d: %s\n\n",
errPos, debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(buffer->buffer);
ret = -1;
}
else
{
GLint native;
GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
checkGLcall("glGetProgramivARB()");
if (!native) WARN("Program exceeds native resource limits.\n");
}
if (!shader_arb_compile(gl_info, GL_VERTEX_PROGRAM_ARB, buffer->buffer))
return -1;
return ret;
}
......@@ -6296,7 +6250,6 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, con
BOOL tempreg_used = FALSE, tfactor_used = FALSE;
BOOL op_equal;
const char *final_combiner_src = "ret";
GLint pos;
BOOL custom_linear_fog = FALSE;
if (!shader_buffer_init(&buffer))
......@@ -6570,25 +6523,7 @@ static GLuint gen_arbfp_ffp_shader(const struct ffp_frag_settings *settings, con
/* Generate the shader */
GL_EXTCALL(glGenProgramsARB(1, &ret));
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ret));
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(buffer.buffer), buffer.buffer));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if (pos != -1)
{
FIXME("Fragment program error at position %d: %s\n\n", pos,
debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(buffer.buffer);
}
else
{
GLint native;
GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
checkGLcall("glGetProgramivARB()");
if (!native) WARN("Program exceeds native resource limits.\n");
}
shader_arb_compile(gl_info, GL_FRAGMENT_PROGRAM_ARB, buffer.buffer);
shader_buffer_free(&buffer);
return ret;
......@@ -7367,7 +7302,6 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv,
{
GLenum shader;
struct wined3d_shader_buffer buffer;
GLint pos;
const char *tex_target = arbfp_texture_target(type->res_type);
/* This should not happen because we only use this conversion for
......@@ -7406,17 +7340,7 @@ static GLuint gen_p8_shader(struct arbfp_blit_priv *priv,
shader_addline(&buffer, "TEX result.color, index.a, texture[1], 1D;\n");
shader_addline(&buffer, "END\n");
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(buffer.buffer), buffer.buffer));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if (pos != -1)
{
FIXME("Fragment program error at position %d: %s\n\n", pos,
debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(buffer.buffer);
}
shader_arb_compile(gl_info, GL_FRAGMENT_PROGRAM_ARB, buffer.buffer);
shader_buffer_free(&buffer);
......@@ -7468,7 +7392,6 @@ static GLuint gen_yuv_shader(struct arbfp_blit_priv *priv, const struct wined3d_
GLenum shader;
struct wined3d_shader_buffer buffer;
char luminance_component;
GLint pos;
if (type->use_color_key)
FIXME("Implement YUV color keying.\n");
......@@ -7580,25 +7503,7 @@ static GLuint gen_yuv_shader(struct arbfp_blit_priv *priv, const struct wined3d_
shader_addline(&buffer, "MAD result.color.z, chroma.y, yuv_coef.w, luminance.%c;\n", luminance_component);
shader_addline(&buffer, "END\n");
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(buffer.buffer), buffer.buffer));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if (pos != -1)
{
FIXME("Fragment program error at position %d: %s\n\n", pos,
debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(buffer.buffer);
}
else
{
GLint native;
GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
checkGLcall("glGetProgramivARB()");
if (!native) WARN("Program exceeds native resource limits.\n");
}
shader_arb_compile(gl_info, GL_FRAGMENT_PROGRAM_ARB, buffer.buffer);
shader_buffer_free(&buffer);
......@@ -7611,7 +7516,6 @@ static GLuint arbfp_gen_plain_shader(struct arbfp_blit_priv *priv,
{
GLenum shader;
struct wined3d_shader_buffer buffer;
GLint pos;
const char *tex_target = arbfp_texture_target(type->res_type);
/* Shader header */
......@@ -7650,17 +7554,7 @@ static GLuint arbfp_gen_plain_shader(struct arbfp_blit_priv *priv,
shader_addline(&buffer, "END\n");
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(buffer.buffer), buffer.buffer));
checkGLcall("glProgramStringARB()");
gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
if (pos != -1)
{
FIXME("Fragment program error at position %d: %s\n\n", pos,
debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
shader_arb_dump_program_source(buffer.buffer);
}
shader_arb_compile(gl_info, GL_FRAGMENT_PROGRAM_ARB, buffer.buffer);
shader_buffer_free(&buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment