st/nine: Back vs to nine_context

And move programmable_vs storage and computation.
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 <axel.davy@ens.fr>
This commit is contained in:
Axel Davy 2016-10-17 21:43:11 +02:00
parent 43288cf376
commit 2a698c3df2
5 changed files with 71 additions and 41 deletions

View File

@ -2928,6 +2928,7 @@ NineDevice9_ProcessVertices( struct NineDevice9 *This,
struct pipe_stream_output_target *target;
struct pipe_draw_info draw;
struct pipe_box box;
bool programmable_vs = This->state.vs && !(This->state.vdecl && This->state.vdecl->position_t);
unsigned offsets[1] = {0};
HRESULT hr;
unsigned buffer_size;
@ -2944,7 +2945,7 @@ NineDevice9_ProcessVertices( struct NineDevice9 *This,
}
vs = This->state.programmable_vs ? This->state.vs : This->ff.vs;
vs = programmable_vs ? This->state.vs : This->ff.vs;
/* Note: version is 0 for ff */
user_assert(vdecl || (vs->byte_code.version < 0x30 && dst->desc.FVF),
D3DERR_INVALIDCALL);
@ -2966,7 +2967,7 @@ NineDevice9_ProcessVertices( struct NineDevice9 *This,
* if not set, everything from src will be used, and dst
* must match exactly the ff vs outputs.
* TODO: Handle all the checks, etc for ff */
user_assert(vdecl->position_t || This->state.programmable_vs,
user_assert(vdecl->position_t || programmable_vs,
D3DERR_INVALIDCALL);
/* TODO: Support vs < 3 and ff */
@ -3154,23 +3155,22 @@ NineDevice9_SetVertexShader( struct NineDevice9 *This,
IDirect3DVertexShader9 *pShader )
{
struct nine_state *state = This->update;
struct nine_context *context = &This->context;
BOOL was_programmable_vs = This->state.programmable_vs;
struct NineVertexShader9 *vs_shader = (struct NineVertexShader9*)pShader;
DBG("This=%p pShader=%p\n", This, pShader);
if (!This->is_recording && state->vs == (struct NineVertexShader9*)pShader)
if (unlikely(This->is_recording)) {
nine_bind(&state->vs, vs_shader);
state->changed.group |= NINE_STATE_VS;
return D3D_OK;
}
if (state->vs == vs_shader)
return D3D_OK;
nine_bind(&state->vs, pShader);
nine_bind(&state->vs, vs_shader);
This->state.programmable_vs = This->state.vs && !(This->context.vdecl && This->context.vdecl->position_t);
/* ff -> non-ff: commit back non-ff constants */
if (!was_programmable_vs && This->state.programmable_vs)
context->commit |= NINE_STATE_COMMIT_CONST_VS;
state->changed.group |= NINE_STATE_VS;
nine_context_set_vertex_shader(This, vs_shader);
return D3D_OK;
}

View File

@ -1832,7 +1832,7 @@ nine_ff_get_ps(struct NineDevice9 *device)
* Tests on Win 10 seem to indicate _34
* and _33 are checked against 0, 1. */
if (key.fog_mode && key.fog)
key.fog_source = !state->programmable_vs &&
key.fog_source = !context->programmable_vs &&
!(projection_matrix->_34 == 0.0f &&
projection_matrix->_44 == 1.0f);
@ -2042,10 +2042,10 @@ nine_ff_update(struct NineDevice9 *device)
struct nine_context *context = &device->context;
struct pipe_constant_buffer cb;
DBG("vs=%p ps=%p\n", device->state.vs, device->state.ps);
DBG("vs=%p ps=%p\n", context->vs, device->state.ps);
/* NOTE: the only reference belongs to the hash table */
if (!state->programmable_vs) {
if (!context->programmable_vs) {
device->ff.vs = nine_ff_get_vs(device);
device->state.changed.group |= NINE_STATE_VS;
}
@ -2054,7 +2054,7 @@ nine_ff_update(struct NineDevice9 *device)
device->state.changed.group |= NINE_STATE_PS;
}
if (!state->programmable_vs) {
if (!context->programmable_vs) {
nine_ff_load_vs_transforms(device);
nine_ff_load_tex_matrices(device);
nine_ff_load_lights(device);

View File

@ -85,7 +85,7 @@ nine_ff_get_projected_key(struct nine_state *state, struct nine_context *context
unsigned dim = state->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & 0x7;
unsigned proj = !!(state->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED);
if (!state->vs) {
if (!context->vs) {
if (dim > 4)
dim = input_texture_coord[s];

View File

@ -95,8 +95,8 @@ prepare_vs_constants_userbuf_swvp(struct NineDevice9 *device)
cb.buffer_size = 4096 * sizeof(float[4]);
cb.user_buffer = state->vs_const_f_swvp;
if (state->vs->lconstf.ranges) {
const struct nine_lconstf *lconstf = &device->state.vs->lconstf;
if (context->vs->lconstf.ranges) {
const struct nine_lconstf *lconstf = &(context->vs->lconstf);
const struct nine_range *r = lconstf->ranges;
unsigned n = 0;
float *dst = device->state.vs_lconstf_temp;
@ -234,7 +234,7 @@ prepare_vs_constants_userbuf(struct NineDevice9 *device)
struct pipe_constant_buffer cb;
cb.buffer = NULL;
cb.buffer_offset = 0;
cb.buffer_size = device->state.vs->const_used_size;
cb.buffer_size = context->vs->const_used_size;
cb.user_buffer = device->state.vs_const_f;
if (device->swvp) {
@ -274,9 +274,9 @@ prepare_vs_constants_userbuf(struct NineDevice9 *device)
if (!cb.buffer_size)
return;
if (device->state.vs->lconstf.ranges) {
if (context->vs->lconstf.ranges) {
/* TODO: Can we make it so that we don't have to copy everything ? */
const struct nine_lconstf *lconstf = &device->state.vs->lconstf;
const struct nine_lconstf *lconstf = &(context->vs->lconstf);
const struct nine_range *r = lconstf->ranges;
unsigned n = 0;
float *dst = device->state.vs_lconstf_temp;
@ -400,20 +400,19 @@ prepare_ps_constants_userbuf(struct NineDevice9 *device)
static inline uint32_t
prepare_vs(struct NineDevice9 *device, uint8_t shader_changed)
{
struct nine_state *state = &device->state;
struct nine_context *context = &device->context;
struct NineVertexShader9 *vs = state->vs;
struct NineVertexShader9 *vs = context->vs;
uint32_t changed_group = 0;
int has_key_changed = 0;
if (likely(state->programmable_vs))
if (likely(context->programmable_vs))
has_key_changed = NineVertexShader9_UpdateKey(vs, device);
if (!shader_changed && !has_key_changed)
return 0;
/* likely because we dislike FF */
if (likely(state->programmable_vs)) {
if (likely(context->programmable_vs)) {
context->cso.vs = NineVertexShader9_GetVariant(vs);
} else {
vs = device->ff.vs;
@ -610,7 +609,7 @@ update_vertex_elements(struct NineDevice9 *device)
context->stream_usage_mask = 0;
memset(vdecl_index_map, -1, 16);
memset(used_streams, 0, device->caps.MaxStreams);
vs = state->programmable_vs ? device->state.vs : device->ff.vs;
vs = context->programmable_vs ? context->vs : device->ff.vs;
if (vdecl) {
for (n = 0; n < vs->num_inputs; ++n) {
@ -810,7 +809,7 @@ update_textures_and_samplers(struct NineDevice9 *device)
cso_single_sampler_done(device->cso, PIPE_SHADER_FRAGMENT);
commit_samplers = FALSE;
sampler_mask = state->programmable_vs ? state->vs->sampler_mask : 0;
sampler_mask = context->programmable_vs ? context->vs->sampler_mask : 0;
context->bound_samplers_mask_vs = 0;
for (num_textures = 0, i = 0; i < NINE_MAX_SAMPLERS_VS; ++i) {
const unsigned s = NINE_SAMPLER_VS(i);
@ -901,7 +900,7 @@ commit_vs_constants(struct NineDevice9 *device)
{
struct pipe_context *pipe = device->pipe;
if (unlikely(!device->state.programmable_vs))
if (unlikely(!device->context.programmable_vs))
pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &device->context.pipe.cb_vs_ff);
else {
if (device->swvp) {
@ -1022,7 +1021,7 @@ nine_update_state(struct NineDevice9 *device)
update_managed_buffers(device);
/* ff_update may change VS/PS dirty bits */
if (unlikely(!state->programmable_vs || !state->ps))
if (unlikely(!context->programmable_vs || !state->ps))
nine_ff_update(device);
group = state->changed.group;
@ -1055,7 +1054,7 @@ nine_update_state(struct NineDevice9 *device)
prepare_rasterizer(device);
if (group & (NINE_STATE_TEXTURE | NINE_STATE_SAMPLER))
update_textures_and_samplers(device);
if ((group & (NINE_STATE_VS_CONST | NINE_STATE_VS | NINE_STATE_SWVP)) && state->programmable_vs)
if ((group & (NINE_STATE_VS_CONST | NINE_STATE_VS | NINE_STATE_SWVP)) && context->programmable_vs)
prepare_vs_constants_userbuf(device);
if ((group & (NINE_STATE_PS_CONST | NINE_STATE_PS)) && state->ps)
prepare_ps_constants_userbuf(device);
@ -1282,12 +1281,12 @@ nine_context_set_vertex_declaration(struct NineDevice9 *device,
{
struct nine_state *state = &device->state;
struct nine_context *context = &device->context;
BOOL was_programmable_vs = device->state.programmable_vs;
BOOL was_programmable_vs = context->programmable_vs;
nine_bind(&context->vdecl, vdecl);
device->state.programmable_vs = device->state.vs && !(device->context.vdecl && device->context.vdecl->position_t);
if (was_programmable_vs != device->state.programmable_vs) {
context->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
if (was_programmable_vs != context->programmable_vs) {
context->commit |= NINE_STATE_COMMIT_CONST_VS;
state->changed.group |= NINE_STATE_VS;
}
@ -1295,6 +1294,25 @@ nine_context_set_vertex_declaration(struct NineDevice9 *device,
state->changed.group |= NINE_STATE_VDECL;
}
void
nine_context_set_vertex_shader(struct NineDevice9 *device,
struct NineVertexShader9 *pShader)
{
struct nine_state *state = &device->state;
struct nine_context *context = &device->context;
BOOL was_programmable_vs = context->programmable_vs;
nine_bind(&context->vs, pShader);
context->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
/* ff -> non-ff: commit back non-ff constants */
if (!was_programmable_vs && context->programmable_vs)
context->commit |= NINE_STATE_COMMIT_CONST_VS;
state->changed.group |= NINE_STATE_VS;
}
void
nine_context_apply_stateblock(struct NineDevice9 *device,
const struct nine_state *src)
@ -1355,7 +1373,11 @@ nine_context_apply_stateblock(struct NineDevice9 *device,
if ((src->changed.group & NINE_STATE_VDECL) && src->vdecl)
nine_context_set_vertex_declaration(device, src->vdecl);
device->state.programmable_vs = device->state.vs && !(context->vdecl && context->vdecl->position_t);
/* Vertex shader */
if (src->changed.group & NINE_STATE_VS)
nine_bind(&context->vs, src->vs);
context->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
}
static void
@ -1882,6 +1904,7 @@ nine_context_clear(struct nine_context *context)
{
unsigned i;
nine_bind(&context->vs, NULL);
nine_bind(&context->vdecl, NULL);
for (i = 0; i < PIPE_MAX_ATTRIBS; ++i)
pipe_resource_reference(&context->vtxbuf[i].buffer, NULL);
@ -1932,10 +1955,11 @@ update_vertex_elements_sw(struct NineDevice9 *device)
int dummy_vbo_stream = -1;
BOOL need_dummy_vbo = FALSE;
struct pipe_vertex_element ve[PIPE_MAX_ATTRIBS];
bool programmable_vs = state->vs && !(state->vdecl && state->vdecl->position_t);
memset(vdecl_index_map, -1, 16);
memset(used_streams, 0, device->caps.MaxStreams);
vs = state->programmable_vs ? device->state.vs : device->ff.vs;
vs = programmable_vs ? device->state.vs : device->ff.vs;
if (vdecl) {
for (n = 0; n < vs->num_inputs; ++n) {
@ -2202,10 +2226,10 @@ nine_state_prepare_draw_sw(struct NineDevice9 *device, struct NineVertexDeclarat
int start_vertice, int num_vertices, struct pipe_stream_output_info *so)
{
struct nine_state *state = &device->state;
bool programmable_vs = state->vs && !(state->vdecl && state->vdecl->position_t);
struct NineVertexShader9 *vs = programmable_vs ? device->state.vs : device->ff.vs;
struct NineVertexShader9 *vs = state->programmable_vs ? device->state.vs : device->ff.vs;
assert(state->programmable_vs);
assert(programmable_vs);
DBG("Preparing draw\n");
cso_set_vertex_shader_handle(device->cso_sw,

View File

@ -166,7 +166,6 @@ struct nine_state
int *vs_const_i;
BOOL *vs_const_b;
float *vs_lconstf_temp;
BOOL programmable_vs;
struct NinePixelShader9 *ps;
float *ps_const_f;
@ -227,6 +226,9 @@ struct nine_context {
uint8_t rt_mask;
struct NineVertexShader9 *vs;
BOOL programmable_vs;
struct NineVertexDeclaration9 *vdecl;
struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
@ -304,6 +306,10 @@ void
nine_context_set_vertex_declaration(struct NineDevice9 *device,
struct NineVertexDeclaration9 *vdecl);
void
nine_context_set_vertex_shader(struct NineDevice9 *device,
struct NineVertexShader9 *pShader);
void
nine_context_apply_stateblock(struct NineDevice9 *device,
const struct nine_state *src);