From 93ac6dfdcce5260ee06b8c32306cb2af8ee782e3 Mon Sep 17 00:00:00 2001 From: Axel Davy Date: Tue, 18 Oct 2016 20:48:54 +0200 Subject: [PATCH] st/nine: Back sampler states to nine_context Part of the refactor to move all gallium calls to nine_state.c, and have all internal states required for those calls in nine_context. Signed-off-by: Axel Davy --- src/gallium/state_trackers/nine/device9.c | 18 +++--- src/gallium/state_trackers/nine/nine_state.c | 83 +++++++++++++++++++-------- src/gallium/state_trackers/nine/nine_state.h | 16 +++++- src/gallium/state_trackers/nine/stateblock9.c | 3 - 4 files changed, 82 insertions(+), 38 deletions(-) diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c index 3b682065709..3bfff86f56b 100644 --- a/src/gallium/state_trackers/nine/device9.c +++ b/src/gallium/state_trackers/nine/device9.c @@ -2600,15 +2600,19 @@ NineDevice9_SetSamplerState( struct NineDevice9 *This, if (Sampler >= D3DDMAPSAMPLER) Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS; - if (state->samp_advertised[Sampler][Type] != Value || unlikely(This->is_recording)) { - /* Contrary to render states, old value is kept if new value is wrong (except intel + Value == 0) */ - if (likely(nine_check_sampler_state_value(Type, Value))) - state->samp[Sampler][Type] = Value; + if (unlikely(This->is_recording)) { state->samp_advertised[Sampler][Type] = Value; state->changed.group |= NINE_STATE_SAMPLER; state->changed.sampler[Sampler] |= 1 << Type; + return D3D_OK; } + if (state->samp_advertised[Sampler][Type] == Value) + return D3D_OK; + + state->samp_advertised[Sampler][Type] = Value; + nine_context_set_sampler_state(This, Sampler, Type, Value); + return D3D_OK; } @@ -2622,9 +2626,9 @@ NineDevice9_ValidateDevice( struct NineDevice9 *This, DBG("This=%p pNumPasses=%p\n", This, pNumPasses); - for (i = 0; i < ARRAY_SIZE(state->samp); ++i) { - if (state->samp[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE || - state->samp[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE) + for (i = 0; i < ARRAY_SIZE(state->samp_advertised); ++i) { + if (state->samp_advertised[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE || + state->samp_advertised[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE) return D3DERR_UNSUPPORTEDTEXTUREFILTER; } diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c index a560b897e60..17a6934740e 100644 --- a/src/gallium/state_trackers/nine/nine_state.c +++ b/src/gallium/state_trackers/nine/nine_state.c @@ -715,32 +715,32 @@ update_vertex_buffers(struct NineDevice9 *device) } static inline boolean -update_sampler_derived(struct nine_state *state, struct nine_context *context, unsigned s) +update_sampler_derived(struct nine_context *context, unsigned s) { boolean changed = FALSE; - if (state->samp[s][NINED3DSAMP_SHADOW] != context->texture[s]->shadow) { + if (context->samp[s][NINED3DSAMP_SHADOW] != context->texture[s]->shadow) { changed = TRUE; - state->samp[s][NINED3DSAMP_SHADOW] = context->texture[s]->shadow; + context->samp[s][NINED3DSAMP_SHADOW] = context->texture[s]->shadow; } - if (state->samp[s][NINED3DSAMP_CUBETEX] != + if (context->samp[s][NINED3DSAMP_CUBETEX] != (NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE)) { changed = TRUE; - state->samp[s][NINED3DSAMP_CUBETEX] = + context->samp[s][NINED3DSAMP_CUBETEX] = NineResource9(context->texture[s])->type == D3DRTYPE_CUBETEXTURE; } - if (state->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) { - int lod = state->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s]->managed.lod; + if (context->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) { + int lod = context->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s]->managed.lod; if (lod < 0) lod = 0; - if (state->samp[s][NINED3DSAMP_MINLOD] != lod) { + if (context->samp[s][NINED3DSAMP_MINLOD] != lod) { changed = TRUE; - state->samp[s][NINED3DSAMP_MINLOD] = lod; + context->samp[s][NINED3DSAMP_MINLOD] = lod; } } else { - state->changed.sampler[s] &= ~0x300; /* lod changes irrelevant */ + context->changed.sampler[s] &= ~0x300; /* lod changes irrelevant */ } return changed; @@ -773,15 +773,15 @@ update_textures_and_samplers(struct NineDevice9 *device) } if (context->texture[s]) { - sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0; + sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0; view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB); num_textures = i + 1; - if (update_sampler_derived(state, context, s) || (state->changed.sampler[s] & 0x05fe)) { - state->changed.sampler[s] = 0; + if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) { + context->changed.sampler[s] = 0; commit_samplers = TRUE; - nine_convert_sampler_state(device->cso, s, state->samp[s]); + nine_convert_sampler_state(device->cso, s, context->samp[s]); } } else { /* Bind dummy sampler. We do not bind dummy sampler when @@ -797,7 +797,7 @@ update_textures_and_samplers(struct NineDevice9 *device) s - NINE_SAMPLER_PS(0), &device->dummy_sampler_state); commit_samplers = TRUE; - state->changed.sampler[s] = ~0; + context->changed.sampler[s] = ~0; } context->bound_samplers_mask_ps |= (1 << s); @@ -821,15 +821,15 @@ update_textures_and_samplers(struct NineDevice9 *device) } if (context->texture[s]) { - sRGB = state->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0; + sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0; view[i] = NineBaseTexture9_GetSamplerView(context->texture[s], sRGB); num_textures = i + 1; - if (update_sampler_derived(state, context, s) || (state->changed.sampler[s] & 0x05fe)) { - state->changed.sampler[s] = 0; + if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) { + context->changed.sampler[s] = 0; commit_samplers = TRUE; - nine_convert_sampler_state(device->cso, s, state->samp[s]); + nine_convert_sampler_state(device->cso, s, context->samp[s]); } } else { /* Bind dummy sampler. We do not bind dummy sampler when @@ -845,7 +845,7 @@ update_textures_and_samplers(struct NineDevice9 *device) s - NINE_SAMPLER_VS(0), &device->dummy_sampler_state); commit_samplers = TRUE; - state->changed.sampler[s] = ~0; + context->changed.sampler[s] = ~0; } context->bound_samplers_mask_vs |= (1 << s); @@ -1237,6 +1237,23 @@ nine_context_set_texture(struct NineDevice9 *device, } void +nine_context_set_sampler_state(struct NineDevice9 *device, + DWORD Sampler, + D3DSAMPLERSTATETYPE Type, + DWORD Value) +{ + struct nine_state *state = &device->state; + struct nine_context *context = &device->context; + + if (unlikely(!nine_check_sampler_state_value(Type, Value))) + return; + + context->samp[Sampler][Type] = Value; + state->changed.group |= NINE_STATE_SAMPLER; + context->changed.sampler[Sampler] |= 1 << Type; +} + +void nine_context_set_stream_source(struct NineDevice9 *device, UINT StreamNumber, struct NineVertexBuffer9 *pVBuf9, @@ -1346,6 +1363,22 @@ nine_context_apply_stateblock(struct NineDevice9 *device, } } + /* Sampler state */ + if (src->changed.group & NINE_STATE_SAMPLER) { + unsigned s; + + for (s = 0; s < NINE_MAX_SAMPLERS; ++s) { + uint32_t m = src->changed.sampler[s]; + while (m) { + const int i = ffs(m) - 1; + m &= ~(1 << i); + if (nine_check_sampler_state_value(i, src->samp_advertised[s][i])) + context->samp[s][i] = src->samp_advertised[s][i]; + } + context->changed.sampler[s] |= src->changed.sampler[s]; + } + } + /* Vertex buffers */ if (src->changed.vtxbuf | src->changed.stream_freq) { uint32_t m = src->changed.vtxbuf | src->changed.stream_freq; @@ -1834,9 +1867,9 @@ nine_state_set_defaults(struct NineDevice9 *device, const D3DCAPS9 *caps, state->ff.tex_stage[0][D3DTSS_ALPHAOP] = D3DTOP_SELECTARG1; memset(&context->bumpmap_vars, 0, sizeof(context->bumpmap_vars)); - for (s = 0; s < ARRAY_SIZE(state->samp); ++s) { - memcpy(&state->samp[s], nine_samp_state_defaults, - sizeof(state->samp[s])); + for (s = 0; s < NINE_MAX_SAMPLERS; ++s) { + memcpy(&context->samp[s], nine_samp_state_defaults, + sizeof(context->samp[s])); memcpy(&state->samp_advertised[s], nine_samp_state_defaults, sizeof(state->samp_advertised[s])); } @@ -1866,8 +1899,8 @@ nine_state_set_defaults(struct NineDevice9 *device, const D3DCAPS9 *caps, state->viewport.MaxZ = 1.0f; } - for (s = 0; s < ARRAY_SIZE(state->changed.sampler); ++s) - state->changed.sampler[s] = ~0; + for (s = 0; s < NINE_MAX_SAMPLERS; ++s) + context->changed.sampler[s] = ~0; if (!is_reset) { context->dummy_vbo_bound_at = -1; diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h index c648c0dce1a..b6b8d76833d 100644 --- a/src/gallium/state_trackers/nine/nine_state.h +++ b/src/gallium/state_trackers/nine/nine_state.h @@ -42,12 +42,14 @@ #define NINED3DRS_MULTISAMPLE (D3DRS_BLENDOPALPHA + 4) #define D3DRS_LAST D3DRS_BLENDOPALPHA +#define D3DSAMP_LAST D3DSAMP_DMAPOFFSET #define NINED3DRS_LAST NINED3DRS_MULTISAMPLE /* 214 */ #define NINED3DSAMP_LAST NINED3DSAMP_CUBETEX /* 16 */ #define NINED3DTSS_LAST D3DTSS_CONSTANT #define NINED3DTS_LAST D3DTS_WORLDMATRIX(255) #define D3DRS_COUNT (D3DRS_LAST + 1) +#define D3DSAMP_COUNT (D3DSAMP_LAST + 1) #define NINED3DRS_COUNT (NINED3DRS_LAST + 1) #define NINED3DSAMP_COUNT (NINED3DSAMP_LAST + 1) #define NINED3DTSS_COUNT (NINED3DTSS_LAST + 1) @@ -139,7 +141,7 @@ struct nine_state uint32_t vtxbuf; /* stateblocks only */ uint32_t stream_freq; /* stateblocks only */ uint32_t texture; /* stateblocks only */ - uint16_t sampler[NINE_MAX_SAMPLERS]; + uint16_t sampler[NINE_MAX_SAMPLERS]; /* stateblocks only */ struct nine_range *vs_const_f; struct nine_range *ps_const_f; struct nine_range *vs_const_i; @@ -186,8 +188,7 @@ struct nine_state struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS]; /* PS, DMAP, VS */ - DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT]; - DWORD samp_advertised[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT]; + DWORD samp_advertised[NINE_MAX_SAMPLERS][D3DSAMP_COUNT]; struct { struct { @@ -214,6 +215,7 @@ struct nine_state struct nine_context { struct { + uint16_t sampler[NINE_MAX_SAMPLERS]; uint32_t vtxbuf; } changed; @@ -240,6 +242,8 @@ struct nine_context { struct NineBaseTexture9 *texture[NINE_MAX_SAMPLERS]; + DWORD samp[NINE_MAX_SAMPLERS][NINED3DSAMP_COUNT]; + uint32_t samplers_shadow; uint8_t bound_samplers_mask_vs; @@ -291,6 +295,12 @@ nine_context_set_texture(struct NineDevice9 *device, struct NineBaseTexture9 *tex); void +nine_context_set_sampler_state(struct NineDevice9 *device, + DWORD Sampler, + D3DSAMPLERSTATETYPE Type, + DWORD Value); + +void nine_context_set_stream_source(struct NineDevice9 *device, UINT StreamNumber, struct NineVertexBuffer9 *pVBuf9, diff --git a/src/gallium/state_trackers/nine/stateblock9.c b/src/gallium/state_trackers/nine/stateblock9.c index 1ed251af623..0c19703e64b 100644 --- a/src/gallium/state_trackers/nine/stateblock9.c +++ b/src/gallium/state_trackers/nine/stateblock9.c @@ -246,7 +246,6 @@ nine_state_copy_common(struct NineDevice9 *device, if (mask->changed.group & NINE_STATE_SAMPLER) { for (s = 0; s < NINE_MAX_SAMPLERS; ++s) { if (mask->changed.sampler[s] == 0x3ffe) { - memcpy(&dst->samp[s], &src->samp[s], sizeof(dst->samp[s])); memcpy(&dst->samp_advertised[s], &src->samp_advertised[s], sizeof(dst->samp_advertised[s])); } else { uint32_t m = mask->changed.sampler[s]; @@ -254,7 +253,6 @@ nine_state_copy_common(struct NineDevice9 *device, while (m) { const int i = ffs(m) - 1; m &= ~(1 << i); - dst->samp[s][i] = src->samp[s][i]; dst->samp_advertised[s][i] = src->samp_advertised[s][i]; } } @@ -444,7 +442,6 @@ nine_state_copy_common_all(struct NineDevice9 *device, dst->changed.ucp = src->changed.ucp; /* Sampler state. */ - memcpy(dst->samp, src->samp, sizeof(dst->samp)); memcpy(dst->samp_advertised, src->samp_advertised, sizeof(dst->samp_advertised)); if (apply) memcpy(dst->changed.sampler, -- 2.11.0