VideoBackends/D3D11: Simplify vertex attribute code

This commit is contained in:
Pokechu22 2022-10-12 15:20:12 -07:00
parent cc5640245c
commit f5d11c1e38
2 changed files with 22 additions and 56 deletions

View File

@ -103,69 +103,18 @@ D3DVertexFormat::D3DVertexFormat(const PortableVertexDeclaration& vtx_decl)
: NativeVertexFormat(vtx_decl)
{
const AttributeFormat* format = &vtx_decl.position;
if (format->enable)
{
m_elems[m_num_elems].SemanticName = "TEXCOORD";
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::Position);
m_elems[m_num_elems].AlignedByteOffset = format->offset;
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
++m_num_elems;
}
AddAttribute(vtx_decl.position, ShaderAttrib::Position);
for (u32 i = 0; i < 3; i++)
{
format = &vtx_decl.normals[i];
if (format->enable)
{
m_elems[m_num_elems].SemanticName = "TEXCOORD";
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::Normal + i);
m_elems[m_num_elems].AlignedByteOffset = format->offset;
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
++m_num_elems;
}
}
AddAttribute(vtx_decl.normals[i], ShaderAttrib::Normal + i);
for (u32 i = 0; i < 2; i++)
{
format = &vtx_decl.colors[i];
if (format->enable)
{
m_elems[m_num_elems].SemanticName = "TEXCOORD";
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::Color0 + i);
m_elems[m_num_elems].AlignedByteOffset = format->offset;
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
++m_num_elems;
}
}
AddAttribute(vtx_decl.colors[i], ShaderAttrib::Color0 + i);
for (u32 i = 0; i < 8; i++)
{
format = &vtx_decl.texcoords[i];
if (format->enable)
{
m_elems[m_num_elems].SemanticName = "TEXCOORD";
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::TexCoord0 + i);
m_elems[m_num_elems].AlignedByteOffset = format->offset;
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
++m_num_elems;
}
}
AddAttribute(vtx_decl.texcoords[i], ShaderAttrib::TexCoord0 + i);
format = &vtx_decl.posmtx;
if (format->enable)
{
m_elems[m_num_elems].SemanticName = "TEXCOORD";
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::PositionMatrix);
m_elems[m_num_elems].AlignedByteOffset = format->offset;
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
++m_num_elems;
}
AddAttribute(vtx_decl.posmtx, ShaderAttrib::PositionMatrix);
}
D3DVertexFormat::~D3DVertexFormat()
@ -201,4 +150,17 @@ ID3D11InputLayout* D3DVertexFormat::GetInputLayout(const void* vs_bytecode, size
return layout;
}
void D3DVertexFormat::AddAttribute(const AttributeFormat& format, ShaderAttrib semantic_index)
{
if (format.enable)
{
m_elems[m_num_elems].SemanticName = "TEXCOORD";
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(semantic_index);
m_elems[m_num_elems].AlignedByteOffset = format.offset;
m_elems[m_num_elems].Format = VarToD3D(format.type, format.components, format.integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
++m_num_elems;
}
}
} // namespace DX11

View File

@ -12,6 +12,8 @@
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/VertexManagerBase.h"
enum class ShaderAttrib : u32;
namespace DX11
{
class D3DVertexFormat : public NativeVertexFormat
@ -22,6 +24,8 @@ public:
ID3D11InputLayout* GetInputLayout(const void* vs_bytecode, size_t vs_bytecode_size);
private:
void AddAttribute(const AttributeFormat& format, ShaderAttrib semantic_index);
std::array<D3D11_INPUT_ELEMENT_DESC, 32> m_elems{};
UINT m_num_elems = 0;