wined3d: Implement index buffer offset.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Józef Kucia 2016-06-02 11:14:13 +02:00 committed by Alexandre Julliard
parent 3bac75c040
commit 42fcf20221
12 changed files with 53 additions and 47 deletions

View File

@ -3392,7 +3392,7 @@ float4 main(float4 color : COLOR) : SV_TARGET
ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
ID3D10Buffer_Release(tmp_buffer[0]);
ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
todo_wine ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
ID3D10Device_IAGetInputLayout(device, &tmp_input_layout);
ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
tmp_input_layout, input_layout);

View File

@ -360,13 +360,10 @@ static void STDMETHODCALLTYPE d3d11_immediate_context_IASetIndexBuffer(ID3D11Dev
TRACE("iface %p, buffer %p, format %s, offset %u.\n",
iface, buffer, debug_dxgi_format(format), offset);
if (offset)
FIXME("offset %u not supported.\n", offset);
wined3d_mutex_lock();
wined3d_device_set_index_buffer(device->wined3d_device,
buffer_impl ? buffer_impl->wined3d_buffer : NULL,
wined3dformat_from_dxgi_format(format));
wined3dformat_from_dxgi_format(format), offset);
wined3d_mutex_unlock();
}
@ -3061,9 +3058,8 @@ static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface
wined3d_mutex_lock();
wined3d_device_set_index_buffer(This->wined3d_device,
buffer_impl ? buffer_impl->wined3d_buffer : NULL,
wined3dformat_from_dxgi_format(format));
wined3dformat_from_dxgi_format(format), offset);
wined3d_mutex_unlock();
if (offset) FIXME("offset %u not supported.\n", offset);
}
static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
@ -3724,9 +3720,8 @@ static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface
TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
wined3d_mutex_lock();
wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, offset);
*format = dxgi_format_from_wined3dformat(wined3d_format);
*offset = 0; /* FIXME */
if (!wined3d_buffer)
{
wined3d_mutex_unlock();
@ -4212,7 +4207,7 @@ static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
{
wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
}
wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)

View File

@ -2178,14 +2178,14 @@ static HRESULT WINAPI d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface
goto done;
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer,
wined3dformat_from_d3dformat(index_format));
wined3dformat_from_d3dformat(index_format), 0);
wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / vertex_stride);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / idx_fmt_size, idx_count);
wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
wined3d_device_set_base_vertex_index(device->wined3d_device, 0);
done:
@ -2550,8 +2550,7 @@ static HRESULT WINAPI d3d8_device_SetIndices(IDirect3DDevice8 *iface,
wined3d_mutex_lock();
wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
wined3d_device_set_index_buffer(device->wined3d_device,
ib ? ib->wined3d_buffer : NULL,
ib ? ib->format : WINED3DFMT_UNKNOWN);
ib ? ib->wined3d_buffer : NULL, ib ? ib->format : WINED3DFMT_UNKNOWN, 0);
wined3d_mutex_unlock();
return D3D_OK;
@ -2573,7 +2572,7 @@ static HRESULT WINAPI d3d8_device_GetIndices(IDirect3DDevice8 *iface,
/* The case from UINT to INT is safe because d3d8 will never set negative values */
wined3d_mutex_lock();
*base_vertex_index = wined3d_device_get_base_vertex_index(device->wined3d_device);
if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format)))
if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, NULL)))
{
buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
*buffer = &buffer_impl->IDirect3DIndexBuffer8_iface;

View File

@ -2537,14 +2537,14 @@ static HRESULT WINAPI d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex *ifa
goto done;
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer,
wined3dformat_from_d3dformat(index_format));
wined3dformat_from_d3dformat(index_format), 0);
wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / vertex_stride);
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / idx_fmt_size, idx_count);
wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN, 0);
wined3d_device_set_base_vertex_index(device->wined3d_device, 0);
done:
@ -3024,8 +3024,7 @@ static HRESULT WINAPI d3d9_device_SetIndices(IDirect3DDevice9Ex *iface, IDirect3
wined3d_mutex_lock();
wined3d_device_set_index_buffer(device->wined3d_device,
ib ? ib->wined3d_buffer : NULL,
ib ? ib->format : WINED3DFMT_UNKNOWN);
ib ? ib->wined3d_buffer : NULL, ib ? ib->format : WINED3DFMT_UNKNOWN, 0);
wined3d_mutex_unlock();
return D3D_OK;
@ -3044,7 +3043,7 @@ static HRESULT WINAPI d3d9_device_GetIndices(IDirect3DDevice9Ex *iface, IDirect3
return D3DERR_INVALIDCALL;
wined3d_mutex_lock();
if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format)))
if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format, NULL)))
{
buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
*buffer = &buffer_impl->IDirect3DIndexBuffer9_iface;

View File

@ -3739,7 +3739,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, stride);
if (FAILED(hr))
goto done;
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT);
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT, 0);
wined3d_device_set_vertex_declaration(device->wined3d_device, ddraw_find_decl(device->ddraw, fvf));
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
@ -4184,7 +4184,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, vtx_dst_stride);
if (FAILED(hr))
goto done;
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT);
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT, 0);
wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / vtx_dst_stride);
wined3d_device_set_vertex_declaration(device->wined3d_device, ddraw_find_decl(device->ddraw, fvf));
@ -4406,7 +4406,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
/* Set the index stream */
wined3d_device_set_base_vertex_index(device->wined3d_device, start_vertex);
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT);
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT, 0);
/* Set the vertex stream source */
hr = wined3d_device_set_stream_source(device->wined3d_device, 0, vb_impl->wineD3DVertexBuffer, 0, stride);

View File

@ -153,6 +153,7 @@ struct wined3d_cs_set_index_buffer
enum wined3d_cs_op opcode;
struct wined3d_buffer *buffer;
enum wined3d_format_id format_id;
unsigned int offset;
};
struct wined3d_cs_set_constant_buffer
@ -580,6 +581,7 @@ static void wined3d_cs_exec_set_index_buffer(struct wined3d_cs *cs, const void *
prev = cs->state.index_buffer;
cs->state.index_buffer = op->buffer;
cs->state.index_format = op->format_id;
cs->state.index_offset = op->offset;
if (op->buffer)
InterlockedIncrement(&op->buffer->resource.bind_count);
@ -590,7 +592,7 @@ static void wined3d_cs_exec_set_index_buffer(struct wined3d_cs *cs, const void *
}
void wined3d_cs_emit_set_index_buffer(struct wined3d_cs *cs, struct wined3d_buffer *buffer,
enum wined3d_format_id format_id)
enum wined3d_format_id format_id, unsigned int offset)
{
struct wined3d_cs_set_index_buffer *op;
@ -598,6 +600,7 @@ void wined3d_cs_emit_set_index_buffer(struct wined3d_cs *cs, struct wined3d_buff
op->opcode = WINED3D_CS_OP_SET_INDEX_BUFFER;
op->buffer = buffer;
op->format_id = format_id;
op->offset = offset;
cs->ops->submit(cs);
}

View File

@ -1952,40 +1952,45 @@ void CDECL wined3d_device_get_material(const struct wined3d_device *device, stru
}
void CDECL wined3d_device_set_index_buffer(struct wined3d_device *device,
struct wined3d_buffer *buffer, enum wined3d_format_id format_id)
struct wined3d_buffer *buffer, enum wined3d_format_id format_id, unsigned int offset)
{
enum wined3d_format_id prev_format;
struct wined3d_buffer *prev_buffer;
unsigned int prev_offset;
TRACE("device %p, buffer %p, format %s.\n",
device, buffer, debug_d3dformat(format_id));
TRACE("device %p, buffer %p, format %s, offset %u.\n",
device, buffer, debug_d3dformat(format_id), offset);
prev_buffer = device->update_state->index_buffer;
prev_format = device->update_state->index_format;
prev_offset = device->update_state->index_offset;
device->update_state->index_buffer = buffer;
device->update_state->index_format = format_id;
device->update_state->index_offset = offset;
if (device->recording)
device->recording->changed.indices = TRUE;
if (prev_buffer == buffer && prev_format == format_id)
if (prev_buffer == buffer && prev_format == format_id && prev_offset == offset)
return;
if (buffer)
wined3d_buffer_incref(buffer);
if (!device->recording)
wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id);
wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id, offset);
if (prev_buffer)
wined3d_buffer_decref(prev_buffer);
}
struct wined3d_buffer * CDECL wined3d_device_get_index_buffer(const struct wined3d_device *device,
enum wined3d_format_id *format)
enum wined3d_format_id *format, unsigned int *offset)
{
TRACE("device %p, format %p.\n", device, format);
TRACE("device %p, format %p, offset %p.\n", device, format, offset);
*format = device->state.index_format;
if (offset)
*offset = device->state.index_offset;
return device->state.index_buffer;
}

View File

@ -418,12 +418,12 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s
struct wined3d_rendertarget_view *dsv;
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
BOOL emulation = FALSE;
unsigned int i, idx_size = 0;
const void *idx_data = NULL;
UINT idx_size = 0;
unsigned int i;
BOOL emulation = FALSE;
if (!index_count) return;
if (!index_count)
return;
context = context_acquire(device, wined3d_rendertarget_view_get_surface(fb->render_targets[0]));
if (!context->valid)
@ -521,12 +521,15 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s
{
struct wined3d_buffer *index_buffer = state->index_buffer;
if (!index_buffer->buffer_object || !stream_info->all_vbo)
{
idx_data = index_buffer->resource.heap_memory;
}
else
{
ib_query = index_buffer->query;
idx_data = NULL;
}
idx_data = (const BYTE *)idx_data + state->index_offset;
if (state->index_format == WINED3DFMT_R16_UINT)
idx_size = 2;
@ -579,14 +582,12 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s
if (ib_query)
wined3d_event_query_issue(ib_query, device);
for (i = 0; i < context->num_buffer_queries; ++i)
{
wined3d_event_query_issue(context->buffer_queries[i], device);
}
if (wined3d_settings.strict_draw_ordering)
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
context_release(context);
TRACE("Done all gl drawing\n");
TRACE("Done all gl drawing.\n");
}

View File

@ -705,7 +705,8 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock)
if (stateblock->changed.indices
&& ((stateblock->state.index_buffer != src_state->index_buffer)
|| (stateblock->state.base_vertex_index != src_state->base_vertex_index)
|| (stateblock->state.index_format != src_state->index_format)))
|| (stateblock->state.index_format != src_state->index_format)
|| (stateblock->state.index_offset != src_state->index_offset)))
{
TRACE("Updating index buffer to %p, base vertex index to %d.\n",
src_state->index_buffer, src_state->base_vertex_index);
@ -717,6 +718,7 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock)
stateblock->state.index_buffer = src_state->index_buffer;
stateblock->state.base_vertex_index = src_state->base_vertex_index;
stateblock->state.index_format = src_state->index_format;
stateblock->state.index_offset = src_state->index_offset;
}
if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration != src_state->vertex_declaration)
@ -985,7 +987,8 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock)
if (stateblock->changed.indices)
{
wined3d_device_set_index_buffer(device, stateblock->state.index_buffer, stateblock->state.index_format);
wined3d_device_set_index_buffer(device, stateblock->state.index_buffer,
stateblock->state.index_format, stateblock->state.index_offset);
wined3d_device_set_base_vertex_index(device, stateblock->state.base_vertex_index);
}

View File

@ -61,7 +61,7 @@
@ cdecl wined3d_device_get_gs_cb(ptr long)
@ cdecl wined3d_device_get_gs_resource_view(ptr long)
@ cdecl wined3d_device_get_gs_sampler(ptr long)
@ cdecl wined3d_device_get_index_buffer(ptr ptr)
@ cdecl wined3d_device_get_index_buffer(ptr ptr ptr)
@ cdecl wined3d_device_get_light(ptr long ptr)
@ cdecl wined3d_device_get_light_enable(ptr long ptr)
@ cdecl wined3d_device_get_material(ptr ptr)
@ -119,7 +119,7 @@
@ cdecl wined3d_device_set_gs_cb(ptr long ptr)
@ cdecl wined3d_device_set_gs_resource_view(ptr long ptr)
@ cdecl wined3d_device_set_gs_sampler(ptr long ptr)
@ cdecl wined3d_device_set_index_buffer(ptr ptr long)
@ cdecl wined3d_device_set_index_buffer(ptr ptr long long)
@ cdecl wined3d_device_set_light(ptr long ptr)
@ cdecl wined3d_device_set_light_enable(ptr long long)
@ cdecl wined3d_device_set_material(ptr ptr)

View File

@ -2227,8 +2227,9 @@ struct wined3d_state
struct wined3d_stream_state streams[MAX_STREAMS + 1 /* tesselated pseudo-stream */];
struct wined3d_buffer *index_buffer;
enum wined3d_format_id index_format;
INT base_vertex_index;
INT load_base_vertex_index; /* Non-indexed drawing needs 0 here, indexed needs base_vertex_index. */
unsigned int index_offset;
int base_vertex_index;
int load_base_vertex_index; /* Non-indexed drawing needs 0 here, indexed needs base_vertex_index. */
GLenum gl_primitive_type;
struct wined3d_query *predicate;
BOOL predicate_value;
@ -2910,7 +2911,7 @@ void wined3d_cs_emit_set_constant_buffer(struct wined3d_cs *cs, enum wined3d_sha
void wined3d_cs_emit_set_depth_stencil_view(struct wined3d_cs *cs,
struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_index_buffer(struct wined3d_cs *cs, struct wined3d_buffer *buffer,
enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
enum wined3d_format_id format_id, unsigned int offset) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_material(struct wined3d_cs *cs, const struct wined3d_material *material) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_predication(struct wined3d_cs *cs,
struct wined3d_query *predicate, BOOL value) DECLSPEC_HIDDEN;

View File

@ -2121,7 +2121,7 @@ struct wined3d_shader_resource_view * __cdecl wined3d_device_get_gs_resource_vie
UINT idx);
struct wined3d_sampler * __cdecl wined3d_device_get_gs_sampler(const struct wined3d_device *device, UINT idx);
struct wined3d_buffer * __cdecl wined3d_device_get_index_buffer(const struct wined3d_device *device,
enum wined3d_format_id *format);
enum wined3d_format_id *format, unsigned int *offset);
HRESULT __cdecl wined3d_device_get_light(const struct wined3d_device *device,
UINT light_idx, struct wined3d_light *light);
HRESULT __cdecl wined3d_device_get_light_enable(const struct wined3d_device *device, UINT light_idx, BOOL *enable);
@ -2211,7 +2211,7 @@ void __cdecl wined3d_device_set_gs_resource_view(struct wined3d_device *device,
UINT idx, struct wined3d_shader_resource_view *view);
void __cdecl wined3d_device_set_gs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler);
void __cdecl wined3d_device_set_index_buffer(struct wined3d_device *device,
struct wined3d_buffer *index_buffer, enum wined3d_format_id format_id);
struct wined3d_buffer *index_buffer, enum wined3d_format_id format_id, unsigned int offset);
HRESULT __cdecl wined3d_device_set_light(struct wined3d_device *device,
UINT light_idx, const struct wined3d_light *light);
HRESULT __cdecl wined3d_device_set_light_enable(struct wined3d_device *device, UINT light_idx, BOOL enable);