> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GetResourceAllocationInfo

> GetResourceAllocationInfo（XBOX 上的 Direct3D 12）— 获取此适配器上一组资源所需的内存大小和对齐方式。

获取此适配器上一组资源所需的内存大小和对齐方式。

## 语法

```cpp theme={null}
D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfo(
    UINT visibleMask,
    UINT numResourceDescs,
    const D3D12_RESOURCE_DESC* pResourceDescs
)
```

### 参数

*visibleMask \[in]*\
类型：UINT

对于单 GPU 操作，将其设置为零。如果有多个 GPU 节点，则设置位以标识节点（设备的物理适配器）。掩码中的每一位都对应一个节点。另请参阅 [多适配器系统](https://learn.microsoft.com/en-us/windows/win32/direct3d12/multi-engine)。

*numResourceDescs \[in]*\
类型：**[UINT](https://learn.microsoft.com/en-us/windows/win32/WinProg/windows-data-types)**

*pResourceDescs* 数组中资源描述符的数量。

*pResourceDescs \[in]*\
类型：**const [D3D12\_RESOURCE\_DESC](/reference/graphics/d3d12/structs/d3d12_resource_desc_public)\***

**D3D12\_RESOURCE\_DESC** 结构体数组，用于描述要获取信息的资源。

### 返回值

类型：D3D12\_RESOURCE\_ALLOCATION\_INFO

一个 [D3D12\_RESOURCE\_ALLOCATION\_INFO](/reference/graphics/d3d12/structs/d3d12_resource_allocation_info_public) 结构体，提供有关为指定资源数组分配的显存的信息。

如果发生错误，则 **D3D12\_RESOURCE\_ALLOCATION\_INFO::SizeInBytes** 等于 **UINT64\_MAX**。

## 备注

使用 [CreatePlacedResource](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createplacedresource_public) 时，您的应用程序必须使用 **GetResourceAllocationInfo** 来了解纹理资源的大小和对齐特性。此方法的结果因特定适配器而异，必须视为对该适配器和驱动程序版本唯一的结果。

您的应用程序无法使用 **GetResourceAllocationInfo** 的输出来了解纹理的打包 mip 属性。要了解纹理的打包 mip 属性，您的应用程序必须使用 [GetResourceTiling](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_getresourcetiling_public)。

纹理资源大小与 **GetResourceTiling** 返回的信息有显著差异，因为某些适配器架构为纹理分配额外内存以减少常见渲染场景中的有效带宽。这甚至包括对其纹理布局有约束的纹理，或具有标准化纹理布局的纹理。使用 [CreateReservedResource](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createreservedresource_public) 和 [UpdateTileMappings](/reference/graphics/d3d12/interfaces/id3d12commandqueue/methods/id3d12commandqueue_updatetilemappings_public) 的应用程序不能稀疏地映射或重新映射这些额外内存，因此 **GetResourceTiling** 不会报告它们。

您的应用程序可以放弃对缓冲区资源（[D3D12\_RESOURCE\_DIMENSION\_BUFFER](/reference/graphics/d3d12_x/enums/d3d12_resource_dimension)）使用 **GetResourceAllocationInfo**。缓冲区在所有适配器上都具有相同的大小，仅仅是大于或等于 [D3D12\_RESOURCE\_DESC::Width](/reference/graphics/d3d12/structs/d3d12_resource_desc_public) 的 64KB 的最小倍数。

当传入多个资源描述时，将使用 C++ 计算结构体大小和对齐方式的算法。例如，一个包含两个小的 64KB 对齐资源和一个小的 4MB 对齐资源的三元素数组，根据数组的顺序会报告不同的大小。如果 4MB 对齐资源位于中间，则生成的 **Size** 为 12MB。否则，生成的 **Size** 为 8MB。返回的 **Alignment** 始终为 4MB，因为它是资源数组中所有对齐的超集。

## 要求

**头文件：** d3d12\_xs.h 或 d3d12\_x.h\
**库：** d3d12\_xs.lib 或 d3d12\_x.lib\
**支持的平台**：XBOX Series 主机和 XBOX One 系列

## 另请参阅

[ID3D12Device](/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

- [GetResourceAllocationInfo1 (XBOX Series 主机)](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device4/methods/id3d12device4_getresourceallocationinfo1_public.md)
- [D3D12_RESOURCE_ALLOCATION_INFO](/zh-CN/reference/graphics/d3d12/structs/d3d12_resource_allocation_info_public.md)
- [GetResourceTiling](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_getresourcetiling_public.md)
- [CreatePlacedResource](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createplacedresource_public.md)
- [CreatePlacedResource2 (XBOX Series 主机)](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device10/methods/id3d12device10_createplacedresource2_public.md)
