From 10fadadc54310546845b1ed8acdcaa0d54cea2f6 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 27 May 2009 10:24:49 +0200 Subject: [PATCH] wined3d: Use the "input_registers" bitmap for vertex shader attributes as well. --- dlls/wined3d/baseshader.c | 5 ++--- dlls/wined3d/glsl_shader.c | 24 ++++++++++++++++-------- dlls/wined3d/vertexshader.c | 17 ++++++++--------- dlls/wined3d/wined3d_private.h | 3 +-- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c index 076070a8fee..4ec4073c339 100644 --- a/dlls/wined3d/baseshader.c +++ b/dlls/wined3d/baseshader.c @@ -260,7 +260,7 @@ static void shader_record_register_usage(IWineD3DBaseShaderImpl *This, struct sh break; case WINED3DSPR_INPUT: - if (!pshader) reg_maps->attributes[reg->idx] = 1; + if (!pshader) reg_maps->input_registers |= 1 << reg->idx; else { if (reg->rel_addr) @@ -410,8 +410,7 @@ HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3 /* Vshader: mark attributes used * Pshader: mark 3.0 input registers used, save token */ case WINED3DSPR_INPUT: - if (!pshader) reg_maps->attributes[semantic.reg.reg.idx] = 1; - else reg_maps->input_registers |= 1 << semantic.reg.reg.idx; + reg_maps->input_registers |= 1 << semantic.reg.reg.idx; semantics_in[semantic.reg.reg.idx] = semantic; break; diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index a1e5aef305b..b99e7df3cc4 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -964,9 +964,16 @@ static void shader_generate_glsl_declarations(IWineD3DBaseShader *iface, const s } /* Declare attributes */ - for (i = 0; i < This->baseShader.limits.attributes; i++) { - if (reg_maps->attributes[i]) + if (reg_maps->shader_version.type == WINED3D_SHADER_TYPE_VERTEX) + { + WORD map = reg_maps->input_registers; + + for (i = 0; map; map >>= 1, ++i) + { + if (!(map & 1)) continue; + shader_addline(buffer, "attribute vec4 attrib%i;\n", i); + } } /* Declare loop registers aLx */ @@ -3652,7 +3659,7 @@ static void set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use /* Attach GLSL vshader */ if (vshader_id) { - const unsigned int max_attribs = 16; /* TODO: Will this always be the case? It is at the moment... */ + WORD map = ((IWineD3DBaseShaderImpl *)vshader)->baseShader.reg_maps.input_registers; char tmp_name[10]; reorder_shader_id = generate_param_reorder_function(vshader, pshader, gl_info); @@ -3677,11 +3684,12 @@ static void set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use * We have to do this here because we need to know the Program ID * in order to make the bindings work, and it has to be done prior * to linking the GLSL program. */ - for (i = 0; i < max_attribs; ++i) { - if (((IWineD3DBaseShaderImpl*)vshader)->baseShader.reg_maps.attributes[i]) { - snprintf(tmp_name, sizeof(tmp_name), "attrib%i", i); - GL_EXTCALL(glBindAttribLocationARB(programId, i, tmp_name)); - } + for (i = 0; map; map >>= 1, ++i) + { + if (!(map & 1)) continue; + + snprintf(tmp_name, sizeof(tmp_name), "attrib%u", i); + GL_EXTCALL(glBindAttribLocationARB(programId, i, tmp_name)); } checkGLcall("glBindAttribLocationARB"); diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c index 26350d999ab..9b8fcfdbfac 100644 --- a/dlls/wined3d/vertexshader.c +++ b/dlls/wined3d/vertexshader.c @@ -134,16 +134,15 @@ static BOOL match_usage(BYTE usage1, BYTE usage_idx1, BYTE usage2, BYTE usage_id return FALSE; } -BOOL vshader_get_input( - IWineD3DVertexShader* iface, - BYTE usage_req, BYTE usage_idx_req, - unsigned int* regnum) { +BOOL vshader_get_input(IWineD3DVertexShader* iface, BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) +{ + IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface; + WORD map = This->baseShader.reg_maps.input_registers; + unsigned int i; - IWineD3DVertexShaderImpl* This = (IWineD3DVertexShaderImpl*) iface; - int i; - - for (i = 0; i < MAX_ATTRIBS; i++) { - if (!This->baseShader.reg_maps.attributes[i]) continue; + for (i = 0; map; map >>= 1, ++i) + { + if (!(map & 1)) continue; if (match_usage(This->semantics_in[i].usage, This->semantics_in[i].usage_idx, usage_req, usage_idx_req)) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 114407f1324..e82d1e15f09 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -622,11 +622,10 @@ typedef struct shader_reg_maps char temporary[MAX_REG_TEMP]; /* pixel, vertex */ char address[MAX_REG_ADDR]; /* vertex */ char packed_output[MAX_REG_OUTPUT]; /* vertex >= 3.0 */ - char attributes[MAX_ATTRIBS]; /* vertex */ char labels[MAX_LABELS]; /* pixel, vertex */ DWORD *constf; /* pixel, vertex */ DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */ - WORD input_registers; /* MAX_REG_INPUT, 12 */ + WORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 16 */ WORD integer_constants; /* MAX_CONST_I, 16 */ WORD boolean_constants; /* MAX_CONST_B, 16 */