Path: blob/21.2-virgl/src/gallium/drivers/d3d12/d3d12_resource.h
4570 views
/*1* Copyright © Microsoft Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef D3D12_RESOURCE_H24#define D3D12_RESOURCE_H2526struct pipe_screen;27#include "d3d12_bufmgr.h"28#include "util/u_range.h"29#include "util/u_transfer.h"3031#include <directx/d3d12.h>3233enum d3d12_resource_binding_type {34D3D12_RESOURCE_BINDING_TYPE_SRV,35D3D12_RESOURCE_BINDING_TYPE_CBV,36D3D12_RESOURCE_BINDING_TYPES37};3839struct d3d12_resource {40struct pipe_resource base;41struct d3d12_bo *bo;42DXGI_FORMAT dxgi_format;43unsigned mip_levels;44struct sw_displaytarget *dt;45unsigned dt_stride;46struct util_range valid_buffer_range;47uint32_t bind_counts[PIPE_SHADER_TYPES][D3D12_RESOURCE_BINDING_TYPES];48};4950struct d3d12_transfer {51struct pipe_transfer base;52struct pipe_resource *staging_res;53void *data;54};5556static inline struct d3d12_resource *57d3d12_resource(struct pipe_resource *r)58{59return (struct d3d12_resource *)r;60}6162/* Returns the underlying ID3D12Resource and offset for this resource */63static inline ID3D12Resource *64d3d12_resource_underlying(struct d3d12_resource *res, uint64_t *offset)65{66if (!res->bo)67return NULL;6869return d3d12_bo_get_base(res->bo, offset)->res;70}7172/* Returns the underlying ID3D12Resource for this resource. */73static inline ID3D12Resource *74d3d12_resource_resource(struct d3d12_resource *res)75{76ID3D12Resource *ret;77uint64_t offset;78ret = d3d12_resource_underlying(res, &offset);79return ret;80}8182static inline struct TransitionableResourceState *83d3d12_resource_state(struct d3d12_resource *res)84{85uint64_t offset;86if (!res->bo)87return NULL;88return d3d12_bo_get_base(res->bo, &offset)->trans_state;89}9091static inline D3D12_GPU_VIRTUAL_ADDRESS92d3d12_resource_gpu_virtual_address(struct d3d12_resource *res)93{94uint64_t offset;95ID3D12Resource *base_res = d3d12_resource_underlying(res, &offset);96return base_res->GetGPUVirtualAddress() + offset;97}9899static inline bool100d3d12_subresource_id_uses_layer(enum pipe_texture_target target)101{102return target == PIPE_TEXTURE_CUBE ||103target == PIPE_TEXTURE_1D_ARRAY ||104target == PIPE_TEXTURE_2D_ARRAY;105}106107void108d3d12_resource_release(struct d3d12_resource *res);109110void111d3d12_resource_wait_idle(struct d3d12_context *ctx,112struct d3d12_resource *res);113114void115d3d12_resource_make_writeable(struct pipe_context *pctx,116struct pipe_resource *pres);117118void119d3d12_screen_resource_init(struct pipe_screen *pscreen);120121void122d3d12_context_resource_init(struct pipe_context *pctx);123124#endif125126127