wined3d: Move the vertex shader to wined3d_state.

This commit is contained in:
Henri Verbeet 2010-09-20 12:04:27 +02:00 committed by Alexandre Julliard
parent 493a3172f4
commit dd4aea36c9
6 changed files with 36 additions and 29 deletions

View File

@ -640,8 +640,9 @@ static void shader_arb_load_constants(const struct wined3d_context *context, cha
IWineD3DStateBlockImpl* stateBlock = device->stateBlock; IWineD3DStateBlockImpl* stateBlock = device->stateBlock;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
if (useVertexShader) { if (useVertexShader)
IWineD3DBaseShaderImpl* vshader = (IWineD3DBaseShaderImpl*) stateBlock->vertexShader; {
IWineD3DBaseShaderImpl *vshader = (IWineD3DBaseShaderImpl *)stateBlock->state.vertex_shader;
/* Load DirectX 9 float constants for 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, 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) { if (useVS) {
struct arb_vs_compile_args compile_args; struct arb_vs_compile_args compile_args;
struct arb_vs_compiled_shader *compiled; 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); find_arb_vs_compile_args(vs, This->stateBlock, &compile_args);
compiled = find_arb_vshader(vs, &compile_args); compiled = find_arb_vshader(vs, &compile_args);
priv->current_vprogram_id = compiled->prgId; priv->current_vprogram_id = compiled->prgId;

View File

@ -259,7 +259,7 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
/* TODO: Assuming vertexdeclarations are usually used with the /* TODO: Assuming vertexdeclarations are usually used with the
* same or a similar shader, it might be worth it to store the * same or a similar shader, it might be worth it to store the
* last used output slot and try that one first. */ * 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); element->usage, element->usage_idx, &idx);
} }
else else
@ -408,7 +408,7 @@ void device_update_stream_info(IWineD3DDeviceImpl *device, const struct wined3d_
{ {
struct wined3d_stream_info *stream_info = &device->strided_streams; struct wined3d_stream_info *stream_info = &device->strided_streams;
IWineD3DStateBlockImpl *stateblock = device->stateBlock; 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; BOOL fixup = FALSE;
if (device->up_strided) if (device->up_strided)
@ -472,7 +472,7 @@ void device_preload_textures(IWineD3DDeviceImpl *device)
{ {
for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) 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); device_preload_texture(stateblock, MAX_FRAGMENT_SAMPLERS + i);
} }
} }
@ -3197,11 +3197,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetVertexDeclaration(IWineD3DDevice* if
return WINED3D_OK; return WINED3D_OK;
} }
static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShader(IWineD3DDevice *iface, IWineD3DVertexShader* pShader) { static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShader(IWineD3DDevice *iface, IWineD3DVertexShader *pShader)
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; {
IWineD3DVertexShader* oldShader = This->updateStateBlock->vertexShader; 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; This->updateStateBlock->changed.vertexShader = TRUE;
if (This->isRecordingState) { if (This->isRecordingState) {
@ -3231,7 +3232,7 @@ static IWineD3DVertexShader * WINAPI IWineD3DDeviceImpl_GetVertexShader(IWineD3D
TRACE("iface %p.\n", iface); TRACE("iface %p.\n", iface);
shader = device->stateBlock->vertexShader; shader = (IWineD3DVertexShader *)device->stateBlock->state.vertex_shader;
if (shader) IWineD3DVertexShader_AddRef(shader); if (shader) IWineD3DVertexShader_AddRef(shader);
TRACE("Returning %p.\n", 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) static void device_map_vsamplers(IWineD3DDeviceImpl *This, BOOL ps, const struct wined3d_gl_info *gl_info)
{ {
const WINED3DSAMPLER_TEXTURE_TYPE *vshader_sampler_type = 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; const WINED3DSAMPLER_TEXTURE_TYPE *pshader_sampler_type = NULL;
int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1; int start = min(MAX_COMBINED_SAMPLERS, gl_info->limits.combined_samplers) - 1;
int i; int i;

View File

@ -752,8 +752,9 @@ static void shader_glsl_load_constants(const struct wined3d_context *context,
programId = prog->programId; programId = prog->programId;
constant_version = prog->constant_version; constant_version = prog->constant_version;
if (useVertexShader) { if (useVertexShader)
IWineD3DBaseShaderImpl* vshader = (IWineD3DBaseShaderImpl*) stateBlock->vertexShader; {
IWineD3DBaseShaderImpl *vshader = (IWineD3DBaseShaderImpl *)stateBlock->state.vertex_shader;
/* Load DirectX 9 float constants/uniforms for vertex shader */ /* Load DirectX 9 float constants/uniforms for vertex shader */
shader_glsl_load_constantsF(vshader, gl_info, stateBlock->vertexShaderConstantF, 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, static void set_glsl_shader_program(const struct wined3d_context *context,
IWineD3DDeviceImpl *device, BOOL use_ps, BOOL use_vs) 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; IWineD3DPixelShader *pshader = use_ps ? device->stateBlock->pixelShader : NULL;
const struct wined3d_gl_info *gl_info = context->gl_info; const struct wined3d_gl_info *gl_info = context->gl_info;
struct shader_glsl_priv *priv = device->shader_priv; struct shader_glsl_priv *priv = device->shader_priv;

View File

@ -1726,9 +1726,9 @@ static BOOL match_usage(BYTE usage1, BYTE usage_idx1, BYTE usage2, BYTE usage_id
return FALSE; 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; WORD map = shader->baseShader.reg_maps.input_registers;
unsigned int i; unsigned int i;

View File

@ -513,7 +513,7 @@ static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
} }
} }
if(This->pIndexData) IWineD3DBuffer_Release(This->pIndexData); 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); if(This->pixelShader) IWineD3DPixelShader_Release(This->pixelShader);
for(counter = 0; counter < LIGHTMAP_SIZE; counter++) { 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); 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 (targetStateBlock->state.vertex_shader)
if (This->vertexShader) IWineD3DVertexShader_Release(This->vertexShader); IWineD3DVertexShader_AddRef((IWineD3DVertexShader *)targetStateBlock->state.vertex_shader);
This->vertexShader = targetStateBlock->vertexShader; if (This->state.vertex_shader)
IWineD3DVertexShader_Release((IWineD3DVertexShader *)This->state.vertex_shader);
This->state.vertex_shader = targetStateBlock->state.vertex_shader;
} }
/* Vertex Shader Float Constants */ /* Vertex Shader Float Constants */
@ -909,7 +912,8 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface)
TRACE("Blocktype: %d\n", This->blockType); 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 */ /* Vertex Shader Constants */
for (i = 0; i < This->num_contained_vs_consts_f; ++i) for (i = 0; i < This->num_contained_vs_consts_f; ++i)

View File

@ -2351,6 +2351,8 @@ struct wined3d_state
{ {
IWineD3DVertexDeclarationImpl *vertex_declaration; IWineD3DVertexDeclarationImpl *vertex_declaration;
struct IWineD3DVertexShaderImpl *vertex_shader;
IWineD3DBaseTextureImpl *textures[MAX_COMBINED_SAMPLERS]; IWineD3DBaseTextureImpl *textures[MAX_COMBINED_SAMPLERS];
DWORD sampler_states[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1]; DWORD sampler_states[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1]; DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
@ -2378,8 +2380,6 @@ struct IWineD3DStateBlockImpl
SAVEDSTATES changed; SAVEDSTATES changed;
struct wined3d_state state; struct wined3d_state state;
IWineD3DVertexShader *vertexShader;
/* Vertex Shader Constants */ /* Vertex Shader Constants */
BOOL vertexShaderConstantB[MAX_CONST_B]; BOOL vertexShaderConstantB[MAX_CONST_B];
INT vertexShaderConstantI[MAX_CONST_I * 4]; 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; int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN;
/* Vertex shader utility functions */ /* 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; 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 * IWineD3DDeviceImpl_FindTexUnitMap(). This is safe because
* stateblock->vertexShader implies a vertex declaration instead of ddraw * stateblock->vertexShader implies a vertex declaration instead of ddraw
* style strided data. */ * style strided data. */
return (stateblock->vertexShader return (stateblock->state.vertex_shader
&& !stateblock->state.vertex_declaration->position_transformed && !stateblock->state.vertex_declaration->position_transformed
&& stateblock->device->vs_selected_mode != SHADER_NONE); && stateblock->device->vs_selected_mode != SHADER_NONE);
} }