From 1e434b52d0896371138b0fcd6726ad75f3c1fc33 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 16 Sep 2014 10:44:16 +0200 Subject: [PATCH] d3d10core: Implement d3d10_device_VSSetShaderResources(). --- dlls/d3d10core/d3d10core_private.h | 2 + dlls/d3d10core/device.c | 13 ++++- dlls/d3d10core/view.c | 8 ++++ dlls/wined3d/cs.c | 77 +++++++++++++++++++++--------- dlls/wined3d/device.c | 32 +++++++++++++ dlls/wined3d/wined3d.spec | 1 + dlls/wined3d/wined3d_private.h | 24 ++++++---- include/wine/wined3d.h | 2 + 8 files changed, 125 insertions(+), 34 deletions(-) diff --git a/dlls/d3d10core/d3d10core_private.h b/dlls/d3d10core/d3d10core_private.h index ca8735c477f..0e0fdfd5dc1 100644 --- a/dlls/d3d10core/d3d10core_private.h +++ b/dlls/d3d10core/d3d10core_private.h @@ -165,6 +165,8 @@ struct d3d10_shader_resource_view HRESULT d3d10_shader_resource_view_init(struct d3d10_shader_resource_view *view, struct d3d10_device *device, ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc) DECLSPEC_HIDDEN; +struct d3d10_shader_resource_view *unsafe_impl_from_ID3D10ShaderResourceView( + ID3D10ShaderResourceView *iface) DECLSPEC_HIDDEN; /* ID3D10InputLayout */ struct d3d10_input_layout diff --git a/dlls/d3d10core/device.c b/dlls/d3d10core/device.c index 425bf74ee0e..89c0bba1be4 100644 --- a/dlls/d3d10core/device.c +++ b/dlls/d3d10core/device.c @@ -339,8 +339,19 @@ static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface, UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views) { - FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n", + struct d3d10_device *device = impl_from_ID3D10Device(iface); + unsigned int i; + + TRACE("iface %p, start_slot %u, view_count %u, views %p.\n", iface, start_slot, view_count, views); + + for (i = 0; i < view_count; ++i) + { + struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]); + + wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i, + view ? view->wined3d_view : NULL); + } } static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface, diff --git a/dlls/d3d10core/view.c b/dlls/d3d10core/view.c index 40b6201dab6..5c021313ed7 100644 --- a/dlls/d3d10core/view.c +++ b/dlls/d3d10core/view.c @@ -1015,3 +1015,11 @@ HRESULT d3d10_shader_resource_view_init(struct d3d10_shader_resource_view *view, return S_OK; } + +struct d3d10_shader_resource_view *unsafe_impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d10_shader_resource_view_vtbl); + return CONTAINING_RECORD(iface, struct d3d10_shader_resource_view, ID3D10ShaderResourceView_iface); +} diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index a6032d67e65..205f3d8a39d 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -40,6 +40,7 @@ enum wined3d_cs_op WINED3D_CS_OP_SET_INDEX_BUFFER, WINED3D_CS_OP_SET_CONSTANT_BUFFER, WINED3D_CS_OP_SET_TEXTURE, + WINED3D_CS_OP_SET_SHADER_RESOURCE_VIEW, WINED3D_CS_OP_SET_SAMPLER, WINED3D_CS_OP_SET_SHADER, WINED3D_CS_OP_SET_RENDER_STATE, @@ -161,6 +162,14 @@ struct wined3d_cs_set_texture struct wined3d_texture *texture; }; +struct wined3d_cs_set_shader_resource_view +{ + enum wined3d_cs_op opcode; + enum wined3d_shader_type type; + UINT view_idx; + struct wined3d_shader_resource_view *view; +}; + struct wined3d_cs_set_sampler { enum wined3d_cs_op opcode; @@ -657,6 +666,27 @@ void wined3d_cs_emit_set_texture(struct wined3d_cs *cs, UINT stage, struct wined cs->ops->submit(cs); } +static void wined3d_cs_exec_set_shader_resource_view(struct wined3d_cs *cs, const void *data) +{ + const struct wined3d_cs_set_shader_resource_view *op = data; + + cs->state.shader_resource_view[op->type][op->view_idx] = op->view; +} + +void wined3d_cs_emit_set_shader_resource_view(struct wined3d_cs *cs, enum wined3d_shader_type type, + UINT view_idx, struct wined3d_shader_resource_view *view) +{ + struct wined3d_cs_set_shader_resource_view *op; + + op = cs->ops->require_space(cs, sizeof(*op)); + op->opcode = WINED3D_CS_OP_SET_SHADER_RESOURCE_VIEW; + op->type = type; + op->view_idx = view_idx; + op->view = view; + + cs->ops->submit(cs); +} + static void wined3d_cs_exec_set_sampler(struct wined3d_cs *cs, const void *data) { const struct wined3d_cs_set_sampler *op = data; @@ -847,29 +877,30 @@ void wined3d_cs_emit_reset_state(struct wined3d_cs *cs) static void (* const wined3d_cs_op_handlers[])(struct wined3d_cs *cs, const void *data) = { - /* WINED3D_CS_OP_PRESENT */ wined3d_cs_exec_present, - /* WINED3D_CS_OP_CLEAR */ wined3d_cs_exec_clear, - /* WINED3D_CS_OP_DRAW */ wined3d_cs_exec_draw, - /* WINED3D_CS_OP_SET_VIEWPORT */ wined3d_cs_exec_set_viewport, - /* WINED3D_CS_OP_SET_SCISSOR_RECT */ wined3d_cs_exec_set_scissor_rect, - /* WINED3D_CS_OP_SET_RENDERTARGET_VIEW */ wined3d_cs_exec_set_rendertarget_view, - /* WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW */ wined3d_cs_exec_set_depth_stencil_view, - /* WINED3D_CS_OP_SET_VERTEX_DECLARATION */ wined3d_cs_exec_set_vertex_declaration, - /* WINED3D_CS_OP_SET_STREAM_SOURCE */ wined3d_cs_exec_set_stream_source, - /* WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ */ wined3d_cs_exec_set_stream_source_freq, - /* WINED3D_CS_OP_SET_STREAM_OUTPUT */ wined3d_cs_exec_set_stream_output, - /* WINED3D_CS_OP_SET_INDEX_BUFFER */ wined3d_cs_exec_set_index_buffer, - /* WINED3D_CS_OP_SET_CONSTANT_BUFFER */ wined3d_cs_exec_set_constant_buffer, - /* WINED3D_CS_OP_SET_TEXTURE */ wined3d_cs_exec_set_texture, - /* WINED3D_CS_OP_SET_SAMPLER */ wined3d_cs_exec_set_sampler, - /* WINED3D_CS_OP_SET_SHADER */ wined3d_cs_exec_set_shader, - /* WINED3D_CS_OP_SET_RENDER_STATE */ wined3d_cs_exec_set_render_state, - /* WINED3D_CS_OP_SET_TEXTURE_STATE */ wined3d_cs_exec_set_texture_state, - /* WINED3D_CS_OP_SET_SAMPLER_STATE */ wined3d_cs_exec_set_sampler_state, - /* WINED3D_CS_OP_SET_TRANSFORM */ wined3d_cs_exec_set_transform, - /* WINED3D_CS_OP_SET_CLIP_PLANE */ wined3d_cs_exec_set_clip_plane, - /* WINED3D_CS_OP_SET_MATERIAL */ wined3d_cs_exec_set_material, - /* WINED3D_CS_OP_RESET_STATE */ wined3d_cs_exec_reset_state, + /* WINED3D_CS_OP_PRESENT */ wined3d_cs_exec_present, + /* WINED3D_CS_OP_CLEAR */ wined3d_cs_exec_clear, + /* WINED3D_CS_OP_DRAW */ wined3d_cs_exec_draw, + /* WINED3D_CS_OP_SET_VIEWPORT */ wined3d_cs_exec_set_viewport, + /* WINED3D_CS_OP_SET_SCISSOR_RECT */ wined3d_cs_exec_set_scissor_rect, + /* WINED3D_CS_OP_SET_RENDERTARGET_VIEW */ wined3d_cs_exec_set_rendertarget_view, + /* WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW */ wined3d_cs_exec_set_depth_stencil_view, + /* WINED3D_CS_OP_SET_VERTEX_DECLARATION */ wined3d_cs_exec_set_vertex_declaration, + /* WINED3D_CS_OP_SET_STREAM_SOURCE */ wined3d_cs_exec_set_stream_source, + /* WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ */ wined3d_cs_exec_set_stream_source_freq, + /* WINED3D_CS_OP_SET_STREAM_OUTPUT */ wined3d_cs_exec_set_stream_output, + /* WINED3D_CS_OP_SET_INDEX_BUFFER */ wined3d_cs_exec_set_index_buffer, + /* WINED3D_CS_OP_SET_CONSTANT_BUFFER */ wined3d_cs_exec_set_constant_buffer, + /* WINED3D_CS_OP_SET_TEXTURE */ wined3d_cs_exec_set_texture, + /* WINED3D_CS_OP_SET_SHADER_RESOURCE_VIEW */ wined3d_cs_exec_set_shader_resource_view, + /* WINED3D_CS_OP_SET_SAMPLER */ wined3d_cs_exec_set_sampler, + /* WINED3D_CS_OP_SET_SHADER */ wined3d_cs_exec_set_shader, + /* WINED3D_CS_OP_SET_RENDER_STATE */ wined3d_cs_exec_set_render_state, + /* WINED3D_CS_OP_SET_TEXTURE_STATE */ wined3d_cs_exec_set_texture_state, + /* WINED3D_CS_OP_SET_SAMPLER_STATE */ wined3d_cs_exec_set_sampler_state, + /* WINED3D_CS_OP_SET_TRANSFORM */ wined3d_cs_exec_set_transform, + /* WINED3D_CS_OP_SET_CLIP_PLANE */ wined3d_cs_exec_set_clip_plane, + /* WINED3D_CS_OP_SET_MATERIAL */ wined3d_cs_exec_set_material, + /* WINED3D_CS_OP_RESET_STATE */ wined3d_cs_exec_reset_state, }; static void *wined3d_cs_st_require_space(struct wined3d_cs *cs, size_t size) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 9df422f2cba..be5c461e21d 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -2140,6 +2140,38 @@ struct wined3d_buffer * CDECL wined3d_device_get_vs_cb(const struct wined3d_devi return device->state.cb[WINED3D_SHADER_TYPE_VERTEX][idx]; } +static void wined3d_device_set_shader_resource_view(struct wined3d_device *device, + enum wined3d_shader_type type, UINT idx, struct wined3d_shader_resource_view *view) +{ + struct wined3d_shader_resource_view *prev; + + if (idx >= MAX_SHADER_RESOURCE_VIEWS) + { + WARN("Invalid view index %u.\n", idx); + return; + } + + prev = device->update_state->shader_resource_view[type][idx]; + if (view == prev) + return; + + if (view) + wined3d_shader_resource_view_incref(view); + device->update_state->shader_resource_view[type][idx] = view; + if (!device->recording) + wined3d_cs_emit_set_shader_resource_view(device->cs, type, idx, view); + if (prev) + wined3d_shader_resource_view_decref(prev); +} + +void CDECL wined3d_device_set_vs_resource_view(struct wined3d_device *device, + UINT idx, struct wined3d_shader_resource_view *view) +{ + TRACE("device %p, idx %u, view %p.\n", device, idx, view); + + wined3d_device_set_shader_resource_view(device, WINED3D_SHADER_TYPE_VERTEX, idx, view); +} + static void wined3d_device_set_sampler(struct wined3d_device *device, enum wined3d_shader_type type, UINT idx, struct wined3d_sampler *sampler) { diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 80052e56159..2437aac7b31 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -146,6 +146,7 @@ @ cdecl wined3d_device_set_vs_consts_b(ptr long ptr long) @ cdecl wined3d_device_set_vs_consts_f(ptr long ptr long) @ cdecl wined3d_device_set_vs_consts_i(ptr long ptr long) +@ cdecl wined3d_device_set_vs_resource_view(ptr long ptr) @ cdecl wined3d_device_set_vs_sampler(ptr long ptr) @ cdecl wined3d_device_setup_fullscreen_window(ptr ptr long long) @ cdecl wined3d_device_show_cursor(ptr long) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index e43c35681eb..ff98ec05515 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -156,16 +156,17 @@ void *wined3d_rb_realloc(void *ptr, size_t size) DECLSPEC_HIDDEN; void wined3d_rb_free(void *ptr) DECLSPEC_HIDDEN; /* Device caps */ -#define MAX_STREAM_OUT 4 -#define MAX_STREAMS 16 -#define MAX_TEXTURES 8 -#define MAX_FRAGMENT_SAMPLERS 16 -#define MAX_VERTEX_SAMPLERS 4 -#define MAX_COMBINED_SAMPLERS (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS) -#define MAX_ACTIVE_LIGHTS 8 -#define MAX_CLIPPLANES WINED3DMAXUSERCLIPPLANES -#define MAX_CONSTANT_BUFFERS 15 -#define MAX_SAMPLER_OBJECTS 16 +#define MAX_STREAM_OUT 4 +#define MAX_STREAMS 16 +#define MAX_TEXTURES 8 +#define MAX_FRAGMENT_SAMPLERS 16 +#define MAX_VERTEX_SAMPLERS 4 +#define MAX_COMBINED_SAMPLERS (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS) +#define MAX_ACTIVE_LIGHTS 8 +#define MAX_CLIPPLANES WINED3DMAXUSERCLIPPLANES +#define MAX_CONSTANT_BUFFERS 15 +#define MAX_SAMPLER_OBJECTS 16 +#define MAX_SHADER_RESOURCE_VIEWS 128 struct min_lookup { @@ -1865,6 +1866,7 @@ struct wined3d_state struct wined3d_shader *shader[WINED3D_SHADER_TYPE_COUNT]; struct wined3d_buffer *cb[WINED3D_SHADER_TYPE_COUNT][MAX_CONSTANT_BUFFERS]; struct wined3d_sampler *sampler[WINED3D_SHADER_TYPE_COUNT][MAX_SAMPLER_OBJECTS]; + struct wined3d_shader_resource_view *shader_resource_view[WINED3D_SHADER_TYPE_COUNT][MAX_SHADER_RESOURCE_VIEWS]; BOOL vs_consts_b[MAX_CONST_B]; INT vs_consts_i[MAX_CONST_I * 4]; @@ -2510,6 +2512,8 @@ void wined3d_cs_emit_set_render_state(struct wined3d_cs *cs, enum wined3d_render_state state, DWORD value) DECLSPEC_HIDDEN; void wined3d_cs_emit_set_rendertarget_view(struct wined3d_cs *cs, unsigned int view_idx, struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN; +void wined3d_cs_emit_set_shader_resource_view(struct wined3d_cs *cs, enum wined3d_shader_type type, + UINT view_idx, struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN; void wined3d_cs_emit_set_sampler(struct wined3d_cs *cs, enum wined3d_shader_type type, UINT sampler_idx, struct wined3d_sampler *sampler) DECLSPEC_HIDDEN; void wined3d_cs_emit_set_sampler_state(struct wined3d_cs *cs, UINT sampler_idx, diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 336749dc5e1..e66faef28c6 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2265,6 +2265,8 @@ HRESULT __cdecl wined3d_device_set_vs_consts_f(struct wined3d_device *device, UINT start_register, const float *constants, UINT vector4f_count); HRESULT __cdecl wined3d_device_set_vs_consts_i(struct wined3d_device *device, UINT start_register, const int *constants, UINT vector4i_count); +void __cdecl wined3d_device_set_vs_resource_view(struct wined3d_device *device, + UINT idx, struct wined3d_shader_resource_view *view); void __cdecl wined3d_device_set_vs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler); void __cdecl wined3d_device_setup_fullscreen_window(struct wined3d_device *device, HWND window, UINT w, UINT h); BOOL __cdecl wined3d_device_show_cursor(struct wined3d_device *device, BOOL show);