Path: blob/21.2-virgl/src/gallium/frontends/d3d10umd/State.h
4565 views
/**************************************************************************1*2* Copyright 2012-2021 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25**************************************************************************/2627/*28* State.h --29* State declarations.30*/313233#include "DriverIncludes.h"34#include "util/u_hash_table.h"353637#define SUPPORT_MSAA 038#define SUPPORT_D3D10_1 039#define SUPPORT_D3D11 0404142struct Adapter43{44struct pipe_screen *screen;45};464748static inline Adapter *49CastAdapter(D3D10DDI_HADAPTER hAdapter)50{51return static_cast<Adapter *>(hAdapter.pDrvPrivate);52}5354struct Shader55{56void *handle;57uint type;58struct pipe_shader_state state;59unsigned output_mapping[PIPE_MAX_SHADER_OUTPUTS];60boolean output_resolved;61};6263struct Query;6465struct Device66{67struct pipe_context *pipe;6869struct pipe_framebuffer_state fb;70struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];71struct pipe_resource *index_buffer;72unsigned restart_index;73unsigned index_size;74unsigned ib_offset;75void *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];76struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];7778void *empty_fs;79void *empty_vs;8081enum pipe_prim_type primitive;8283struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];84struct pipe_stream_output_target *draw_so_target;85Shader *bound_empty_gs;86Shader *bound_vs;8788unsigned max_dual_source_render_targets;8990D3D10DDI_HRTCORELAYER hRTCoreLayer;9192HANDLE hDevice;93HANDLE hContext;9495D3DDDI_DEVICECALLBACKS KTCallbacks;96D3D10DDI_CORELAYER_DEVICECALLBACKS UMCallbacks;97DXGI_DDI_BASE_CALLBACKS *pDXGIBaseCallbacks;9899INT LastEmittedQuerySeqNo;100INT LastFinishedQuerySeqNo;101102Query *pPredicate;103BOOL PredicateValue;104};105106107static inline Device *108CastDevice(D3D10DDI_HDEVICE hDevice)109{110return static_cast<Device *>(hDevice.pDrvPrivate);111}112113114static inline struct pipe_context *115CastPipeContext(D3D10DDI_HDEVICE hDevice)116{117Device *pDevice = CastDevice(hDevice);118return pDevice ? pDevice->pipe : NULL;119}120121122static inline Device *123CastDevice(DXGI_DDI_HDEVICE hDevice)124{125return reinterpret_cast<Device *>(hDevice);126}127128129static inline struct pipe_context *130CastPipeDevice(DXGI_DDI_HDEVICE hDevice)131{132Device *pDevice = CastDevice(hDevice);133return pDevice ? pDevice->pipe : NULL;134}135136137static inline void138SetError(D3D10DDI_HDEVICE hDevice, HRESULT hr)139{140if (FAILED(hr)) {141Device *pDevice = CastDevice(hDevice);142pDevice->UMCallbacks.pfnSetErrorCb(pDevice->hRTCoreLayer, hr);143}144}145146147struct Resource148{149DXGI_FORMAT Format;150UINT MipLevels;151UINT NumSubResources;152struct pipe_resource *resource;153struct pipe_transfer **transfers;154struct pipe_stream_output_target *so_target;155};156157158static inline Resource *159CastResource(D3D10DDI_HRESOURCE hResource)160{161return static_cast<Resource *>(hResource.pDrvPrivate);162}163164165static inline Resource *166CastResource(DXGI_DDI_HRESOURCE hResource)167{168return reinterpret_cast<Resource *>(hResource);169}170171172static inline struct pipe_resource *173CastPipeResource(D3D10DDI_HRESOURCE hResource)174{175Resource *pResource = CastResource(hResource);176return pResource ? pResource->resource : NULL;177}178179180static inline struct pipe_resource *181CastPipeResource(DXGI_DDI_HRESOURCE hResource)182{183Resource *pResource = CastResource(hResource);184return pResource ? pResource->resource : NULL;185}186187188static inline struct pipe_resource *189CastPipeBuffer(D3D10DDI_HRESOURCE hResource)190{191Resource *pResource = CastResource(hResource);192if (!pResource) {193return NULL;194}195return static_cast<struct pipe_resource *>(pResource->resource);196}197198199struct RenderTargetView200{201struct pipe_surface *surface;202D3D10DDI_HRTRENDERTARGETVIEW hRTRenderTargetView;203};204205206static inline RenderTargetView *207CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)208{209return static_cast<RenderTargetView *>(hRenderTargetView.pDrvPrivate);210}211212213static inline struct pipe_surface *214CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)215{216RenderTargetView *pRenderTargetView = CastRenderTargetView(hRenderTargetView);217return pRenderTargetView ? pRenderTargetView->surface : NULL;218}219220221struct DepthStencilView222{223struct pipe_surface *surface;224D3D10DDI_HRTDEPTHSTENCILVIEW hRTDepthStencilView;225};226227228static inline DepthStencilView *229CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)230{231return static_cast<DepthStencilView *>(hDepthStencilView.pDrvPrivate);232}233234235static inline struct pipe_surface *236CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)237{238DepthStencilView *pDepthStencilView = CastDepthStencilView(hDepthStencilView);239return pDepthStencilView ? pDepthStencilView->surface : NULL;240}241242243struct BlendState244{245void *handle;246};247248249static inline BlendState *250CastBlendState(D3D10DDI_HBLENDSTATE hBlendState)251{252return static_cast<BlendState *>(hBlendState.pDrvPrivate);253}254255256static inline void *257CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState)258{259BlendState *pBlendState = CastBlendState(hBlendState);260return pBlendState ? pBlendState->handle : NULL;261}262263264struct DepthStencilState265{266void *handle;267};268269270static inline DepthStencilState *271CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)272{273return static_cast<DepthStencilState *>(hDepthStencilState.pDrvPrivate);274}275276277static inline void *278CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)279{280DepthStencilState *pDepthStencilState = CastDepthStencilState(hDepthStencilState);281return pDepthStencilState ? pDepthStencilState->handle : NULL;282}283284285struct RasterizerState286{287void *handle;288};289290291static inline RasterizerState *292CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)293{294return static_cast<RasterizerState *>(hRasterizerState.pDrvPrivate);295}296297298static inline void *299CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)300{301RasterizerState *pRasterizerState = CastRasterizerState(hRasterizerState);302return pRasterizerState ? pRasterizerState->handle : NULL;303}304305306static inline Shader *307CastShader(D3D10DDI_HSHADER hShader)308{309return static_cast<Shader *>(hShader.pDrvPrivate);310}311312313static inline void *314CastPipeShader(D3D10DDI_HSHADER hShader)315{316Shader *pShader = static_cast<Shader *>(hShader.pDrvPrivate);317return pShader ? pShader->handle : NULL;318}319320321struct ElementLayout322{323void *handle;324};325326327static inline ElementLayout *328CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)329{330return static_cast<ElementLayout *>(hElementLayout.pDrvPrivate);331}332333static inline void *334CastPipeInputLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)335{336ElementLayout *pElementLayout = CastElementLayout(hElementLayout);337return pElementLayout ? pElementLayout->handle : NULL;338}339340341struct SamplerState342{343void *handle;344};345346347static inline SamplerState *348CastSamplerState(D3D10DDI_HSAMPLER hSampler)349{350return static_cast<SamplerState *>(hSampler.pDrvPrivate);351}352353354static inline void *355CastPipeSamplerState(D3D10DDI_HSAMPLER hSampler)356{357SamplerState *pSamplerState = CastSamplerState(hSampler);358return pSamplerState ? pSamplerState->handle : NULL;359}360361362struct ShaderResourceView363{364struct pipe_sampler_view *handle;365};366367368static inline ShaderResourceView *369CastShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)370{371return static_cast<ShaderResourceView *>(hShaderResourceView.pDrvPrivate);372}373374375static inline struct pipe_sampler_view *376CastPipeShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)377{378ShaderResourceView *pSRView = CastShaderResourceView(hShaderResourceView);379return pSRView ? pSRView->handle : NULL;380}381382383struct Query384{385D3D10DDI_QUERY Type;386UINT Flags;387388unsigned pipe_type;389struct pipe_query *handle;390INT SeqNo;391UINT GetDataCount;392393D3D10_DDI_QUERY_DATA_PIPELINE_STATISTICS Statistics;394};395396397static inline Query *398CastQuery(D3D10DDI_HQUERY hQuery)399{400return static_cast<Query *>(hQuery.pDrvPrivate);401}402403404static inline struct pipe_query *405CastPipeQuery(D3D10DDI_HQUERY hQuery)406{407Query *pQuery = CastQuery(hQuery);408return pQuery ? pQuery->handle : NULL;409}410411412413