8 ComputeInputLayout
Chuck Walbourn редактировал(а) эту страницу 2022-01-20 17:34:24 -08:00
DirectXMesh

Returns the byte offsets for each element of an input layout and the implied vertex stride from a given Direct3D input layout description.

void ComputeInputLayout(
   const D3D11_INPUT_ELEMENT_DESC* vbDecl, size_t nDecl,
   uint32_t* offsets, uint32_t* strides );
void ComputeInputLayout(
   const D3D12_INPUT_LAYOUT_DESC& vbDecl,
   uint32_t* offsets, uint32_t* strides );

Header

#include "DirectXMesh.h"

By default, the library supports Direct3D 11. If you want to support Direct3D 12, then you need to #include <d3d12.h> before you do #include "DirectXMesh.h".

Parameters

vbDecl: Input layout description, which is nDecl elements long.

offsets: Returns the offset for each element in the description. Must have nDecl elements of space. Can be nullptr.

strides: Returns the stride of each VB in the description (or 0 if that the slot is unused). Must have D3D1x_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT space. Can be nullptr.

Example

Direct3D 11

const D3D11_INPUT_ELEMENT_DESC inputLayout[] =
{
{ "SV_Position", 0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL",      0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TANGENT",     0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR",       0, DXGI_FORMAT_R8G8B8A8_UNORM,     0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD",    0, DXGI_FORMAT_R32G32_FLOAT,       0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BLENDINDICES",0, DXGI_FORMAT_R8G8B8A8_UINT,      0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BLENDWEIGHT", 0, DXGI_FORMAT_R8G8B8A8_UNORM,     0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

uint32_t offsets[ D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT ];
uint32_t strides[ D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT ];
ComputeInputLayout( &inputLayout, std::size(inputLayout), offsets, strides );

// strides[0] contains 60
// offsets contains = { 0, 12, 24, 40, 44, 52, 56 }

Direct3D 12

const D3D12_INPUT_ELEMENT_DESC inputLayout[] =
{
{ "SV_Position", 0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "NORMAL",      0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "TANGENT",     0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "COLOR",       0, DXGI_FORMAT_R8G8B8A8_UNORM,     0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "TEXCOORD",    0, DXGI_FORMAT_R32G32_FLOAT,       0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "BLENDINDICES",0, DXGI_FORMAT_R8G8B8A8_UINT,      0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "BLENDWEIGHT", 0, DXGI_FORMAT_R8G8B8A8_UNORM,     0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
};

uint32_t offsets[ D3D12_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT ];
uint32_t strides[ D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT ];

D3D12_INPUT_LAYOUT_DESC desc = { inputLayout, static_cast<UINT>(std::size(inputLayout)) };
ComputeInputLayout( desc, offsets, strides );

// strides[0] contains 60
// offsets contains = { 0, 12, 24, 40, 44, 52, 56 }