diff --git a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp index a205f828e6..aca5a177fa 100644 --- a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp @@ -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(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(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(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(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(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(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 diff --git a/Source/Core/VideoBackends/D3D/D3DVertexManager.h b/Source/Core/VideoBackends/D3D/D3DVertexManager.h index f61a264c88..669d670fed 100644 --- a/Source/Core/VideoBackends/D3D/D3DVertexManager.h +++ b/Source/Core/VideoBackends/D3D/D3DVertexManager.h @@ -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 m_elems{}; UINT m_num_elems = 0;