192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri/************************************************************************** 292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Copyright 2010 Luca Barbieri 492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Permission is hereby granted, free of charge, to any person obtaining 692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * a copy of this software and associated documentation files (the 792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * "Software"), to deal in the Software without restriction, including 892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * without limitation the rights to use, copy, modify, merge, publish, 992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * distribute, sublicense, and/or sell copies of the Software, and to 1092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * permit persons to whom the Software is furnished to do so, subject to 1192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * the following conditions: 1292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 1392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * The above copyright notice and this permission notice (including the 1492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * next paragraph) shall be included in all copies or substantial 1592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * portions of the Software. 1692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 1792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 2092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 2192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 2292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 2592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri **************************************************************************/ 2692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 2792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri/* used to unbind things, we need 128 due to resources */ 2892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristatic const void* zero_data[128]; 2992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 3092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define UPDATE_VIEWS_SHIFT (D3D11_STAGES * 0) 3192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define UPDATE_SAMPLERS_SHIFT (D3D11_STAGES * 1) 3292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define UPDATE_VERTEX_BUFFERS (1 << (D3D11_STAGES * 2)) 3392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 3492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 3592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieritemplate<typename PtrTraits> 3692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristruct GalliumD3D11DeviceContext : 3792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri public GalliumD3D11DeviceChild<ID3D11DeviceContext> 3892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 3992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#else 4092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieritemplate<bool threadsafe> 4192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristruct GalliumD3D10Device : public GalliumD3D10ScreenImpl<threadsafe> 4292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 4392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri typedef simple_ptr_traits PtrTraits; 4492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri typedef GalliumD3D10Device GalliumD3D10DeviceContext; 4592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 4692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 4792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11Shader<>, PtrTraits> shaders[D3D11_STAGES]; 4892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11InputLayout, PtrTraits> input_layout; 4992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11Buffer, PtrTraits> index_buffer; 5092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11RasterizerState, PtrTraits> rasterizer_state; 5192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11DepthStencilState, PtrTraits> depth_stencil_state; 5292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11BlendState, PtrTraits> blend_state; 5392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11DepthStencilView, PtrTraits> depth_stencil_view; 5492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11Predicate, PtrTraits> render_predicate; 5592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 5692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11Buffer, PtrTraits> constant_buffers[D3D11_STAGES][D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]; 5792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11ShaderResourceView, PtrTraits> shader_resource_views[D3D11_STAGES][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]; 5892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11SamplerState, PtrTraits> samplers[D3D11_STAGES][D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT]; 5992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11Buffer, PtrTraits> input_buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; 6092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<GalliumD3D11RenderTargetView, PtrTraits> render_target_views[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; 6114193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller refcnt_ptr<GalliumD3D11Buffer, PtrTraits> so_buffers[D3D11_SO_BUFFER_SLOT_COUNT]; 6292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 6392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 6492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<ID3D11UnorderedAccessView, PtrTraits> cs_unordered_access_views[D3D11_PS_CS_UAV_REGISTER_COUNT]; 6592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri refcnt_ptr<ID3D11UnorderedAccessView, PtrTraits> om_unordered_access_views[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; 6692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 6792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 6892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri D3D11_VIEWPORT viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 6992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri D3D11_RECT scissor_rects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; 7092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri D3D11_PRIMITIVE_TOPOLOGY primitive_topology; 7192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri DXGI_FORMAT index_format; 7292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned index_offset; 730cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller uint32_t strip_cut_index; 7492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri BOOL render_predicate_value; 7592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri float blend_color[4]; 7692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned sample_mask; 7792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned stencil_ref; 7892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 7992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void* default_input_layout; 8092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void* default_rasterizer; 8192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void* default_depth_stencil; 8292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void* default_blend; 8392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void* default_sampler; 8465303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller void* default_shaders[D3D11_STAGES]; 8592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 8692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // derived state 8792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri int primitive_mode; 8892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_vertex_buffer vertex_buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; 8914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller struct pipe_stream_output_target* so_targets[D3D11_SO_BUFFER_SLOT_COUNT]; 9092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_sampler_view* sampler_views[D3D11_STAGES][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT]; 9165303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller void* sampler_csos[D3D11_STAGES][D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT]; 9292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num_shader_resource_views[D3D11_STAGES]; 9392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num_samplers[D3D11_STAGES]; 9492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num_vertex_buffers; 9592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num_render_target_views; 9692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num_viewports; 9792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num_scissor_rects; 9892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num_so_targets; 9992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_context* pipe; 10192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned update_flags; 10292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri bool owns_pipe; 10492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned context_flags; 10592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11Caps caps; 10792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri cso_context* cso_ctx; 10992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri gen_mipmap_state* gen_mipmap; 11092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 11192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 11292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define SYNCHRONIZED do {} while(0) 11392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 11492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext(GalliumD3D11Screen* device, pipe_context* pipe, bool owns_pipe, unsigned context_flags = 0) 115b4b2091655676ec3b898d3ae7298192aa7f9147fLuca Barbieri : GalliumD3D11DeviceChild<ID3D11DeviceContext>(device), pipe(pipe), owns_pipe(owns_pipe), context_flags(context_flags) 11692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 11792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri caps = device->screen_caps; 11892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri init_context(); 11992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 12092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 12192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ~GalliumD3D11DeviceContext() 12292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 12392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri destroy_context(); 12492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 12592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#else 12692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define SYNCHRONIZED lock_t<maybe_mutex_t<threadsafe> > lock_(this->mutex) 12792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 12892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D10Device(pipe_screen* screen, pipe_context* pipe, bool owns_pipe, unsigned creation_flags, IDXGIAdapter* adapter) 12992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri : GalliumD3D10ScreenImpl<threadsafe>(screen, pipe, owns_pipe, creation_flags, adapter), pipe(pipe), owns_pipe(owns_pipe), context_flags(0) 13092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 13192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri caps = this->screen_caps; 13292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri init_context(); 13392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 13492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 13592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ~GalliumD3D10Device() 13692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 13792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri destroy_context(); 13892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 13992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 14092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 14192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void init_context() 14292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 14392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!pipe->begin_query) 14492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri caps.queries = false; 14592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!pipe->bind_gs_state) 14692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 14792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri caps.gs = false; 14892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri caps.stages = 2; 14992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 15014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller assert(!caps.so || pipe->set_stream_output_targets); 151f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri if(!pipe->set_geometry_sampler_views) 152f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri caps.stages_with_sampling &=~ (1 << PIPE_SHADER_GEOMETRY); 153f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri if(!pipe->set_fragment_sampler_views) 154f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri caps.stages_with_sampling &=~ (1 << PIPE_SHADER_FRAGMENT); 155f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri if(!pipe->set_vertex_sampler_views) 156f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri caps.stages_with_sampling &=~ (1 << PIPE_SHADER_VERTEX); 15792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 15892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags = 0; 15992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 16092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // pipeline state 16192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(viewports, 0, sizeof(viewports)); 16292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(scissor_rects, 0, sizeof(scissor_rects)); 16392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri primitive_topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; 16492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri index_format = DXGI_FORMAT_UNKNOWN; 16592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri index_offset = 0; 1660cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller strip_cut_index = 0xffffffff; 16792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri render_predicate_value = 0; 16892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(blend_color, 0, sizeof(blend_color)); 16992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri sample_mask = ~0; 17092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri stencil_ref = 0; 17192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 17292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // derived state 17392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri primitive_mode = 0; 17492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(vertex_buffers, 0, sizeof(vertex_buffers)); 17514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller memset(so_targets, 0, sizeof(so_buffers)); 17692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(sampler_views, 0, sizeof(sampler_views)); 17792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(sampler_csos, 0, sizeof(sampler_csos)); 17892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(num_shader_resource_views, 0, sizeof(num_shader_resource_views)); 17992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(num_samplers, 0, sizeof(num_samplers)); 18092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri num_vertex_buffers = 0; 18192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri num_render_target_views = 0; 18292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri num_viewports = 0; 18392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri num_scissor_rects = 0; 18492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri num_so_targets = 0; 18592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 18692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri default_input_layout = pipe->create_vertex_elements_state(pipe, 0, 0); 18792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 18892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_rasterizer_state rasterizerd; 18992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&rasterizerd, 0, sizeof(rasterizerd)); 19092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri rasterizerd.gl_rasterization_rules = 1; 19192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri rasterizerd.cull_face = PIPE_FACE_BACK; 1924a06248281f65d8a653c1bb744947bb6d47fdc9cChristoph Bumiller rasterizerd.flatshade_first = 1; 193e27d72d6c3ca3512bfea524b8a7b007960841057Christoph Bumiller rasterizerd.line_width = 1.0f; 194e27d72d6c3ca3512bfea524b8a7b007960841057Christoph Bumiller rasterizerd.point_size = 1.0f; 195dc4c821f0817a3db716f965692fb701079f66340Marek Olšák rasterizerd.depth_clip = TRUE; 19692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri default_rasterizer = pipe->create_rasterizer_state(pipe, &rasterizerd); 19792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 19892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_depth_stencil_alpha_state depth_stencild; 19992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&depth_stencild, 0, sizeof(depth_stencild)); 20092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri depth_stencild.depth.enabled = TRUE; 20192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri depth_stencild.depth.writemask = 1; 20292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri depth_stencild.depth.func = PIPE_FUNC_LESS; 20392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri default_depth_stencil = pipe->create_depth_stencil_alpha_state(pipe, &depth_stencild); 20492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 20592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_blend_state blendd; 20692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&blendd, 0, sizeof(blendd)); 20792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri blendd.rt[0].colormask = 0xf; 20892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri default_blend = pipe->create_blend_state(pipe, &blendd); 20992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 21092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_sampler_state samplerd; 21192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&samplerd, 0, sizeof(samplerd)); 21292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.normalized_coords = 1; 21392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.min_img_filter = PIPE_TEX_FILTER_LINEAR; 21492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.mag_img_filter = PIPE_TEX_FILTER_LINEAR; 21592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.min_mip_filter = PIPE_TEX_MIPFILTER_LINEAR; 21692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 21792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 21892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 2199f61e43b4903c6cf0ac03a479ec9ed7b15fd6ccfDave Airlie samplerd.border_color.f[0] = 1.0f; 2209f61e43b4903c6cf0ac03a479ec9ed7b15fd6ccfDave Airlie samplerd.border_color.f[1] = 1.0f; 2219f61e43b4903c6cf0ac03a479ec9ed7b15fd6ccfDave Airlie samplerd.border_color.f[2] = 1.0f; 2229f61e43b4903c6cf0ac03a479ec9ed7b15fd6ccfDave Airlie samplerd.border_color.f[3] = 1.0f; 22392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.min_lod = -FLT_MAX; 22492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.max_lod = FLT_MAX; 22592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.max_anisotropy = 1; 22692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri default_sampler = pipe->create_sampler_state(pipe, &samplerd); 22792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 22892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&samplerd, 0, sizeof(samplerd)); 22992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.normalized_coords = 0; 23092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.min_img_filter = PIPE_TEX_FILTER_NEAREST; 23192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.mag_img_filter = PIPE_TEX_FILTER_NEAREST; 23292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; 23392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_BORDER; 23492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_BORDER; 23592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_BORDER; 23692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.min_lod = -FLT_MAX; 23792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.max_lod = FLT_MAX; 23892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplerd.max_anisotropy = 1; 23992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 24092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned s = 0; s < D3D11_STAGES; ++s) 24192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i) 24265303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller sampler_csos[s][i] = default_sampler; 24392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 24492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // TODO: should this really be empty shaders, or should they be all-passthrough? 24592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(default_shaders, 0, sizeof(default_shaders)); 24692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct ureg_program *ureg; 24792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); 24892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ureg_END(ureg); 24992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri default_shaders[PIPE_SHADER_FRAGMENT] = ureg_create_shader_and_destroy(ureg, pipe); 25092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 25192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ureg = ureg_create(TGSI_PROCESSOR_VERTEX); 25292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ureg_END(ureg); 25392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri default_shaders[PIPE_SHADER_VERTEX] = ureg_create_shader_and_destroy(ureg, pipe); 25492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 25592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri cso_ctx = cso_create_context(pipe); 25692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri gen_mipmap = util_create_gen_mipmap(pipe, cso_ctx); 25792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 25892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri RestoreGalliumState(); 25992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 26092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 26192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void destroy_context() 26292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 26392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri util_destroy_gen_mipmap(gen_mipmap); 26492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri cso_destroy_context(cso_ctx); 2651b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 2661b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_vertex_elements_state(pipe, 0); 26792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->delete_vertex_elements_state(pipe, default_input_layout); 2681b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 2691b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_rasterizer_state(pipe, 0); 27092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->delete_rasterizer_state(pipe, default_rasterizer); 2711b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 2721b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_depth_stencil_alpha_state(pipe, 0); 27392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->delete_depth_stencil_alpha_state(pipe, default_depth_stencil); 2741b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 2751b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_blend_state(pipe, 0); 27692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->delete_blend_state(pipe, default_blend); 2771b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 2781b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_fragment_sampler_states(pipe, 0, 0); 2791b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_vertex_sampler_states(pipe, 0, 0); 2801b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri if(pipe->bind_geometry_sampler_states) 2811b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_geometry_sampler_states(pipe, 0, 0); 28292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->delete_sampler_state(pipe, default_sampler); 2831b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 2841b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_fs_state(pipe, 0); 28592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->delete_fs_state(pipe, default_shaders[PIPE_SHADER_FRAGMENT]); 2861b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 2871b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri pipe->bind_vs_state(pipe, 0); 28892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->delete_vs_state(pipe, default_shaders[PIPE_SHADER_VERTEX]); 2891b15a3cafdc699c63466059d56f36b295475ee9eLuca Barbieri 29092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(owns_pipe) 29192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->destroy(pipe); 29292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 29392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 29492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual unsigned STDMETHODCALLTYPE GetContextFlags(void) 29592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 29692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return context_flags; 29792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 29892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 29992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define SET_SHADER_EXTRA_ARGS , \ 3008224256946619fb25278718bbf4703e3b9d60c93Luca Barbieri ID3D11ClassInstance *const *ppClassInstances, \ 3013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count 30292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define GET_SHADER_EXTRA_ARGS , \ 3038224256946619fb25278718bbf4703e3b9d60c93Luca Barbieri ID3D11ClassInstance **ppClassInstances, \ 3043e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_count 30592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#else 30692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define SET_SHADER_EXTRA_ARGS 30792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define GET_SHADER_EXTRA_ARGS 30892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 30992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 31092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri/* On Windows D3D11, SetConstantBuffers and SetShaderResources crash if passed a null pointer. 31192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Instead, you have to pass a pointer to nulls to unbind things. 31292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * We do the same. 31392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * TODO: is D3D10 the same? 31492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri */ 31592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri template<unsigned s> 31692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void xs_set_shader(GalliumD3D11Shader<>* shader) 31792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 31892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(shader != shaders[s].p) 31992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 32092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri shaders[s] = shader; 32192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void* shader_cso = shader ? shader->object : default_shaders[s]; 32292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri switch(s) 32392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 32492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_VERTEX: 32592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_vs_state(pipe, shader_cso); 32692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 32792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_FRAGMENT: 32892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_fs_state(pipe, shader_cso); 32992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 33092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_GEOMETRY: 33192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_gs_state(pipe, shader_cso); 33292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 33392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 33492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + s)) | (1 << (UPDATE_VIEWS_SHIFT + s)); 33592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 33692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 33792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 33892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri template<unsigned s> 33992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void xs_set_constant_buffers(unsigned start, unsigned count, GalliumD3D11Buffer *const *constbufs) 34092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 34192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < count; ++i) 34292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 34355592d9da1bb694c7275984cf9a3ecaafcccf46aChristoph Bumiller if(constbufs[i] != constant_buffers[s][start + i].p) 34492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 34555592d9da1bb694c7275984cf9a3ecaafcccf46aChristoph Bumiller constant_buffers[s][start + i] = constbufs[i]; 34692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(s < caps.stages && start + i < caps.constant_buffers[s]) 347507337864fa80caf9f26602324d2c28dd0a75d61Marek Olšák pipe_set_constant_buffer(pipe, s, start + i, constbufs[i] ? constbufs[i]->resource : NULL); 34892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 34992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 35092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 35192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 35292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri template<unsigned s> 35392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void xs_set_shader_resources(unsigned start, unsigned count, GalliumD3D11ShaderResourceView *const *srvs) 35492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 35592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri int last_different = -1; 35692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < count; ++i) 35792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 35892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(shader_resource_views[s][start + i].p != srvs[i]) 35992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 36092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri shader_resource_views[s][start + i] = srvs[i]; 36192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri sampler_views[s][start + i] = srvs[i] ? srvs[i]->object : 0; 36292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri last_different = i; 36392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 36492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 36592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(last_different >= 0) 36692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 36792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri num_shader_resource_views[s] = std::max(num_shader_resource_views[s], start + last_different + 1); 36892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= 1 << (UPDATE_VIEWS_SHIFT + s); 36992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 37092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 37192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 37292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri template<unsigned s> 37392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void xs_set_samplers(unsigned start, unsigned count, GalliumD3D11SamplerState *const *samps) 37492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 37592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri int last_different = -1; 37692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < count; ++i) 37792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 37892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(samplers[s][start + i].p != samps[i]) 37992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 38092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplers[s][start + i] = samps[i]; 38165303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller sampler_csos[s][start + i] = samps[i] ? samps[i]->object : default_sampler; 382974412d7b985f44c2d3a68f818d2723346a4512bChristoph Bumiller last_different = i; 38392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 38465303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller } 38565303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller if(last_different >= 0) 38665303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller { 38765303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller num_samplers[s] = std::max(num_samplers[s], start + last_different + 1); 38865303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller update_flags |= 1 << (UPDATE_SAMPLERS_SHIFT + s); 38992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 39092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 39192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 39292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define IMPLEMENT_SHADER_STAGE(XS, Stage) \ 39392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##SetShader( \ 3948224256946619fb25278718bbf4703e3b9d60c93Luca Barbieri ID3D11##Stage##Shader *pShader \ 39592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SET_SHADER_EXTRA_ARGS) \ 39692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 39792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 39892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri xs_set_shader<D3D11_STAGE_##XS>((GalliumD3D11Shader<>*)pShader); \ 39992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 40092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##GetShader(\ 4018224256946619fb25278718bbf4703e3b9d60c93Luca Barbieri ID3D11##Stage##Shader **ppShader \ 40292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GET_SHADER_EXTRA_ARGS) \ 40392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 40492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 40592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri *ppShader = (ID3D11##Stage##Shader*)shaders[D3D11_STAGE_##XS].ref(); \ 40692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 40792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##SetConstantBuffers(\ 4083e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, \ 4093e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, \ 4103e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *const* constant_buffers) \ 41192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 41292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 4133e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri xs_set_constant_buffers<D3D11_STAGE_##XS>(start, count, (GalliumD3D11Buffer *const *)constant_buffers); \ 41492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 41592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##GetConstantBuffers(\ 4163e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, \ 4173e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, \ 4183e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer **out_constant_buffers) \ 41992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 42092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 4213e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) \ 4223e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_constant_buffers[i] = constant_buffers[D3D11_STAGE_##XS][start + i].ref(); \ 42392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 42492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##SetShaderResources(\ 4253e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, \ 4263e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, \ 4273e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11ShaderResourceView *const *new_shader_resource_views) \ 42892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 42992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 4303e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri xs_set_shader_resources<D3D11_STAGE_##XS>(start, count, (GalliumD3D11ShaderResourceView *const *)new_shader_resource_views); \ 43192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 43292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##GetShaderResources(\ 4333e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, \ 4343e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, \ 4353e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11ShaderResourceView **out_shader_resource_views) \ 43692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 43792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 4383e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) \ 4393e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_shader_resource_views[i] = shader_resource_views[D3D11_STAGE_##XS][start + i].ref(); \ 44092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 44192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##SetSamplers(\ 4423e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, \ 4433e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, \ 4443e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11SamplerState *const *new_samplers) \ 44592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 44692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 4473e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri xs_set_samplers<D3D11_STAGE_##XS>(start, count, (GalliumD3D11SamplerState *const *)new_samplers); \ 44892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 44992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE XS##GetSamplers( \ 4503e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, \ 4513e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, \ 4523e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11SamplerState **out_samplers) \ 45392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 45492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 4553e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) \ 4563e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_samplers[i] = samplers[D3D11_STAGE_##XS][start + i].ref(); \ 45792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 45892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 45992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define DO_VS(x) x 46092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define DO_GS(x) do {if(caps.gs) {x;}} while(0) 46192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define DO_PS(x) x 46292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define DO_HS(x) 46392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define DO_DS(x) 46492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define DO_CS(x) 46592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SHADER_STAGE(VS, Vertex) 46692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SHADER_STAGE(GS, Geometry) 46792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SHADER_STAGE(PS, Pixel) 46892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 46992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 47092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SHADER_STAGE(HS, Hull) 47192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SHADER_STAGE(DS, Domain) 47292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SHADER_STAGE(CS, Compute) 47392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 47492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE CSSetUnorderedAccessViews( 4753e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, 4763e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 4773e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11UnorderedAccessView *const *new_unordered_access_views, 4783e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const unsigned *new_uav_initial_counts) 47992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 48092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 4813e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) 4823e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri cs_unordered_access_views[start + i] = new_unordered_access_views[i]; 48392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 48492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 48592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE CSGetUnorderedAccessViews( 4863e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, 4873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 4883e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11UnorderedAccessView **out_unordered_access_views) 48992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 49092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 4913e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) 4923e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_unordered_access_views[i] = cs_unordered_access_views[start + i].ref(); 49392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 49492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 49592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 49692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri template<unsigned s> 49792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void update_stage() 49892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 49992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags & (1 << (UPDATE_VIEWS_SHIFT + s))) 50092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 50192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri while(num_shader_resource_views[s] && !sampler_views[s][num_shader_resource_views[s] - 1]) \ 50292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri --num_shader_resource_views[s]; 503f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri if((1 << s) & caps.stages_with_sampling) 50492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 50565303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller const unsigned num_views_to_bind = num_shader_resource_views[s]; 50692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri switch(s) 50792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 50892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_VERTEX: 50965303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller pipe->set_vertex_sampler_views(pipe, num_views_to_bind, sampler_views[s]); 51092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 51192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_FRAGMENT: 51265303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller pipe->set_fragment_sampler_views(pipe, num_views_to_bind, sampler_views[s]); 51392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 51492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_GEOMETRY: 51565303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller pipe->set_geometry_sampler_views(pipe, num_views_to_bind, sampler_views[s]); 51692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 51792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 51892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 51992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 52092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 52192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags & (1 << (UPDATE_SAMPLERS_SHIFT + s))) 52292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 52365303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller while(num_samplers[s] && !sampler_csos[s][num_samplers[s] - 1]) 52492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri --num_samplers[s]; 525f1063cfee213ba92f7c9e34199caccf4bed78c1cLuca Barbieri if((1 << s) & caps.stages_with_sampling) 52692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 52765303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller const unsigned num_samplers_to_bind = num_samplers[s]; 52892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri switch(s) 52992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 53092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_VERTEX: 53165303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller pipe->bind_vertex_sampler_states(pipe, num_samplers_to_bind, sampler_csos[s]); 53292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 53392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_FRAGMENT: 53465303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller pipe->bind_fragment_sampler_states(pipe, num_samplers_to_bind, sampler_csos[s]); 53592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 53692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri case PIPE_SHADER_GEOMETRY: 53765303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller pipe->bind_geometry_sampler_states(pipe, num_samplers_to_bind, sampler_csos[s]); 53892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri break; 53992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 54092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 54192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 54292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 54392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 54492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void update_state() 54592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 54692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_stage<D3D11_STAGE_PS>(); 54792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_stage<D3D11_STAGE_VS>(); 54892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_stage<D3D11_STAGE_GS>(); 54992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 55092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_stage<D3D11_STAGE_HS>(); 55192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_stage<D3D11_STAGE_DS>(); 55292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_stage<D3D11_STAGE_CS>(); 55392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 55492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 55592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags & UPDATE_VERTEX_BUFFERS) 55692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 55792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri while(num_vertex_buffers && !vertex_buffers[num_vertex_buffers - 1].buffer) 55892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri --num_vertex_buffers; 55992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_vertex_buffers(pipe, num_vertex_buffers, vertex_buffers); 56092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 56192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 56292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags = 0; 56392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 56492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 56592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IASetInputLayout( 5663e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11InputLayout *new_input_layout) 56792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 56892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 5693e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(new_input_layout != input_layout.p) 57092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 5713e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri input_layout = new_input_layout; 5723e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->bind_vertex_elements_state(pipe, new_input_layout ? ((GalliumD3D11InputLayout*)new_input_layout)->object : default_input_layout); 57392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 57492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 57592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 57692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IAGetInputLayout( 5773e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11InputLayout **out_input_layout) 57892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 57992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 5803e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_input_layout = input_layout.ref(); 58192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 58292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 58392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IASetVertexBuffers( 5843e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, 5853e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 5863e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *const *new_vertex_buffers, 5873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const unsigned *new_strides, 5883e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const unsigned *new_offsets) 58992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 59092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 59192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri int last_different = -1; 5923e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) 59392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 5943e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer* buffer = new_vertex_buffers[i]; 5953e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(buffer != input_buffers[start + i].p 5963e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri || vertex_buffers[start + i].buffer_offset != new_offsets[i] 597856f3336dc6687c6629f88f67e589e007763ddf0Christoph Bumiller || vertex_buffers[start + i].stride != new_strides[i] 59892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ) 59992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 6003e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri input_buffers[start + i] = buffer; 6013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri vertex_buffers[start + i].buffer = buffer ? ((GalliumD3D11Buffer*)buffer)->resource : 0; 6023e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri vertex_buffers[start + i].buffer_offset = new_offsets[i]; 6033e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri vertex_buffers[start + i].stride = new_strides[i]; 60492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri last_different = i; 60592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 60692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 60792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(last_different >= 0) 60892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 6093e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri num_vertex_buffers = std::max(num_vertex_buffers, start + count); 61092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= UPDATE_VERTEX_BUFFERS; 61192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 61292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 61392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 61492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IAGetVertexBuffers( 6153e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start, 6163e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 6173e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer **out_vertex_buffers, 6183e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_strides, 6193e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_offsets) 62092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 62192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 6223e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_vertex_buffers) 62392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 6243e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) 6253e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_vertex_buffers[i] = input_buffers[start + i].ref(); 62692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 62792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 6283e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_offsets) 62992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 6303e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) 6313e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_offsets[i] = vertex_buffers[start + i].buffer_offset; 63292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 63392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 6343e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_strides) 63592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 6363e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) 6373e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_strides[i] = vertex_buffers[start + i].stride; 63892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 63992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 64092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 64192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void set_index_buffer() 64292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 64392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_index_buffer ib; 64492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!index_buffer) 64592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 64692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&ib, 0, sizeof(ib)); 64792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 64892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else 64992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 6500cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller switch(index_format) { 6510cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller case DXGI_FORMAT_R32_UINT: 65292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ib.index_size = 4; 6530cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller strip_cut_index = 0xffffffff; 6540cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller break; 6550cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller case DXGI_FORMAT_R16_UINT: 65692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ib.index_size = 2; 6570cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller strip_cut_index = 0xffff; 6580cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller break; 6590cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller default: 66092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ib.index_size = 1; 6610cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller strip_cut_index = 0xff; 6620cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller break; 6630cf1a55568dc7e511cbd8e3f5277ccfc272e4febChristoph Bumiller } 66492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ib.offset = index_offset; 66592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ib.buffer = index_buffer ? ((GalliumD3D11Buffer*)index_buffer.p)->resource : 0; 66692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 66792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_index_buffer(pipe, &ib); 66892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 66992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 67092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IASetIndexBuffer( 6713e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *new_index_buffer, 6723e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri DXGI_FORMAT new_index_format, 6733e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned new_index_offset) 67492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 67592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 6763e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(index_buffer.p != new_index_buffer || index_format != new_index_format || index_offset != new_index_offset) 67792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 6783e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri index_buffer = new_index_buffer; 6793e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri index_format = new_index_format; 6803e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri index_offset = new_index_offset; 68192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 68292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_index_buffer(); 68392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 68492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 68592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 68692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IAGetIndexBuffer( 6873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer **out_index_buffer, 6883e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri DXGI_FORMAT *out_index_format, 6893e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_index_offset) 69092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 69192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 6923e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_index_buffer) 6933e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_index_buffer = index_buffer.ref(); 6943e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_index_format) 6953e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_index_format = index_format; 6963e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_index_offset) 6973e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_index_offset = index_offset; 69892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 69992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 70092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IASetPrimitiveTopology( 7013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri D3D11_PRIMITIVE_TOPOLOGY new_primitive_topology) 70292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 70392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 7043e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(primitive_topology != new_primitive_topology) 70592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 7063e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(new_primitive_topology < D3D_PRIMITIVE_TOPOLOGY_COUNT) 7073e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri primitive_mode = d3d_to_pipe_prim[new_primitive_topology]; 70892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else 70992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri primitive_mode = 0; 7103e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri primitive_topology = new_primitive_topology; 71192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 71292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 71392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 71492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE IAGetPrimitiveTopology( 7153e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri D3D11_PRIMITIVE_TOPOLOGY *out_primitive_topology) 71692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 71792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 7183e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_primitive_topology = primitive_topology; 71992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 72092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 72192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE DrawIndexed( 7223e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned index_count, 7233e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start_index_location, 7243e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri int base_vertex_location) 72592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 72692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 72792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags) 72892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_state(); 72992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 73092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_draw_info info; 73192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.mode = primitive_mode; 73292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.indexed = TRUE; 7333e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.count = index_count; 7343e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.start = start_index_location; 7353e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.index_bias = base_vertex_location; 73692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.min_index = 0; 73792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.max_index = ~0; 73892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.start_instance = 0; 73992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.instance_count = 1; 74027b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.primitive_restart = TRUE; 74127b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.restart_index = strip_cut_index; 74214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count_from_stream_output = NULL; 74392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 74492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->draw_vbo(pipe, &info); 74592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 74692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 74792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE Draw( 7483e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned vertex_count, 7493e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start_vertex_location) 75092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 75192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 75292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags) 75392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_state(); 75492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 75592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_draw_info info; 75692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.mode = primitive_mode; 75792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.indexed = FALSE; 7583e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.count = vertex_count; 7593e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.start = start_vertex_location; 76092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.index_bias = 0; 76192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.min_index = 0; 76292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.max_index = ~0; 76392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.start_instance = 0; 76492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.instance_count = 1; 76527b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.primitive_restart = FALSE; 76614193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count_from_stream_output = NULL; 76792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 76892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->draw_vbo(pipe, &info); 76992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 77092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 77192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE DrawIndexedInstanced( 7723e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned index_countPerInstance, 7733e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned instance_count, 7743e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start_index_location, 7753e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri int base_vertex_location, 7763e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start_instance_location) 77792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 77892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 77992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags) 78092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_state(); 78192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 78292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_draw_info info; 78392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.mode = primitive_mode; 78492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.indexed = TRUE; 7853e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.count = index_countPerInstance; 7863e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.start = start_index_location; 7873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.index_bias = base_vertex_location; 78892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.min_index = 0; 78992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.max_index = ~0; 7903e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.start_instance = start_instance_location; 7913e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.instance_count = instance_count; 79227b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.primitive_restart = TRUE; 79327b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.restart_index = strip_cut_index; 79414193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count_from_stream_output = NULL; 79592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 79692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->draw_vbo(pipe, &info); 79792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 79892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 79992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE DrawInstanced( 8003e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned vertex_countPerInstance, 8013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned instance_count, 8023e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start_vertex_location, 8033e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned start_instance_location) 80492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 80592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 80692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags) 80792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_state(); 80892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 80992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_draw_info info; 81092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.mode = primitive_mode; 81192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.indexed = FALSE; 8123e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.count = vertex_countPerInstance; 8133e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.start = start_vertex_location; 81492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.index_bias = 0; 81592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.min_index = 0; 81692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.max_index = ~0; 8173e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.start_instance = start_instance_location; 8183e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri info.instance_count = instance_count; 81927b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.primitive_restart = FALSE; 82014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count_from_stream_output = NULL; 82192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 82292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->draw_vbo(pipe, &info); 82392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 82492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 82592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE DrawAuto(void) 82692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 82792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!caps.so) 82892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return; 82992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 83092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 83192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags) 83292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_state(); 83392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 83414193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller pipe_draw_info info; 83514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.mode = primitive_mode; 83614193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.indexed = FALSE; 83714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count = 0; 83814193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.start = 0; 83914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.index_bias = 0; 84014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.min_index = 0; 84114193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.max_index = ~0; 84214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.start_instance = 0; 84314193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.instance_count = 1; 84414193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.primitive_restart = FALSE; 84514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.restart_index = 0; 84614193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count_from_stream_output = input_buffers[0].p->so_target; 84714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller 84814193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller pipe->draw_vbo(pipe, &info); 84992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 85092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 85192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE DrawIndexedInstancedIndirect( 8523e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *buffer, 8533e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned aligned_byte_offset) 85492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 85592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 85692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags) 85792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_state(); 85892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 85992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct { 86092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned count; 86192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned instance_count; 86292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned start; 86392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned index_bias; 86492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } data; 86592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 8663e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe_buffer_read(pipe, ((GalliumD3D11Buffer*)buffer)->resource, aligned_byte_offset, sizeof(data), &data); 86792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 86892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_draw_info info; 86992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.mode = primitive_mode; 87092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.indexed = TRUE; 87192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.start = data.start; 87292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.count = data.count; 87392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.index_bias = data.index_bias; 87492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.min_index = 0; 87592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.max_index = ~0; 87692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.start_instance = 0; 87792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.instance_count = data.instance_count; 87827b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.primitive_restart = TRUE; 87927b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.restart_index = strip_cut_index; 88014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count_from_stream_output = NULL; 88192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 88292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->draw_vbo(pipe, &info); 88392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 88492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 88592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE DrawInstancedIndirect( 8863e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *buffer, 8873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned aligned_byte_offset) 88892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 88992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 89092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(update_flags) 89192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_state(); 89292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 89392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct { 89492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned count; 89592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned instance_count; 89692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned start; 89792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } data; 89892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 8993e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe_buffer_read(pipe, ((GalliumD3D11Buffer*)buffer)->resource, aligned_byte_offset, sizeof(data), &data); 90092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 90192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_draw_info info; 90292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.mode = primitive_mode; 90392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.indexed = FALSE; 90492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.start = data.start; 90592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.count = data.count; 90692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.index_bias = 0; 90792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.min_index = 0; 90892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.max_index = ~0; 90992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.start_instance = 0; 91092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri info.instance_count = data.instance_count; 91127b0c9d51300712f3b5d4af6cc20d53fcf9c8c46Christoph Bumiller info.primitive_restart = FALSE; 91214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller info.count_from_stream_output = NULL; 91392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 91492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->draw_vbo(pipe, &info); 91592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 91692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 91792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 91892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE Dispatch( 9193e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned thread_group_count_x, 9203e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned thread_group_count_y, 9213e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned thread_group_count_z) 92292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 92392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// uncomment this when this is implemented 92492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// SYNCHRONIZED; 92592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// if(update_flags) 92692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// update_state(); 92792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 92892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 92992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE DispatchIndirect( 9303e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *buffer, 9313e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned aligned_byte_offset) 93292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 93392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// uncomment this when this is implemented 93492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// SYNCHRONIZED; 93592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// if(update_flags) 93692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri// update_state(); 93792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 93892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 93992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 94092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE RSSetState( 9413e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11RasterizerState *new_rasterizer_state) 94292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 94392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 9443e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(new_rasterizer_state != rasterizer_state.p) 94592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 9463e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri rasterizer_state = new_rasterizer_state; 9473e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->bind_rasterizer_state(pipe, new_rasterizer_state ? ((GalliumD3D11RasterizerState*)new_rasterizer_state)->object : default_rasterizer); 94892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 94992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 95092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 95192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE RSGetState( 9523e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11RasterizerState **out_rasterizer_state) 95392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 95492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 9553e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_rasterizer_state = rasterizer_state.ref(); 95692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 95792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 95892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void set_viewport() 95992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 96092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // TODO: is depth correct? it seems D3D10/11 uses a [-1,1]x[-1,1]x[0,1] cube 96192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_viewport_state viewport; 96292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri float half_width = viewports[0].Width * 0.5f; 96392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri float half_height = viewports[0].Height * 0.5f; 96492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 96592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.scale[0] = half_width; 96692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.scale[1] = -half_height; 96792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.scale[2] = (viewports[0].MaxDepth - viewports[0].MinDepth); 96892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.scale[3] = 1.0f; 96992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.translate[0] = half_width + viewports[0].TopLeftX; 97092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.translate[1] = half_height + viewports[0].TopLeftY; 97192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.translate[2] = viewports[0].MinDepth; 97292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri viewport.translate[3] = 1.0f; 97392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_viewport_state(pipe, &viewport); 97492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 97592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 97692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE RSSetViewports( 9773e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 9783e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const D3D11_VIEWPORT *new_viewports) 97992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 98092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 9813e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(count) 98292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 9833e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(memcmp(&viewports[0], &new_viewports[0], sizeof(viewports[0]))) 98492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 9853e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri viewports[0] = new_viewports[0]; 98692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_viewport(); 98792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 9883e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 1; i < count; ++i) 9893e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri viewports[i] = new_viewports[i]; 99092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 99192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else if(num_viewports) 99292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 99392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // TODO: what should we do here? 99492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&viewports[0], 0, sizeof(viewports[0])); 99592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_viewport(); 99692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 9973e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri num_viewports = count; 99892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 99992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 100092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE RSGetViewports( 10013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_count, 10023e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri D3D11_VIEWPORT *out_viewports) 100392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 100492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 10053e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_viewports) 100692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 100792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned i; 10083e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(i = 0; i < std::min(*out_count, num_viewports); ++i) 10093e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_viewports[i] = viewports[i]; 101092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10113e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri memset(out_viewports + i, 0, (*out_count - i) * sizeof(D3D11_VIEWPORT)); 101292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 101392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10143e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_count = num_viewports; 101592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 101692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 101792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void set_scissor() 101892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 101992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe_scissor_state scissor; 102092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri scissor.minx = scissor_rects[0].left; 102192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri scissor.miny = scissor_rects[0].top; 102292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri scissor.maxx = scissor_rects[0].right; 102392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri scissor.maxy = scissor_rects[0].bottom; 102492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_scissor_state(pipe, &scissor); 102592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 102692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 102792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE RSSetScissorRects( 10283e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 10293e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const D3D11_RECT *new_rects) 103092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 103192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 10323e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(count) 103392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 10343e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(memcmp(&scissor_rects[0], &new_rects[0], sizeof(scissor_rects[0]))) 103592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 10363e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri scissor_rects[0] = new_rects[0]; 103792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_scissor(); 103892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 10393e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 1; i < count; ++i) 10403e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri scissor_rects[i] = new_rects[i]; 104192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 104292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else if(num_scissor_rects) 104392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 104492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // TODO: what should we do here? 104592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&scissor_rects[0], 0, sizeof(scissor_rects[0])); 104692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_scissor(); 104792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 104892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10493e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri num_scissor_rects = count; 105092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 105192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 105292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE RSGetScissorRects( 10533e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_count, 10543e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri D3D11_RECT *out_rects) 105592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 105692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 10573e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_rects) 105892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 105992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned i; 10603e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(i = 0; i < std::min(*out_count, num_scissor_rects); ++i) 10613e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_rects[i] = scissor_rects[i]; 106292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10633e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri memset(out_rects + i, 0, (*out_count - i) * sizeof(D3D11_RECT)); 106492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 106592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10663e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_count = num_scissor_rects; 106792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 106892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 106992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMSetBlendState( 10703e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11BlendState *new_blend_state, 10713e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const float new_blend_factor[4], 10723e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned new_sample_mask) 107392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 107492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 107592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri float white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; 107692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10773e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(blend_state.p != new_blend_state) 107892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 10793e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->bind_blend_state(pipe, new_blend_state ? ((GalliumD3D11BlendState*)new_blend_state)->object : default_blend); 10803e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri blend_state = new_blend_state; 108192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 108292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 108392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // Windows D3D11 does this, even though it's apparently undocumented 10843e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(!new_blend_factor) 10853e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri new_blend_factor = white; 108692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(memcmp(blend_color, new_blend_factor, sizeof(blend_color))) 108892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 10893e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->set_blend_color(pipe, (struct pipe_blend_color*)new_blend_factor); 10903e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri memcpy(blend_color, new_blend_factor, sizeof(blend_color)); 109192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 109292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 10933e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(sample_mask != new_sample_mask) 109492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 10953e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->set_sample_mask(pipe, new_sample_mask); 10963e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri sample_mask = new_sample_mask; 109792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 109892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 109992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 110092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMGetBlendState( 11013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11BlendState **out_blend_state, 11023e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri float out_blend_factor[4], 11033e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_sample_mask) 110492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 110592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 11063e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_blend_state) 11073e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_blend_state = blend_state.ref(); 11083e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_blend_factor) 11093e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri memcpy(out_blend_factor, blend_color, sizeof(blend_color)); 11103e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_sample_mask) 11113e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_sample_mask = sample_mask; 111292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 111392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 111492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void set_stencil_ref() 111592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 111692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_stencil_ref sref; 111792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri sref.ref_value[0] = stencil_ref; 111892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri sref.ref_value[1] = stencil_ref; 111992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_stencil_ref(pipe, &sref); 112092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 112192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 112292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMSetDepthStencilState( 11233e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11DepthStencilState *new_depth_stencil_state, 11243e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned new_stencil_ref) 112592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 112692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 11273e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(new_depth_stencil_state != depth_stencil_state.p) 112892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 11293e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->bind_depth_stencil_alpha_state(pipe, new_depth_stencil_state ? ((GalliumD3D11DepthStencilState*)new_depth_stencil_state)->object : default_depth_stencil); 11303e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri depth_stencil_state = new_depth_stencil_state; 113192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 113292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 11333e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(new_stencil_ref != stencil_ref) 113492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 11353e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri stencil_ref = new_stencil_ref; 113692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_stencil_ref(); 113792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 113892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 113992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 114092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMGetDepthStencilState( 11413e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11DepthStencilState **out_depth_stencil_state, 11423e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned *out_stencil_ref) 114392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 114492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 11453e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(*out_depth_stencil_state) 11463e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_depth_stencil_state = depth_stencil_state.ref(); 11473e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_stencil_ref) 11483e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_stencil_ref = stencil_ref; 114992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 115092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 115192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void set_framebuffer() 115292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 115392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_framebuffer_state fb; 115492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&fb, 0, sizeof(fb)); 115592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(depth_stencil_view) 115692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 115792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_surface* surf = ((GalliumD3D11DepthStencilView*)depth_stencil_view.p)->object; 115892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri fb.zsbuf = surf; 115992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(surf->width > fb.width) 116092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri fb.width = surf->width; 116192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(surf->height > fb.height) 116292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri fb.height = surf->height; 116392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 116492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri fb.nr_cbufs = num_render_target_views; 116592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned i; 116692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(i = 0; i < num_render_target_views; ++i) 116792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 116892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(render_target_views[i]) 116992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 117092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_surface* surf = ((GalliumD3D11RenderTargetView*)render_target_views[i].p)->object; 117192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri fb.cbufs[i] = surf; 117292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(surf->width > fb.width) 117392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri fb.width = surf->width; 117492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(surf->height > fb.height) 117592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri fb.height = surf->height; 117692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 117792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 117892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 117992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_framebuffer_state(pipe, &fb); 118092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 118192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 118292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri /* TODO: the docs say that we should unbind conflicting resources (e.g. those bound for read while we are binding them for write too), but we aren't. 118392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Hopefully nobody relies on this happening 118492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri */ 118592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 118692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMSetRenderTargets( 11873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 11883e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11RenderTargetView *const *new_render_target_views, 11893e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11DepthStencilView *new_depth_stencil_view) 119092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 119192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 1192d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller 1193d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller bool update = false; 1194d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller unsigned i, num; 1195d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller 1196d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller if(depth_stencil_view.p != new_depth_stencil_view) { 1197d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller update = true; 1198d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller depth_stencil_view = new_depth_stencil_view; 1199d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller } 1200d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller 12013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(!new_render_target_views) 12023e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri count = 0; 1203d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller 1204d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller for(num = 0, i = 0; i < count; ++i) { 120592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 1206d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller // XXX: is unbinding the UAVs here correct ? 120792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri om_unordered_access_views[i] = (ID3D11UnorderedAccessView*)NULL; 120892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 1209d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller if(new_render_target_views[i] != render_target_views[i].p) { 1210d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller update = true; 1211d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller render_target_views[i] = new_render_target_views[i]; 1212d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller } 1213d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller if(new_render_target_views[i]) 1214d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller num = i + 1; 1215d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller } 1216d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller if(num != num_render_target_views) { 1217d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller update = true; 1218d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller for(; i < num_render_target_views; ++i) 1219d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller render_target_views[i] = (ID3D11RenderTargetView*)NULL; 122092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 1221d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller num_render_target_views = num; 1222d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller if(update) 1223d5cfab703b1179ac6e81c6281f6e25d1cab9d4c2Christoph Bumiller set_framebuffer(); 122492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 122592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 122692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMGetRenderTargets( 12273e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 12283e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11RenderTargetView **out_render_target_views, 12293e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11DepthStencilView **out_depth_stencil_view) 123092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 123192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 12323e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_render_target_views) 123392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 123492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned i; 12353e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(i = 0; i < std::min(num_render_target_views, count); ++i) 12363e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_render_target_views[i] = render_target_views[i].ref(); 123792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 12383e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(; i < count; ++i) 12393e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_render_target_views[i] = 0; 124092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 124192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 12423e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_depth_stencil_view) 12433e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_depth_stencil_view = depth_stencil_view.ref(); 124492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 124592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 124692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 124792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri /* TODO: what is this supposed to do _exactly_? are we doing the right thing? */ 124892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMSetRenderTargetsAndUnorderedAccessViews( 12493e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned rtv_count, 12503e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11RenderTargetView *const *new_render_target_views, 12513e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11DepthStencilView *new_depth_stencil_view, 12523e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned uav_start, 12533e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned uav_count, 12543e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11UnorderedAccessView *const *new_unordered_access_views, 12553e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const unsigned *new_uav_initial_counts) 125692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 125792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 12583e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(rtv_count != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL) 12593e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri OMSetRenderTargets(rtv_count, new_render_target_views, new_depth_stencil_view); 126092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 12613e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(uav_count != D3D11_KEEP_UNORDERED_ACCESS_VIEWS) 126292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 12633e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < uav_count; ++i) 126492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 12653e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri om_unordered_access_views[uav_start + i] = new_unordered_access_views[i]; 12663e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri render_target_views[uav_start + i] = (ID3D11RenderTargetView*)0; 126792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 126892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 126992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 127092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 127192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE OMGetRenderTargetsAndUnorderedAccessViews( 12723e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned rtv_count, 12733e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11RenderTargetView **out_render_target_views, 12743e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11DepthStencilView **out_depth_stencil_view, 12753e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned uav_start, 12763e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned uav_count, 12773e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11UnorderedAccessView **out_unordered_access_views) 127892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 127992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 12803e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_render_target_views) 12813e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri OMGetRenderTargets(rtv_count, out_render_target_views, out_depth_stencil_view); 128292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 12833e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_unordered_access_views) 128492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 12853e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < uav_count; ++i) 12863e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri out_unordered_access_views[i] = om_unordered_access_views[uav_start + i].ref(); 128792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 128892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 128992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 129092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 129192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE SOSetTargets( 12923e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 12933e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *const *new_so_targets, 12943e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const unsigned *new_offsets) 129592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 129692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 129714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller 129814193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller unsigned new_count, i; 129914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller bool changed = false; 130014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller 130114193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller uint32_t append_mask = 0xffffffff; 130214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller 13033e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(!new_so_targets) 13043e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri count = 0; 130514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller for(new_count = 0, i = 0; i < count; ++i) 130692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 130714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller GalliumD3D11Buffer* buffer = static_cast<GalliumD3D11Buffer*>(new_so_targets[i]); 130814193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller 130914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(buffer != so_buffers[i].p) 131092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 131192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri changed = true; 131214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller so_buffers[i] = buffer; 131314193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller so_targets[i] = buffer ? buffer->so_target : 0; 131492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 131514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(!buffer) 131614193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller continue; 131714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller new_count = i + 1; 131814193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller 131914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(new_offsets[i] == (unsigned)-1) 132014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller { 132114193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller assert(so_targets[i]); 132214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller continue; 132314193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller } 132414193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller append_mask &= ~(1 << i); 132514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller 132614193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(!so_targets[i] || new_offsets[i] != so_targets[i]->buffer_offset) 132792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 132814193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller pipe_so_target_reference(&buffer->so_target, NULL); 132914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller buffer->so_target = pipe->create_stream_output_target( 133014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller pipe, buffer->resource, new_offsets[i], buffer->resource->width0 - new_offsets[i]); 133114193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller so_targets[i] = buffer->so_target; 133292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri changed = true; 133392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 133492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 133514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(i < num_so_targets) { 133614193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller changed = true; 133714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller for(; i < num_so_targets; ++i) 133814193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller so_buffers[i] = (GalliumD3D11Buffer*)0; 133914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller } 134014193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller num_so_targets = new_count; 134192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 134214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(likely(caps.so) && (changed || append_mask != 0xffffffff)) 134314193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller pipe->set_stream_output_targets(pipe, num_so_targets, so_targets, append_mask); 134492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 134592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 134692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE SOGetTargets( 13473e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned count, 13483e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer **out_so_targets 134992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API < 11 13503e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri , UINT *out_offsets 135192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 135292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ) 135392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 135492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 13553e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri for(unsigned i = 0; i < count; ++i) 135692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 135714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller out_so_targets[i] = so_buffers[i].ref(); 135892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API < 11 135914193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller out_offsets[i] = so_targets[i]->buffer_offset; 136092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 136192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 136292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 136392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 136492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE Begin( 13653e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Asynchronous *async) 136692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 136792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 136892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(caps.queries) 13693e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->begin_query(pipe, ((GalliumD3D11Asynchronous<>*)async)->query); 137092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 137192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 137292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE End( 13733e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Asynchronous *async) 137492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 137592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 137692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(caps.queries) 13773e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->end_query(pipe, ((GalliumD3D11Asynchronous<>*)async)->query); 137892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 137992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 138092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual HRESULT STDMETHODCALLTYPE GetData( 13813e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Asynchronous *iasync, 13823e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri void *out_data, 13833e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned data_size, 13843e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned get_data_flags) 138592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 138692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 138792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!caps.queries) 138892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return E_NOTIMPL; 138992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 13903e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Asynchronous<>* async = (GalliumD3D11Asynchronous<>*)iasync; 13913e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri void* tmp_data = alloca(async->data_size); 139214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller memset(tmp_data, 0, async->data_size); // sizeof(BOOL) is 4, sizeof(boolean) is 1 13933e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri boolean ret = pipe->get_query_result(pipe, async->query, !(get_data_flags & D3D11_ASYNC_GETDATA_DONOTFLUSH), tmp_data); 13943e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_data) 139514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller { 13963e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri memcpy(out_data, tmp_data, std::min(async->data_size, data_size)); 139714193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller } 139892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return ret ? S_OK : S_FALSE; 139992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 140092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 140192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void set_render_condition() 140292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 140392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(caps.render_condition) 140492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 140592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!render_predicate) 140692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->render_condition(pipe, 0, 0); 140792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else 140892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 140992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11Predicate* predicate = (GalliumD3D11Predicate*)render_predicate.p; 141092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!render_predicate_value && predicate->desc.Query == D3D11_QUERY_OCCLUSION_PREDICATE) 141192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 141292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned mode = (predicate->desc.MiscFlags & D3D11_QUERY_MISC_PREDICATEHINT) ? PIPE_RENDER_COND_NO_WAIT : PIPE_RENDER_COND_WAIT; 141392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->render_condition(pipe, predicate->query, mode); 141492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 141592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else 141692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 141792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri /* TODO: add inverted predication to Gallium*/ 141892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->render_condition(pipe, 0, 0); 141992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 142092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 142192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 142292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 142392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 142492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE SetPredication( 14253e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Predicate *new_predicate, 14263e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri BOOL new_predicate_value) 142792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 142892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 14293e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(render_predicate.p != new_predicate || render_predicate_value != new_predicate_value) 143092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 14313e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri render_predicate = new_predicate; 14323e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri render_predicate_value = new_predicate_value; 143392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_render_condition(); 143492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 143592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 143692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 143792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE GetPredication( 14383e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Predicate **out_predicate, 14393e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri BOOL *out_predicate_value) 144092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 144192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 14423e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_predicate) 14433e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_predicate = render_predicate.ref(); 14443e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(out_predicate_value) 14453e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri *out_predicate_value = render_predicate_value; 144692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 144792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 14484c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger static unsigned d3d11_subresource_to_level(struct pipe_resource* resource, unsigned subresource) 144992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 145092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(subresource <= resource->last_level) 145192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 14524c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger return subresource; 145392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 145492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else 145592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 145692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned levels = resource->last_level + 1; 14574c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger return subresource % levels; 145892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 145992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 146092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 14616ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller static unsigned d3d11_subresource_to_layer(struct pipe_resource* resource, unsigned subresource) 14624c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger { 14634c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger if(subresource <= resource->last_level) 14644c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger { 14654c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger return 0; 14664c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger } 14674c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger else 14684c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger { 14694c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger unsigned levels = resource->last_level + 1; 14704c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger return subresource / levels; 14714c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger } 14724c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger } 14734c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger 14744c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger 1475a359eb80c5e141f625cfe42b4d97bf78cf25d128Luca Barbieri /* TODO: deferred contexts will need a different implementation of this, 1476a359eb80c5e141f625cfe42b4d97bf78cf25d128Luca Barbieri * because we can't put the transfer info into the resource itself. 1477a359eb80c5e141f625cfe42b4d97bf78cf25d128Luca Barbieri * Also, there are very different restrictions, for obvious reasons. 1478a359eb80c5e141f625cfe42b4d97bf78cf25d128Luca Barbieri */ 147992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual HRESULT STDMETHODCALLTYPE Map( 14803e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *iresource, 14813e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned subresource, 14823e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri D3D11_MAP map_type, 14833e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned map_flags, 14843e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri D3D11_MAPPED_SUBRESOURCE *mapped_resource) 148592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 148692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 14873e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; 14883e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(resource->transfers.count(subresource)) 148992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return E_FAIL; 14904c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger unsigned level = d3d11_subresource_to_level(resource->resource, subresource); 14916ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller unsigned layer = d3d11_subresource_to_layer(resource->resource, subresource); 14924c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe_box box = d3d11_to_pipe_box(resource->resource, level, 0); 14936ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller box.z += layer; 149492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned usage = 0; 14953e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(map_type == D3D11_MAP_READ) 149692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri usage = PIPE_TRANSFER_READ; 14973e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri else if(map_type == D3D11_MAP_WRITE) 149892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri usage = PIPE_TRANSFER_WRITE; 14993e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri else if(map_type == D3D11_MAP_READ_WRITE) 150092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri usage = PIPE_TRANSFER_READ_WRITE; 15013e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri else if(map_type == D3D11_MAP_WRITE_DISCARD) 150292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD; 15033e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri else if(map_type == D3D11_MAP_WRITE_NO_OVERWRITE) 15045db9cedeafe98c5ac094fc32f7b4d275c273b867Marek Olšák usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_UNSYNCHRONIZED; 150592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else 150692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return E_INVALIDARG; 15073e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(map_type & D3D10_MAP_FLAG_DO_NOT_WAIT) 150892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri usage |= PIPE_TRANSFER_DONTBLOCK; 15094c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger struct pipe_transfer* transfer = pipe->get_transfer(pipe, resource->resource, level, usage, &box); 151092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(!transfer) { 15113e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(map_type & D3D10_MAP_FLAG_DO_NOT_WAIT) 151292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return DXGI_ERROR_WAS_STILL_DRAWING; 151392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri else 151492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return E_FAIL; 151592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 15163e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri resource->transfers[subresource] = transfer; 1517a359eb80c5e141f625cfe42b4d97bf78cf25d128Luca Barbieri mapped_resource->pData = pipe->transfer_map(pipe, transfer); 15183e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri mapped_resource->RowPitch = transfer->stride; 15194c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger mapped_resource->DepthPitch = transfer->layer_stride; 152092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return S_OK; 152192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 152292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 152392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE Unmap( 15243e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *iresource, 15253e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned subresource) 152692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 152792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 15283e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; 15293e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri std::unordered_map<unsigned, pipe_transfer*>::iterator i = resource->transfers.find(subresource); 153092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(i != resource->transfers.end()) 153192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 153292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->transfer_unmap(pipe, i->second); 15336c598c78bd17642d731cf57b8369cc794f64ba2fLuca Barbieri pipe->transfer_destroy(pipe, i->second); 153492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri resource->transfers.erase(i); 153592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 153692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 153792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 153892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE CopySubresourceRegion( 15393e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *dst_resource, 15403e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned dst_subresource, 15413e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned dst_x, 15423e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned dst_y, 15433e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned dst_z, 15443e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *src_resource, 15453e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned src_subresource, 15463e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const D3D11_BOX *src_box) 154792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 154892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 15493e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; 15503e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)src_resource; 15514c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger unsigned dst_level = d3d11_subresource_to_level(dst->resource, dst_subresource); 15526ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller unsigned dst_layer = d3d11_subresource_to_layer(dst->resource, dst_subresource); 15534c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger unsigned src_level = d3d11_subresource_to_level(src->resource, src_subresource); 15546ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller unsigned src_layer = d3d11_subresource_to_layer(src->resource, src_subresource); 15554c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe_box box = d3d11_to_pipe_box(src->resource, src_level, src_box); 15566ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller dst_z += dst_layer; 15576ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller box.z += src_layer; 155892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 155992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->resource_copy_region(pipe, 15604c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger dst->resource, dst_level, dst_x, dst_y, dst_z, 15614c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger src->resource, src_level, &box); 156292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 156392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 156492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 156592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE CopyResource( 15663e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *dst_resource, 15673e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *src_resource) 156892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 156992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 15703e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; 15713e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)src_resource; 15724c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger unsigned level; 15734c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger for(level = 0; level <= dst->resource->last_level; ++level) 157492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 15754c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe_box box; 15764c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger box.x = box.y = box.z = 0; 15774c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger box.width = u_minify(dst->resource->width0, level); 15784c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger box.height = u_minify(dst->resource->height0, level); 15796ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller if(dst->resource->target == PIPE_TEXTURE_3D) 15806ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller box.depth = u_minify(dst->resource->depth0, level); 15816ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller else 15826ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller box.depth = dst->resource->array_size; 15834c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe->resource_copy_region(pipe, 15844c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger dst->resource, level, 0, 0, 0, 15854c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger src->resource, level, &box); 158692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 158792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 158892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 158992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE UpdateSubresource( 15903e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *dst_resource, 15913e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned dst_subresource, 15928224256946619fb25278718bbf4703e3b9d60c93Luca Barbieri const D3D11_BOX *pDstBox, 15938224256946619fb25278718bbf4703e3b9d60c93Luca Barbieri const void *pSrcData, 15943e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned src_row_pitch, 15953e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned src_depth_pitch) 159692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 159792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 15983e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; 15994c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger unsigned dst_level = d3d11_subresource_to_level(dst->resource, dst_subresource); 16006ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller unsigned dst_layer = d3d11_subresource_to_layer(dst->resource, dst_subresource); 16014c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe_box box = d3d11_to_pipe_box(dst->resource, dst_level, pDstBox); 16026ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller box.z += dst_layer; 16034c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe->transfer_inline_write(pipe, dst->resource, dst_level, PIPE_TRANSFER_WRITE, &box, pSrcData, src_row_pitch, src_depth_pitch); 160492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 160592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 160692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 160792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE CopyStructureCount( 16083e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Buffer *dst_buffer, 16093e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned dst_aligned_byte_offset, 16103e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11UnorderedAccessView *src_view) 161192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 161292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 161392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 161492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 161592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 161692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE ClearRenderTargetView( 16173e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11RenderTargetView *render_target_view, 16183e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const float color[4]) 161992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 162092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 16213e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11RenderTargetView* view = ((GalliumD3D11RenderTargetView*)render_target_view); 16226dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie union pipe_color_union cc; 16236dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie cc.f[0] = color[0]; 16246dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie cc.f[1] = color[1]; 16256dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie cc.f[2] = color[2]; 16266dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie cc.f[3] = color[3]; 16276dd284f7c8fac22f64c13fdf9909094f5ec59086Dave Airlie pipe->clear_render_target(pipe, view->object, &cc, 0, 0, view->object->width, view->object->height); 162892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 162992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 163092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE ClearDepthStencilView( 16313e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11DepthStencilView *depth_stencil_view, 16323e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned clear_flags, 16333e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri float depth, 16343e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri UINT8 stencil) 163592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 163692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 16373e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11DepthStencilView* view = ((GalliumD3D11DepthStencilView*)depth_stencil_view); 163892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned flags = 0; 16393e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(clear_flags & D3D11_CLEAR_DEPTH) 164092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri flags |= PIPE_CLEAR_DEPTH; 16413e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(clear_flags & D3D11_CLEAR_STENCIL) 164292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri flags |= PIPE_CLEAR_STENCIL; 16433e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri pipe->clear_depth_stencil(pipe, view->object, flags, depth, stencil, 0, 0, view->object->width, view->object->height); 164492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 164592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 164692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 164792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE ClearUnorderedAccessViewUint( 16483e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11UnorderedAccessView *unordered_access_view, 16493e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const unsigned values[4]) 165092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 165192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 165292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 165392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 165492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE ClearUnorderedAccessViewFloat( 16553e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11UnorderedAccessView *unordered_access_view, 16563e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri const float values[4]) 165792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 165892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 165992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 166092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 166192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 166217ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri void restore_gallium_state_blit_only() 166392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 166492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_blend_state(pipe, blend_state.p ? blend_state.p->object : default_blend); 166592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_depth_stencil_alpha_state(pipe, depth_stencil_state.p ? depth_stencil_state.p->object : default_depth_stencil); 166692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_rasterizer_state(pipe, rasterizer_state.p ? rasterizer_state.p->object : default_rasterizer); 166792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_vertex_elements_state(pipe, input_layout.p ? input_layout.p->object : default_input_layout); 166892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_fs_state(pipe, shaders[D3D11_STAGE_PS].p ? shaders[D3D11_STAGE_PS].p->object : default_shaders[PIPE_SHADER_FRAGMENT]); 166992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_vs_state(pipe, shaders[D3D11_STAGE_VS].p ? shaders[D3D11_STAGE_VS].p->object : default_shaders[PIPE_SHADER_VERTEX]); 167092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(caps.gs) 167192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_gs_state(pipe, shaders[D3D11_STAGE_GS].p ? shaders[D3D11_STAGE_GS].p->object : default_shaders[PIPE_SHADER_GEOMETRY]); 167214193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(caps.so && num_so_targets) 167314193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller pipe->set_stream_output_targets(pipe, num_so_targets, so_targets, ~0); 167492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_framebuffer(); 167592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_viewport(); 167692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_render_condition(); 167792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 167892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= UPDATE_VERTEX_BUFFERS | (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_PS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_PS)); 167992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 168092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 168117ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri virtual void STDMETHODCALLTYPE RestoreGalliumStateBlitOnly() 168217ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri { 168317ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri SYNCHRONIZED; 168417ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri restore_gallium_state_blit_only(); 168517ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri } 168617ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri 168792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE GenerateMips( 16883e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11ShaderResourceView *shader_resource_view) 168992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 169092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 169192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 16923e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11ShaderResourceView* view = (GalliumD3D11ShaderResourceView*)shader_resource_view; 169392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(caps.gs) 169492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_gs_state(pipe, 0); 169514193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller if(caps.so && num_so_targets) 169614193da589275969be31dbdb3280bb48cd24d0c0Christoph Bumiller pipe->set_stream_output_targets(pipe, 0, NULL, 0); 169792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(pipe->render_condition) 169892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->render_condition(pipe, 0, 0); 1699c463dfe4e4999a0d745c31bce9a2a2bbe6a05899Christoph Bumiller for(unsigned layer = view->object->u.tex.first_layer; layer <= view->object->u.tex.last_layer; ++layer) 1700c463dfe4e4999a0d745c31bce9a2a2bbe6a05899Christoph Bumiller util_gen_mipmap(gen_mipmap, view->object, layer, view->object->u.tex.first_level, view->object->u.tex.last_level, PIPE_TEX_FILTER_LINEAR); 170117ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri restore_gallium_state_blit_only(); 170292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 170392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 170492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE RestoreGalliumState() 170592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 170692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 170717ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri restore_gallium_state_blit_only(); 170892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 170992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_index_buffer(); 171092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_stencil_ref(); 171192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_blend_color(pipe, (struct pipe_blend_color*)blend_color); 171292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_sample_mask(pipe, sample_mask); 171392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 171492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned s = 0; s < 3; ++s) 171592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 171692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri unsigned num = std::min(caps.constant_buffers[s], (unsigned)D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); 171792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < num; ++i) 1718507337864fa80caf9f26602324d2c28dd0a75d61Marek Olšák pipe_set_constant_buffer(pipe, s, i, constant_buffers[s][i].p ? constant_buffers[s][i].p->resource : 0); 171992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 172092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 172192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_VS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_VS)); 172292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_GS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_GS)); 172392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 172492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_scissor(); 172592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 172692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 172792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 172892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri /* TODO: hack SRVs or sampler states to handle this, or add to Gallium */ 172992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE SetResourceMinLOD( 17303e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *iresource, 17313e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri float min_lod) 173292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 173392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 17343e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; 17353e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri if(resource->min_lod != min_lod) 173692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 173792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // TODO: actually do anything? 17383e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri resource->min_lod = min_lod; 173992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 174092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 174192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 174292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual float STDMETHODCALLTYPE GetResourceMinLOD( 17433e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *iresource) 174492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 174592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 17463e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)iresource; 174792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return resource->min_lod; 174892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 174992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 175092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 175192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE ResolveSubresource( 17523e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *dst_resource, 17533e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned dst_subresource, 17543e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11Resource *src_resource, 17553e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri unsigned src_subresource, 17563e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri DXGI_FORMAT format) 175792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 175892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 17593e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)dst_resource; 17603e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)src_resource; 17614dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller struct pipe_resolve_info info; 17624dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller 17634dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.dst.res = dst->resource; 17644dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.src.res = src->resource; 17654dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.dst.level = 0; 17666ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller info.dst.layer = d3d11_subresource_to_layer(dst->resource, dst_subresource); 17676ab6c43079083c811761241b901d07f9ad2c9affChristoph Bumiller info.src.layer = d3d11_subresource_to_layer(src->resource, src_subresource); 17684dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller 17694dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.src.x0 = 0; 17704dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.src.x1 = info.src.res->width0; 17714dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.src.y0 = 0; 17724dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.src.y1 = info.src.res->height0; 17734dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.dst.x0 = 0; 17744dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.dst.x1 = info.dst.res->width0; 17754dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.dst.y0 = 0; 17764dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.dst.y1 = info.dst.res->height0; 17774dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller 17784dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller info.mask = PIPE_MASK_RGBA | PIPE_MASK_ZS; 17794dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller 17804dd3272df9f6d483cb3734c3b8c77e9c190b3773Christoph Bumiller pipe->resource_resolve(pipe, &info); 178192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 178292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 178392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 178492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE ExecuteCommandList( 17853e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11CommandList *command_list, 17863e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri BOOL restore_context_state) 178792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 178892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 178992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 179092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 179192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual HRESULT STDMETHODCALLTYPE FinishCommandList( 17923e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri BOOL restore_deferred_context_state, 17933e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri ID3D11CommandList **out_command_list) 179492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 179592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 179692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return E_NOTIMPL; 179792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 179892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 179992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 180092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE ClearState(void) 180192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 180217ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri /* we don't take a lock here because we would deadlock otherwise 180317ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri * TODO: this is probably incorrect, because ClearState should likely be atomic. 180417ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri * However, I can't think of any correct usage that would be affected by this 180517ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri * being non-atomic, and making this atomic is quite expensive and complicates 180617ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri * the code 180717ad9972f4b998dbf1a046780b6bde461d721dd0Luca Barbieri */ 180892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 180992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // we qualify all calls so that we avoid virtual dispatch and might get them inlined 181092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // TODO: make sure all this gets inlined, which might require more compiler flags 181192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // TODO: optimize this 181292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 181392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::PSSetShader(0, 0, 0); 181492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::GSSetShader(0, 0, 0); 181592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::VSSetShader(0, 0, 0); 181692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::HSSetShader(0, 0, 0); 181792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::DSSetShader(0, 0, 0); 181892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::CSSetShader(0, 0, 0); 181992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#else 182092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::PSSetShader(0); 182192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::GSSetShader(0); 182292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::VSSetShader(0); 182392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 182492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 182592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::IASetInputLayout(0); 182692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::IASetIndexBuffer(0, DXGI_FORMAT_UNKNOWN, 0); 182792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::RSSetState(0); 182892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::OMSetDepthStencilState(0, 0); 182992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::OMSetBlendState(0, (float*)zero_data, ~0); 183092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::SetPredication(0, 0); 183192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_UNDEFINED); 183292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 183392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::PSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); 183492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::GSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); 183592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::VSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); 183692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 183792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::HSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); 183892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::DSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); 183992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::CSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data); 184092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 184192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 184292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::IASetVertexBuffers(0, num_vertex_buffers, (ID3D11Buffer**)zero_data, (unsigned*)zero_data, (unsigned*)zero_data); 184392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 184492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews(0, 0, 0 , 0, 0, 0, 0); 184592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#else 184692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::OMSetRenderTargets(0, 0, 0 ); 184792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 184892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::SOSetTargets(0, 0, 0); 184992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 185092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::PSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_PS], (ID3D11ShaderResourceView**)zero_data); 185192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::GSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_GS], (ID3D11ShaderResourceView**)zero_data); 185292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::VSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_VS], (ID3D11ShaderResourceView**)zero_data); 185392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 185492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::HSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_HS], (ID3D11ShaderResourceView**)zero_data); 185592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::DSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_DS], (ID3D11ShaderResourceView**)zero_data); 185692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::CSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_CS], (ID3D11ShaderResourceView**)zero_data); 185792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 185892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 185992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::PSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_PS], (ID3D11SamplerState**)zero_data); 186092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::GSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_GS], (ID3D11SamplerState**)zero_data); 186192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::VSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_VS], (ID3D11SamplerState**)zero_data); 186292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 186392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::HSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_HS], (ID3D11SamplerState**)zero_data); 186492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::DSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_DS], (ID3D11SamplerState**)zero_data); 186592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::CSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_CS], (ID3D11SamplerState**)zero_data); 186692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 186792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 186892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::RSSetViewports(0, 0); 186992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11DeviceContext::RSSetScissorRects(0, 0); 187092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 187192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 187292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual void STDMETHODCALLTYPE Flush(void) 187392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 187492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 18757e02303497237cde958c28608477d0c355a8038bMarek Olšák pipe->flush(pipe, 0); 187692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 187792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 187892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri /* In Direct3D 10, if the reference count of an object drops to 0, it is automatically 187992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * cleanly unbound from the pipeline. 188092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * In Direct3D 11, the pipeline holds a reference. 188192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 188292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Note that instead of always scanning the pipeline on destruction, we could 188392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * maintain the internal reference count on DirectX 10 and use it to check if an 188492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * object is still bound. 188592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Presumably, on average, scanning is faster if the application is well written. 188692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri */ 188792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API < 11 188892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#define IMPLEMENT_SIMPLE_UNBIND(name, member, gallium, def) \ 188992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void Unbind##name(ID3D11##name* state) \ 189092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 189192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; \ 189292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if((void*)state == (void*)member.p) \ 189392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { \ 189492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri member.p = 0; \ 189592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->bind_##gallium##_state(pipe, default_##def); \ 189692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } \ 189792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 189892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SIMPLE_UNBIND(BlendState, blend_state, blend, blend) 189992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SIMPLE_UNBIND(RasterizerState, rasterizer_state, rasterizer, rasterizer) 190092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SIMPLE_UNBIND(DepthStencilState, depth_stencil_state, depth_stencil_alpha, depth_stencil) 190192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SIMPLE_UNBIND(InputLayout, input_layout, vertex_elements, input_layout) 190292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SIMPLE_UNBIND(PixelShader, shaders[D3D11_STAGE_PS], fs, shaders[D3D11_STAGE_PS]) 190392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SIMPLE_UNBIND(VertexShader, shaders[D3D11_STAGE_VS], vs, shaders[D3D11_STAGE_VS]) 190492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri IMPLEMENT_SIMPLE_UNBIND(GeometryShader, shaders[D3D11_STAGE_GS], gs, shaders[D3D11_STAGE_GS]) 190592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 190692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void UnbindPredicate(ID3D11Predicate* predicate) 190792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 190892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 190992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(predicate == render_predicate) 191092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 191192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri render_predicate.p = NULL; 191292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri render_predicate_value = 0; 191392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->render_condition(pipe, 0, 0); 191492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 191592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 191692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 191792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void UnbindSamplerState(ID3D11SamplerState* state) 191892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 191992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 192092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned s = 0; s < D3D11_STAGES; ++s) 192192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 192292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < num_samplers[s]; ++i) 192392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 192492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(samplers[s][i] == state) 192592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 192692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri samplers[s][i].p = NULL; 192765303c49d1efc996f5cc9dafa2768d0225b76f1cChristoph Bumiller sampler_csos[s][i] = NULL; 192892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + s)); 192992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 193092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 193192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 193292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 193392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 193492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void UnbindBuffer(ID3D11Buffer* buffer) 193592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 193692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 193792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(buffer == index_buffer) 193892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 193992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri index_buffer.p = 0; 194092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri index_format = DXGI_FORMAT_UNKNOWN; 194192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri index_offset = 0; 194292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri struct pipe_index_buffer ib; 194392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&ib, 0, sizeof(ib)); 194492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri pipe->set_index_buffer(pipe, &ib); 194592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 194692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 194792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < num_vertex_buffers; ++i) 194892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 194992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(buffer == input_buffers[i]) 195092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 195192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri input_buffers[i].p = 0; 195292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri memset(&vertex_buffers[num_vertex_buffers], 0, sizeof(vertex_buffers[num_vertex_buffers])); 195392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= UPDATE_VERTEX_BUFFERS; 195492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 195592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 195692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 195792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned s = 0; s < D3D11_STAGES; ++s) 195892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 195992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < sizeof(constant_buffers) / sizeof(constant_buffers[0]); ++i) 196092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 196192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(constant_buffers[s][i] == buffer) 196292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 196392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri constant_buffers[s][i] = (ID3D10Buffer*)NULL; 1964507337864fa80caf9f26602324d2c28dd0a75d61Marek Olšák pipe_set_constant_buffer(pipe, s, i, NULL); 196592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 196692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 196792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 196892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 196992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 19703e0f57b6401e7ddd0a5dc89b5b7fdd6c8d85818dLuca Barbieri void UnbindDepthStencilView(ID3D11DepthStencilView * view) 197192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 197292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 197392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(view == depth_stencil_view) 197492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 197592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri depth_stencil_view.p = NULL; 197692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_framebuffer(); 197792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 197892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 197992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 198092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void UnbindRenderTargetView(ID3D11RenderTargetView* view) 198192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 198292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 198392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri bool any_bound = false; 198492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < num_render_target_views; ++i) 198592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 198692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(render_target_views[i] == view) 198792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 198892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri render_target_views[i].p = NULL; 198992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri any_bound = true; 199092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 199192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 199292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(any_bound) 199392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri set_framebuffer(); 199492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 199592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 199692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri void UnbindShaderResourceView(ID3D11ShaderResourceView* view) 199792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 199892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri SYNCHRONIZED; 199992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned s = 0; s < D3D11_STAGES; ++s) 200092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 200192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri for(unsigned i = 0; i < num_shader_resource_views[s]; ++i) 200292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 200392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(shader_resource_views[s][i] == view) 200492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 200592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri shader_resource_views[s][i].p = NULL; 200692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri sampler_views[s][i] = NULL; 200792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri update_flags |= (1 << (UPDATE_VIEWS_SHIFT + s)); 200892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 200992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 201092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 201192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 201292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 201392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 201492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#undef SYNCHRONIZED 201592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri}; 201692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 201792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#if API >= 11 201892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri/* This approach serves two purposes. 201992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * First, we don't want to do an atomic operation to manipulate the reference 202092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * count every time something is bound/unbound to the pipeline, since they are 202192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * expensive. 202292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Fortunately, the immediate context can only be used by a single thread, so 202392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * we don't have to use them, as long as a separate reference count is used 202492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * (see dual_refcnt_t). 202592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 202692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Second, we want to avoid the Device -> DeviceContext -> bound DeviceChild -> Device 202792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * garbage cycle. 202892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * To avoid it, DeviceChild doesn't hold a reference to Device as usual, but adds 202992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * one for each external reference count, while internal nonatomic_add_ref doesn't 203092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * add any. 203192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 203292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Note that ideally we would to eliminate the non-atomic op too, but this is more 203392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * complicated, since we would either need to use garbage collection and give up 203492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * deterministic destruction (especially bad for large textures), or scan the whole 203592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * pipeline state every time the reference count of object drops to 0, which risks 203692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * pathological slowdowns. 203792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 203892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Since this microoptimization should matter relatively little, let's avoid it for now. 203992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 204092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Note that deferred contexts don't use this, since as a whole, they must thread-safe. 204192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Eliminating the atomic ops for deferred contexts seems substantially harder. 204292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * This might be a problem if they are used in a one-shot multithreaded rendering 204392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * fashion, where SMP cacheline bouncing on the reference count may be visible. 204492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 204592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * The idea would be to attach a structure of reference counts indexed by deferred 204692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * context id to each object. Ideally, this should be organized like ext2 block pointers. 204792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 204892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Every deferred context would get a reference count in its own cacheline. 204992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * The external count is protected by a lock bit, and there is also a "lock bit" in each 205092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * internal count. 205192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 205292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * When the external count has to be dropped to 0, the lock bit is taken and all internal 205392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * reference counts are scanned, taking a count of them. A flag would also be set on them. 205492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Deferred context manipulation would notice the flag, and update the count. 205592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Once the count goes to zero, the object is freed. 205692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 205792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * The problem of this is that if the external reference count ping-pongs between 205892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * zero and non-zero, the scans will take a lot of time. 205992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 206092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * The idea to solve this is to compute the scans in a binary-tree like fashion, where 206192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * each binary tree node would have a "determined bit", which would be invalidated 206292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * by manipulations. 206392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 206492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * However, all this complexity might actually be a loss in most cases, so let's just 206592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * stick to a single atomic refcnt for now. 206692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * 206792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri * Also, we don't even support deferred contexts yet, so this can wait. 206892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri */ 206992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristruct nonatomic_device_child_ptr_traits 207092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 207192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri static void add_ref(void* p) 207292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 207392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(p) 207492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ((GalliumD3D11DeviceChild<>*)p)->nonatomic_add_ref(); 207592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 207692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 207792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri static void release(void* p) 207892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 207992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri if(p) 208092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ((GalliumD3D11DeviceChild<>*)p)->nonatomic_release(); 208192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 208292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri}; 208392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 208492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristruct GalliumD3D11ImmediateDeviceContext 208592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri : public GalliumD3D11DeviceContext<nonatomic_device_child_ptr_traits> 208692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 208792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri GalliumD3D11ImmediateDeviceContext(GalliumD3D11Screen* device, pipe_context* pipe, unsigned context_flags = 0) 2088b4b2091655676ec3b898d3ae7298192aa7f9147fLuca Barbieri : GalliumD3D11DeviceContext<nonatomic_device_child_ptr_traits>(device, pipe, context_flags) 208992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 209092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri // not necessary, but tests that the API at least basically works 209192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ClearState(); 209292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 209392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 209492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri /* we do this since otherwise we would have a garbage cycle between this and the device */ 209592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual ULONG STDMETHODCALLTYPE AddRef() 209692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 209792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return this->device->AddRef(); 209892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 209992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 210092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual ULONG STDMETHODCALLTYPE Release() 210192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 210292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return this->device->Release(); 210392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 210492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 210592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri virtual D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE GetType() 210692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri { 210792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return D3D11_DEVICE_CONTEXT_IMMEDIATE; 210892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri } 210992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri}; 211092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 211192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristatic ID3D11DeviceContext* GalliumD3D11ImmediateDeviceContext_Create(GalliumD3D11Screen* device, struct pipe_context* pipe, bool owns_pipe) 211292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 211392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri return new GalliumD3D11ImmediateDeviceContext(device, pipe, owns_pipe); 211492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri} 211592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 211692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristatic void GalliumD3D11ImmediateDeviceContext_RestoreGalliumState(ID3D11DeviceContext* context) 211792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 211892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ((GalliumD3D11ImmediateDeviceContext*)context)->RestoreGalliumState(); 211992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri} 212092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 212192617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristatic void GalliumD3D11ImmediateDeviceContext_RestoreGalliumStateBlitOnly(ID3D11DeviceContext* context) 212292617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 212392617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri ((GalliumD3D11ImmediateDeviceContext*)context)->RestoreGalliumStateBlitOnly(); 212492617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri} 212592617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri 212692617aeac109481258f0c3863d09c1b8903d438bLuca Barbieristatic void GalliumD3D11ImmediateDeviceContext_Destroy(ID3D11DeviceContext* context) 212792617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri{ 212892617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri delete (GalliumD3D11ImmediateDeviceContext*)context; 212992617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri} 213092617aeac109481258f0c3863d09c1b8903d438bLuca Barbieri#endif 2131