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;
}
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;
{
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);
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
prepare_ps_constants_userbuf(device);
}
- if (state->changed.vtxbuf)
+ if (context->changed.vtxbuf)
update_vertex_buffers(device);
if (context->commit & NINE_STATE_COMMIT_BLEND)
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)
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
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;
}
/* 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;
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 &&
{
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);
}
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);
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];
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 */
};
struct nine_context {
+ struct {
+ uint32_t vtxbuf;
+ } changed;
+
uint32_t bumpmap_vars[6 * NINE_MAX_TEXTURE_STAGES];
struct {
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];
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);