wined3d: Introduce a structure for stream state.

This commit is contained in:
Henri Verbeet 2010-09-14 13:38:41 +02:00 committed by Alexandre Julliard
parent 0b15963b4e
commit 6ce848bee4
6 changed files with 185 additions and 145 deletions

View File

@ -231,10 +231,10 @@ static BOOL buffer_process_converted_attribute(struct wined3d_buffer *This,
const enum wined3d_buffer_conversion_type conversion_type,
const struct wined3d_stream_info_element *attrib, DWORD *stride_this_run)
{
DWORD offset = This->resource.device->stateBlock->streams[attrib->stream_idx].offset;
DWORD attrib_size;
BOOL ret = FALSE;
unsigned int i;
DWORD offset = This->resource.device->stateBlock->streamOffset[attrib->stream_idx];
DWORD_PTR data;
/* Check for some valid situations which cause us pain. One is if the buffer is used for

View File

@ -191,6 +191,7 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
for (i = 0; i < declaration->element_count; ++i)
{
const struct wined3d_vertex_declaration_element *element = &declaration->elements[i];
struct wined3d_buffer *buffer = This->stateBlock->streams[element->input_slot].buffer;
GLuint buffer_object = 0;
const BYTE *data = NULL;
BOOL stride_used;
@ -200,20 +201,19 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
TRACE("%p Element %p (%u of %u)\n", declaration->elements,
element, i + 1, declaration->element_count);
if (!This->stateBlock->streamSource[element->input_slot]) continue;
if (!buffer) continue;
stride = This->stateBlock->streamStride[element->input_slot];
stride = This->stateBlock->streams[element->input_slot].stride;
if (This->stateBlock->streamIsUP)
{
TRACE("Stream %u is UP, %p\n", element->input_slot, This->stateBlock->streamSource[element->input_slot]);
TRACE("Stream %u is UP, %p\n", element->input_slot, buffer);
buffer_object = 0;
data = (BYTE *)This->stateBlock->streamSource[element->input_slot];
data = (BYTE *)buffer;
}
else
{
TRACE("Stream %u isn't UP, %p\n", element->input_slot, This->stateBlock->streamSource[element->input_slot]);
data = buffer_get_memory(This->stateBlock->streamSource[element->input_slot],
&This->adapter->gl_info, &buffer_object);
TRACE("Stream %u isn't UP, %p\n", element->input_slot, buffer);
data = buffer_get_memory((IWineD3DBuffer *)buffer, &This->adapter->gl_info, &buffer_object);
/* Can't use vbo's if the base vertex index is negative. OpenGL doesn't accept negative offsets
* (or rather offsets bigger than the vbo, because the pointer is unsigned), so use system memory
@ -224,8 +224,7 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
{
WARN("loadBaseVertexIndex is < 0 (%d), not using vbos\n", This->stateBlock->loadBaseVertexIndex);
buffer_object = 0;
data = buffer_get_sysmem((struct wined3d_buffer *)This->stateBlock->streamSource[element->input_slot],
&This->adapter->gl_info);
data = buffer_get_sysmem(buffer, &This->adapter->gl_info);
if ((UINT_PTR)data < -This->stateBlock->loadBaseVertexIndex * stride)
{
FIXME("System memory vertex data load offset is negative!\n");
@ -316,12 +315,11 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
{
struct wined3d_stream_info_element *element;
struct wined3d_buffer *buffer;
struct wined3d_event_query *query;
if (!(map & 1)) continue;
element = &stream_info->elements[i];
buffer = (struct wined3d_buffer *)This->stateBlock->streamSource[element->stream_idx];
buffer = This->stateBlock->streams[element->stream_idx].buffer;
IWineD3DBuffer_PreLoad((IWineD3DBuffer *)buffer);
/* If PreLoad dropped the buffer object, update the stream info. */
@ -331,11 +329,8 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
element->data = buffer_get_sysmem(buffer, &This->adapter->gl_info) + (ptrdiff_t)element->data;
}
query = ((struct wined3d_buffer *) buffer)->query;
if(query)
{
This->buffer_queries[This->num_buffer_queries++] = query;
}
if (buffer->query)
This->buffer_queries[This->num_buffer_queries++] = buffer->query;
}
}
}
@ -2269,8 +2264,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetStreamSource(IWineD3DDevice *iface,
IWineD3DBuffer *pStreamData, UINT OffsetInBytes, UINT Stride)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
struct wined3d_stream_state *stream;
IWineD3DBuffer *oldSrc;
TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
iface, StreamNumber, pStreamData, OffsetInBytes, Stride);
if (StreamNumber >= MAX_STREAMS) {
WARN("Stream out of range %d\n", StreamNumber);
return WINED3DERR_INVALIDCALL;
@ -2279,22 +2278,24 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetStreamSource(IWineD3DDevice *iface,
return WINED3DERR_INVALIDCALL;
}
oldSrc = This->updateStateBlock->streamSource[StreamNumber];
TRACE("(%p) : StreamNo: %u, OldStream (%p), NewStream (%p), OffsetInBytes %u, NewStride %u\n", This, StreamNumber, oldSrc, pStreamData, OffsetInBytes, Stride);
stream = &This->updateStateBlock->streams[StreamNumber];
oldSrc = (IWineD3DBuffer *)stream->buffer;
This->updateStateBlock->changed.streamSource |= 1 << StreamNumber;
if(oldSrc == pStreamData &&
This->updateStateBlock->streamStride[StreamNumber] == Stride &&
This->updateStateBlock->streamOffset[StreamNumber] == OffsetInBytes) {
if (oldSrc == pStreamData
&& stream->stride == Stride
&& stream->offset == OffsetInBytes)
{
TRACE("Application is setting the old values over, nothing to do\n");
return WINED3D_OK;
}
This->updateStateBlock->streamSource[StreamNumber] = pStreamData;
if (pStreamData) {
This->updateStateBlock->streamStride[StreamNumber] = Stride;
This->updateStateBlock->streamOffset[StreamNumber] = OffsetInBytes;
stream->buffer = (struct wined3d_buffer *)pStreamData;
if (pStreamData)
{
stream->stride = Stride;
stream->offset = OffsetInBytes;
}
/* Handle recording of state blocks */
@ -2325,21 +2326,21 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetStreamSource(IWineD3DDevice *iface,
UINT StreamNumber, IWineD3DBuffer **pStream, UINT *pOffset, UINT *pStride)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
struct wined3d_stream_state *stream;
TRACE("(%p) : StreamNo: %u, Stream (%p), Offset %u, Stride %u\n", This, StreamNumber,
This->stateBlock->streamSource[StreamNumber],
This->stateBlock->streamOffset[StreamNumber],
This->stateBlock->streamStride[StreamNumber]);
TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
iface, StreamNumber, pStream, pOffset, pStride);
if (StreamNumber >= MAX_STREAMS) {
if (StreamNumber >= MAX_STREAMS)
{
WARN("Stream out of range %d\n", StreamNumber);
return WINED3DERR_INVALIDCALL;
}
*pStream = This->stateBlock->streamSource[StreamNumber];
*pStride = This->stateBlock->streamStride[StreamNumber];
if (pOffset) {
*pOffset = This->stateBlock->streamOffset[StreamNumber];
}
stream = &This->stateBlock->streams[StreamNumber];
*pStream = (IWineD3DBuffer *)stream->buffer;
*pStride = stream->stride;
if (pOffset) *pOffset = stream->offset;
if (*pStream) IWineD3DBuffer_AddRef(*pStream);
@ -2348,11 +2349,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetStreamSource(IWineD3DDevice *iface,
static HRESULT WINAPI IWineD3DDeviceImpl_SetStreamSourceFreq(IWineD3DDevice *iface, UINT StreamNumber, UINT Divider) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
UINT oldFlags = This->updateStateBlock->streamFlags[StreamNumber];
UINT oldFreq = This->updateStateBlock->streamFreq[StreamNumber];
struct wined3d_stream_state *stream;
UINT oldFlags, oldFreq;
/* Verify input at least in d3d9 this is invalid*/
if( (Divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && (Divider & WINED3DSTREAMSOURCE_INDEXEDDATA)){
TRACE("iface %p, stream_idx %u, divider %#x.\n", iface, StreamNumber, Divider);
/* Verify input at least in d3d9 this is invalid. */
if ((Divider & WINED3DSTREAMSOURCE_INSTANCEDATA) && (Divider & WINED3DSTREAMSOURCE_INDEXEDDATA))
{
WARN("INSTANCEDATA and INDEXEDDATA were set, returning D3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL;
}
@ -2367,27 +2371,31 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetStreamSourceFreq(IWineD3DDevice *ifa
return WINED3DERR_INVALIDCALL;
}
TRACE("(%p) StreamNumber(%d), Divider(%d)\n", This, StreamNumber, Divider);
This->updateStateBlock->streamFlags[StreamNumber] = Divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA );
stream = &This->updateStateBlock->streams[StreamNumber];
oldFlags = stream->flags;
oldFreq = stream->frequency;
stream->flags = Divider & (WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA);
stream->frequency = Divider & 0x7FFFFF;
This->updateStateBlock->changed.streamFreq |= 1 << StreamNumber;
This->updateStateBlock->streamFreq[StreamNumber] = Divider & 0x7FFFFF;
if(This->updateStateBlock->streamFreq[StreamNumber] != oldFreq ||
This->updateStateBlock->streamFlags[StreamNumber] != oldFlags) {
if (stream->frequency != oldFreq || stream->flags != oldFlags)
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_STREAMSRC);
}
return WINED3D_OK;
}
static HRESULT WINAPI IWineD3DDeviceImpl_GetStreamSourceFreq(IWineD3DDevice *iface, UINT StreamNumber, UINT* Divider) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
struct wined3d_stream_state *stream;
TRACE("(%p) StreamNumber(%d), Divider(%p)\n", This, StreamNumber, Divider);
*Divider = This->updateStateBlock->streamFreq[StreamNumber] | This->updateStateBlock->streamFlags[StreamNumber];
TRACE("iface %p, stream_idx %u, divider %p.\n", iface, StreamNumber, Divider);
TRACE("(%p) : returning %d\n", This, *Divider);
stream = &This->updateStateBlock->streams[StreamNumber];
*Divider = stream->flags | stream->frequency;
TRACE("Returning %#x.\n", *Divider);
return WINED3D_OK;
}
@ -4167,7 +4175,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_ProcessVertices(IWineD3DDevice *iface,
e = &stream_info.elements[i];
if (e->buffer_object)
{
struct wined3d_buffer *vb = (struct wined3d_buffer *)This->stateBlock->streamSource[e->stream_idx];
struct wined3d_buffer *vb = This->stateBlock->streams[e->stream_idx].buffer;
e->buffer_object = 0;
e->data = (BYTE *)((ULONG_PTR)e->data + (ULONG_PTR)buffer_get_sysmem(vb, gl_info));
ENTER_GL();
@ -4716,6 +4724,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveUP(IWineD3DDevice *iface,
const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
struct wined3d_stream_state *stream;
IWineD3DBuffer *vb;
TRACE("(%p) : vertex count %u, pVtxData %p, stride %u\n",
@ -4727,11 +4736,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveUP(IWineD3DDevice *iface,
}
/* Note in the following, it's not this type, but that's the purpose of streamIsUP */
vb = This->stateBlock->streamSource[0];
This->stateBlock->streamSource[0] = (IWineD3DBuffer *)pVertexStreamZeroData;
stream = &This->stateBlock->streams[0];
vb = (IWineD3DBuffer *)stream->buffer;
stream->buffer = (struct wined3d_buffer *)pVertexStreamZeroData;
if (vb) IWineD3DBuffer_Release(vb);
This->stateBlock->streamOffset[0] = 0;
This->stateBlock->streamStride[0] = VertexStreamZeroStride;
stream->offset = 0;
stream->stride = VertexStreamZeroStride;
This->stateBlock->streamIsUP = TRUE;
This->stateBlock->loadBaseVertexIndex = 0;
@ -4741,8 +4751,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitiveUP(IWineD3DDevice *iface,
drawPrimitive(iface, vertex_count, 0 /* start_idx */, 0 /* indxSize*/, NULL /* indxData */);
/* MSDN specifies stream zero settings must be set to NULL */
This->stateBlock->streamStride[0] = 0;
This->stateBlock->streamSource[0] = NULL;
stream->buffer = NULL;
stream->stride = 0;
/* stream zero settings set to null at end, as per the msdn. No need to mark dirty here, the app has to set
* the new stream sources or use UP drawing again
@ -4756,6 +4766,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *
{
int idxStride;
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
struct wined3d_stream_state *stream;
IWineD3DBuffer *vb;
IWineD3DBuffer *ib;
@ -4774,12 +4785,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *
}
/* Note in the following, it's not this type, but that's the purpose of streamIsUP */
vb = This->stateBlock->streamSource[0];
This->stateBlock->streamSource[0] = (IWineD3DBuffer *)pVertexStreamZeroData;
stream = &This->stateBlock->streams[0];
vb = (IWineD3DBuffer *)stream->buffer;
stream->buffer = (struct wined3d_buffer *)pVertexStreamZeroData;
if (vb) IWineD3DBuffer_Release(vb);
stream->offset = 0;
stream->stride = VertexStreamZeroStride;
This->stateBlock->streamIsUP = TRUE;
This->stateBlock->streamOffset[0] = 0;
This->stateBlock->streamStride[0] = VertexStreamZeroStride;
/* Set to 0 as per msdn. Do it now due to the stream source loading during drawPrimitive */
This->stateBlock->baseVertexIndex = 0;
@ -4791,8 +4803,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *
drawPrimitive(iface, index_count, 0 /* start_idx */, idxStride, pIndexData);
/* MSDN specifies stream zero settings and index buffer must be set to NULL */
This->stateBlock->streamSource[0] = NULL;
This->stateBlock->streamStride[0] = 0;
stream->buffer = NULL;
stream->stride = 0;
ib = This->stateBlock->pIndexData;
if(ib) {
IWineD3DBuffer_Release(ib);
@ -6577,19 +6589,19 @@ void device_resource_released(IWineD3DDeviceImpl *device, IWineD3DResource *reso
case WINED3DRTYPE_BUFFER:
for (i = 0; i < MAX_STREAMS; ++i)
{
if (device->stateBlock && device->stateBlock->streamSource[i] == (IWineD3DBuffer *)resource)
if (device->stateBlock && device->stateBlock->streams[i].buffer == (struct wined3d_buffer *)resource)
{
ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
resource, device->stateBlock, i);
device->stateBlock->streamSource[i] = NULL;
device->stateBlock->streams[i].buffer = NULL;
}
if (device->updateStateBlock != device->stateBlock
&& device->updateStateBlock->streamSource[i] == (IWineD3DBuffer *)resource)
&& device->updateStateBlock->streams[i].buffer == (struct wined3d_buffer *)resource)
{
ERR("Buffer %p is still in use by stateblock %p, stream %u.\n",
resource, device->updateStateBlock, i);
device->updateStateBlock->streamSource[i] = NULL;
device->updateStateBlock->streams[i].buffer = NULL;
}
}

View File

@ -69,9 +69,9 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_context
const DWORD *pIdxBufL = NULL;
UINT vx_index;
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
const UINT *streamOffset = This->stateBlock->streamOffset;
LONG SkipnStrides = startIdx + This->stateBlock->loadBaseVertexIndex;
BOOL pixelShader = use_ps(This->stateBlock);
const struct wined3d_stream_state *streams = This->stateBlock->streams;
LONG SkipnStrides = startIdx + This->stateBlock->loadBaseVertexIndex;
BOOL pixelShader = use_ps(This->stateBlock);
BOOL specular_fog = FALSE;
const BYTE *texCoords[WINED3DDP_MAXTEXCOORD];
const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL;
@ -106,13 +106,13 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_context
if (si->use_map & (1 << WINED3D_FFP_POSITION))
{
element = &si->elements[WINED3D_FFP_POSITION];
position = element->data + streamOffset[element->stream_idx];
position = element->data + streams[element->stream_idx].offset;
}
if (si->use_map & (1 << WINED3D_FFP_NORMAL))
{
element = &si->elements[WINED3D_FFP_NORMAL];
normal = element->data + streamOffset[element->stream_idx];
normal = element->data + streams[element->stream_idx].offset;
}
else
{
@ -123,7 +123,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_context
if (si->use_map & (1 << WINED3D_FFP_DIFFUSE))
{
element = &si->elements[WINED3D_FFP_DIFFUSE];
diffuse = element->data + streamOffset[element->stream_idx];
diffuse = element->data + streams[element->stream_idx].offset;
if (num_untracked_materials && element->format->id != WINED3DFMT_B8G8R8A8_UNORM)
FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format->id));
@ -136,7 +136,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_context
if (si->use_map & (1 << WINED3D_FFP_SPECULAR))
{
element = &si->elements[WINED3D_FFP_SPECULAR];
specular = element->data + streamOffset[element->stream_idx];
specular = element->data + streams[element->stream_idx].offset;
/* special case where the fog density is stored in the specular alpha channel */
if (This->stateBlock->renderState[WINED3DRS_FOGENABLE]
@ -196,7 +196,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_context
if (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)))
{
element = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
texCoords[coordIdx] = element->data + streamOffset[element->stream_idx];
texCoords[coordIdx] = element->data + streams[element->stream_idx].offset;
tex_mask |= (1 << textureNo);
}
else
@ -466,7 +466,7 @@ static void drawStridedSlowVs(IWineD3DDevice *iface, const struct wined3d_stream
ptr = si->elements[i].data +
si->elements[i].stride * SkipnStrides +
stateblock->streamOffset[si->elements[i].stream_idx];
stateblock->streams[si->elements[i].stream_idx].offset;
send_attribute(This, si->elements[i].format->id, i, ptr);
}
@ -505,13 +505,13 @@ static inline void drawStridedInstanced(IWineD3DDevice *iface, const struct wine
for (i = 0; i < MAX_STREAMS; ++i)
{
/* Look at the streams and take the first one which matches */
if (stateblock->streamSource[i] && ((stateblock->streamFlags[i] & WINED3DSTREAMSOURCE_INSTANCEDATA)
|| (stateblock->streamFlags[i] & WINED3DSTREAMSOURCE_INDEXEDDATA)))
if (stateblock->streams[i].buffer && ((stateblock->streams[i].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
|| (stateblock->streams[i].flags & WINED3DSTREAMSOURCE_INDEXEDDATA)))
{
/* Use the specified number of instances from the first matched
* stream. A streamFreq of 0 (with INSTANCEDATA or INDEXEDDATA)
* is handled as 1. See d3d9/tests/visual.c-> stream_test(). */
numInstances = stateblock->streamFreq[i] ? stateblock->streamFreq[i] : 1;
numInstances = stateblock->streams[i].frequency ? stateblock->streams[i].frequency : 1;
break;
}
}
@ -520,7 +520,7 @@ static inline void drawStridedInstanced(IWineD3DDevice *iface, const struct wine
{
if (!(si->use_map & (1 << i))) continue;
if (stateblock->streamFlags[si->elements[i].stream_idx] & WINED3DSTREAMSOURCE_INSTANCEDATA)
if (stateblock->streams[si->elements[i].stream_idx].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
{
instancedData[numInstancedAttribs] = i;
numInstancedAttribs++;
@ -533,11 +533,10 @@ static inline void drawStridedInstanced(IWineD3DDevice *iface, const struct wine
for(j = 0; j < numInstancedAttribs; j++) {
const BYTE *ptr = si->elements[instancedData[j]].data +
si->elements[instancedData[j]].stride * i +
stateblock->streamOffset[si->elements[instancedData[j]].stream_idx];
stateblock->streams[si->elements[instancedData[j]].stream_idx].offset;
if (si->elements[instancedData[j]].buffer_object)
{
struct wined3d_buffer *vb =
(struct wined3d_buffer *)stateblock->streamSource[si->elements[instancedData[j]].stream_idx];
struct wined3d_buffer *vb = stateblock->streams[si->elements[instancedData[j]].stream_idx].buffer;
ptr += (ULONG_PTR)buffer_get_sysmem(vb, &This->adapter->gl_info);
}
@ -564,7 +563,7 @@ static inline void remove_vbos(IWineD3DDeviceImpl *This, const struct wined3d_gl
e = &s->elements[i];
if (e->buffer_object)
{
struct wined3d_buffer *vb = (struct wined3d_buffer *)This->stateBlock->streamSource[e->stream_idx];
struct wined3d_buffer *vb = This->stateBlock->streams[e->stream_idx].buffer;
e->buffer_object = 0;
e->data = (BYTE *)((ULONG_PTR)e->data + (ULONG_PTR)buffer_get_sysmem(vb, gl_info));
}
@ -801,8 +800,7 @@ HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This,
e = &stream_info.elements[WINED3D_FFP_POSITION];
if (e->buffer_object)
{
struct wined3d_buffer *vb;
vb = (struct wined3d_buffer *)This->stateBlock->streamSource[e->stream_idx];
struct wined3d_buffer *vb = This->stateBlock->streams[e->stream_idx].buffer;
e->data = (BYTE *)((ULONG_PTR)e->data + (ULONG_PTR)buffer_get_sysmem(vb, context->gl_info));
}
vtxStride = e->stride;

View File

@ -3234,7 +3234,6 @@ static void unloadTexCoords(const struct wined3d_gl_info *gl_info)
static void loadTexCoords(const struct wined3d_gl_info *gl_info, IWineD3DStateBlockImpl *stateblock,
const struct wined3d_stream_info *si, GLuint *curVBO)
{
const UINT *offset = stateblock->streamOffset;
unsigned int mapped_stage = 0;
unsigned int textureNo = 0;
@ -3248,6 +3247,7 @@ static void loadTexCoords(const struct wined3d_gl_info *gl_info, IWineD3DStateBl
if (coordIdx < MAX_TEXTURES && (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))))
{
const struct wined3d_stream_info_element *e = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
const struct wined3d_stream_state *stream = &stateblock->streams[e->stream_idx];
TRACE("Setting up texture %u, idx %d, cordindx %u, data %p\n",
textureNo, mapped_stage, coordIdx, e->data);
@ -3264,7 +3264,7 @@ static void loadTexCoords(const struct wined3d_gl_info *gl_info, IWineD3DStateBl
/* The coords to supply depend completely on the fvf / vertex shader */
glTexCoordPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
} else {
GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + mapped_stage, 0, 0, 0, 1));
@ -4041,22 +4041,26 @@ static inline void loadNumberedArrays(IWineD3DStateBlockImpl *stateblock,
const struct wined3d_gl_info *gl_info = context->gl_info;
GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
int i;
const UINT *offset = stateblock->streamOffset;
struct wined3d_buffer *vb;
DWORD_PTR shift_index;
/* Default to no instancing */
stateblock->device->instancedDraw = FALSE;
for (i = 0; i < MAX_ATTRIBS; i++) {
for (i = 0; i < MAX_ATTRIBS; i++)
{
const struct wined3d_stream_state *stream;
if (!(stream_info->use_map & (1 << i)))
{
if (context->numbered_array_mask & (1 << i)) unload_numbered_array(context, i);
continue;
}
stream = &stateblock->streams[stream_info->elements[i].stream_idx];
/* Do not load instance data. It will be specified using glTexCoord by drawprim */
if (stateblock->streamFlags[stream_info->elements[i].stream_idx] & WINED3DSTREAMSOURCE_INSTANCEDATA)
if (stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
{
if (context->numbered_array_mask & (1 << i)) unload_numbered_array(context, i);
stateblock->device->instancedDraw = TRUE;
@ -4073,11 +4077,11 @@ static inline void loadNumberedArrays(IWineD3DStateBlockImpl *stateblock,
checkGLcall("glBindBufferARB");
curVBO = stream_info->elements[i].buffer_object;
}
vb = (struct wined3d_buffer *)stateblock->streamSource[stream_info->elements[i].stream_idx];
/* Use the VBO to find out if a vertex buffer exists, not the vb pointer. vb can point to a
* user pointer data blob. In that case curVBO will be 0. If there is a vertex buffer but no
* vbo we won't be load converted attributes anyway
*/
/* Use the VBO to find out if a vertex buffer exists, not the vb
* pointer. vb can point to a user pointer data blob. In that case
* curVBO will be 0. If there is a vertex buffer but no vbo we
* won't be load converted attributes anyway. */
vb = stream->buffer;
if (curVBO && vb->conversion_shift)
{
TRACE("Loading attribute from shifted buffer\n");
@ -4086,14 +4090,14 @@ static inline void loadNumberedArrays(IWineD3DStateBlockImpl *stateblock,
TRACE("Original offset %p, additional offset 0x%08x\n",
stream_info->elements[i].data, vb->conversion_shift[(DWORD_PTR)stream_info->elements[i].data]);
TRACE("Opengl type %#x\n", stream_info->elements[i].format->gl_vtx_type);
shift_index = ((DWORD_PTR)stream_info->elements[i].data + offset[stream_info->elements[i].stream_idx]);
shift_index = ((DWORD_PTR)stream_info->elements[i].data + stream->offset);
shift_index = shift_index % stream_info->elements[i].stride;
GL_EXTCALL(glVertexAttribPointerARB(i, stream_info->elements[i].format->gl_vtx_format,
stream_info->elements[i].format->gl_vtx_type,
stream_info->elements[i].format->gl_normalized,
vb->conversion_stride, stream_info->elements[i].data + vb->conversion_shift[shift_index]
+ stateblock->loadBaseVertexIndex * stream_info->elements[i].stride
+ offset[stream_info->elements[i].stream_idx]));
+ stream->offset));
} else {
GL_EXTCALL(glVertexAttribPointerARB(i, stream_info->elements[i].format->gl_vtx_format,
@ -4101,7 +4105,7 @@ static inline void loadNumberedArrays(IWineD3DStateBlockImpl *stateblock,
stream_info->elements[i].format->gl_normalized,
stream_info->elements[i].stride, stream_info->elements[i].data
+ stateblock->loadBaseVertexIndex * stream_info->elements[i].stride
+ offset[stream_info->elements[i].stream_idx]));
+ stream->offset));
}
if (!(context->numbered_array_mask & (1 << i)))
@ -4109,14 +4113,17 @@ static inline void loadNumberedArrays(IWineD3DStateBlockImpl *stateblock,
GL_EXTCALL(glEnableVertexAttribArrayARB(i));
context->numbered_array_mask |= (1 << i);
}
} else {
/* Stride = 0 means always the same values. glVertexAttribPointerARB doesn't do that. Instead disable the pointer and
* set up the attribute statically. But we have to figure out the system memory address.
*/
const BYTE *ptr = stream_info->elements[i].data + offset[stream_info->elements[i].stream_idx];
}
else
{
/* Stride = 0 means always the same values.
* glVertexAttribPointerARB doesn't do that. Instead disable the
* pointer and set up the attribute statically. But we have to
* figure out the system memory address. */
const BYTE *ptr = stream_info->elements[i].data + stream->offset;
if (stream_info->elements[i].buffer_object)
{
vb = (struct wined3d_buffer *)stateblock->streamSource[stream_info->elements[i].stream_idx];
vb = stream->buffer;
ptr += (ULONG_PTR)buffer_get_sysmem(vb, gl_info);
}
@ -4215,9 +4222,9 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
const struct wined3d_stream_info *si)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
const UINT *offset = stateblock->streamOffset;
GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
const struct wined3d_stream_info_element *e;
const struct wined3d_stream_state *stream;
TRACE("Using fast vertex array code\n");
@ -4229,11 +4236,12 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
|| si->use_map & (1 << WINED3D_FFP_BLENDINDICES))
{
e = &si->elements[WINED3D_FFP_BLENDWEIGHT];
stream = &stateblock->streams[e->stream_idx];
if (gl_info->supported[ARB_VERTEX_BLEND])
{
TRACE("Blend %u %p %u\n", e->format->component_count,
e->data + stateblock->loadBaseVertexIndex * e->stride, e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride, e->stride + stream->offset);
glEnableClientState(GL_WEIGHT_ARRAY_ARB);
checkGLcall("glEnableClientState(GL_WEIGHT_ARRAY_ARB)");
@ -4251,9 +4259,9 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
e->format->gl_vtx_format,
e->format->gl_vtx_type,
e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
GL_EXTCALL(glWeightPointerARB(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]));
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset));
checkGLcall("glWeightPointerARB");
@ -4295,6 +4303,8 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
if (si->use_map & (1 << WINED3D_FFP_POSITION))
{
e = &si->elements[WINED3D_FFP_POSITION];
stream = &stateblock->streams[e->stream_idx];
if (curVBO != e->buffer_object)
{
GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object));
@ -4313,17 +4323,17 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
if (!e->buffer_object)
{
TRACE("glVertexPointer(3, %#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
glVertexPointer(3 /* min(e->format->gl_vtx_format, 3) */, e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
}
else
{
TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
glVertexPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
}
checkGLcall("glVertexPointer(...)");
glEnableClientState(GL_VERTEX_ARRAY);
@ -4334,6 +4344,8 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
if (si->use_map & (1 << WINED3D_FFP_NORMAL))
{
e = &si->elements[WINED3D_FFP_NORMAL];
stream = &stateblock->streams[e->stream_idx];
if (curVBO != e->buffer_object)
{
GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object));
@ -4342,9 +4354,9 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
}
TRACE("glNormalPointer(%#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
glNormalPointer(e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
checkGLcall("glNormalPointer(...)");
glEnableClientState(GL_NORMAL_ARRAY);
checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
@ -4366,6 +4378,8 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
if (si->use_map & (1 << WINED3D_FFP_DIFFUSE))
{
e = &si->elements[WINED3D_FFP_DIFFUSE];
stream = &stateblock->streams[e->stream_idx];
if (curVBO != e->buffer_object)
{
GL_EXTCALL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, e->buffer_object));
@ -4375,9 +4389,9 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
glColorPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
glEnableClientState(GL_COLOR_ARRAY);
checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");
@ -4393,6 +4407,8 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
TRACE("setting specular colour\n");
e = &si->elements[WINED3D_FFP_SPECULAR];
stream = &stateblock->streams[e->stream_idx];
if (gl_info->supported[EXT_SECONDARY_COLOR])
{
GLenum type = e->format->gl_vtx_type;
@ -4413,9 +4429,9 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
* 4 component secondary colors use it
*/
TRACE("glSecondaryColorPointer(%#x, %#x, %#x, %p);\n", format, type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
GL_EXTCALL(glSecondaryColorPointerEXT(format, type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]));
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset));
checkGLcall("glSecondaryColorPointerEXT(format, type, ...)");
}
else
@ -4424,9 +4440,9 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
{
case GL_UNSIGNED_BYTE:
TRACE("glSecondaryColorPointer(3, GL_UNSIGNED_BYTE, %#x, %p);\n", e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
GL_EXTCALL(glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]));
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset));
checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)");
break;
@ -4434,9 +4450,9 @@ static void loadVertexData(const struct wined3d_context *context, IWineD3DStateB
FIXME("Add 4 component specular color pointers for type %x\n", type);
/* Make sure that the right color component is dropped */
TRACE("glSecondaryColorPointer(3, %#x, %#x, %p);\n", type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset);
GL_EXTCALL(glSecondaryColorPointerEXT(3, type, e->stride,
e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]));
e->data + stateblock->loadBaseVertexIndex * e->stride + stream->offset));
checkGLcall("glSecondaryColorPointerEXT(3, type, ...)");
}
}

View File

@ -499,11 +499,14 @@ static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
if (This->textures[counter]) IWineD3DBaseTexture_Release(This->textures[counter]);
}
for (counter = 0; counter < MAX_STREAMS; counter++) {
if(This->streamSource[counter]) {
if (IWineD3DBuffer_Release(This->streamSource[counter]))
for (counter = 0; counter < MAX_STREAMS; ++counter)
{
struct wined3d_buffer *buffer = This->streams[counter].buffer;
if (buffer)
{
if (IWineD3DBuffer_Release((IWineD3DBuffer *)buffer))
{
TRACE("Vertex buffer still referenced by stateblock, applications has leaked Stream %u, buffer %p\n", counter, This->streamSource[counter]);
WARN("Buffer %p still referenced by stateblock, stream %u.\n", buffer, counter);
}
}
}
@ -765,16 +768,18 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
{
if (!(map & 1)) continue;
if (This->streamStride[i] != targetStateBlock->streamStride[i]
|| This->streamSource[i] != targetStateBlock->streamSource[i])
if (This->streams[i].stride != targetStateBlock->streams[i].stride
|| This->streams[i].buffer != targetStateBlock->streams[i].buffer)
{
TRACE("Updating stream source %u to %p, stride to %u.\n",
i, targetStateBlock->streamSource[i], targetStateBlock->streamStride[i]);
i, targetStateBlock->streams[i].buffer, targetStateBlock->streams[i].stride);
This->streamStride[i] = targetStateBlock->streamStride[i];
if (targetStateBlock->streamSource[i]) IWineD3DBuffer_AddRef(targetStateBlock->streamSource[i]);
if (This->streamSource[i]) IWineD3DBuffer_Release(This->streamSource[i]);
This->streamSource[i] = targetStateBlock->streamSource[i];
This->streams[i].stride = targetStateBlock->streams[i].stride;
if (targetStateBlock->streams[i].buffer)
IWineD3DBuffer_AddRef((IWineD3DBuffer *)targetStateBlock->streams[i].buffer);
if (This->streams[i].buffer)
IWineD3DBuffer_Release((IWineD3DBuffer *)This->streams[i].buffer);
This->streams[i].buffer = targetStateBlock->streams[i].buffer;
}
}
@ -783,14 +788,14 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
{
if (!(map & 1)) continue;
if (This->streamFreq[i] != targetStateBlock->streamFreq[i]
|| This->streamFlags[i] != targetStateBlock->streamFlags[i])
if (This->streams[i].frequency != targetStateBlock->streams[i].frequency
|| This->streams[i].flags != targetStateBlock->streams[i].flags)
{
TRACE("Updating stream frequency %u to %u flags to %#x.\n",
i, targetStateBlock->streamFreq[i], targetStateBlock->streamFlags[i]);
i, targetStateBlock->streams[i].frequency, targetStateBlock->streams[i].flags);
This->streamFreq[i] = targetStateBlock->streamFreq[i];
This->streamFlags[i] = targetStateBlock->streamFlags[i];
This->streams[i].frequency = targetStateBlock->streams[i].frequency;
This->streams[i].flags = targetStateBlock->streams[i].flags;
}
}
@ -1001,13 +1006,17 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface)
map = This->changed.streamSource;
for (i = 0; map; map >>= 1, ++i)
{
if (map & 1) IWineD3DDevice_SetStreamSource(device, i, This->streamSource[i], 0, This->streamStride[i]);
if (map & 1)
IWineD3DDevice_SetStreamSource(device, i,
(IWineD3DBuffer *)This->streams[i].buffer,
0, This->streams[i].stride);
}
map = This->changed.streamFreq;
for (i = 0; map; map >>= 1, ++i)
{
if (map & 1) IWineD3DDevice_SetStreamSourceFreq(device, i, This->streamFreq[i] | This->streamFlags[i]);
if (map & 1)
IWineD3DDevice_SetStreamSourceFreq(device, i, This->streams[i].frequency | This->streams[i].flags);
}
map = This->changed.textures;

View File

@ -2338,6 +2338,15 @@ struct StageState {
DWORD state;
};
struct wined3d_stream_state
{
struct wined3d_buffer *buffer;
UINT offset;
UINT stride;
UINT frequency;
UINT flags;
};
struct IWineD3DStateBlockImpl
{
/* IUnknown fields */
@ -2366,11 +2375,7 @@ struct IWineD3DStateBlockImpl
/* Stream Source */
BOOL streamIsUP;
UINT streamStride[MAX_STREAMS];
UINT streamOffset[MAX_STREAMS + 1 /* tesselated pseudo-stream */ ];
IWineD3DBuffer *streamSource[MAX_STREAMS];
UINT streamFreq[MAX_STREAMS + 1];
UINT streamFlags[MAX_STREAMS + 1]; /*0 | WINED3DSTREAMSOURCE_INSTANCEDATA | WINED3DSTREAMSOURCE_INDEXEDDATA */
struct wined3d_stream_state streams[MAX_STREAMS + 1 /* tesselated pseudo-stream */];
/* Indices */
IWineD3DBuffer* pIndexData;