17ec681f3Smrg/* 27ec681f3Smrg * Copyright © Microsoft Corporation 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ec681f3Smrg * IN THE SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg 247ec681f3Smrg#ifndef D3D12_BUFMGR_H 257ec681f3Smrg#define D3D12_BUFMGR_H 267ec681f3Smrg 277ec681f3Smrg#include "pipebuffer/pb_buffer.h" 287ec681f3Smrg#include "util/u_atomic.h" 297ec681f3Smrg 307ec681f3Smrg#ifndef _WIN32 317ec681f3Smrg#include <wsl/winadapter.h> 327ec681f3Smrg#endif 337ec681f3Smrg 347ec681f3Smrg#include <directx/d3d12.h> 357ec681f3Smrg 367ec681f3Smrgstruct d3d12_bufmgr; 377ec681f3Smrgstruct d3d12_screen; 387ec681f3Smrgstruct pb_manager; 397ec681f3Smrgstruct TransitionableResourceState; 407ec681f3Smrg 417ec681f3Smrgstruct d3d12_bo { 427ec681f3Smrg int refcount; 437ec681f3Smrg ID3D12Resource *res; 447ec681f3Smrg struct pb_buffer *buffer; 457ec681f3Smrg struct TransitionableResourceState *trans_state; 467ec681f3Smrg}; 477ec681f3Smrg 487ec681f3Smrgstruct d3d12_buffer { 497ec681f3Smrg struct pb_buffer base; 507ec681f3Smrg 517ec681f3Smrg struct d3d12_bo *bo; 527ec681f3Smrg D3D12_RANGE range; 537ec681f3Smrg void *map; 547ec681f3Smrg}; 557ec681f3Smrg 567ec681f3Smrgstatic inline struct d3d12_buffer * 577ec681f3Smrgd3d12_buffer(struct pb_buffer *buf) 587ec681f3Smrg{ 597ec681f3Smrg assert(buf); 607ec681f3Smrg return (struct d3d12_buffer *)buf; 617ec681f3Smrg} 627ec681f3Smrg 637ec681f3Smrgstatic inline struct d3d12_bo * 647ec681f3Smrgd3d12_bo_get_base(struct d3d12_bo *bo, uint64_t *offset) 657ec681f3Smrg{ 667ec681f3Smrg if (bo->buffer) { 677ec681f3Smrg struct pb_buffer *base_buffer; 687ec681f3Smrg pb_get_base_buffer(bo->buffer, &base_buffer, offset); 697ec681f3Smrg return d3d12_buffer(base_buffer)->bo; 707ec681f3Smrg } else { 717ec681f3Smrg *offset = 0; 727ec681f3Smrg return bo; 737ec681f3Smrg } 747ec681f3Smrg} 757ec681f3Smrg 767ec681f3Smrgstatic inline uint64_t 777ec681f3Smrgd3d12_bo_get_size(struct d3d12_bo *bo) 787ec681f3Smrg{ 797ec681f3Smrg if (bo->buffer) 807ec681f3Smrg return bo->buffer->size; 817ec681f3Smrg else 827ec681f3Smrg return bo->res->GetDesc().Width; 837ec681f3Smrg} 847ec681f3Smrg 857ec681f3Smrgstatic inline bool 867ec681f3Smrgd3d12_bo_is_suballocated(struct d3d12_bo *bo) 877ec681f3Smrg{ 887ec681f3Smrg struct d3d12_bo *base_bo; 897ec681f3Smrg uint64_t offset; 907ec681f3Smrg 917ec681f3Smrg if (!bo->buffer) 927ec681f3Smrg return false; 937ec681f3Smrg 947ec681f3Smrg base_bo = d3d12_bo_get_base(bo, &offset); 957ec681f3Smrg return d3d12_bo_get_size(base_bo) != d3d12_bo_get_size(bo); 967ec681f3Smrg} 977ec681f3Smrg 987ec681f3Smrgstruct d3d12_bo * 997ec681f3Smrgd3d12_bo_new(ID3D12Device *dev, uint64_t size, uint64_t alignment); 1007ec681f3Smrg 1017ec681f3Smrgstruct d3d12_bo * 1027ec681f3Smrgd3d12_bo_wrap_res(ID3D12Resource *res, enum pipe_format format); 1037ec681f3Smrg 1047ec681f3Smrgstruct d3d12_bo * 1057ec681f3Smrgd3d12_bo_wrap_buffer(struct pb_buffer *buf); 1067ec681f3Smrg 1077ec681f3Smrgstatic inline void 1087ec681f3Smrgd3d12_bo_reference(struct d3d12_bo *bo) 1097ec681f3Smrg{ 1107ec681f3Smrg p_atomic_inc(&bo->refcount); 1117ec681f3Smrg} 1127ec681f3Smrg 1137ec681f3Smrgvoid 1147ec681f3Smrgd3d12_bo_unreference(struct d3d12_bo *bo); 1157ec681f3Smrg 1167ec681f3Smrgvoid * 1177ec681f3Smrgd3d12_bo_map(struct d3d12_bo *bo, D3D12_RANGE *range); 1187ec681f3Smrg 1197ec681f3Smrgvoid 1207ec681f3Smrgd3d12_bo_unmap(struct d3d12_bo *bo, D3D12_RANGE *range); 1217ec681f3Smrg 1227ec681f3Smrgstruct pb_manager * 1237ec681f3Smrgd3d12_bufmgr_create(struct d3d12_screen *screen); 1247ec681f3Smrg 1257ec681f3Smrg#endif 126