#include "texture9.h"
#include "cubetexture9.h"
#include "volumetexture9.h"
+#include "nine_buffer_upload.h"
#include "nine_helpers.h"
#include "nine_pipe.h"
#include "nine_ff.h"
This->state.viewport.Width = refSurf->desc.Width;
This->state.viewport.Height = refSurf->desc.Height;
+ nine_context_set_viewport(This, &This->state.viewport);
+
This->state.scissor.minx = 0;
This->state.scissor.miny = 0;
This->state.scissor.maxx = refSurf->desc.Width;
This->state.scissor.maxy = refSurf->desc.Height;
+ nine_context_set_scissor(This, &This->state.scissor);
+
if (This->nswapchains && This->swapchains[0]->params.EnableAutoDepthStencil) {
nine_context_set_render_state(This, D3DRS_ZENABLE, TRUE);
This->state.rs_advertised[D3DRS_ZENABLE] = TRUE;
DBG("Application asked mixed Software Vertex Processing.\n");
This->may_swvp = true;
}
+ This->context.swvp = This->swvp;
/* TODO: check if swvp is resetted by device Resets */
if (This->may_swvp &&
if (This->may_swvp)
This->caps.MaxVertexShaderConst = NINE_MAX_CONST_F_SWVP;
- This->pipe = This->screen->context_create(This->screen, NULL, 0);
- if (!This->pipe) { return E_OUTOFMEMORY; } /* guess */
+ This->context.pipe = This->screen->context_create(This->screen, NULL, 0);
+ This->pipe_secondary = This->screen->context_create(This->screen, NULL, 0);
+ if (!This->context.pipe || !This->pipe_secondary) { return E_OUTOFMEMORY; } /* guess */
This->pipe_sw = This->screen_sw->context_create(This->screen_sw, NULL, 0);
if (!This->pipe_sw) { return E_OUTOFMEMORY; }
- This->cso = cso_create_context(This->pipe);
- if (!This->cso) { return E_OUTOFMEMORY; } /* also a guess */
- This->cso_sw = cso_create_context(This->pipe_sw);
+ This->context.cso = cso_create_context(This->context.pipe, 0);
+ if (!This->context.cso) { return E_OUTOFMEMORY; } /* also a guess */
+ This->cso_sw = cso_create_context(This->pipe_sw, 0);
if (!This->cso_sw) { return E_OUTOFMEMORY; }
/* Create first, it messes up our state. */
- This->hud = hud_create(This->pipe, This->cso); /* NULL result is fine */
+ This->hud = hud_create(This->context.cso, NULL); /* NULL result is fine */
/* Available memory counter. Updated only for allocations with this device
* instance. This is the Win 7 behavior.
if (FAILED(hr))
return hr;
NineUnknown_ConvertRefToBind(NineUnknown(This->state.rt[i]));
+ nine_bind(&This->context.rt[i], This->state.rt[i]);
}
+ /* Initialize CSMT */
+ if (pCTX->csmt_force == 1)
+ This->csmt_active = true;
+ else if (pCTX->csmt_force == 0)
+ This->csmt_active = false;
+ else
+ /* r600 and radeonsi are thread safe. */
+ This->csmt_active = strstr(pScreen->get_name(pScreen), "AMD") != NULL;
+
+ /* We rely on u_upload_mgr using persistent coherent buffers (which don't
+ * require flush to work in multi-pipe_context scenario) for vertex and
+ * index buffers */
+ if (!GET_PCAP(BUFFER_MAP_PERSISTENT_COHERENT))
+ This->csmt_active = false;
+
+ if (This->csmt_active) {
+ This->csmt_ctx = nine_csmt_create(This);
+ if (!This->csmt_ctx)
+ return E_OUTOFMEMORY;
+ }
+
+ if (This->csmt_active)
+ DBG("\033[1;32mCSMT is active\033[0m\n");
+
+ This->buffer_upload = nine_upload_create(This->pipe_secondary, 4 * 1024 * 1024, 4);
+
/* Initialize a dummy VBO to be used when a vertex declaration does not
* specify all the inputs needed by vertex shader, on win default behavior
* is to pass 0,0,0,0 to the shader */
return D3DERR_OUTOFVIDEOMEMORY;
u_box_1d(0, 16, &box);
- data = This->pipe->transfer_map(This->pipe, This->dummy_vbo, 0,
+ data = This->context.pipe->transfer_map(This->context.pipe, This->dummy_vbo, 0,
PIPE_TRANSFER_WRITE |
PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
&box, &transfer);
assert(data);
assert(transfer);
memset(data, 0, 16);
- This->pipe->transfer_unmap(This->pipe, transfer);
+ This->context.pipe->transfer_unmap(This->context.pipe, transfer);
}
This->cursor.software = FALSE;
This->cursor.hotspot.x = -1;
This->cursor.hotspot.y = -1;
+ This->cursor.w = This->cursor.h = 0;
+ This->cursor.visible = FALSE;
+ if (ID3DPresent_GetCursorPos(This->swapchains[0]->present, &This->cursor.pos) != S_OK) {
+ This->cursor.pos.x = 0;
+ This->cursor.pos.y = 0;
+ }
+
{
struct pipe_resource tmpl;
memset(&tmpl, 0, sizeof(tmpl));
This->ps_const_size = max_const_ps * sizeof(float[4]);
/* Include space for I,B constants for user constbuf. */
if (This->may_swvp) {
- This->state.vs_const_f_swvp = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
- if (!This->state.vs_const_f_swvp)
+ This->state.vs_const_f = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
+ This->context.vs_const_f_swvp = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
+ if (!This->context.vs_const_f_swvp)
return E_OUTOFMEMORY;
This->state.vs_lconstf_temp = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
+ This->context.vs_lconstf_temp = CALLOC(NINE_MAX_CONST_F_SWVP * sizeof(float[4]),1);
This->state.vs_const_i = CALLOC(NINE_MAX_CONST_I_SWVP * sizeof(int[4]), 1);
+ This->context.vs_const_i = CALLOC(NINE_MAX_CONST_I_SWVP * sizeof(int[4]), 1);
This->state.vs_const_b = CALLOC(NINE_MAX_CONST_B_SWVP * sizeof(BOOL), 1);
+ This->context.vs_const_b = CALLOC(NINE_MAX_CONST_B_SWVP * sizeof(BOOL), 1);
} else {
- This->state.vs_const_f_swvp = NULL;
+ This->state.vs_const_f = CALLOC(NINE_MAX_CONST_F * sizeof(float[4]), 1);
+ This->context.vs_const_f_swvp = NULL;
This->state.vs_lconstf_temp = CALLOC(This->vs_const_size,1);
+ This->context.vs_lconstf_temp = CALLOC(This->vs_const_size,1);
This->state.vs_const_i = CALLOC(NINE_MAX_CONST_I * sizeof(int[4]), 1);
+ This->context.vs_const_i = CALLOC(NINE_MAX_CONST_I * sizeof(int[4]), 1);
This->state.vs_const_b = CALLOC(NINE_MAX_CONST_B * sizeof(BOOL), 1);
+ This->context.vs_const_b = CALLOC(NINE_MAX_CONST_B * sizeof(BOOL), 1);
}
- This->state.vs_const_f = CALLOC(This->vs_const_size, 1);
+ This->context.vs_const_f = CALLOC(This->vs_const_size, 1);
This->state.ps_const_f = CALLOC(This->ps_const_size, 1);
- This->state.ps_lconstf_temp = CALLOC(This->ps_const_size,1);
- if (!This->state.vs_const_f || !This->state.ps_const_f ||
- !This->state.vs_lconstf_temp || !This->state.ps_lconstf_temp ||
- !This->state.vs_const_i || !This->state.vs_const_b)
+ This->context.ps_const_f = CALLOC(This->ps_const_size, 1);
+ This->context.ps_lconstf_temp = CALLOC(This->ps_const_size,1);
+ if (!This->state.vs_const_f || !This->context.vs_const_f ||
+ !This->state.ps_const_f || !This->context.ps_const_f ||
+ !This->state.vs_lconstf_temp || !This->context.vs_lconstf_temp ||
+ !This->context.ps_lconstf_temp ||
+ !This->state.vs_const_i || !This->context.vs_const_i ||
+ !This->state.vs_const_b || !This->context.vs_const_b)
return E_OUTOFMEMORY;
if (strstr(pScreen->get_name(pScreen), "AMD") ||
templ.swizzle_a = PIPE_SWIZZLE_1;
templ.target = This->dummy_texture->target;
- This->dummy_sampler_view = This->pipe->create_sampler_view(This->pipe, This->dummy_texture, &templ);
+ This->dummy_sampler_view = This->context.pipe->create_sampler_view(This->context.pipe, This->dummy_texture, &templ);
if (!This->dummy_sampler_view)
return D3DERR_DRIVERINTERNALERROR;
/* Allocate upload helper for drivers that suck (from st pov ;). */
- This->driver_caps.user_vbufs = GET_PCAP(USER_VERTEX_BUFFERS);
- This->driver_caps.user_ibufs = GET_PCAP(USER_INDEX_BUFFERS);
- This->driver_caps.user_cbufs = GET_PCAP(USER_CONSTANT_BUFFERS);
+ This->driver_caps.user_vbufs = GET_PCAP(USER_VERTEX_BUFFERS) && !This->csmt_active;
This->driver_caps.user_sw_vbufs = This->screen_sw->get_param(This->screen_sw, PIPE_CAP_USER_VERTEX_BUFFERS);
- This->driver_caps.user_sw_cbufs = This->screen_sw->get_param(This->screen_sw, PIPE_CAP_USER_CONSTANT_BUFFERS);
-
- if (!This->driver_caps.user_vbufs)
- This->vertex_uploader = u_upload_create(This->pipe, 65536,
- PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM);
- This->vertex_sw_uploader = u_upload_create(This->pipe_sw, 65536,
- PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM);
- if (!This->driver_caps.user_ibufs)
- This->index_uploader = u_upload_create(This->pipe, 128 * 1024,
- PIPE_BIND_INDEX_BUFFER, PIPE_USAGE_STREAM);
- if (!This->driver_caps.user_cbufs) {
- This->constbuf_alignment = GET_PCAP(CONSTANT_BUFFER_OFFSET_ALIGNMENT);
- This->constbuf_uploader = u_upload_create(This->pipe, This->vs_const_size,
- PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STREAM);
- }
-
- This->constbuf_sw_uploader = u_upload_create(This->pipe_sw, 128 * 1024,
- PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STREAM);
-
+ This->vertex_uploader = This->csmt_active ? This->pipe_secondary->stream_uploader : This->context.pipe->stream_uploader;
This->driver_caps.window_space_position_support = GET_PCAP(TGSI_VS_WINDOW_SPACE_POSITION);
This->driver_caps.vs_integer = pScreen->get_shader_param(pScreen, PIPE_SHADER_VERTEX, PIPE_SHADER_CAP_INTEGERS);
This->driver_caps.ps_integer = pScreen->get_shader_param(pScreen, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_INTEGERS);
{
struct pipe_poly_stipple stipple;
memset(&stipple, ~0, sizeof(stipple));
- This->pipe->set_polygon_stipple(This->pipe, &stipple);
+ This->context.pipe->set_polygon_stipple(This->context.pipe, &stipple);
}
This->update = &This->state;
nine_state_init_sw(This);
ID3DPresentGroup_Release(This->present);
+ nine_csmt_process(This);
return D3D_OK;
}
DBG("This=%p\n", This);
- if (This->pipe && This->cso)
- nine_pipe_context_clear(This);
+ /* Flush all pending commands to get refcount right,
+ * and properly release bound objects. It is ok to still
+ * execute commands while we are in device dtor, because
+ * we haven't released anything yet. Note that no pending
+ * command can increase the device refcount. */
+ if (This->csmt_active && This->csmt_ctx) {
+ nine_csmt_process(This);
+ nine_csmt_destroy(This, This->csmt_ctx);
+ This->csmt_active = FALSE;
+ This->csmt_ctx = NULL;
+ }
+
nine_ff_fini(This);
nine_state_destroy_sw(This);
nine_state_clear(&This->state, TRUE);
- nine_context_clear(&This->context);
-
- if (This->vertex_uploader)
- u_upload_destroy(This->vertex_uploader);
- if (This->index_uploader)
- u_upload_destroy(This->index_uploader);
- if (This->constbuf_uploader)
- u_upload_destroy(This->constbuf_uploader);
- if (This->vertex_sw_uploader)
- u_upload_destroy(This->vertex_sw_uploader);
- if (This->constbuf_sw_uploader)
- u_upload_destroy(This->constbuf_sw_uploader);
+ nine_context_clear(This);
nine_bind(&This->record, NULL);
pipe_resource_reference(&This->dummy_texture, NULL);
pipe_resource_reference(&This->dummy_vbo, NULL);
FREE(This->state.vs_const_f);
+ FREE(This->context.vs_const_f);
FREE(This->state.ps_const_f);
+ FREE(This->context.ps_const_f);
FREE(This->state.vs_lconstf_temp);
- FREE(This->state.ps_lconstf_temp);
+ FREE(This->context.vs_lconstf_temp);
+ FREE(This->context.ps_lconstf_temp);
FREE(This->state.vs_const_i);
+ FREE(This->context.vs_const_i);
FREE(This->state.vs_const_b);
- FREE(This->state.vs_const_f_swvp);
+ FREE(This->context.vs_const_b);
+ FREE(This->context.vs_const_f_swvp);
pipe_resource_reference(&This->cursor.image, NULL);
FREE(This->cursor.hw_upload_temp);
FREE(This->swapchains);
}
+ if (This->buffer_upload)
+ nine_upload_destroy(This->buffer_upload);
+
/* Destroy cso first */
- if (This->cso) { cso_destroy_context(This->cso); }
+ if (This->context.cso) { cso_destroy_context(This->context.cso); }
if (This->cso_sw) { cso_destroy_context(This->cso_sw); }
- if (This->pipe && This->pipe->destroy) { This->pipe->destroy(This->pipe); }
+ if (This->context.pipe && This->context.pipe->destroy) { This->context.pipe->destroy(This->context.pipe); }
+ if (This->pipe_secondary && This->pipe_secondary->destroy) { This->pipe_secondary->destroy(This->pipe_secondary); }
if (This->pipe_sw && This->pipe_sw->destroy) { This->pipe_sw->destroy(This->pipe_sw); }
if (This->present) { ID3DPresentGroup_Release(This->present); }
struct pipe_context *
NineDevice9_GetPipe( struct NineDevice9 *This )
{
- return This->pipe;
-}
-
-struct cso_context *
-NineDevice9_GetCSO( struct NineDevice9 *This )
-{
- return This->cso;
+ return nine_context_get_pipe(This);
}
const D3DCAPS9 *
IDirect3DSurface9 *pCursorBitmap )
{
struct NineSurface9 *surf = NineSurface9(pCursorBitmap);
- struct pipe_context *pipe = This->pipe;
+ struct pipe_context *pipe = NineDevice9_GetPipe(This);
struct pipe_box box;
struct pipe_transfer *transfer;
BOOL hw_cursor;
DBG("This=%p X=%d Y=%d Flags=%d\n", This, X, Y, Flags);
+ if (This->cursor.pos.x == X &&
+ This->cursor.pos.y == Y)
+ return;
+
This->cursor.pos.x = X;
This->cursor.pos.y = Y;
DBG("This=%p bShow=%d\n", This, (int) bShow);
- This->cursor.visible = bShow && (This->cursor.hotspot.x != -1);
+ /* No-op until a cursor is set in d3d */
+ if (This->cursor.hotspot.x == -1)
+ return old;
+
+ This->cursor.visible = bShow;
+ /* Note: Don't optimize by avoiding the call if This->cursor.visible
+ * hasn't changed. One has to keep in mind the app may do SetCursor
+ * calls outside d3d, thus such an optimization affects behaviour. */
if (!This->cursor.software)
This->cursor.software = ID3DPresent_SetCursor(This->swapchains[0]->present, NULL, NULL, bShow) != D3D_OK;
break;
}
- nine_pipe_context_clear(This);
+ nine_csmt_process(This);
nine_state_clear(&This->state, TRUE);
- nine_context_clear(&This->context);
+ nine_context_clear(This);
NineDevice9_SetDefaultState(This, TRUE);
NineDevice9_SetRenderTarget(
D3DTEXTUREFILTERTYPE Filter )
{
struct pipe_screen *screen = This->screen;
- struct pipe_context *pipe = This->pipe;
struct NineSurface9 *dst = NineSurface9(pDestSurface);
struct NineSurface9 *src = NineSurface9(pSourceSurface);
struct pipe_resource *dst_res = NineSurface9_GetResource(dst);
user_assert(screen->is_format_supported(screen, src_res->format,
src_res->target,
src_res->nr_samples,
+ src_res->nr_storage_samples,
PIPE_BIND_SAMPLER_VIEW),
D3DERR_INVALIDCALL);
user_assert(screen->is_format_supported(screen, dst_res->format,
dst_res->target,
dst_res->nr_samples,
+ dst_res->nr_storage_samples,
zs ? PIPE_BIND_DEPTH_STENCIL :
PIPE_BIND_RENDER_TARGET),
D3DERR_INVALIDCALL);
- pipe->blit(pipe, &blit);
+ nine_context_blit(This, (struct NineUnknown *)dst,
+ (struct NineUnknown *)src, &blit);
} else {
assert(blit.dst.box.x >= 0 && blit.dst.box.y >= 0 &&
blit.src.box.x >= 0 && blit.src.box.y >= 0 &&
blit.src.box.y + blit.src.box.height <= src->desc.Height);
/* Or drivers might crash ... */
DBG("Using resource_copy_region.\n");
- pipe->resource_copy_region(pipe,
- blit.dst.resource, blit.dst.level,
- blit.dst.box.x, blit.dst.box.y, blit.dst.box.z,
- blit.src.resource, blit.src.level,
- &blit.src.box);
+ nine_context_resource_copy_region(This, (struct NineUnknown *)dst,
+ (struct NineUnknown *)src,
+ blit.dst.resource, blit.dst.level,
+ &blit.dst.box,
+ blit.src.resource, blit.src.level,
+ &blit.src.box);
}
/* Communicate the container it needs to update sublevels - if apply */
const RECT *pRect,
D3DCOLOR color )
{
- struct pipe_context *pipe = This->pipe;
struct NineSurface9 *surf = NineSurface9(pSurface);
- struct pipe_surface *psurf;
unsigned x, y, w, h;
- union pipe_color_union rgba;
- boolean fallback;
DBG("This=%p pSurface=%p pRect=%p color=%08x\n", This,
pSurface, pRect, color);
w = surf->desc.Width;
h = surf->desc.Height;
}
- d3dcolor_to_pipe_color_union(&rgba, color);
-
- fallback = !(surf->base.info.bind & PIPE_BIND_RENDER_TARGET);
- if (!fallback) {
- psurf = NineSurface9_GetSurface(surf, 0);
- if (!psurf)
- fallback = TRUE;
- }
-
- if (!fallback) {
- pipe->clear_render_target(pipe, psurf, &rgba, x, y, w, h, false);
+ if (surf->base.info.bind & PIPE_BIND_RENDER_TARGET) {
+ nine_context_clear_render_target(This, surf, color, x, y, w, h);
} else {
D3DLOCKED_RECT lock;
union util_color uc;
HRESULT hr;
/* XXX: lock pRect and fix util_fill_rect */
- hr = NineSurface9_LockRect(surf, &lock, NULL, 0);
+ hr = NineSurface9_LockRect(surf, &lock, NULL, pRect ? 0 : D3DLOCK_DISCARD);
if (FAILED(hr))
return hr;
util_pack_color_ub(color >> 16, color >> 8, color >> 0, color >> 24,
This->state.scissor.miny = 0;
This->state.scissor.maxx = rt->desc.Width;
This->state.scissor.maxy = rt->desc.Height;
-
- This->state.changed.group |= NINE_STATE_VIEWPORT | NINE_STATE_SCISSOR | NINE_STATE_MULTISAMPLE;
-
- if (This->state.rt[0] &&
- (This->state.rt[0]->desc.MultiSampleType <= D3DMULTISAMPLE_NONMASKABLE) !=
- (rt->desc.MultiSampleType <= D3DMULTISAMPLE_NONMASKABLE))
- This->state.changed.group |= NINE_STATE_SAMPLE_MASK;
}
- if (This->state.rt[i] != NineSurface9(pRenderTarget)) {
- nine_bind(&This->state.rt[i], pRenderTarget);
- This->state.changed.group |= NINE_STATE_FB;
- }
+ if (This->state.rt[i] != NineSurface9(pRenderTarget))
+ nine_bind(&This->state.rt[i], pRenderTarget);
+
+ nine_context_set_render_target(This, i, rt);
return D3D_OK;
}
NineDevice9_SetDepthStencilSurface( struct NineDevice9 *This,
IDirect3DSurface9 *pNewZStencil )
{
+ struct NineSurface9 *ds = NineSurface9(pNewZStencil);
DBG("This=%p pNewZStencil=%p\n", This, pNewZStencil);
- if (This->state.ds != NineSurface9(pNewZStencil)) {
- nine_bind(&This->state.ds, pNewZStencil);
- This->state.changed.group |= NINE_STATE_FB;
+ if (This->state.ds != ds) {
+ nine_bind(&This->state.ds, ds);
+ nine_context_set_depth_stencil(This, ds);
}
return D3D_OK;
}
return D3D_OK;
}
+static void
+nine_D3DMATRIX_print(const D3DMATRIX *M)
+{
+ DBG("\n(%f %f %f %f)\n"
+ "(%f %f %f %f)\n"
+ "(%f %f %f %f)\n"
+ "(%f %f %f %f)\n",
+ M->m[0][0], M->m[0][1], M->m[0][2], M->m[0][3],
+ M->m[1][0], M->m[1][1], M->m[1][2], M->m[1][3],
+ M->m[2][0], M->m[2][1], M->m[2][2], M->m[2][3],
+ M->m[3][0], M->m[3][1], M->m[3][2], M->m[3][3]);
+}
+
HRESULT NINE_WINAPI
NineDevice9_SetTransform( struct NineDevice9 *This,
D3DTRANSFORMSTATETYPE State,
const D3DMATRIX *pMatrix )
{
struct nine_state *state = This->update;
- D3DMATRIX *M = nine_state_access_transform(state, State, TRUE);
+ D3DMATRIX *M = nine_state_access_transform(&state->ff, State, TRUE);
DBG("This=%p State=%d pMatrix=%p\n", This, State, pMatrix);
user_assert(M, D3DERR_INVALIDCALL);
+ nine_D3DMATRIX_print(pMatrix);
*M = *pMatrix;
- state->ff.changed.transform[State / 32] |= 1 << (State % 32);
- state->changed.group |= NINE_STATE_FF;
+ if (unlikely(This->is_recording)) {
+ state->ff.changed.transform[State / 32] |= 1 << (State % 32);
+ state->changed.group |= NINE_STATE_FF;
+ } else
+ nine_context_set_transform(This, State, pMatrix);
return D3D_OK;
}
D3DTRANSFORMSTATETYPE State,
D3DMATRIX *pMatrix )
{
- D3DMATRIX *M = nine_state_access_transform(&This->state, State, FALSE);
+ D3DMATRIX *M = nine_state_access_transform(&This->state.ff, State, FALSE);
user_assert(M, D3DERR_INVALIDCALL);
*pMatrix = *M;
return D3D_OK;
{
struct nine_state *state = This->update;
D3DMATRIX T;
- D3DMATRIX *M = nine_state_access_transform(state, State, TRUE);
+ D3DMATRIX *M = nine_state_access_transform(&state->ff, State, TRUE);
DBG("This=%p State=%d pMatrix=%p\n", This, State, pMatrix);
pViewport->MinZ, pViewport->MaxZ);
state->viewport = *pViewport;
- state->changed.group |= NINE_STATE_VIEWPORT;
+ nine_context_set_viewport(This, pViewport);
return D3D_OK;
}
user_assert(pMaterial, E_POINTER);
state->ff.material = *pMaterial;
- state->changed.group |= NINE_STATE_FF_MATERIAL;
+ if (unlikely(This->is_recording))
+ state->changed.group |= NINE_STATE_FF_MATERIAL;
+ else
+ nine_context_set_material(This, pMaterial);
return D3D_OK;
}
const D3DLIGHT9 *pLight )
{
struct nine_state *state = This->update;
+ HRESULT hr;
DBG("This=%p Index=%u pLight=%p\n", This, Index, pLight);
if (pLight)
user_assert(Index < NINE_MAX_LIGHTS, D3DERR_INVALIDCALL); /* sanity */
- if (Index >= state->ff.num_lights) {
- unsigned n = state->ff.num_lights;
- unsigned N = Index + 1;
-
- state->ff.light = REALLOC(state->ff.light, n * sizeof(D3DLIGHT9),
- N * sizeof(D3DLIGHT9));
- if (!state->ff.light)
- return E_OUTOFMEMORY;
- state->ff.num_lights = N;
-
- for (; n < Index; ++n) {
- memset(&state->ff.light[n], 0, sizeof(D3DLIGHT9));
- state->ff.light[n].Type = (D3DLIGHTTYPE)NINED3DLIGHT_INVALID;
- }
- }
- state->ff.light[Index] = *pLight;
+ hr = nine_state_set_light(&state->ff, Index, pLight);
+ if (hr != D3D_OK)
+ return hr;
- if (pLight->Type == D3DLIGHT_SPOT && pLight->Theta >= pLight->Phi) {
- DBG("Warning: clamping D3DLIGHT9.Theta\n");
- state->ff.light[Index].Theta = state->ff.light[Index].Phi;
- }
if (pLight->Type != D3DLIGHT_DIRECTIONAL &&
pLight->Attenuation0 == 0.0f &&
pLight->Attenuation1 == 0.0f &&
DBG("Warning: all D3DLIGHT9.Attenuation[i] are 0\n");
}
- state->changed.group |= NINE_STATE_FF_LIGHTING;
+ if (unlikely(This->is_recording))
+ state->changed.group |= NINE_STATE_FF_LIGHTING;
+ else
+ nine_context_set_light(This, Index, pLight);
return D3D_OK;
}
BOOL Enable )
{
struct nine_state *state = This->update;
- unsigned i;
DBG("This=%p Index=%u Enable=%i\n", This, Index, Enable);
light.Direction.z = 1.0f;
NineDevice9_SetLight(This, Index, &light);
}
- user_assert(Index < state->ff.num_lights, D3DERR_INVALIDCALL);
-
- for (i = 0; i < state->ff.num_lights_active; ++i) {
- if (state->ff.active_light[i] == Index)
- break;
- }
- if (Enable) {
- if (i < state->ff.num_lights_active)
- return D3D_OK;
- /* XXX wine thinks this should still succeed:
- */
- user_assert(i < NINE_MAX_LIGHTS_ACTIVE, D3DERR_INVALIDCALL);
-
- state->ff.active_light[i] = Index;
- state->ff.num_lights_active++;
- } else {
- if (i == state->ff.num_lights_active)
- return D3D_OK;
- --state->ff.num_lights_active;
- for (; i < state->ff.num_lights_active; ++i)
- state->ff.active_light[i] = state->ff.active_light[i + 1];
- }
- state->changed.group |= NINE_STATE_FF_LIGHTING;
+ nine_state_light_enable(&state->ff, &state->changed.group, Index, Enable);
+ if (likely(!This->is_recording))
+ nine_context_light_enable(This, Index, Enable);
return D3D_OK;
}
user_assert(Index < PIPE_MAX_CLIP_PLANES, D3DERR_INVALIDCALL);
memcpy(&state->clip.ucp[Index][0], pPlane, sizeof(state->clip.ucp[0]));
- state->changed.ucp |= 1 << Index;
+ if (unlikely(This->is_recording))
+ state->changed.ucp |= 1 << Index;
+ else
+ nine_context_set_clip_plane(This, Index, (struct nine_clipplane *)pPlane);
return D3D_OK;
}
if (Type == D3DSBT_ALL || Type == D3DSBT_PIXELSTATE) {
dst->changed.group |=
NINE_STATE_PS | NINE_STATE_PS_CONST | NINE_STATE_BLEND |
- NINE_STATE_FF_OTHER | NINE_STATE_FF_PSSTAGES | NINE_STATE_PS_CONST |
+ NINE_STATE_FF_VS_OTHER | NINE_STATE_FF_PS_CONSTS | NINE_STATE_PS_CONST |
NINE_STATE_FB | NINE_STATE_DSA | NINE_STATE_MULTISAMPLE |
NINE_STATE_RASTERIZER | NINE_STATE_STENCIL_REF;
memcpy(dst->changed.rs,
NINE_STATE_BLEND |
NINE_STATE_DSA |
NINE_STATE_IDXBUF |
- NINE_STATE_MATERIAL |
+ NINE_STATE_FF_MATERIAL |
NINE_STATE_BLEND_COLOR |
- NINE_STATE_SAMPLE_MASK;
+ NINE_STATE_SAMPLE_MASK |
+ NINE_STATE_FF_VSTRANSF;
memset(dst->changed.rs, ~0, (D3DRS_COUNT / 32) * sizeof(uint32_t));
dst->changed.rs[D3DRS_LAST / 32] |= (1 << (D3DRS_COUNT % 32)) - 1;
dst->changed.vtxbuf = (1ULL << This->caps.MaxStreams) - 1;
dst->changed.stream_freq = dst->changed.vtxbuf;
dst->changed.ucp = (1 << PIPE_MAX_CLIP_PLANES) - 1;
dst->changed.texture = (1 << NINE_MAX_SAMPLERS) - 1;
+ /* The doc says the projection, world, view and texture matrices
+ * are saved, which would translate to:
+ * dst->ff.changed.transform[0] = 0x00FF000C;
+ * dst->ff.changed.transform[D3DTS_WORLD / 32] |= 1 << (D3DTS_WORLD % 32);
+ * However we assume they meant save everything (which is basically just the
+ * above plus the other world matrices).
+ */
+ dst->ff.changed.transform[0] = 0x00FF000C;
+ for (s = 0; s < 8; s++)
+ dst->ff.changed.transform[8+s] = ~0;
}
NineStateBlock9_Capture(NineStateBlock9(*ppSB));
if (old == tex)
return D3D_OK;
- if (tex) {
- if ((tex->managed.dirty | tex->dirty_mip) && LIST_IS_EMPTY(&tex->list))
- list_add(&tex->list, &This->update_textures);
-
- tex->bind_count++;
- }
- if (old)
- old->bind_count--;
+ NineBindTextureToDevice(This, &state->texture[Stage], tex);
nine_context_set_texture(This, Stage, tex);
- nine_bind(&state->texture[Stage], pTexture);
-
return D3D_OK;
}
DWORD Value )
{
struct nine_state *state = This->update;
- struct nine_context *context = &This->context;
- int bumpmap_index = -1;
DBG("Stage=%u Type=%u Value=%08x\n", Stage, Type, Value);
nine_dump_D3DTSS_value(DBG_FF, Type, Value);
user_assert(Type < ARRAY_SIZE(state->ff.tex_stage[0]), D3DERR_INVALIDCALL);
state->ff.tex_stage[Stage][Type] = Value;
- switch (Type) {
- case D3DTSS_BUMPENVMAT00:
- bumpmap_index = 4 * Stage;
- break;
- case D3DTSS_BUMPENVMAT01:
- bumpmap_index = 4 * Stage + 1;
- break;
- case D3DTSS_BUMPENVMAT10:
- bumpmap_index = 4 * Stage + 2;
- break;
- case D3DTSS_BUMPENVMAT11:
- bumpmap_index = 4 * Stage + 3;
- break;
- case D3DTSS_BUMPENVLSCALE:
- bumpmap_index = 4 * 8 + 2 * Stage;
- break;
- case D3DTSS_BUMPENVLOFFSET:
- bumpmap_index = 4 * 8 + 2 * Stage + 1;
- break;
- case D3DTSS_TEXTURETRANSFORMFLAGS:
- state->changed.group |= NINE_STATE_PS1X_SHADER;
- break;
- default:
- break;
- }
- if (bumpmap_index >= 0 && !This->is_recording) {
- context->bumpmap_vars[bumpmap_index] = Value;
- state->changed.group |= NINE_STATE_PS_CONST;
- }
-
- state->changed.group |= NINE_STATE_FF_PSSTAGES;
- state->ff.changed.tex_stage[Stage][Type / 32] |= 1 << (Type % 32);
+ if (unlikely(This->is_recording)) {
+ if (Type == D3DTSS_TEXTURETRANSFORMFLAGS)
+ state->changed.group |= NINE_STATE_PS_PARAMS_MISC;
+ state->changed.group |= NINE_STATE_FF_PS_CONSTS;
+ state->ff.changed.tex_stage[Stage][Type / 32] |= 1 << (Type % 32);
+ } else
+ nine_context_set_texture_stage_state(This, Stage, Type, Value);
return D3D_OK;
}
if (Sampler >= D3DDMAPSAMPLER)
Sampler = Sampler - D3DDMAPSAMPLER + NINE_MAX_SAMPLERS_PS;
- if (state->samp_advertised[Sampler][Type] != Value || unlikely(This->is_recording)) {
- /* Contrary to render states, old value is kept if new value is wrong (except intel + Value == 0) */
- if (likely(nine_check_sampler_state_value(Type, Value)))
- state->samp[Sampler][Type] = Value;
+ if (unlikely(This->is_recording)) {
state->samp_advertised[Sampler][Type] = Value;
state->changed.group |= NINE_STATE_SAMPLER;
state->changed.sampler[Sampler] |= 1 << Type;
+ return D3D_OK;
}
+ if (state->samp_advertised[Sampler][Type] == Value)
+ return D3D_OK;
+
+ state->samp_advertised[Sampler][Type] = Value;
+ nine_context_set_sampler_state(This, Sampler, Type, Value);
+
return D3D_OK;
}
DBG("This=%p pNumPasses=%p\n", This, pNumPasses);
- for (i = 0; i < ARRAY_SIZE(state->samp); ++i) {
- if (state->samp[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE ||
- state->samp[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE)
+ for (i = 0; i < ARRAY_SIZE(state->samp_advertised); ++i) {
+ if (state->samp_advertised[i][D3DSAMP_MINFILTER] == D3DTEXF_NONE ||
+ state->samp_advertised[i][D3DSAMP_MAGFILTER] == D3DTEXF_NONE)
return D3DERR_UNSUPPORTEDTEXTUREFILTER;
}
state->scissor.maxx = pRect->right;
state->scissor.maxy = pRect->bottom;
- state->changed.group |= NINE_STATE_SCISSOR;
+ if (unlikely(This->is_recording))
+ state->changed.group |= NINE_STATE_SCISSOR;
+ else
+ nine_context_set_scissor(This, &state->scissor);
return D3D_OK;
}
{
if (This->params.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING) {
This->swvp = bSoftware;
- This->state.changed.group |= NINE_STATE_SWVP;
+ nine_context_set_swvp(This, bSoftware);
return D3D_OK;
} else
return D3DERR_INVALIDCALL; /* msdn. TODO: check in practice */
STUB(0);
}
+/* TODO: only go through dirty textures */
+static void
+validate_textures(struct NineDevice9 *device)
+{
+ struct NineBaseTexture9 *tex, *ptr;
+ LIST_FOR_EACH_ENTRY_SAFE(tex, ptr, &device->update_textures, list) {
+ list_delinit(&tex->list);
+ NineBaseTexture9_Validate(tex);
+ }
+}
+
+static void
+update_managed_buffers(struct NineDevice9 *device)
+{
+ struct NineBuffer9 *buf, *ptr;
+ LIST_FOR_EACH_ENTRY_SAFE(buf, ptr, &device->update_buffers, managed.list) {
+ list_delinit(&buf->managed.list);
+ NineBuffer9_Upload(buf);
+ }
+}
+
+static void
+NineBeforeDraw( struct NineDevice9 *This )
+{
+ /* Upload Managed dirty content */
+ validate_textures(This); /* may clobber state */
+ update_managed_buffers(This);
+}
+
+static void
+NineAfterDraw( struct NineDevice9 *This )
+{
+ unsigned i;
+ struct nine_state *state = &This->state;
+ unsigned ps_mask = state->ps ? state->ps->rt_mask : 1;
+
+ /* Flag render-targets with autogenmipmap for mipmap regeneration */
+ for (i = 0; i < This->caps.NumSimultaneousRTs; ++i) {
+ struct NineSurface9 *rt = state->rt[i];
+
+ if (rt && rt->desc.Format != D3DFMT_NULL && (ps_mask & (1 << i)) &&
+ rt->desc.Usage & D3DUSAGE_AUTOGENMIPMAP) {
+ assert(rt->texture == D3DRTYPE_TEXTURE ||
+ rt->texture == D3DRTYPE_CUBETEXTURE);
+ NineBaseTexture9(rt->base.base.container)->dirty_mip = TRUE;
+ }
+ }
+}
+
HRESULT NINE_WINAPI
NineDevice9_DrawPrimitive( struct NineDevice9 *This,
D3DPRIMITIVETYPE PrimitiveType,
DBG("iface %p, PrimitiveType %u, StartVertex %u, PrimitiveCount %u\n",
This, PrimitiveType, StartVertex, PrimitiveCount);
+ NineBeforeDraw(This);
nine_context_draw_primitive(This, PrimitiveType, StartVertex, PrimitiveCount);
+ NineAfterDraw(This);
return D3D_OK;
}
user_assert(This->state.idxbuf, D3DERR_INVALIDCALL);
user_assert(This->state.vdecl, D3DERR_INVALIDCALL);
+ NineBeforeDraw(This);
nine_context_draw_indexed_primitive(This, PrimitiveType, BaseVertexIndex,
MinVertexIndex, NumVertices, StartIndex,
PrimitiveCount);
+ NineAfterDraw(This);
return D3D_OK;
}
vtxbuf.stride = VertexStreamZeroStride;
vtxbuf.buffer_offset = 0;
- vtxbuf.buffer = NULL;
- vtxbuf.user_buffer = pVertexStreamZeroData;
+ vtxbuf.is_user_buffer = true;
+ vtxbuf.buffer.user = pVertexStreamZeroData;
if (!This->driver_caps.user_vbufs) {
+ vtxbuf.is_user_buffer = false;
+ vtxbuf.buffer.resource = NULL;
u_upload_data(This->vertex_uploader,
0,
(prim_count_to_vertex_count(PrimitiveType, PrimitiveCount)) * VertexStreamZeroStride, /* XXX */
4,
- vtxbuf.user_buffer,
+ pVertexStreamZeroData,
&vtxbuf.buffer_offset,
- &vtxbuf.buffer);
+ &vtxbuf.buffer.resource);
u_upload_unmap(This->vertex_uploader);
- vtxbuf.user_buffer = NULL;
}
+ NineBeforeDraw(This);
nine_context_draw_primitive_from_vtxbuf(This, PrimitiveType, PrimitiveCount, &vtxbuf);
+ NineAfterDraw(This);
- pipe_resource_reference(&vtxbuf.buffer, NULL);
+ pipe_vertex_buffer_unreference(&vtxbuf);
NineDevice9_PauseRecording(This);
NineDevice9_SetStreamSource(This, 0, NULL, 0, 0);
UINT VertexStreamZeroStride )
{
struct pipe_vertex_buffer vbuf;
- struct pipe_index_buffer ibuf;
DBG("iface %p, PrimitiveType %u, MinVertexIndex %u, NumVertices %u "
"PrimitiveCount %u, pIndexData %p, IndexDataFormat %u "
vbuf.stride = VertexStreamZeroStride;
vbuf.buffer_offset = 0;
- vbuf.buffer = NULL;
- vbuf.user_buffer = pVertexStreamZeroData;
+ vbuf.is_user_buffer = true;
+ vbuf.buffer.user = pVertexStreamZeroData;
- ibuf.index_size = (IndexDataFormat == D3DFMT_INDEX16) ? 2 : 4;
- ibuf.offset = 0;
- ibuf.buffer = NULL;
- ibuf.user_buffer = pIndexData;
+ unsigned index_size = (IndexDataFormat == D3DFMT_INDEX16) ? 2 : 4;
+ struct pipe_resource *ibuf = NULL;
if (!This->driver_caps.user_vbufs) {
const unsigned base = MinVertexIndex * VertexStreamZeroStride;
+ vbuf.is_user_buffer = false;
+ vbuf.buffer.resource = NULL;
u_upload_data(This->vertex_uploader,
base,
NumVertices * VertexStreamZeroStride, /* XXX */
4,
- (const uint8_t *)vbuf.user_buffer + base,
+ (const uint8_t *)pVertexStreamZeroData + base,
&vbuf.buffer_offset,
- &vbuf.buffer);
+ &vbuf.buffer.resource);
u_upload_unmap(This->vertex_uploader);
/* Won't be used: */
vbuf.buffer_offset -= base;
- vbuf.user_buffer = NULL;
}
- if (!This->driver_caps.user_ibufs) {
- u_upload_data(This->index_uploader,
+
+ unsigned index_offset = 0;
+ if (This->csmt_active) {
+ u_upload_data(This->pipe_secondary->stream_uploader,
0,
- (prim_count_to_vertex_count(PrimitiveType, PrimitiveCount)) * ibuf.index_size,
+ (prim_count_to_vertex_count(PrimitiveType, PrimitiveCount)) * index_size,
4,
- ibuf.user_buffer,
- &ibuf.offset,
- &ibuf.buffer);
- u_upload_unmap(This->index_uploader);
- ibuf.user_buffer = NULL;
+ pIndexData,
+ &index_offset,
+ &ibuf);
+ u_upload_unmap(This->pipe_secondary->stream_uploader);
}
+ NineBeforeDraw(This);
nine_context_draw_indexed_primitive_from_vtxbuf_idxbuf(This, PrimitiveType,
MinVertexIndex,
NumVertices,
PrimitiveCount,
&vbuf,
- &ibuf);
+ ibuf,
+ ibuf ? NULL : (void*)pIndexData,
+ index_offset,
+ index_size);
+ NineAfterDraw(This);
- pipe_resource_reference(&vbuf.buffer, NULL);
- pipe_resource_reference(&ibuf.buffer, NULL);
+ pipe_vertex_buffer_unreference(&vbuf);
+ pipe_resource_reference(&ibuf, NULL);
NineDevice9_PauseRecording(This);
NineDevice9_SetIndices(This, NULL);
templ.bind = PIPE_BIND_STREAM_OUTPUT;
templ.usage = PIPE_USAGE_STREAM;
templ.height0 = templ.depth0 = templ.array_size = 1;
- templ.last_level = templ.nr_samples = 0;
+ templ.last_level = templ.nr_samples = templ.nr_storage_samples = 0;
resource = screen_sw->resource_create(screen_sw, &templ);
if (!resource)
draw.restart_index = 0;
draw.count_from_stream_output = NULL;
draw.indirect = NULL;
- draw.indirect_params = NULL;
draw.instance_count = 1;
- draw.indexed = FALSE;
+ draw.index_size = 0;
draw.start = 0;
draw.index_bias = 0;
draw.min_index = 0;
UINT Vector4fCount )
{
struct nine_state *state = This->update;
- float *vs_const_f = This->may_swvp ? state->vs_const_f_swvp : state->vs_const_f;
+ float *vs_const_f = state->vs_const_f;
DBG("This=%p StartRegister=%u pConstantData=%p Vector4fCount=%u\n",
This, StartRegister, pConstantData, Vector4fCount);
return D3D_OK;
user_assert(pConstantData, D3DERR_INVALIDCALL);
- if (!This->is_recording) {
- if (!memcmp(&vs_const_f[StartRegister * 4], pConstantData,
- Vector4fCount * 4 * sizeof(state->vs_const_f[0])))
- return D3D_OK;
+ if (unlikely(This->is_recording)) {
+ memcpy(&vs_const_f[StartRegister * 4],
+ pConstantData,
+ Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
+
+ nine_ranges_insert(&state->changed.vs_const_f,
+ StartRegister, StartRegister + Vector4fCount,
+ &This->range_pool);
+
+ state->changed.group |= NINE_STATE_VS_CONST;
+
+ return D3D_OK;
}
+ if (!memcmp(&vs_const_f[StartRegister * 4], pConstantData,
+ Vector4fCount * 4 * sizeof(state->vs_const_f[0])))
+ return D3D_OK;
+
memcpy(&vs_const_f[StartRegister * 4],
pConstantData,
Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
- nine_ranges_insert(&state->changed.vs_const_f,
- StartRegister, StartRegister + Vector4fCount,
- &This->range_pool);
-
- if (This->may_swvp) {
- Vector4fCount = MIN2(StartRegister + Vector4fCount, NINE_MAX_CONST_F) - StartRegister;
- if (StartRegister < NINE_MAX_CONST_F)
- memcpy(&state->vs_const_f[StartRegister * 4],
- pConstantData,
- Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
- }
-
- state->changed.group |= NINE_STATE_VS_CONST;
+ nine_context_set_vertex_shader_constant_f(This, StartRegister, pConstantData,
+ Vector4fCount * 4 * sizeof(state->vs_const_f[0]),
+ Vector4fCount);
return D3D_OK;
}
UINT Vector4fCount )
{
const struct nine_state *state = &This->state;
- float *vs_const_f = This->may_swvp ? state->vs_const_f_swvp : state->vs_const_f;
user_assert(StartRegister < This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
user_assert(StartRegister + Vector4fCount <= This->caps.MaxVertexShaderConst, D3DERR_INVALIDCALL);
user_assert(pConstantData, D3DERR_INVALIDCALL);
memcpy(pConstantData,
- &vs_const_f[StartRegister * 4],
+ &state->vs_const_f[StartRegister * 4],
Vector4fCount * 4 * sizeof(state->vs_const_f[0]));
return D3D_OK;
}
}
- nine_ranges_insert(&state->changed.vs_const_i,
- StartRegister, StartRegister + Vector4iCount,
- &This->range_pool);
- state->changed.group |= NINE_STATE_VS_CONST;
+ if (unlikely(This->is_recording)) {
+ nine_ranges_insert(&state->changed.vs_const_i,
+ StartRegister, StartRegister + Vector4iCount,
+ &This->range_pool);
+ state->changed.group |= NINE_STATE_VS_CONST;
+ } else
+ nine_context_set_vertex_shader_constant_i(This, StartRegister, pConstantData,
+ Vector4iCount * sizeof(int[4]), Vector4iCount);
return D3D_OK;
}
for (i = 0; i < BoolCount; i++)
state->vs_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
- nine_ranges_insert(&state->changed.vs_const_b,
- StartRegister, StartRegister + BoolCount,
- &This->range_pool);
- state->changed.group |= NINE_STATE_VS_CONST;
+ if (unlikely(This->is_recording)) {
+ nine_ranges_insert(&state->changed.vs_const_b,
+ StartRegister, StartRegister + BoolCount,
+ &This->range_pool);
+ state->changed.group |= NINE_STATE_VS_CONST;
+ } else
+ nine_context_set_vertex_shader_constant_b(This, StartRegister, pConstantData,
+ sizeof(BOOL) * BoolCount, BoolCount);
return D3D_OK;
}
state->vtxbuf[i].stride = Stride;
state->vtxbuf[i].buffer_offset = OffsetInBytes;
- nine_bind(&state->stream[i], pStreamData);
+ NineBindBufferToDevice(This,
+ (struct NineBuffer9 **)&state->stream[i],
+ (struct NineBuffer9 *)pVBuf9);
nine_context_set_stream_source(This,
StreamNumber,
IDirect3DIndexBuffer9 *pIndexData )
{
struct nine_state *state = This->update;
+ struct NineIndexBuffer9 *idxbuf = NineIndexBuffer9(pIndexData);
DBG("This=%p pIndexData=%p\n", This, pIndexData);
- if (likely(!This->is_recording))
- if (state->idxbuf == NineIndexBuffer9(pIndexData))
- return D3D_OK;
- nine_bind(&state->idxbuf, pIndexData);
+ if (unlikely(This->is_recording)) {
+ nine_bind(&state->idxbuf, idxbuf);
+ state->changed.group |= NINE_STATE_IDXBUF;
+ return D3D_OK;
+ }
- state->changed.group |= NINE_STATE_IDXBUF;
+ if (state->idxbuf == idxbuf)
+ return D3D_OK;
+
+ NineBindBufferToDevice(This,
+ (struct NineBuffer9 **)&state->idxbuf,
+ (struct NineBuffer9 *)idxbuf);
+
+ nine_context_set_indices(This, idxbuf);
return D3D_OK;
}
IDirect3DPixelShader9 *pShader )
{
struct nine_state *state = This->update;
- struct nine_context *context = &This->context;
- unsigned old_mask = state->ps ? state->ps->rt_mask : 1;
- unsigned mask;
+ struct NinePixelShader9 *ps = (struct NinePixelShader9*)pShader;
DBG("This=%p pShader=%p\n", This, pShader);
- if (!This->is_recording && state->ps == (struct NinePixelShader9*)pShader)
- return D3D_OK;
-
- /* ff -> non-ff: commit back non-ff constants */
- if (!state->ps && pShader)
- context->commit |= NINE_STATE_COMMIT_CONST_PS;
+ if (unlikely(This->is_recording)) {
+ /* Technically we need NINE_STATE_FB only
+ * if the ps mask changes, but put it always
+ * to be safe */
+ nine_bind(&state->ps, pShader);
+ state->changed.group |= NINE_STATE_PS | NINE_STATE_FB;
+ return D3D_OK;
+ }
- nine_bind(&state->ps, pShader);
+ if (state->ps == ps)
+ return D3D_OK;
- state->changed.group |= NINE_STATE_PS;
+ nine_bind(&state->ps, ps);
- mask = state->ps ? state->ps->rt_mask : 1;
- /* We need to update cbufs if the pixel shader would
- * write to different render targets */
- if (mask != old_mask)
- state->changed.group |= NINE_STATE_FB;
+ nine_context_set_pixel_shader(This, ps);
return D3D_OK;
}
return D3D_OK;
user_assert(pConstantData, D3DERR_INVALIDCALL);
- if (!This->is_recording) {
- if (!memcmp(&state->ps_const_f[StartRegister * 4], pConstantData,
- Vector4fCount * 4 * sizeof(state->ps_const_f[0])))
- return D3D_OK;
+ if (unlikely(This->is_recording)) {
+ memcpy(&state->ps_const_f[StartRegister * 4],
+ pConstantData,
+ Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
+
+ nine_ranges_insert(&state->changed.ps_const_f,
+ StartRegister, StartRegister + Vector4fCount,
+ &This->range_pool);
+
+ state->changed.group |= NINE_STATE_PS_CONST;
+ return D3D_OK;
}
+ if (!memcmp(&state->ps_const_f[StartRegister * 4], pConstantData,
+ Vector4fCount * 4 * sizeof(state->ps_const_f[0])))
+ return D3D_OK;
+
memcpy(&state->ps_const_f[StartRegister * 4],
pConstantData,
Vector4fCount * 4 * sizeof(state->ps_const_f[0]));
- nine_ranges_insert(&state->changed.ps_const_f,
- StartRegister, StartRegister + Vector4fCount,
- &This->range_pool);
-
- state->changed.group |= NINE_STATE_PS_CONST;
+ nine_context_set_pixel_shader_constant_f(This, StartRegister, pConstantData,
+ Vector4fCount * 4 * sizeof(state->ps_const_f[0]),
+ Vector4fCount);
return D3D_OK;
}
state->ps_const_i[StartRegister+i][3] = fui((float)(pConstantData[4*i+3]));
}
}
- state->changed.ps_const_i |= ((1 << Vector4iCount) - 1) << StartRegister;
- state->changed.group |= NINE_STATE_PS_CONST;
+
+ if (unlikely(This->is_recording)) {
+ state->changed.ps_const_i |= ((1 << Vector4iCount) - 1) << StartRegister;
+ state->changed.group |= NINE_STATE_PS_CONST;
+ } else
+ nine_context_set_pixel_shader_constant_i(This, StartRegister, pConstantData,
+ sizeof(state->ps_const_i[0]) * Vector4iCount, Vector4iCount);
return D3D_OK;
}
for (i = 0; i < BoolCount; i++)
state->ps_const_b[StartRegister + i] = pConstantData[i] ? bool_true : 0;
- state->changed.ps_const_b |= ((1 << BoolCount) - 1) << StartRegister;
- state->changed.group |= NINE_STATE_PS_CONST;
+ if (unlikely(This->is_recording)) {
+ state->changed.ps_const_b |= ((1 << BoolCount) - 1) << StartRegister;
+ state->changed.group |= NINE_STATE_PS_CONST;
+ } else
+ nine_context_set_pixel_shader_constant_b(This, StartRegister, pConstantData,
+ sizeof(BOOL) * BoolCount, BoolCount);
return D3D_OK;
}