Lines Matching defs:context

138 /* Create a CSMT context.
172 DBG("Returning context %p\n", ctx);
223 /* Destroys a CSMT context.
299 return device->context.pipe;
308 return device->context.pipe;
313 return device->context.pipe;
320 return device->context.pipe;
347 struct nine_context *context = &device->context;
348 DWORD *rs = context->rs;
349 struct NineSurface9 *rt0 = context->rt[0];
354 if (rt0 && rt0->desc.Format == D3DFMT_NULL && context->ds)
355 multisampled_target = context->ds->desc.MultiSampleType >= 1;
369 nine_convert_blend_state(&device->context.pipe_data.blend, device->context.rs);
370 device->context.commit |= NINE_STATE_COMMIT_BLEND;
376 nine_convert_dsa_state(&device->context.pipe_data.dsa, device->context.rs);
377 device->context.commit |= NINE_STATE_COMMIT_DSA;
383 nine_convert_rasterizer_state(device, &device->context.pipe_data.rast, device->context.rs);
384 device->context.commit |= NINE_STATE_COMMIT_RASTERIZER;
390 struct nine_context *context = &device->context;
392 if (context->changed.vs_const_f || context->changed.group & NINE_STATE_SWVP) {
397 cb.user_buffer = context->vs_const_f_swvp;
399 if (context->vs->lconstf.ranges) {
400 const struct nine_lconstf *lconstf = &(context->vs->lconstf);
403 float *dst = context->vs_lconstf_temp;
416 context->pipe_data.cb0_swvp.buffer_offset = cb.buffer_offset;
417 context->pipe_data.cb0_swvp.buffer_size = cb.buffer_size;
418 context->pipe_data.cb0_swvp.user_buffer = cb.user_buffer;
421 context->pipe_data.cb1_swvp.buffer_offset = cb.buffer_offset;
422 context->pipe_data.cb1_swvp.buffer_size = cb.buffer_size;
423 context->pipe_data.cb1_swvp.user_buffer = cb.user_buffer;
425 context->changed.vs_const_f = 0;
428 if (context->changed.vs_const_i || context->changed.group & NINE_STATE_SWVP) {
433 cb.user_buffer = context->vs_const_i;
435 context->pipe_data.cb2_swvp.buffer_offset = cb.buffer_offset;
436 context->pipe_data.cb2_swvp.buffer_size = cb.buffer_size;
437 context->pipe_data.cb2_swvp.user_buffer = cb.user_buffer;
438 context->changed.vs_const_i = 0;
441 if (context->changed.vs_const_b || context->changed.group & NINE_STATE_SWVP) {
446 cb.user_buffer = context->vs_const_b;
448 context->pipe_data.cb3_swvp.buffer_offset = cb.buffer_offset;
449 context->pipe_data.cb3_swvp.buffer_size = cb.buffer_size;
450 context->pipe_data.cb3_swvp.user_buffer = cb.user_buffer;
451 context->changed.vs_const_b = 0;
454 context->changed.group &= ~NINE_STATE_VS_CONST;
455 context->commit |= NINE_STATE_COMMIT_CONST_VS;
461 struct nine_context *context = &device->context;
466 cb.buffer_size = context->cso_shader.vs_const_used_size;
467 cb.user_buffer = context->vs_const_f;
469 if (context->swvp) {
474 if (context->changed.vs_const_i || context->changed.group & NINE_STATE_SWVP) {
475 int *idst = (int *)&context->vs_const_f[4 * device->max_vs_const_f];
476 memcpy(idst, context->vs_const_i, NINE_MAX_CONST_I * sizeof(int[4]));
477 context->changed.vs_const_i = 0;
480 if (context->changed.vs_const_b || context->changed.group & NINE_STATE_SWVP) {
481 int *idst = (int *)&context->vs_const_f[4 * device->max_vs_const_f];
483 memcpy(bdst, context->vs_const_b, NINE_MAX_CONST_B * sizeof(BOOL));
484 context->changed.vs_const_b = 0;
490 if (context->vs->lconstf.ranges) {
492 const struct nine_lconstf *lconstf = &(context->vs->lconstf);
495 float *dst = context->vs_lconstf_temp;
510 * at random locations (context->vs->lconstf.ranges),
514 u_upload_alloc(context->pipe->const_uploader,
524 if (!context->cso_shader.vs_const_ranges) {
529 while (context->cso_shader.vs_const_ranges[i*2+1] != 0) {
531 &((float*)cb.user_buffer)[4*context->cso_shader.vs_const_ranges[i*2]],
532 context->cso_shader.vs_const_ranges[i*2+1] * sizeof(float[4]));
533 offset += context->cso_shader.vs_const_ranges[i*2+1] * sizeof(float[4]);
538 u_upload_unmap(context->pipe->const_uploader);
542 pipe_resource_reference(&context->pipe_data.cb_vs.buffer, NULL);
544 context->pipe_data.cb_vs = cb;
545 context->changed.vs_const_f = 0;
547 context->changed.group &= ~NINE_STATE_VS_CONST;
548 context->commit |= NINE_STATE_COMMIT_CONST_VS;
554 struct nine_context *context = &device->context;
559 cb.buffer_size = context->cso_shader.ps_const_used_size;
560 cb.user_buffer = context->ps_const_f;
562 if (context->changed.ps_const_i) {
563 int *idst = (int *)&context->ps_const_f[4 * device->max_ps_const_f];
564 memcpy(idst, context->ps_const_i, sizeof(context->ps_const_i));
565 context->changed.ps_const_i = 0;
567 if (context->changed.ps_const_b) {
568 int *idst = (int *)&context->ps_const_f[4 * device->max_ps_const_f];
570 memcpy(bdst, context->ps_const_b, sizeof(context->ps_const_b));
571 context->changed.ps_const_b = 0;
575 if (context->ps->bumpenvmat_needed) {
576 memcpy(context->ps_lconstf_temp, cb.user_buffer, 8 * sizeof(float[4]));
577 memcpy(&context->ps_lconstf_temp[4 * 8], &device->context.bumpmap_vars, sizeof(device->context.bumpmap_vars));
579 cb.user_buffer = context->ps_lconstf_temp;
582 if (context->ps->byte_code.version < 0x30 &&
583 context->rs[D3DRS_FOGENABLE]) {
584 float *dst = &context->ps_lconstf_temp[4 * 32];
585 if (cb.user_buffer != context->ps_lconstf_temp) {
586 memcpy(context->ps_lconstf_temp, cb.user_buffer, 32 * sizeof(float[4]));
587 cb.user_buffer = context->ps_lconstf_temp;
590 d3dcolor_to_rgba(dst, context->rs[D3DRS_FOGCOLOR]);
591 if (context->rs[D3DRS_FOGTABLEMODE] == D3DFOG_LINEAR) {
592 dst[4] = asfloat(context->rs[D3DRS_FOGEND]);
593 dst[5] = 1.0f / (asfloat(context->rs[D3DRS_FOGEND]) - asfloat(context->rs[D3DRS_FOGSTART]));
594 } else if (context->rs[D3DRS_FOGTABLEMODE] != D3DFOG_NONE) {
595 dst[4] = asfloat(context->rs[D3DRS_FOGDENSITY]);
602 u_upload_alloc(context->pipe->const_uploader,
612 if (!context->cso_shader.ps_const_ranges) {
617 while (context->cso_shader.ps_const_ranges[i*2+1] != 0) {
619 &((float*)cb.user_buffer)[4*context->cso_shader.ps_const_ranges[i*2]],
620 context->cso_shader.ps_const_ranges[i*2+1] * sizeof(float[4]));
621 offset += context->cso_shader.ps_const_ranges[i*2+1] * sizeof(float[4]);
626 u_upload_unmap(context->pipe->const_uploader);
630 pipe_resource_reference(&context->pipe_data.cb_ps.buffer, NULL);
632 context->pipe_data.cb_ps = cb;
633 context->changed.ps_const_f = 0;
635 context->changed.group &= ~NINE_STATE_PS_CONST;
636 context->commit |= NINE_STATE_COMMIT_CONST_PS;
642 struct nine_context *context = &device->context;
643 struct NineVertexShader9 *vs = context->vs;
647 if (likely(context->programmable_vs))
654 if (likely(context->programmable_vs)) {
655 context->cso_shader.vs = NineVertexShader9_GetVariant(vs,
656 &context->cso_shader.vs_const_ranges,
657 &context->cso_shader.vs_const_used_size);
660 context->cso_shader.vs = vs->ff_cso;
663 if (context->rs[NINED3DRS_VSPOINTSIZE] != vs->point_size) {
664 context->rs[NINED3DRS_VSPOINTSIZE] = vs->point_size;
668 if ((context->bound_samplers_mask_vs & vs->sampler_mask) != vs->sampler_mask)
672 context->commit |= NINE_STATE_COMMIT_VS;
679 struct nine_context *context = &device->context;
680 struct NinePixelShader9 *ps = context->ps;
685 has_key_changed = NinePixelShader9_UpdateKey(ps, context);
691 context->cso_shader.ps = NinePixelShader9_GetVariant(ps,
692 &context->cso_shader.ps_const_ranges,
693 &context->cso_shader.ps_const_used_size);
696 context->cso_shader.ps = ps->ff_cso;
699 if ((context->bound_samplers_mask_ps & ps->sampler_mask) != ps->sampler_mask)
703 context->commit |= NINE_STATE_COMMIT_PS;
714 struct nine_context *context = &device->context;
715 struct pipe_context *pipe = context->pipe;
716 struct pipe_framebuffer_state *fb = &context->pipe_data.fb;
718 struct NineSurface9 *rt0 = context->rt[0];
722 unsigned ps_mask = context->ps ? context->ps->rt_mask : 1;
724 const int sRGB = context->rs[D3DRS_SRGBWRITEENABLE] ? 1 : 0;
728 context->rt_mask = 0x0;
741 if (rt0->desc.Format == D3DFMT_NULL && context->ds) {
742 w = context->ds->desc.Width;
743 h = context->ds->desc.Height;
744 nr_samples = context->ds->base.info.nr_samples;
748 struct NineSurface9 *rt = context->rt[i];
754 context->rt_mask |= 1 << i;
764 if (context->ds && context->ds->desc.Width >= w &&
765 context->ds->desc.Height >= h &&
766 context->ds->base.info.nr_samples == nr_samples) {
767 fb->zsbuf = NineSurface9_GetSurface(context->ds, 0);
777 if (is_clear && context->rt_mask == ps_mask)
778 context->changed.group &= ~NINE_STATE_FB;
784 struct nine_context *context = &device->context;
785 const D3DVIEWPORT9 *vport = &context->viewport;
827 cso_set_viewport(context->cso, &pvport);
837 struct nine_context *context = &device->context;
838 const struct NineVertexDeclaration9 *vdecl = device->context.vdecl;
848 context->stream_usage_mask = 0;
850 vs = context->programmable_vs ? context->vs : device->ff.vs;
888 context->stream_usage_mask |= 1 << b;
890 if (context->stream_freq[b] & D3DSTREAMSOURCE_INSTANCEDATA)
891 ve.velems[n].instance_divisor = context->stream_freq[b] & 0x7FFFFF;
905 if (context->dummy_vbo_bound_at != dummy_vbo_stream) {
906 if (context->dummy_vbo_bound_at >= 0)
907 context->changed.vtxbuf |= 1 << context->dummy_vbo_bound_at;
909 context->changed.vtxbuf |= 1 << dummy_vbo_stream;
910 context->vbo_bound_done = FALSE;
912 context->dummy_vbo_bound_at = dummy_vbo_stream;
916 cso_set_vertex_elements(context->cso, &ve);
922 struct nine_context *context = &device->context;
923 struct pipe_context *pipe = context->pipe;
925 uint32_t mask = context->changed.vtxbuf;
930 if (context->dummy_vbo_bound_at >= 0) {
931 if (!context->vbo_bound_done) {
936 pipe->set_vertex_buffers(pipe, context->dummy_vbo_bound_at,
938 context->vbo_bound_done = TRUE;
940 mask &= ~(1 << context->dummy_vbo_bound_at);
945 if (context->vtxbuf[i].buffer.resource)
946 pipe->set_vertex_buffers(pipe, i, 1, 0, false, &context->vtxbuf[i]);
952 context->changed.vtxbuf = 0;
956 update_sampler_derived(struct nine_context *context, unsigned s)
960 if (context->samp[s][NINED3DSAMP_SHADOW] != context->texture[s].shadow) {
962 context->samp[s][NINED3DSAMP_SHADOW] = context->texture[s].shadow;
965 if (context->samp[s][NINED3DSAMP_CUBETEX] !=
966 (context->texture[s].type == D3DRTYPE_CUBETEXTURE)) {
968 context->samp[s][NINED3DSAMP_CUBETEX] =
969 context->texture[s].type == D3DRTYPE_CUBETEXTURE;
972 if (context->samp[s][D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
973 int lod = context->samp[s][D3DSAMP_MAXMIPLEVEL] - context->texture[s].lod;
976 if (context->samp[s][NINED3DSAMP_MINLOD] != lod) {
978 context->samp[s][NINED3DSAMP_MINLOD] = lod;
981 context->changed.sampler[s] &= ~0x300; /* lod changes irrelevant */
991 struct nine_context *context = &device->context;
992 struct pipe_context *pipe = context->pipe;
996 uint16_t sampler_mask = context->ps ? context->ps->sampler_mask :
1000 const uint16_t ps_mask = sampler_mask | context->enabled_samplers_mask_ps;
1001 context->bound_samplers_mask_ps = ps_mask;
1004 u_foreach_bit(i, context->enabled_samplers_mask_ps) {
1006 int sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
1008 view[i] = context->texture[s].view[sRGB];
1010 if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
1011 context->changed.sampler[s] = 0;
1013 nine_convert_sampler_state(context->cso, s, context->samp[s]);
1017 u_foreach_bit(i, sampler_mask & ~context->enabled_samplers_mask_ps) {
1027 cso_single_sampler(context->cso, PIPE_SHADER_FRAGMENT,
1031 context->changed.sampler[s] = ~0;
1038 num_textures < context->enabled_sampler_count_ps ? context->enabled_sampler_count_ps - num_textures : 0,
1040 context->enabled_sampler_count_ps = num_textures;
1043 cso_single_sampler_done(context->cso, PIPE_SHADER_FRAGMENT);
1046 sampler_mask = context->programmable_vs ? context->vs->sampler_mask : 0;
1047 const uint16_t vs_mask = sampler_mask | context->enabled_samplers_mask_vs;
1048 context->bound_samplers_mask_vs = vs_mask;
1050 u_foreach_bit(i, context->enabled_samplers_mask_vs) {
1052 int sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
1054 view[i] = context->texture[s].view[sRGB];
1056 if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
1057 context->changed.sampler[s] = 0;
1059 nine_convert_sampler_state(context->cso, s, context->samp[s]);
1062 u_foreach_bit(i, sampler_mask & ~context->enabled_samplers_mask_vs) {
1072 cso_single_sampler(context->cso, PIPE_SHADER_VERTEX,
1076 context->changed.sampler[s] = ~0;
1083 num_textures < context->enabled_sampler_count_vs ? context->enabled_sampler_count_vs - num_textures : 0,
1085 context->enabled_sampler_count_vs = num_textures;
1088 cso_single_sampler_done(context->cso, PIPE_SHADER_VERTEX);
1096 struct nine_context *context = &device->context;
1098 cso_set_blend(context->cso, &context->pipe_data.blend);
1104 struct nine_context *context = &device->context;
1106 cso_set_depth_stencil_alpha(context->cso, &context->pipe_data.dsa);
1112 struct nine_context *context = &device->context;
1113 struct pipe_context *pipe = context->pipe;
1115 pipe->set_scissor_states(pipe, 0, 1, &context->scissor);
1121 struct nine_context *context = &device->context;
1123 cso_set_rasterizer(context->cso, &context->pipe_data.rast);
1129 struct nine_context *context = &device->context;
1130 struct pipe_context *pipe = context->pipe;
1132 if (unlikely(!context->programmable_vs))
1133 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &context->pipe_data.cb_vs_ff);
1135 if (context->swvp) {
1136 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &context->pipe_data.cb0_swvp);
1137 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 1, false, &context->pipe_data.cb1_swvp);
1138 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 2, false, &context->pipe_data.cb2_swvp);
1139 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 3, false, &context->pipe_data.cb3_swvp);
1141 pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, false, &context->pipe_data.cb_vs);
1149 struct nine_context *context = &device->context;
1150 struct pipe_context *pipe = context->pipe;
1152 if (unlikely(!context->ps))
1153 pipe->set_constant_buffer(pipe, PIPE_SHADER_FRAGMENT, 0, false, &context->pipe_data.cb_ps_ff);
1155 pipe->set_constant_buffer(pipe, PIPE_SHADER_FRAGMENT, 0, false, &context->pipe_data.cb_ps);
1161 struct nine_context *context = &device->context;
1163 context->pipe->bind_vs_state(context->pipe, context->cso_shader.vs);
1170 struct nine_context *context = &device->context;
1172 context->pipe->bind_fs_state(context->pipe, context->cso_shader.ps);
1213 struct nine_context *context = &device->context;
1214 struct pipe_context *pipe = context->pipe;
1217 DBG("changed state groups: %x\n", context->changed.group);
1227 if (unlikely(!context->programmable_vs || !context->ps))
1229 group = context->changed.group;
1258 if ((group & (NINE_STATE_VS_CONST | NINE_STATE_VS | NINE_STATE_SWVP)) && context->programmable_vs)
1260 if ((group & (NINE_STATE_PS_CONST | NINE_STATE_PS)) && context->ps)
1264 if (context->changed.vtxbuf)
1267 if (context->commit & NINE_STATE_COMMIT_BLEND)
1269 if (context->commit & NINE_STATE_COMMIT_DSA)
1271 if (context->commit & NINE_STATE_COMMIT_RASTERIZER)
1273 if (context->commit & NINE_STATE_COMMIT_CONST_VS)
1275 if (context->commit & NINE_STATE_COMMIT_CONST_PS)
1277 if (context->commit & NINE_STATE_COMMIT_VS)
1279 if (context->commit & NINE_STATE_COMMIT_PS)
1282 context->commit = 0;
1284 if (unlikely(context->changed.ucp)) {
1285 pipe->set_clip_state(pipe, &context->clip);
1286 context->changed.ucp = FALSE;
1294 d3dcolor_to_rgba(&color.color[0], context->rs[D3DRS_BLENDFACTOR]);
1298 if (context->rt[0]->desc.MultiSampleType <= D3DMULTISAMPLE_NONMASKABLE) {
1301 pipe->set_sample_mask(pipe, context->rs[D3DRS_MULTISAMPLEMASK]);
1306 ref.ref_value[0] = context->rs[D3DRS_STENCILREF];
1312 context->changed.group &=
1323 struct nine_context *context = &device->context;
1325 struct NineSurface9 *source = context->ds;
1331 if (!source || !context->texture[0].enabled ||
1332 context->texture[0].type != D3DRTYPE_TEXTURE)
1336 dst = context->texture[0].resource;
1371 context->pipe->blit(context->pipe, &blit);
1405 struct nine_context *context = &device->context;
1422 context->rs[NINED3DRS_ALPHACOVERAGE] &= 3;
1423 context->rs[NINED3DRS_ALPHACOVERAGE] |= (Value == ALPHA_TO_COVERAGE_ENABLE) ? 4 : 0;
1424 context->changed.group |= NINE_STATE_BLEND;
1431 if (Value == D3DFMT_ATOC || (Value == D3DFMT_UNKNOWN && context->rs[NINED3DRS_ALPHACOVERAGE] & 3)) {
1432 context->rs[NINED3DRS_ALPHACOVERAGE] &= 4;
1433 context->rs[NINED3DRS_ALPHACOVERAGE] |=
1434 ((Value == D3DFMT_ATOC) ? 3 : 0) & (context->rs[D3DRS_ALPHATESTENABLE] ? 3 : 2);
1435 context->changed.group |= NINE_STATE_BLEND;
1439 if (unlikely(State == D3DRS_ALPHATESTENABLE && (context->rs[NINED3DRS_ALPHACOVERAGE] & 2))) {
1440 context->rs[NINED3DRS_ALPHACOVERAGE] &= 6;
1441 context->rs[NINED3DRS_ALPHACOVERAGE] |= (Value ? 1 : 0);
1444 context->rs[State] = nine_fix_render_state_value(State, Value);
1445 context->changed.group |= nine_render_state_group[State];
1458 struct nine_context *context = &device->context;
1463 context->texture[stage].enabled = enabled;
1466 context->enabled_samplers_mask_ps |= BITFIELD_BIT(stage - NINE_SAMPLER_PS(0));
1468 context->enabled_samplers_mask_vs |= BITFIELD_BIT(stage - NINE_SAMPLER_VS(0));
1471 context->enabled_samplers_mask_ps &= ~BITFIELD_BIT(stage - NINE_SAMPLER_PS(0));
1473 context->enabled_samplers_mask_vs &= ~BITFIELD_BIT(stage - NINE_SAMPLER_VS(0));
1475 context->samplers_shadow &= ~(1 << stage);
1476 context->samplers_shadow |= shadow << stage;
1477 context->samplers_fetch4 &= ~(1 << stage);
1478 context->samplers_fetch4 |= fetch4_compatible << stage;
1479 context->texture[stage].shadow = shadow;
1480 context->texture[stage].lod = lod;
1481 context->texture[stage].type = type;
1482 context->texture[stage].pstype = pstype;
1483 pipe_resource_reference(&context->texture[stage].resource, res);
1484 pipe_sampler_view_reference(&context->texture[stage].view[0], view0);
1485 pipe_sampler_view_reference(&context->texture[stage].view[1], view1);
1487 context->changed.group |= NINE_STATE_TEXTURE;
1528 struct nine_context *context = &device->context;
1533 context->rs[NINED3DRS_FETCH4] &= ~(1 << Sampler);
1534 context->rs[NINED3DRS_FETCH4] |= (Value == FETCH4_ENABLE) << Sampler;
1535 context->changed.group |= NINE_STATE_PS_PARAMS_MISC;
1545 context->samp[Sampler][Type] = Value;
1546 context->changed.group |= NINE_STATE_SAMPLER;
1547 context->changed.sampler[Sampler] |= 1 << Type;
1556 struct nine_context *context = &device->context;
1561 if (context->vtxbuf[i].buffer.resource == res &&
1562 context->vtxbuf[i].buffer_offset == OffsetInBytes &&
1563 context->vtxbuf[i].stride == Stride)
1566 context->vtxbuf[i].stride = Stride;
1567 context->vtxbuf[i].buffer_offset = OffsetInBytes;
1568 pipe_resource_reference(&context->vtxbuf[i].buffer.resource, res);
1570 context->changed.vtxbuf |= 1 << StreamNumber;
1597 struct nine_context *context = &device->context;
1599 context->stream_freq[StreamNumber] = Setting;
1602 context->stream_instancedata_mask |= 1 << StreamNumber;
1604 context->stream_instancedata_mask &= ~(1 << StreamNumber);
1607 context->changed.group |= NINE_STATE_STREAMFREQ;
1615 struct nine_context *context = &device->context;
1617 context->index_size = IndexSize;
1618 context->index_offset = OffsetInBytes;
1619 pipe_resource_reference(&context->idxbuf, res);
1621 context->changed.group |= NINE_STATE_IDXBUF;
1643 struct nine_context *context = &device->context;
1644 BOOL was_programmable_vs = context->programmable_vs;
1646 nine_bind(&context->vdecl, vdecl);
1648 context->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
1649 if (was_programmable_vs != context->programmable_vs) {
1650 context->commit |= NINE_STATE_COMMIT_CONST_VS;
1651 context->changed.group |= NINE_STATE_VS;
1654 context->changed.group |= NINE_STATE_VDECL;
1660 struct nine_context *context = &device->context;
1661 BOOL was_programmable_vs = context->programmable_vs;
1663 nine_bind(&context->vs, pShader);
1665 context->programmable_vs = context->vs && !(context->vdecl && context->vdecl->position_t);
1668 if (!was_programmable_vs && context->programmable_vs)
1669 context->commit |= NINE_STATE_COMMIT_CONST_VS;
1671 context->changed.group |= NINE_STATE_VS;
1680 struct nine_context *context = &device->context;
1681 float *vs_const_f = device->may_swvp ? context->vs_const_f_swvp : context->vs_const_f;
1690 memcpy(&context->vs_const_f[StartRegister * 4],
1692 Vector4fCount * 4 * sizeof(context->vs_const_f[0]));
1695 context->changed.vs_const_f = TRUE;
1696 context->changed.group |= NINE_STATE_VS_CONST;
1705 struct nine_context *context = &device->context;
1709 memcpy(&context->vs_const_i[4 * StartRegister],
1714 context->vs_const_i[4 * (StartRegister + i)] = fui((float)(pConstantData[4 * i]));
1715 context->vs_const_i[4 * (StartRegister + i) + 1] = fui((float)(pConstantData[4 * i + 1]));
1716 context->vs_const_i[4 * (StartRegister + i) + 2] = fui((float)(pConstantData[4 * i + 2]));
1717 context->vs_const_i[4 * (StartRegister + i) + 3] = fui((float)(pConstantData[4 * i + 3]));
1721 context->changed.vs_const_i = TRUE;
1722 context->changed.group |= NINE_STATE_VS_CONST | NINE_STATE_VS_PARAMS_MISC;
1731 struct nine_context *context = &device->context;
1738 context->vs_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
1740 context->changed.vs_const_b = TRUE;
1741 context->changed.group |= NINE_STATE_VS_CONST | NINE_STATE_VS_PARAMS_MISC;
1747 struct nine_context *context = &device->context;
1748 unsigned old_mask = context->ps ? context->ps->rt_mask : 1;
1752 if (!context->ps && ps)
1753 context->commit |= NINE_STATE_COMMIT_CONST_PS;
1755 nine_bind(&context->ps, ps);
1757 context->changed.group |= NINE_STATE_PS;
1759 mask = context->ps ? context->ps->rt_mask : 1;
1763 context->changed.group |= NINE_STATE_FB;
1772 struct nine_context *context = &device->context;
1774 memcpy(&context->ps_const_f[StartRegister * 4],
1778 context->changed.ps_const_f = TRUE;
1779 context->changed.group |= NINE_STATE_PS_CONST;
1789 struct nine_context *context = &device->context;
1791 memcpy(&context->ps_const_i[StartRegister][0],
1793 Vector4iCount * sizeof(context->ps_const_i[0]));
1795 context->changed.ps_const_i = TRUE;
1796 context->changed.group |= NINE_STATE_PS_CONST | NINE_STATE_PS_PARAMS_MISC;
1805 struct nine_context *context = &device->context;
1809 memcpy(&context->ps_const_i[StartRegister][0],
1814 context->ps_const_i[StartRegister+i][0] = fui((float)(pConstantData[4*i]));
1815 context->ps_const_i[StartRegister+i][1] = fui((float)(pConstantData[4*i+1]));
1816 context->ps_const_i[StartRegister+i][2] = fui((float)(pConstantData[4*i+2]));
1817 context->ps_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
1820 context->changed.ps_const_i = TRUE;
1821 context->changed.group |= NINE_STATE_PS_CONST | NINE_STATE_PS_PARAMS_MISC;
1830 struct nine_context *context = &device->context;
1837 context->ps_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
1839 context->changed.ps_const_b = TRUE;
1840 context->changed.group |= NINE_STATE_PS_CONST | NINE_STATE_PS_PARAMS_MISC;
1848 struct nine_context *context = &device->context;
1852 context->changed.group |= NINE_STATE_MULTISAMPLE;
1854 if (context->rt[0] &&
1855 (context->rt[0]->desc.MultiSampleType <= D3DMULTISAMPLE_NONMASKABLE) !=
1857 context->changed.group |= NINE_STATE_SAMPLE_MASK;
1860 if (context->rt[i] != rt) {
1861 nine_bind(&context->rt[i], rt);
1862 context->changed.group |= NINE_STATE_FB;
1870 struct nine_context *context = &device->context;
1872 nine_bind(&context->ds, ds);
1873 context->changed.group |= NINE_STATE_FB;
1879 struct nine_context *context = &device->context;
1881 if (!memcmp(viewport, &context->viewport, sizeof(context->viewport)))
1884 context->viewport = *viewport;
1885 context->changed.group |= NINE_STATE_VIEWPORT;
1891 struct nine_context *context = &device->context;
1893 if (!memcmp(scissor, &context->scissor, sizeof(context->scissor)))
1896 context->scissor = *scissor;
1897 context->changed.group |= NINE_STATE_SCISSOR;
1904 struct nine_context *context = &device->context;
1905 D3DMATRIX *M = nine_state_access_transform(&context->ff, State, TRUE);
1908 context->ff.changed.transform[State / 32] |= 1 << (State % 32);
1909 context->changed.group |= NINE_STATE_FF;
1915 struct nine_context *context = &device->context;
1917 context->ff.material = *pMaterial;
1918 context->changed.group |= NINE_STATE_FF_MATERIAL;
1925 struct nine_context *context = &device->context;
1927 (void)nine_state_set_light(&context->ff, Index, pLight);
1928 context->changed.group |= NINE_STATE_FF_LIGHTING;
1938 struct nine_context *context = &device->context;
1942 memcpy(context->ff.active_light, active_light, NINE_MAX_LIGHTS_ACTIVE * sizeof(context->ff.active_light[0]));
1943 context->ff.num_lights_active = num_lights_active;
1944 context->changed.group |= NINE_STATE_FF_LIGHTING;
1951 struct nine_context *context = &device->context;
1953 nine_state_light_enable(&context->ff, Index, Enable);
1954 context->changed.group |= NINE_STATE_FF_LIGHTING;
1962 struct nine_context *context = &device->context;
1965 context->ff.tex_stage[Stage][Type] = Value;
1986 context->changed.group |= NINE_STATE_PS_PARAMS_MISC;
1993 context->bumpmap_vars[bumpmap_index] = Value;
1994 context->changed.group |= NINE_STATE_PS_CONST;
1997 context->changed.group |= NINE_STATE_FF_PS_CONSTS;
1998 context->ff.changed.tex_stage[Stage][Type / 32] |= 1 << (Type % 32);
2005 struct nine_context *context = &device->context;
2007 memcpy(&context->clip.ucp[Index][0], pPlane, sizeof(context->clip.ucp[0]));
2008 context->changed.ucp = TRUE;
2014 struct nine_context *context = &device->context;
2016 context->swvp = swvp;
2017 context->changed.group |= NINE_STATE_SWVP;
2032 * set context->changed.group */
2204 struct nine_context *context = &device->context;
2206 if (context->changed.group & NINE_STATE_FB)
2218 struct nine_context *context = &device->context;
2219 const int sRGB = context->rs[D3DRS_SRGBWRITEENABLE] ? 1 : 0;
2221 struct pipe_context *pipe = context->pipe;
2222 struct NineSurface9 *zsbuf_surf = context->ds;
2234 if (context->pipe_data.fb.zsbuf != NULL) {
2242 rect.x1 = context->viewport.X;
2243 rect.y1 = context->viewport.Y;
2244 rect.x2 = context->viewport.Width + rect.x1;
2245 rect.y2 = context->viewport.Height + rect.y1;
2248 if (context->rs[D3DRS_SCISSORTESTENABLE]) {
2249 rect.x1 = MAX2(rect.x1, context->scissor.minx);
2250 rect.y1 = MAX2(rect.y1, context->scissor.miny);
2251 rect.x2 = MIN2(rect.x2, context->scissor.maxx);
2252 rect.y2 = MIN2(rect.y2, context->scissor.maxy);
2265 if (rect.x1 >= context->pipe_data.fb.width || rect.y1 >= context->pipe_data.fb.height)
2269 if (context->rt[i] && context->rt[i]->desc.Format != D3DFMT_NULL)
2275 (!(bufs & PIPE_CLEAR_COLOR) || (rt_mask == context->rt_mask)) &&
2279 rect.x2 >= context->pipe_data.fb.width &&
2280 rect.y2 >= context->pipe_data.fb.height) ||
2297 rt = context->rt[i];
2363 if (dev->context.stream_instancedata_mask & dev->context.stream_usage_mask)
2364 info->instance_count = MAX2(dev->context.stream_freq[0] & 0x7FFFFF, 1);
2380 struct nine_context *context = &device->context;
2384 if (context->vs && context->vs->swvp_only && !context->swvp)
2397 context->pipe->draw_vbo(context->pipe, &info, 0, NULL, &draw, 1);
2408 struct nine_context *context = &device->context;
2412 if (context->vs && context->vs->swvp_only && !context->swvp)
2418 info.index_size = context->index_size;
2419 draw.start = context->index_offset / context->index_size + StartIndex;
2425 info.index.resource = context->idxbuf;
2427 context->pipe->draw_vbo(context->pipe, &info, 0, NULL, &draw, 1);
2441 struct nine_context *context = &device->context;
2445 if (context->vs && context->vs->swvp_only && !context->swvp)
2463 context->pipe->set_vertex_buffers(context->pipe, 0, 1, 0, false, vbuf);
2464 context->changed.vtxbuf |= 1;
2466 context->pipe->draw_vbo(context->pipe, &info, 0, NULL, &draw, 1);
2479 struct nine_context *context = &device->context;
2484 context->pipe->resource_copy_region(context->pipe,
2496 struct nine_context *context = &device->context;
2501 context->pipe->blit(context->pipe, blit);
2512 struct nine_context *context = &device->context;
2518 context->pipe->clear_render_target(context->pipe, surf, &rgba, x, y, width, height, false);
2530 struct nine_context *context = &device->context;
2535 util_gen_mipmap(context->pipe, res, res->format, base_level,
2547 struct nine_context *context = &device->context;
2552 context->pipe->buffer_subdata(context->pipe, res, usage, offset, size, data);
2566 struct nine_context *context = &device->context;
2567 struct pipe_context *pipe = context->pipe;
2625 struct nine_context *context = &device->context;
2627 context->pipe->destroy_query(context->pipe, query);
2633 struct nine_context *context = &device->context;
2635 (void) context->pipe->begin_query(context->pipe, query);
2641 struct nine_context *context = &device->context;
2643 (void) context->pipe->end_query(context->pipe, query);
2673 struct nine_context *context = &device->context;
2675 context->pipe->flush(context->pipe, NULL, PIPE_FLUSH_ASYNC);
2842 struct nine_context *context = &device->context;
2844 context->changed.group = NINE_STATE_ALL; /* TODO: we can remove states that have prepared commits */
2845 context->changed.vtxbuf = (1ULL << device->caps.MaxStreams) - 1;
2846 context->changed.ucp = TRUE;
2847 context->commit |= 0xffffffff; /* re-commit everything */
2848 context->enabled_sampler_count_vs = 0;
2849 context->enabled_sampler_count_ps = 0;
2857 struct nine_context *context = &device->context;
2862 memcpy(context->rs, nine_render_state_defaults, sizeof(context->rs));
2873 memcpy(&context->ff.tex_stage[s], state->ff.tex_stage[s],
2876 memset(&context->bumpmap_vars, 0, sizeof(context->bumpmap_vars));
2879 memcpy(&context->samp[s], nine_samp_state_defaults,
2880 sizeof(context->samp[s]));
2886 memset(context->vs_const_f, 0, device->vs_const_size);
2887 if (context->vs_const_f_swvp)
2888 memset(context->vs_const_f_swvp, 0, NINE_MAX_CONST_F_SWVP * sizeof(float[4]));
2890 memset(context->vs_const_i, 0, VS_CONST_I_SIZE(device));
2892 memset(context->vs_const_b, 0, VS_CONST_B_SIZE(device));
2894 memset(context->ps_const_f, 0, device->ps_const_size);
2896 memset(context->ps_const_i, 0, sizeof(context->ps_const_i));
2898 memset(context->ps_const_b, 0, sizeof(context->ps_const_b));
2902 context->rs[D3DRS_POINTSIZE_MAX] = fui(caps->MaxPointSize);
2904 memcpy(state->rs_advertised, context->rs, sizeof(context->rs));
2908 context->changed.group = NINE_STATE_ALL;
2909 context->changed.vtxbuf = (1ULL << device->caps.MaxStreams) - 1;
2910 context->changed.ucp = TRUE;
2912 context->ff.changed.transform[0] = ~0;
2913 context->ff.changed.transform[D3DTS_WORLD / 32] |= 1 << (D3DTS_WORLD % 32);
2916 state->viewport.MinZ = context->viewport.MinZ = 0.0f;
2917 state->viewport.MaxZ = context->viewport.MaxZ = 1.0f;
2921 context->changed.sampler[s] = ~0;
2924 context->dummy_vbo_bound_at = -1;
2925 context->vbo_bound_done = FALSE;
2956 struct nine_context *context = &device->context;
2957 struct pipe_context *pipe = context->pipe;
2958 struct cso_context *cso = context->cso;
2974 context->enabled_sampler_count_vs = 0;
2975 context->enabled_sampler_count_ps = 0;
2984 for (i = 0; i < ARRAY_SIZE(context->rt); ++i)
2985 nine_bind(&context->rt[i], NULL);
2986 nine_bind(&context->ds, NULL);
2987 nine_bind(&context->vs, NULL);
2988 nine_bind(&context->ps, NULL);
2989 nine_bind(&context->vdecl, NULL);
2991 pipe_vertex_buffer_unreference(&context->vtxbuf[i]);
2992 pipe_resource_reference(&context->idxbuf, NULL);
2993 pipe_resource_reference(&context->pipe_data.cb_vs.buffer, NULL);
2994 pipe_resource_reference(&context->pipe_data.cb_ps.buffer, NULL);
2997 context->texture[i].enabled = FALSE;
2998 pipe_resource_reference(&context->texture[i].resource,
3000 pipe_sampler_view_reference(&context->texture[i].view[0],
3002 pipe_sampler_view_reference(&context->texture[i].view[1],