From dd4aea36c99baca50e86bee26dae05e6630392fc Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 20 Sep 2010 12:04:27 +0200 Subject: [PATCH] wined3d: Move the vertex shader to wined3d_state. --- dlls/wined3d/arb_program_shader.c | 9 +++++---- dlls/wined3d/device.c | 19 ++++++++++--------- dlls/wined3d/glsl_shader.c | 7 ++++--- dlls/wined3d/shader.c | 4 ++-- dlls/wined3d/stateblock.c | 18 +++++++++++------- dlls/wined3d/wined3d_private.h | 8 ++++---- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c index 9b47d7af750..22840676014 100644 --- a/dlls/wined3d/arb_program_shader.c +++ b/dlls/wined3d/arb_program_shader.c @@ -640,8 +640,9 @@ static void shader_arb_load_constants(const struct wined3d_context *context, cha IWineD3DStateBlockImpl* stateBlock = device->stateBlock; const struct wined3d_gl_info *gl_info = context->gl_info; - if (useVertexShader) { - IWineD3DBaseShaderImpl* vshader = (IWineD3DBaseShaderImpl*) stateBlock->vertexShader; + if (useVertexShader) + { + IWineD3DBaseShaderImpl *vshader = (IWineD3DBaseShaderImpl *)stateBlock->state.vertex_shader; /* Load DirectX 9 float constants for vertex shader */ device->highest_dirty_vs_const = shader_arb_load_constantsF(vshader, gl_info, GL_VERTEX_PROGRAM_ARB, @@ -4582,9 +4583,9 @@ static void shader_arb_select(const struct wined3d_context *context, BOOL usePS, if (useVS) { struct arb_vs_compile_args compile_args; struct arb_vs_compiled_shader *compiled; - IWineD3DVertexShaderImpl *vs = (IWineD3DVertexShaderImpl *) This->stateBlock->vertexShader; + IWineD3DVertexShaderImpl *vs = This->stateBlock->state.vertex_shader; - TRACE("Using vertex shader %p\n", This->stateBlock->vertexShader); + TRACE("Using vertex shader %p\n", vs); find_arb_vs_compile_args(vs, This->stateBlock, &compile_args); compiled = find_arb_vshader(vs, &compile_args); priv->current_vprogram_id = compiled->prgId; diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 3a54f421748..151c60cc4e4 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -259,7 +259,7 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This, /* TODO: Assuming vertexdeclarations are usually used with the * same or a similar shader, it might be worth it to store the * last used output slot and try that one first. */ - stride_used = vshader_get_input(This->stateBlock->vertexShader, + stride_used = vshader_get_input(This->stateBlock->state.vertex_shader, element->usage, element->usage_idx, &idx); } else @@ -408,7 +408,7 @@ void device_update_stream_info(IWineD3DDeviceImpl *device, const struct wined3d_ { struct wined3d_stream_info *stream_info = &device->strided_streams; IWineD3DStateBlockImpl *stateblock = device->stateBlock; - BOOL vs = stateblock->vertexShader && device->vs_selected_mode != SHADER_NONE; + BOOL vs = stateblock->state.vertex_shader && device->vs_selected_mode != SHADER_NONE; BOOL fixup = FALSE; if (device->up_strided) @@ -472,7 +472,7 @@ void device_preload_textures(IWineD3DDeviceImpl *device) { for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) { - if (((IWineD3DBaseShaderImpl *)stateblock->vertexShader)->baseShader.reg_maps.sampler_type[i]) + if (stateblock->state.vertex_shader->baseShader.reg_maps.sampler_type[i]) device_preload_texture(stateblock, MAX_FRAGMENT_SAMPLERS + i); } } @@ -3197,11 +3197,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetVertexDeclaration(IWineD3DDevice* if return WINED3D_OK; } -static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShader(IWineD3DDevice *iface, IWineD3DVertexShader* pShader) { - IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - IWineD3DVertexShader* oldShader = This->updateStateBlock->vertexShader; +static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShader(IWineD3DDevice *iface, IWineD3DVertexShader *pShader) +{ + IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; + IWineD3DVertexShader *oldShader = (IWineD3DVertexShader *)This->updateStateBlock->state.vertex_shader; - This->updateStateBlock->vertexShader = pShader; + This->updateStateBlock->state.vertex_shader = (IWineD3DVertexShaderImpl *)pShader; This->updateStateBlock->changed.vertexShader = TRUE; if (This->isRecordingState) { @@ -3231,7 +3232,7 @@ static IWineD3DVertexShader * WINAPI IWineD3DDeviceImpl_GetVertexShader(IWineD3D TRACE("iface %p.\n", iface); - shader = device->stateBlock->vertexShader; + shader = (IWineD3DVertexShader *)device->stateBlock->state.vertex_shader; if (shader) IWineD3DVertexShader_AddRef(shader); TRACE("Returning %p.\n", shader); @@ -3533,7 +3534,7 @@ static BOOL device_unit_free_for_vs(IWineD3DDeviceImpl *This, const WINED3DSAMPL static void device_map_vsamplers(IWineD3DDeviceImpl *This, BOOL ps, const struct wined3d_gl_info *gl_info) { const WINED3DSAMPLER_TEXTURE_TYPE *vshader_sampler_type = - ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.reg_maps.sampler_type; + This->stateBlock->state.vertex_shader->baseShader.reg_maps.sampler_type; const WINED3DSAMPLER_TEXTURE_TYPE *pshader_sampler_type = NULL; int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1; int i; diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index 23821628002..aae3b1154fc 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -752,8 +752,9 @@ static void shader_glsl_load_constants(const struct wined3d_context *context, programId = prog->programId; constant_version = prog->constant_version; - if (useVertexShader) { - IWineD3DBaseShaderImpl* vshader = (IWineD3DBaseShaderImpl*) stateBlock->vertexShader; + if (useVertexShader) + { + IWineD3DBaseShaderImpl *vshader = (IWineD3DBaseShaderImpl *)stateBlock->state.vertex_shader; /* Load DirectX 9 float constants/uniforms for vertex shader */ shader_glsl_load_constantsF(vshader, gl_info, stateBlock->vertexShaderConstantF, @@ -4277,7 +4278,7 @@ static GLhandleARB find_glsl_vshader(const struct wined3d_context *context, static void set_glsl_shader_program(const struct wined3d_context *context, IWineD3DDeviceImpl *device, BOOL use_ps, BOOL use_vs) { - IWineD3DVertexShader *vshader = use_vs ? device->stateBlock->vertexShader : NULL; + IWineD3DVertexShader *vshader = use_vs ? (IWineD3DVertexShader *)device->stateBlock->state.vertex_shader : NULL; IWineD3DPixelShader *pshader = use_ps ? device->stateBlock->pixelShader : NULL; const struct wined3d_gl_info *gl_info = context->gl_info; struct shader_glsl_priv *priv = device->shader_priv; diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index 9077ef8d6d5..969d93a3a4f 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -1726,9 +1726,9 @@ 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(struct IWineD3DVertexShaderImpl *shader, + BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) { - IWineD3DVertexShaderImpl *shader = (IWineD3DVertexShaderImpl *)iface; WORD map = shader->baseShader.reg_maps.input_registers; unsigned int i; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index ac5accbc915..a8d8090c815 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -513,7 +513,7 @@ static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) { } } if(This->pIndexData) IWineD3DBuffer_Release(This->pIndexData); - if(This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader); + if (This->state.vertex_shader) IWineD3DVertexShader_Release((IWineD3DVertexShader *)This->state.vertex_shader); if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader); for(counter = 0; counter < LIGHTMAP_SIZE; counter++) { @@ -603,13 +603,16 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface) TRACE("(%p) : Updating state block %p ------------------v\n", targetStateBlock, This); - if (This->changed.vertexShader && This->vertexShader != targetStateBlock->vertexShader) + if (This->changed.vertexShader && This->state.vertex_shader != targetStateBlock->state.vertex_shader) { - TRACE("Updating vertex shader from %p to %p\n", This->vertexShader, targetStateBlock->vertexShader); + TRACE("Updating vertex shader from %p to %p\n", + This->state.vertex_shader, targetStateBlock->state.vertex_shader); - if (targetStateBlock->vertexShader) IWineD3DVertexShader_AddRef(targetStateBlock->vertexShader); - if (This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader); - This->vertexShader = targetStateBlock->vertexShader; + if (targetStateBlock->state.vertex_shader) + IWineD3DVertexShader_AddRef((IWineD3DVertexShader *)targetStateBlock->state.vertex_shader); + if (This->state.vertex_shader) + IWineD3DVertexShader_Release((IWineD3DVertexShader *)This->state.vertex_shader); + This->state.vertex_shader = targetStateBlock->state.vertex_shader; } /* Vertex Shader Float Constants */ @@ -909,7 +912,8 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface) TRACE("Blocktype: %d\n", This->blockType); - if (This->changed.vertexShader) IWineD3DDevice_SetVertexShader(device, This->vertexShader); + if (This->changed.vertexShader) + IWineD3DDevice_SetVertexShader(device, (IWineD3DVertexShader *)This->state.vertex_shader); /* Vertex Shader Constants */ for (i = 0; i < This->num_contained_vs_consts_f; ++i) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 10ddc4a8e61..8fe3361c281 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2351,6 +2351,8 @@ struct wined3d_state { IWineD3DVertexDeclarationImpl *vertex_declaration; + struct IWineD3DVertexShaderImpl *vertex_shader; + IWineD3DBaseTextureImpl *textures[MAX_COMBINED_SAMPLERS]; DWORD sampler_states[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1]; DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1]; @@ -2378,8 +2380,6 @@ struct IWineD3DStateBlockImpl SAVEDSTATES changed; struct wined3d_state state; - IWineD3DVertexShader *vertexShader; - /* Vertex Shader Constants */ BOOL vertexShaderConstantB[MAX_CONST_B]; INT vertexShaderConstantI[MAX_CONST_I * 4]; @@ -2725,7 +2725,7 @@ int shader_addline(struct wined3d_shader_buffer *buffer, const char *fmt, ...) P int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN; /* Vertex shader utility functions */ -extern BOOL vshader_get_input(IWineD3DVertexShader *iface, +extern BOOL vshader_get_input(struct IWineD3DVertexShaderImpl *shader, BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN; /***************************************************************************** @@ -3034,7 +3034,7 @@ static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock) * IWineD3DDeviceImpl_FindTexUnitMap(). This is safe because * stateblock->vertexShader implies a vertex declaration instead of ddraw * style strided data. */ - return (stateblock->vertexShader + return (stateblock->state.vertex_shader && !stateblock->state.vertex_declaration->position_transformed && stateblock->device->vs_selected_mode != SHADER_NONE); }