深入理解D3D11_BUFFER_DESC

1、缓存区资源描述

typedef struct D3D11_BUFFER_DESC {
  UINT        ByteWidth;
  D3D11_USAGE Usage;
  UINT        BindFlags;
  UINT        CPUAccessFlags;
  UINT        MiscFlags;
  UINT        StructureByteStride;
} D3D11_BUFFER_DESC;

ByteWidth:缓冲区的大小(以字节为单位)

D3D11_USAGE:标识渲染期间的预期资源使用。该用法直接反映CPU和/或图形处理单元(GPU)是否可访问资源

typedef enum D3D11_USAGE {
  D3D11_USAGE_DEFAULT,
  D3D11_USAGE_IMMUTABLE,
  D3D11_USAGE_DYNAMIC,
  D3D11_USAGE_STAGING
} ;
D3D11_USAGE_DEFAULT需要GPU进行读写访问的资源。这可能是最常见的使用选择。
D3D11_USAGE_IMMUTABLE只能由GPU读取的资源。它不能由GPU写入,并且CPU根本无法访问。这种类型的资源在创建时必须初始化,因为它在创建后无法更改。
D3D11_USAGE_DYNAMICGPU(只读)和CPU(仅写入)可访问的资源。对于将由CPU至少每帧更新一次的资源,动态资源是一个不错的选择。要更新动态资源,请使用Map方法。

有关如何使用动态资源的信息,请参见如何:使用动态资源

D3D11_USAGE_STAGING支持从GPU到CPU的数据传输(复制)的资源。

BindFlags:确定缓冲区如何绑定到管道

CPUAccessFlags:CPU访问标志

MiscFlags:杂项标志

StructureByteStride:缓冲区表示结构化缓冲区时缓冲区结构中每个元素的大小(以字节为单位)

2、Buffer Usage Patterns

“Forever”
Long Lived
Transient
Temporary
Constants

2.1 Forever Buffers

Useful for geometry that is loaded once ,IMMUTABLE flag at creation time

2.2 Long Lived Buffers

Data that is streamed in from disk,but is expected to last for “awhile”,Reuse these; stream into them

DEFAULT flag at creation time

UpdateSubresource to update

2.3 Temporary buffers

Fire-and-forget data
● E.g. Particle systems
● Almost certainly lives in system RAM
● DYNAMIC flag at create time
● Prefer Map/Unmap to update these
● UpdateSubresource involves an extra copy

2.4 Constant Buffers

These are different than other buffers in D3D11.
● The GPU can deal with many of them in flight at once
● Create with DYNAMIC
● Map/DISCARD to Update
● More on these in a bit

2.5 Transient Buffers

● New informal class of Buffer
● Used for (e.g.) UI/Text
● Things that are dynamic, but few vertices each—and may need to be updated on odd schedules
● DYNAMIC flag at creation time
● Transient Buffers are part of a new class of buffer
Treat Buffer as a Memory Heap,with a twist
● On CPU, Freed memory available now
● On GPU, Freed memory is available
when GPU is finished with it
● Assume memory is in use until told otherwise
● Determine when GPU must be finished with Freed
memory, then return to the “really free” list

TypeUsage (e.g)Create FlagUpdate Method
“Forever”Level BSPsIMMUTABLECannot Update
Long-LivedCharactersDEFAULTUpdateSubResource
TransientUI/TextDYNAMICCTransientBuffer
TemporaryParticlesDYNAMICMap/NO_OVERWRITE
ConstantMaterial PropsDYNAMICMap/DISCARD


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值