d3d12: Add helpers to build with correct ABI for MinGW

Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17548>
This commit is contained in:
Jesse Natalie 2022-07-14 14:54:18 -07:00 committed by Marge Bot
parent 489ab1aa3b
commit e14beaf05b
12 changed files with 107 additions and 26 deletions

View File

@ -54,7 +54,7 @@ d3d12_bufmgr(struct pb_manager *mgr)
static struct TransitionableResourceState *
create_trans_state(ID3D12Resource *res, enum pipe_format format)
{
D3D12_RESOURCE_DESC desc = res->GetDesc();
D3D12_RESOURCE_DESC desc = GetDesc(res);
// Calculate the total number of subresources
unsigned arraySize = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ?
@ -111,7 +111,7 @@ d3d12_bo_wrap_res(struct d3d12_screen *screen, ID3D12Resource *res, enum pipe_fo
bo->residency_status = residency;
bo->last_used_timestamp = 0;
D3D12_RESOURCE_DESC desc = res->GetDesc();
D3D12_RESOURCE_DESC desc = GetDesc(res);
screen->dev->GetCopyableFootprints(&desc, 0, bo->trans_state->NumSubresources(), 0, nullptr, nullptr, nullptr, &bo->estimated_size);
if (residency != d3d12_evicted) {
mtx_lock(&screen->submit_mutex);
@ -152,7 +152,7 @@ d3d12_bo_new(struct d3d12_screen *screen, uint64_t size, const pb_desc *pb_desc)
enum d3d12_residency_status init_residency = screen->support_create_not_resident ?
d3d12_evicted : d3d12_resident;
D3D12_HEAP_PROPERTIES heap_pris = dev->GetCustomHeapProperties(0, heap_type);
D3D12_HEAP_PROPERTIES heap_pris = GetCustomHeapProperties(dev, heap_type);
HRESULT hres = dev->CreateCommittedResource(&heap_pris,
heap_flags,
&res_desc,

View File

@ -88,7 +88,7 @@ d3d12_bo_get_size(struct d3d12_bo *bo)
if (bo->buffer)
return bo->buffer->size;
else
return bo->res->GetDesc().Width;
return GetDesc(bo->res).Width;
}
static inline bool

View File

@ -35,4 +35,70 @@
#define D3D12_IGNORE_SDK_LAYERS
#include <directx/d3d12.h>
#if defined(__cplusplus)
#if !defined(_WIN32) || defined(_MSC_VER) || D3D12_SDK_VERSION < 606
inline D3D12_CPU_DESCRIPTOR_HANDLE
GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
{
return heap->GetCPUDescriptorHandleForHeapStart();
}
inline D3D12_GPU_DESCRIPTOR_HANDLE
GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
{
return heap->GetGPUDescriptorHandleForHeapStart();
}
inline D3D12_RESOURCE_DESC
GetDesc(ID3D12Resource *res)
{
return res->GetDesc();
}
inline D3D12_HEAP_PROPERTIES
GetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
{
return dev->GetCustomHeapProperties(0, type);
}
inline LUID
GetAdapterLuid(ID3D12Device *dev)
{
return dev->GetAdapterLuid();
}
#else
inline D3D12_CPU_DESCRIPTOR_HANDLE
GetCPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
{
D3D12_CPU_DESCRIPTOR_HANDLE ret;
heap->GetCPUDescriptorHandleForHeapStart(&ret);
return ret;
}
inline D3D12_GPU_DESCRIPTOR_HANDLE
GetGPUDescriptorHandleForHeapStart(ID3D12DescriptorHeap *heap)
{
D3D12_GPU_DESCRIPTOR_HANDLE ret;
heap->GetGPUDescriptorHandleForHeapStart(&ret);
return ret;
}
inline D3D12_RESOURCE_DESC
GetDesc(ID3D12Resource *res)
{
D3D12_RESOURCE_DESC ret;
res->GetDesc(&ret);
return ret;
}
inline D3D12_HEAP_PROPERTIES
GetCustomHeapProperties(ID3D12Device *dev, D3D12_HEAP_TYPE type)
{
D3D12_HEAP_PROPERTIES ret;
dev->GetCustomHeapProperties(&ret, 0, type);
return ret;
}
inline LUID
GetAdapterLuid(ID3D12Device *dev)
{
LUID ret;
dev->GetAdapterLuid(&ret);
return ret;
}
#endif
#endif
#endif

View File

@ -76,9 +76,9 @@ d3d12_descriptor_heap_new(ID3D12Device *dev,
heap->dev = dev;
heap->desc_size = dev->GetDescriptorHandleIncrementSize(type);
heap->size = num_descriptors * heap->desc_size;
heap->cpu_base = heap->heap->GetCPUDescriptorHandleForHeapStart().ptr;
heap->cpu_base = GetCPUDescriptorHandleForHeapStart(heap->heap).ptr;
if (flags & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE)
heap->gpu_base = heap->heap->GetGPUDescriptorHandleForHeapStart().ptr;
heap->gpu_base = GetGPUDescriptorHandleForHeapStart(heap->heap).ptr;
util_dynarray_init(&heap->free_list, NULL);
return heap;

View File

@ -265,7 +265,7 @@ init_texture(struct d3d12_screen *screen,
nullptr,
IID_PPV_ARGS(&d3d12_res));
} else {
D3D12_HEAP_PROPERTIES heap_pris = screen->dev->GetCustomHeapProperties(0, D3D12_HEAP_TYPE_DEFAULT);
D3D12_HEAP_PROPERTIES heap_pris = GetCustomHeapProperties(screen->dev, D3D12_HEAP_TYPE_DEFAULT);
D3D12_HEAP_FLAGS heap_flags = screen->support_create_not_resident ?
D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT : D3D12_HEAP_FLAG_NONE;
@ -329,7 +329,7 @@ convert_planar_resource(struct d3d12_resource *res)
#if DEBUG
struct d3d12_screen *screen = d3d12_screen(res->base.b.screen);
D3D12_RESOURCE_DESC desc = res->bo->res->GetDesc();
D3D12_RESOURCE_DESC desc = GetDesc(res->bo->res);
D3D12_PLACED_SUBRESOURCE_FOOTPRINT placed_footprint = {};
D3D12_SUBRESOURCE_FOOTPRINT *footprint = &placed_footprint.Footprint;
unsigned subresource = plane * desc.MipLevels * desc.DepthOrArraySize;
@ -475,7 +475,7 @@ d3d12_resource_from_handle(struct pipe_screen *pscreen,
pipe_reference_init(&res->base.b.reference, 1);
res->base.b.screen = pscreen;
incoming_res_desc = d3d12_res->GetDesc();
incoming_res_desc = GetDesc(d3d12_res);
/* Get a description for this plane */
if (templ && handle->format != templ->format) {
@ -682,7 +682,7 @@ struct pipe_resource *
d3d12_resource_from_resource(struct pipe_screen *pscreen,
ID3D12Resource* input_res)
{
D3D12_RESOURCE_DESC input_desc = input_res->GetDesc();
D3D12_RESOURCE_DESC input_desc = GetDesc(input_res);
struct winsys_handle handle;
memset(&handle, 0, sizeof(handle));
handle.type = WINSYS_HANDLE_TYPE_D3D12_RES;
@ -977,7 +977,7 @@ fill_buffer_location(struct d3d12_context *ctx,
D3D12_TEXTURE_COPY_LOCATION buf_loc = {0};
D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint;
uint64_t offset = 0;
auto descr = d3d12_resource_underlying(res, &offset)->GetDesc();
auto descr = GetDesc(d3d12_resource_underlying(res, &offset));
struct d3d12_screen *screen = d3d12_screen(ctx->base.screen);
ID3D12Device* dev = screen->dev;

View File

@ -1186,7 +1186,7 @@ d3d12_init_screen(struct d3d12_screen *screen, IUnknown *adapter)
return false;
}
screen->adapter_luid = screen->dev->GetAdapterLuid();
screen->adapter_luid = GetAdapterLuid(screen->dev);
ID3D12InfoQueue *info_queue;
if (SUCCEEDED(screen->dev->QueryInterface(IID_PPV_ARGS(&info_queue)))) {

View File

@ -523,8 +523,7 @@ d3d12_video_decoder_end_frame(struct pipe_video_codec *codec,
d3d12OutputArguments.ConversionArguments.pReferenceTexture2D = pRefOnlyOutputD3D12Texture;
d3d12OutputArguments.ConversionArguments.ReferenceSubresource = refOnlyOutputD3D12Subresource;
const D3D12_RESOURCE_DESC &descReference =
d3d12OutputArguments.ConversionArguments.pReferenceTexture2D->GetDesc();
const D3D12_RESOURCE_DESC &descReference = GetDesc(d3d12OutputArguments.ConversionArguments.pReferenceTexture2D);
d3d12OutputArguments.ConversionArguments.DecodeColorSpace = d3d12_convert_from_legacy_color_space(
!util_format_is_yuv(d3d12_get_pipe_format(descReference.Format)),
util_format_get_blocksize(d3d12_get_pipe_format(descReference.Format)) * 8 /*bytes to bits conversion*/,
@ -532,7 +531,7 @@ d3d12_video_decoder_end_frame(struct pipe_video_codec *codec,
/* P709= */ true,
/* StudioYUV= */ true);
const D3D12_RESOURCE_DESC &descOutput = d3d12OutputArguments.pOutputTexture2D->GetDesc();
const D3D12_RESOURCE_DESC &descOutput = GetDesc(d3d12OutputArguments.pOutputTexture2D);
d3d12OutputArguments.ConversionArguments.OutputColorSpace = d3d12_convert_from_legacy_color_space(
!util_format_is_yuv(d3d12_get_pipe_format(descOutput.Format)),
util_format_get_blocksize(d3d12_get_pipe_format(descOutput.Format)) * 8 /*bytes to bits conversion*/,
@ -540,14 +539,14 @@ d3d12_video_decoder_end_frame(struct pipe_video_codec *codec,
/* P709= */ true,
/* StudioYUV= */ true);
const D3D12_VIDEO_DECODER_HEAP_DESC &HeapDesc = pD3D12Dec->m_spVideoDecoderHeap->GetDesc();
const D3D12_VIDEO_DECODER_HEAP_DESC &HeapDesc = GetDesc(pD3D12Dec->m_spVideoDecoderHeap.Get());
d3d12OutputArguments.ConversionArguments.OutputWidth = HeapDesc.DecodeWidth;
d3d12OutputArguments.ConversionArguments.OutputHeight = HeapDesc.DecodeHeight;
} else {
d3d12OutputArguments.ConversionArguments.Enable = FALSE;
}
CD3DX12_RESOURCE_DESC outputDesc(d3d12OutputArguments.pOutputTexture2D->GetDesc());
CD3DX12_RESOURCE_DESC outputDesc(GetDesc(d3d12OutputArguments.pOutputTexture2D));
uint32_t MipLevel, PlaneSlice, ArraySlice;
D3D12DecomposeSubresource(d3d12OutputArguments.OutputSubresource,
outputDesc.MipLevels,
@ -958,7 +957,7 @@ d3d12_video_decoder_prepare_for_decode_frame(struct d3d12_video_decoder *pD3D12D
needsTransitionToDecodeWrite);
assert(needsTransitionToDecodeWrite);
CD3DX12_RESOURCE_DESC outputDesc((*ppRefOnlyOutTexture2D)->GetDesc());
CD3DX12_RESOURCE_DESC outputDesc(GetDesc(*ppRefOnlyOutTexture2D));
uint32_t MipLevel, PlaneSlice, ArraySlice;
D3D12DecomposeSubresource(*pRefOnlyOutSubresourceIndex,
outputDesc.MipLevels,
@ -1024,7 +1023,7 @@ d3d12_video_decoder_reconfigure_dpb(struct d3d12_video_decoder *pD3D12Dec,
d3d12_video_decoder_get_frame_info(pD3D12Dec, &width, &height, &maxDPB, isInterlaced);
ID3D12Resource *pPipeD3D12DstResource = d3d12_resource_resource(pD3D12VideoBuffer->texture);
D3D12_RESOURCE_DESC outputResourceDesc = pPipeD3D12DstResource->GetDesc();
D3D12_RESOURCE_DESC outputResourceDesc = GetDesc(pPipeD3D12DstResource);
pD3D12VideoBuffer->base.interlaced = isInterlaced;
D3D12_VIDEO_FRAME_CODED_INTERLACE_TYPE interlaceTypeRequested =
@ -1200,7 +1199,7 @@ d3d12_video_decoder_store_converted_dxva_picparams_from_pipe_input(
size_t dxvaPicParamsBufferSize = sizeof(DXVA_PicParams_H264);
pipe_h264_picture_desc *pPicControlH264 = (pipe_h264_picture_desc *) picture;
ID3D12Resource *pPipeD3D12DstResource = d3d12_resource_resource(pD3D12VideoBuffer->texture);
D3D12_RESOURCE_DESC outputResourceDesc = pPipeD3D12DstResource->GetDesc();
D3D12_RESOURCE_DESC outputResourceDesc = GetDesc(pPipeD3D12DstResource);
DXVA_PicParams_H264 dxvaPicParamsH264 =
d3d12_video_decoder_dxva_picparams_from_pipe_picparams_h264(pD3D12Dec->m_fenceValue,
codec->base.profile,

View File

@ -111,7 +111,7 @@ d3d12_video_decoder_references_manager::get_current_frame_decode_output_texture(
*ppOutTexture2D = d3d12_resource_resource(vidBuffer->texture);
*pOutSubresourceIndex = 0;
#if DEBUG
D3D12_RESOURCE_DESC desc = (*ppOutTexture2D)->GetDesc();
D3D12_RESOURCE_DESC desc = GetDesc(*ppOutTexture2D);
assert(desc.DepthOrArraySize == 1);
// if the underlying resource is a texture array at some point (if the impl. changes)
// we need to also return the correct underlying subresource in *pOutSubresourceIndex = <subres>

View File

@ -187,7 +187,7 @@ d3d12_video_decoder_references_manager::update_entries(T (&picEntries)[size],
/// in other areas of D3D12 we need to convert it to the D3D12CalcSubresource format, explained in
/// https://docs.microsoft.com/en-us/windows/win32/direct3d12/subresources
///
CD3DX12_RESOURCE_DESC refDesc(pOutputReference->GetDesc());
CD3DX12_RESOURCE_DESC refDesc(GetDesc(pOutputReference));
uint32_t MipLevel, PlaneSlice, ArraySlice;
D3D12DecomposeSubresource(OutputSubresource,
refDesc.MipLevels,

View File

@ -983,7 +983,7 @@ d3d12_video_encoder_prepare_output_buffers(struct d3d12_video_encoder *pD3D12Enc
D3D12_HEAP_PROPERTIES Properties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
if ((pD3D12Enc->m_spResolvedMetadataBuffer == nullptr) ||
(pD3D12Enc->m_spResolvedMetadataBuffer->GetDesc().Width <
(GetDesc(pD3D12Enc->m_spResolvedMetadataBuffer.Get()).Width <
pD3D12Enc->m_currentEncodeCapabilities.m_resolvedLayoutMetadataBufferRequiredSize)) {
CD3DX12_RESOURCE_DESC resolvedMetadataBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(
pD3D12Enc->m_currentEncodeCapabilities.m_resolvedLayoutMetadataBufferRequiredSize);
@ -1003,7 +1003,7 @@ d3d12_video_encoder_prepare_output_buffers(struct d3d12_video_encoder *pD3D12Enc
}
if ((pD3D12Enc->m_spMetadataOutputBuffer == nullptr) ||
(pD3D12Enc->m_spMetadataOutputBuffer->GetDesc().Width <
(GetDesc(pD3D12Enc->m_spMetadataOutputBuffer.Get()).Width <
pD3D12Enc->m_currentEncodeCapabilities.m_ResourceRequirementsCaps.MaxEncoderOutputMetadataBufferSize)) {
CD3DX12_RESOURCE_DESC metadataBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(
pD3D12Enc->m_currentEncodeCapabilities.m_ResourceRequirementsCaps.MaxEncoderOutputMetadataBufferSize);
@ -1253,7 +1253,7 @@ d3d12_video_encoder_encode_bitstream(struct pipe_video_codec * codec,
// reference pics in ppTexture2Ds and also for the pReconstructedPicture output allocations, just different
// subresources.
CD3DX12_RESOURCE_DESC referencesTexArrayDesc(referenceFramesDescriptor.ppTexture2Ds[0]->GetDesc());
CD3DX12_RESOURCE_DESC referencesTexArrayDesc(GetDesc(referenceFramesDescriptor.ppTexture2Ds[0]));
for (uint32_t referenceSubresource = 0; referenceSubresource < referencesTexArrayDesc.DepthOrArraySize;
referenceSubresource++) {

View File

@ -40,6 +40,22 @@
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;
#if !defined(_WIN32) || defined(_MSC_VER) || D3D12_SDK_VERSION < 606
inline D3D12_VIDEO_DECODER_HEAP_DESC
GetDesc(ID3D12VideoDecoderHeap *heap)
{
return heap->GetDesc();
}
#else
inline D3D12_VIDEO_DECODER_HEAP_DESC
GetDesc(ID3D12VideoDecoderHeap *heap)
{
D3D12_VIDEO_DECODER_HEAP_DESC ret;
heap->GetDesc(&ret);
return ret;
}
#endif
// Allow encoder to continue the encoding session when an optional
// rate control mode such as the following is used but not supported
//

View File

@ -193,7 +193,7 @@ d3d12_wgl_framebuffer_get_resource(struct stw_winsys_framebuffer *pframebuffer,
handle.format = framebuffer->pformat;
handle.com_obj = res;
D3D12_RESOURCE_DESC res_desc = res->GetDesc();
D3D12_RESOURCE_DESC res_desc = GetDesc(res);
struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));