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

wined3d: Abort on invalid instructions in shader_generate_main().

parent 0cdae568
...@@ -3809,7 +3809,8 @@ static GLuint shader_arb_generate_pshader(const struct wined3d_shader *shader, ...@@ -3809,7 +3809,8 @@ static GLuint shader_arb_generate_pshader(const struct wined3d_shader *shader,
} }
/* Base Shader Body */ /* Base Shader Body */
shader_generate_main(shader, buffer, reg_maps, &priv_ctx); if (FAILED(shader_generate_main(shader, buffer, reg_maps, &priv_ctx)))
return 0;
if(args->super.srgb_correction) { if(args->super.srgb_correction) {
arbfp_add_sRGB_correction(buffer, fragcolor, srgbtmp[0], srgbtmp[1], srgbtmp[2], srgbtmp[3], arbfp_add_sRGB_correction(buffer, fragcolor, srgbtmp[0], srgbtmp[1], srgbtmp[2], srgbtmp[3],
...@@ -4222,7 +4223,8 @@ static GLuint shader_arb_generate_vshader(const struct wined3d_shader *shader, ...@@ -4222,7 +4223,8 @@ static GLuint shader_arb_generate_vshader(const struct wined3d_shader *shader,
/* The shader starts with the main function */ /* The shader starts with the main function */
priv_ctx.in_main_func = TRUE; priv_ctx.in_main_func = TRUE;
/* Base Shader Body */ /* Base Shader Body */
shader_generate_main(shader, buffer, reg_maps, &priv_ctx); if (FAILED(shader_generate_main(shader, buffer, reg_maps, &priv_ctx)))
return -1;
if (!priv_ctx.footer_written) vshader_add_footer(&priv_ctx, if (!priv_ctx.footer_written) vshader_add_footer(&priv_ctx,
shader_data, args, reg_maps, gl_info, buffer); shader_data, args, reg_maps, gl_info, buffer);
......
...@@ -6757,9 +6757,7 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context ...@@ -6757,9 +6757,7 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
struct shader_glsl_ctx_priv priv_ctx; struct shader_glsl_ctx_priv priv_ctx;
BOOL legacy_context = gl_info->supported[WINED3D_GL_LEGACY_CONTEXT]; BOOL legacy_context = gl_info->supported[WINED3D_GL_LEGACY_CONTEXT];
GLuint shader_id;
/* Create the hw GLSL shader object and assign it as the shader->prgId */
GLuint shader_id = GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER));
memset(&priv_ctx, 0, sizeof(priv_ctx)); memset(&priv_ctx, 0, sizeof(priv_ctx));
priv_ctx.cur_ps_args = args; priv_ctx.cur_ps_args = args;
...@@ -6850,7 +6848,8 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context ...@@ -6850,7 +6848,8 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context
shader_glsl_input_pack(shader, buffer, &shader->input_signature, reg_maps, args, gl_info); shader_glsl_input_pack(shader, buffer, &shader->input_signature, reg_maps, args, gl_info);
/* Base Shader Body */ /* Base Shader Body */
shader_generate_main(shader, buffer, reg_maps, &priv_ctx); if (FAILED(shader_generate_main(shader, buffer, reg_maps, &priv_ctx)))
return 0;
/* In SM4+ the shader epilogue is generated by the "ret" instruction. */ /* In SM4+ the shader epilogue is generated by the "ret" instruction. */
if (reg_maps->shader_version.major < 4) if (reg_maps->shader_version.major < 4)
...@@ -6858,6 +6857,7 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context ...@@ -6858,6 +6857,7 @@ static GLuint shader_glsl_generate_pshader(const struct wined3d_context *context
shader_addline(buffer, "}\n"); shader_addline(buffer, "}\n");
shader_id = GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER));
TRACE("Compiling shader object %u.\n", shader_id); TRACE("Compiling shader object %u.\n", shader_id);
shader_glsl_compile(gl_info, shader_id, buffer->buffer); shader_glsl_compile(gl_info, shader_id, buffer->buffer);
...@@ -6916,9 +6916,7 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context ...@@ -6916,9 +6916,7 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context
struct wined3d_string_buffer *buffer = &priv->shader_buffer; struct wined3d_string_buffer *buffer = &priv->shader_buffer;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
struct shader_glsl_ctx_priv priv_ctx; struct shader_glsl_ctx_priv priv_ctx;
GLuint shader_id;
/* Create the hw GLSL shader program and assign it as the shader->prgId */
GLuint shader_id = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
shader_glsl_add_version_declaration(buffer, gl_info, &reg_maps->shader_version); shader_glsl_add_version_declaration(buffer, gl_info, &reg_maps->shader_version);
...@@ -6949,7 +6947,8 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context ...@@ -6949,7 +6947,8 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context
shader_addline(buffer, "void main()\n{\n"); shader_addline(buffer, "void main()\n{\n");
/* Base Shader Body */ /* Base Shader Body */
shader_generate_main(shader, buffer, reg_maps, &priv_ctx); if (FAILED(shader_generate_main(shader, buffer, reg_maps, &priv_ctx)))
return 0;
/* In SM4+ the shader epilogue is generated by the "ret" instruction. */ /* In SM4+ the shader epilogue is generated by the "ret" instruction. */
if (reg_maps->shader_version.major < 4) if (reg_maps->shader_version.major < 4)
...@@ -6957,6 +6956,7 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context ...@@ -6957,6 +6956,7 @@ static GLuint shader_glsl_generate_vshader(const struct wined3d_context *context
shader_addline(buffer, "}\n"); shader_addline(buffer, "}\n");
shader_id = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
TRACE("Compiling shader object %u.\n", shader_id); TRACE("Compiling shader object %u.\n", shader_id);
shader_glsl_compile(gl_info, shader_id, buffer->buffer); shader_glsl_compile(gl_info, shader_id, buffer->buffer);
...@@ -6974,8 +6974,6 @@ static GLuint shader_glsl_generate_geometry_shader(const struct wined3d_context ...@@ -6974,8 +6974,6 @@ static GLuint shader_glsl_generate_geometry_shader(const struct wined3d_context
struct shader_glsl_ctx_priv priv_ctx; struct shader_glsl_ctx_priv priv_ctx;
GLuint shader_id; GLuint shader_id;
shader_id = GL_EXTCALL(glCreateShader(GL_GEOMETRY_SHADER));
shader_glsl_add_version_declaration(buffer, gl_info, &reg_maps->shader_version); shader_glsl_add_version_declaration(buffer, gl_info, &reg_maps->shader_version);
shader_glsl_enable_extensions(buffer, gl_info); shader_glsl_enable_extensions(buffer, gl_info);
...@@ -6989,9 +6987,11 @@ static GLuint shader_glsl_generate_geometry_shader(const struct wined3d_context ...@@ -6989,9 +6987,11 @@ static GLuint shader_glsl_generate_geometry_shader(const struct wined3d_context
shader_addline(buffer, "uniform vec4 pos_fixup;\n"); shader_addline(buffer, "uniform vec4 pos_fixup;\n");
shader_glsl_generate_sm4_rasterizer_input_setup(priv, shader, args->ps_input_count, gl_info); shader_glsl_generate_sm4_rasterizer_input_setup(priv, shader, args->ps_input_count, gl_info);
shader_addline(buffer, "void main()\n{\n"); shader_addline(buffer, "void main()\n{\n");
shader_generate_main(shader, buffer, reg_maps, &priv_ctx); if (FAILED(shader_generate_main(shader, buffer, reg_maps, &priv_ctx)))
return 0;
shader_addline(buffer, "}\n"); shader_addline(buffer, "}\n");
shader_id = GL_EXTCALL(glCreateShader(GL_GEOMETRY_SHADER));
TRACE("Compiling shader object %u.\n", shader_id); TRACE("Compiling shader object %u.\n", shader_id);
shader_glsl_compile(gl_info, shader_id, buffer->buffer); shader_glsl_compile(gl_info, shader_id, buffer->buffer);
...@@ -7033,8 +7033,6 @@ static GLuint shader_glsl_generate_compute_shader(const struct wined3d_context * ...@@ -7033,8 +7033,6 @@ static GLuint shader_glsl_generate_compute_shader(const struct wined3d_context *
GLuint shader_id; GLuint shader_id;
unsigned int i; unsigned int i;
shader_id = GL_EXTCALL(glCreateShader(GL_COMPUTE_SHADER));
shader_glsl_add_version_declaration(buffer, gl_info, &reg_maps->shader_version); shader_glsl_add_version_declaration(buffer, gl_info, &reg_maps->shader_version);
shader_glsl_enable_extensions(buffer, gl_info); shader_glsl_enable_extensions(buffer, gl_info);
...@@ -7058,6 +7056,7 @@ static GLuint shader_glsl_generate_compute_shader(const struct wined3d_context * ...@@ -7058,6 +7056,7 @@ static GLuint shader_glsl_generate_compute_shader(const struct wined3d_context *
shader_generate_main(shader, buffer, reg_maps, &priv_ctx); shader_generate_main(shader, buffer, reg_maps, &priv_ctx);
shader_addline(buffer, "}\n"); shader_addline(buffer, "}\n");
shader_id = GL_EXTCALL(glCreateShader(GL_COMPUTE_SHADER));
TRACE("Compiling shader object %u.\n", shader_id); TRACE("Compiling shader object %u.\n", shader_id);
shader_glsl_compile(gl_info, shader_id, buffer->buffer); shader_glsl_compile(gl_info, shader_id, buffer->buffer);
......
...@@ -2282,7 +2282,7 @@ static void shader_dump_src_param(struct wined3d_string_buffer *buffer, ...@@ -2282,7 +2282,7 @@ static void shader_dump_src_param(struct wined3d_string_buffer *buffer,
/* Shared code in order to generate the bulk of the shader string. /* Shared code in order to generate the bulk of the shader string.
* NOTE: A description of how to parse tokens can be found on MSDN. */ * NOTE: A description of how to parse tokens can be found on MSDN. */
void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, HRESULT shader_generate_main(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer,
const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx) const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx)
{ {
struct wined3d_device *device = shader->device; struct wined3d_device *device = shader->device;
...@@ -2320,8 +2320,8 @@ void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_st ...@@ -2320,8 +2320,8 @@ void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_st
/* Unknown opcode and its parameters. */ /* Unknown opcode and its parameters. */
if (ins.handler_idx == WINED3DSIH_TABLE_SIZE) if (ins.handler_idx == WINED3DSIH_TABLE_SIZE)
{ {
TRACE("Skipping unrecognized instruction.\n"); WARN("Encountered unrecognised or invalid instruction.\n");
continue; return WINED3DERR_INVALIDCALL;
} }
if (ins.predicate) if (ins.predicate)
...@@ -2330,6 +2330,8 @@ void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_st ...@@ -2330,6 +2330,8 @@ void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_st
/* Call appropriate function for output target */ /* Call appropriate function for output target */
device->shader_backend->shader_handle_instruction(&ins); device->shader_backend->shader_handle_instruction(&ins);
} }
return WINED3D_OK;
} }
static void shader_dump_ins_modifiers(struct wined3d_string_buffer *buffer, static void shader_dump_ins_modifiers(struct wined3d_string_buffer *buffer,
......
...@@ -3679,7 +3679,7 @@ BOOL string_buffer_init(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN; ...@@ -3679,7 +3679,7 @@ BOOL string_buffer_init(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
void string_buffer_free(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN; void string_buffer_free(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps, unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps,
unsigned int max) DECLSPEC_HIDDEN; unsigned int max) DECLSPEC_HIDDEN;
void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, HRESULT shader_generate_main(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer,
const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx) DECLSPEC_HIDDEN; const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx) DECLSPEC_HIDDEN;
BOOL shader_match_semantic(const char *semantic_name, enum wined3d_decl_usage usage) DECLSPEC_HIDDEN; BOOL shader_match_semantic(const char *semantic_name, enum wined3d_decl_usage usage) DECLSPEC_HIDDEN;
......
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