From: Axel Davy Date: Sun, 16 Oct 2016 16:17:27 +0000 (+0200) Subject: st/nine: Move vtxbuf to nine_context X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=848ffc81e4c91414ec29464ee71560547a12cd64;p=mesa.git st/nine: Move vtxbuf 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 --- diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c index ce30d264f35..102e5fc5919 100644 --- a/src/gallium/state_trackers/nine/device9.c +++ b/src/gallium/state_trackers/nine/device9.c @@ -3404,22 +3404,29 @@ NineDevice9_SetStreamSource( struct NineDevice9 *This, user_assert(StreamNumber < This->caps.MaxStreams, D3DERR_INVALIDCALL); user_assert(Stride <= This->caps.MaxStreamStride, D3DERR_INVALIDCALL); - if (likely(!This->is_recording)) { - if (state->stream[i] == NineVertexBuffer9(pStreamData) && - state->vtxbuf[i].stride == Stride && - state->vtxbuf[i].buffer_offset == OffsetInBytes) - return D3D_OK; - } - nine_bind(&state->stream[i], pStreamData); - - state->changed.vtxbuf |= 1 << StreamNumber; - - if (pStreamData) { + if (unlikely(This->is_recording)) { + nine_bind(&state->stream[i], pStreamData); + state->changed.vtxbuf |= 1 << StreamNumber; state->vtxbuf[i].stride = Stride; state->vtxbuf[i].buffer_offset = OffsetInBytes; + return D3D_OK; } - pipe_resource_reference(&state->vtxbuf[i].buffer, - pStreamData ? NineVertexBuffer9_GetResource(pVBuf9) : NULL); + + if (state->stream[i] == NineVertexBuffer9(pStreamData) && + state->vtxbuf[i].stride == Stride && + state->vtxbuf[i].buffer_offset == OffsetInBytes) + return D3D_OK; + + state->vtxbuf[i].stride = Stride; + state->vtxbuf[i].buffer_offset = OffsetInBytes; + + nine_bind(&state->stream[i], pStreamData); + + nine_context_set_stream_source(This, + StreamNumber, + pVBuf9, + OffsetInBytes, + Stride); return D3D_OK; } diff --git a/src/gallium/state_trackers/nine/nine_state.c b/src/gallium/state_trackers/nine/nine_state.c index 0733d6efea8..066ed7f4aec 100644 --- a/src/gallium/state_trackers/nine/nine_state.c +++ b/src/gallium/state_trackers/nine/nine_state.c @@ -668,9 +668,9 @@ update_vertex_elements(struct NineDevice9 *device) if (context->dummy_vbo_bound_at != dummy_vbo_stream) { if (context->dummy_vbo_bound_at >= 0) - state->changed.vtxbuf |= 1 << context->dummy_vbo_bound_at; + context->changed.vtxbuf |= 1 << context->dummy_vbo_bound_at; if (dummy_vbo_stream >= 0) { - state->changed.vtxbuf |= 1 << dummy_vbo_stream; + context->changed.vtxbuf |= 1 << dummy_vbo_stream; context->vbo_bound_done = FALSE; } context->dummy_vbo_bound_at = dummy_vbo_stream; @@ -686,9 +686,8 @@ update_vertex_buffers(struct NineDevice9 *device) { struct pipe_context *pipe = device->pipe; struct nine_context *context = &device->context; - struct nine_state *state = &device->state; struct pipe_vertex_buffer dummy_vtxbuf; - uint32_t mask = state->changed.vtxbuf; + uint32_t mask = context->changed.vtxbuf; unsigned i; DBG("mask=%x\n", mask); @@ -708,14 +707,14 @@ update_vertex_buffers(struct NineDevice9 *device) for (i = 0; mask; mask >>= 1, ++i) { if (mask & 1) { - if (state->vtxbuf[i].buffer) - pipe->set_vertex_buffers(pipe, i, 1, &state->vtxbuf[i]); + if (context->vtxbuf[i].buffer) + pipe->set_vertex_buffers(pipe, i, 1, &context->vtxbuf[i]); else pipe->set_vertex_buffers(pipe, i, 1, NULL); } } - state->changed.vtxbuf = 0; + context->changed.vtxbuf = 0; } static inline boolean @@ -1064,7 +1063,7 @@ nine_update_state(struct NineDevice9 *device) prepare_ps_constants_userbuf(device); } - if (state->changed.vtxbuf) + if (context->changed.vtxbuf) update_vertex_buffers(device); if (context->commit & NINE_STATE_COMMIT_BLEND) @@ -1240,6 +1239,26 @@ nine_context_set_texture(struct NineDevice9 *device, state->changed.group |= NINE_STATE_TEXTURE; } +void +nine_context_set_stream_source(struct NineDevice9 *device, + UINT StreamNumber, + struct NineVertexBuffer9 *pVBuf9, + UINT OffsetInBytes, + UINT Stride) +{ + struct nine_context *context = &device->context; + const unsigned i = StreamNumber; + + context->changed.vtxbuf |= 1 << StreamNumber; + + if (pVBuf9) { + context->vtxbuf[i].stride = Stride; + context->vtxbuf[i].buffer_offset = OffsetInBytes; + } + pipe_resource_reference(&context->vtxbuf[i].buffer, + pVBuf9 ? NineVertexBuffer9_GetResource(pVBuf9) : NULL); +} + void nine_context_apply_stateblock(struct NineDevice9 *device, const struct nine_state *src) @@ -1272,6 +1291,22 @@ nine_context_apply_stateblock(struct NineDevice9 *device, nine_bind(&context->texture[s], src->texture[s]); } } + + /* Vertex buffers */ + if (src->changed.vtxbuf | src->changed.stream_freq) { + uint32_t m = src->changed.vtxbuf | src->changed.stream_freq; + for (i = 0; m; ++i, m >>= 1) { + if (src->changed.vtxbuf & (1 << i)) { + if (src->stream[i]) { + context->vtxbuf[i].buffer_offset = src->vtxbuf[i].buffer_offset; + pipe_resource_reference(&context->vtxbuf[i].buffer, + src->stream[i] ? NineVertexBuffer9_GetResource(src->stream[i]) : NULL); + context->vtxbuf[i].stride = src->vtxbuf[i].stride; + } + } + } + context->changed.vtxbuf |= src->changed.vtxbuf; + } } static void @@ -1702,7 +1737,7 @@ void nine_state_restore_non_cso(struct NineDevice9 *device) struct nine_context *context = &device->context; state->changed.group = NINE_STATE_ALL; - state->changed.vtxbuf = (1ULL << device->caps.MaxStreams) - 1; + context->changed.vtxbuf = (1ULL << device->caps.MaxStreams) - 1; state->changed.ucp = (1 << PIPE_MAX_CLIP_PLANES) - 1; context->commit |= NINE_STATE_COMMIT_CONST_VS | NINE_STATE_COMMIT_CONST_PS; } @@ -1749,7 +1784,7 @@ nine_state_set_defaults(struct NineDevice9 *device, const D3DCAPS9 *caps, /* Set changed flags to initialize driver. */ state->changed.group = NINE_STATE_ALL; - state->changed.vtxbuf = (1ULL << device->caps.MaxStreams) - 1; + context->changed.vtxbuf = (1ULL << device->caps.MaxStreams) - 1; state->changed.ucp = (1 << PIPE_MAX_CLIP_PLANES) - 1; state->ff.changed.transform[0] = ~0; @@ -1780,10 +1815,9 @@ nine_state_clear(struct nine_state *state, const boolean device) nine_bind(&state->vs, NULL); nine_bind(&state->ps, NULL); nine_bind(&state->vdecl, NULL); - for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) { + for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) nine_bind(&state->stream[i], NULL); - pipe_resource_reference(&state->vtxbuf[i].buffer, NULL); - } + nine_bind(&state->idxbuf, NULL); for (i = 0; i < NINE_MAX_SAMPLERS; ++i) { if (device && @@ -1799,6 +1833,9 @@ nine_context_clear(struct nine_context *context) { unsigned i; + for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) + pipe_resource_reference(&context->vtxbuf[i].buffer, NULL); + for (i = 0; i < NINE_MAX_SAMPLERS; ++i) nine_bind(&context->texture[i], NULL); } @@ -1922,11 +1959,12 @@ update_vertex_buffers_sw(struct NineDevice9 *device, int start_vertice, int num_ for (i = 0; mask; mask >>= 1, ++i) { if (mask & 1) { - if (state->vtxbuf[i].buffer) { + if (state->stream[i]) { struct pipe_resource *buf; struct pipe_box box; vtxbuf = state->vtxbuf[i]; + vtxbuf.buffer = NineVertexBuffer9_GetResource(state->stream[i]); DBG("Locking %p (offset %d, length %d)\n", vtxbuf.buffer, vtxbuf.buffer_offset, num_vertices * vtxbuf.stride); diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h index 7711a2bef62..e111f091443 100644 --- a/src/gallium/state_trackers/nine/nine_state.h +++ b/src/gallium/state_trackers/nine/nine_state.h @@ -136,7 +136,7 @@ struct nine_state struct { uint32_t group; uint32_t rs[(NINED3DRS_COUNT + 31) / 32]; /* stateblocks only */ - uint32_t vtxbuf; + uint32_t vtxbuf; /* stateblocks only */ uint32_t stream_freq; uint32_t texture; /* stateblocks only */ uint16_t sampler[NINE_MAX_SAMPLERS]; @@ -178,7 +178,7 @@ struct nine_state struct NineIndexBuffer9 *idxbuf; struct NineVertexBuffer9 *stream[PIPE_MAX_ATTRIBS]; - struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; + struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; /* vtxbuf.buffer unused */ UINT stream_freq[PIPE_MAX_ATTRIBS]; uint32_t stream_instancedata_mask; /* derived from stream_freq */ @@ -215,6 +215,10 @@ struct nine_state }; struct nine_context { + struct { + uint32_t vtxbuf; + } changed; + uint32_t bumpmap_vars[6 * NINE_MAX_TEXTURE_STAGES]; struct { @@ -224,6 +228,7 @@ struct nine_context { uint8_t rt_mask; + struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; uint32_t stream_usage_mask; /* derived from VS and vdecl */ DWORD rs[NINED3DRS_COUNT]; @@ -280,6 +285,13 @@ nine_context_set_texture(struct NineDevice9 *device, DWORD Stage, struct NineBaseTexture9 *tex); +void +nine_context_set_stream_source(struct NineDevice9 *device, + UINT StreamNumber, + struct NineVertexBuffer9 *pVBuf9, + UINT OffsetInBytes, + UINT Stride); + void nine_context_apply_stateblock(struct NineDevice9 *device, const struct nine_state *src); diff --git a/src/gallium/state_trackers/nine/stateblock9.c b/src/gallium/state_trackers/nine/stateblock9.c index d0063ed774a..3ebee84471f 100644 --- a/src/gallium/state_trackers/nine/stateblock9.c +++ b/src/gallium/state_trackers/nine/stateblock9.c @@ -276,7 +276,6 @@ nine_state_copy_common(struct NineDevice9 *device, nine_bind(&dst->stream[i], src->stream[i]); if (src->stream[i]) { dst->vtxbuf[i].buffer_offset = src->vtxbuf[i].buffer_offset; - pipe_resource_reference(&dst->vtxbuf[i].buffer, src->vtxbuf[i].buffer); dst->vtxbuf[i].stride = src->vtxbuf[i].stride; } } @@ -463,7 +462,6 @@ nine_state_copy_common_all(struct NineDevice9 *device, nine_bind(&dst->stream[i], src->stream[i]); if (src->stream[i]) { dst->vtxbuf[i].buffer_offset = src->vtxbuf[i].buffer_offset; - pipe_resource_reference(&dst->vtxbuf[i].buffer, src->vtxbuf[i].buffer); dst->vtxbuf[i].stride = src->vtxbuf[i].stride; } dst->stream_freq[i] = src->stream_freq[i];