WineD3D State management - going live(TM)

H. Verbeet hverbeet at
Thu Oct 19 05:58:21 CDT 2006

On 19/10/06, Stefan Dösinger <stefandoesinger at> wrote:
> I will move the functions applying the states into a new file,
> opengl_utils.c(name inspired by old ddraw). I don't want to put them into
> drawprim.c because that file is already quite long.
Not sure about the _utils part there, since it's pretty much core
functionality, but fair enough.

> vertex type) will share the same list. The index of the changed state will
> identify the type of the state, e.g.
> #define renderstate_entry(a) (a + 0)
> #define samplerstate_entry(a) (a + 1000) /* or
> renderstate_entry(max_render_state)
> #define texturestate_entry(a) (a + 2000)
> and so on
> This will allow us to group different states, e.g. D3DRS_LIGHTINGENABLE with
> the vertex type.
Can't you do that without putting everything in a single list?

> As many d3d states affect the same opengl state(e.g. D3DRS_FOGVERTEXMODE,
> D3DRS_FOGTABLEMODE, D3DRS_FOGSTART, D3DRS_FOGEND), the states can be grouped
> together for efficient application. This also works accross different types.
I think typically that only goes for states from the same type, ie
different render states that affect the same GL state or different
texture stages that affect the same GL state, but not so much across
state types. ie, it should be fairly uncommon for a render state to
affect the same state as a texture stage state.

> States will be applied in drawprim. BltOverride and UnlockRect change states
> on their own, and they can put the states the change onto the dirty list so
> drawprim will reset them to what the application wants. This avoids gratious
> setting and resetting. An extra last_was_blt field could be used to avoid
> that bltoverride sets its own states again and again.
Display lists could possibly help there as well, and might be easier /
faster than integrating those functions into the state management. You
would have to benchmark that to be sure though.

I assume you won't be changing everything over in one go, so perhaps
it would be best to start with the texture stage states, since those
are currently reapplied every drawprim call, and should be pretty easy
to group.

One concern I've got about lumping all the state changes together
right before the drawprim call is that we might lose some CPU/GPU
parallelism. I guess we won't be able to see how that affects things
until it's pretty much done either, but it's probably a good idea to
run some proper benchmarks before sending any patches in. (It might
actually be a good idea to do that in general).

More information about the wine-devel mailing list