Path: blob/21.2-virgl/src/gallium/drivers/d3d12/d3d12_bufmgr.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_BUFMGR_H24#define D3D12_BUFMGR_H2526#include "pipebuffer/pb_buffer.h"27#include "util/u_atomic.h"2829#ifndef _WIN3230#include <wsl/winadapter.h>31#endif3233#include <directx/d3d12.h>3435struct d3d12_bufmgr;36struct d3d12_screen;37struct pb_manager;38struct TransitionableResourceState;3940struct d3d12_bo {41int refcount;42ID3D12Resource *res;43struct pb_buffer *buffer;44struct TransitionableResourceState *trans_state;45};4647struct d3d12_buffer {48struct pb_buffer base;4950struct d3d12_bo *bo;51D3D12_RANGE range;52void *map;53};5455static inline struct d3d12_buffer *56d3d12_buffer(struct pb_buffer *buf)57{58assert(buf);59return (struct d3d12_buffer *)buf;60}6162static inline struct d3d12_bo *63d3d12_bo_get_base(struct d3d12_bo *bo, uint64_t *offset)64{65if (bo->buffer) {66struct pb_buffer *base_buffer;67pb_get_base_buffer(bo->buffer, &base_buffer, offset);68return d3d12_buffer(base_buffer)->bo;69} else {70*offset = 0;71return bo;72}73}7475static inline uint64_t76d3d12_bo_get_size(struct d3d12_bo *bo)77{78if (bo->buffer)79return bo->buffer->size;80else81return bo->res->GetDesc().Width;82}8384static inline bool85d3d12_bo_is_suballocated(struct d3d12_bo *bo)86{87struct d3d12_bo *base_bo;88uint64_t offset;8990if (!bo->buffer)91return false;9293base_bo = d3d12_bo_get_base(bo, &offset);94return d3d12_bo_get_size(base_bo) != d3d12_bo_get_size(bo);95}9697struct d3d12_bo *98d3d12_bo_new(ID3D12Device *dev, uint64_t size, uint64_t alignment);99100struct d3d12_bo *101d3d12_bo_wrap_res(ID3D12Resource *res, enum pipe_format format);102103struct d3d12_bo *104d3d12_bo_wrap_buffer(struct pb_buffer *buf);105106static inline void107d3d12_bo_reference(struct d3d12_bo *bo)108{109p_atomic_inc(&bo->refcount);110}111112void113d3d12_bo_unreference(struct d3d12_bo *bo);114115void *116d3d12_bo_map(struct d3d12_bo *bo, D3D12_RANGE *range);117118void119d3d12_bo_unmap(struct d3d12_bo *bo, D3D12_RANGE *range);120121struct pb_manager *122d3d12_bufmgr_create(struct d3d12_screen *screen);123124#endif125126127