WIP (VertexDeclaration)

This commit is contained in:
Lynix 2020-03-03 01:04:24 +01:00
parent 287be5d9b6
commit d5c75926c6
12 changed files with 304 additions and 255 deletions

View File

@ -1,40 +1,32 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Algorithm.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
namespace Detail
{
template<typename T>
struct IsSuitableForComponent
{
constexpr static bool value = false;
};
}
template<typename T> constexpr ComponentType ComponentTypeId()
{
static_assert(Detail::IsSuitableForComponent<T>::value, "This type cannot be used as a component.");
static_assert(AlwaysFalse<T>::value, "This type cannot be used as a component.");
return ComponentType{};
}
template<> constexpr ComponentType ComponentTypeId<Color>() { return ComponentType_Color; }
template<> constexpr ComponentType ComponentTypeId<double>() { return ComponentType_Double1; }
template<> constexpr ComponentType ComponentTypeId<Vector2d>() { return ComponentType_Double2; }
template<> constexpr ComponentType ComponentTypeId<Vector3d>() { return ComponentType_Double3; }
template<> constexpr ComponentType ComponentTypeId<Vector4d>() { return ComponentType_Double4; }
template<> constexpr ComponentType ComponentTypeId<float>() { return ComponentType_Float1; }
template<> constexpr ComponentType ComponentTypeId<Vector2f>() { return ComponentType_Float2; }
template<> constexpr ComponentType ComponentTypeId<Vector3f>() { return ComponentType_Float3; }
template<> constexpr ComponentType ComponentTypeId<Vector4f>() { return ComponentType_Float4; }
template<> constexpr ComponentType ComponentTypeId<int>() { return ComponentType_Int1; }
template<> constexpr ComponentType ComponentTypeId<Vector2i>() { return ComponentType_Int2; }
template<> constexpr ComponentType ComponentTypeId<Vector3i>() { return ComponentType_Int3; }
template<> constexpr ComponentType ComponentTypeId<Vector4i>() { return ComponentType_Int4; }
template<> constexpr ComponentType ComponentTypeId<Color>() { return ComponentType_Color; }
template<> constexpr ComponentType ComponentTypeId<double>() { return ComponentType_Double1; }
template<> constexpr ComponentType ComponentTypeId<Vector2d>() { return ComponentType_Double2; }
template<> constexpr ComponentType ComponentTypeId<Vector3d>() { return ComponentType_Double3; }
template<> constexpr ComponentType ComponentTypeId<Vector4d>() { return ComponentType_Double4; }
template<> constexpr ComponentType ComponentTypeId<float>() { return ComponentType_Float1; }
template<> constexpr ComponentType ComponentTypeId<Vector2f>() { return ComponentType_Float2; }
template<> constexpr ComponentType ComponentTypeId<Vector3f>() { return ComponentType_Float3; }
template<> constexpr ComponentType ComponentTypeId<Vector4f>() { return ComponentType_Float4; }
template<> constexpr ComponentType ComponentTypeId<int>() { return ComponentType_Int1; }
template<> constexpr ComponentType ComponentTypeId<Vector2i>() { return ComponentType_Int2; }
template<> constexpr ComponentType ComponentTypeId<Vector3i>() { return ComponentType_Int3; }
template<> constexpr ComponentType ComponentTypeId<Vector4i>() { return ComponentType_Int4; }
template<> constexpr ComponentType ComponentTypeId<Quaternionf>() { return ComponentType_Quaternion; }
template<typename T>

View File

@ -356,35 +356,25 @@ namespace Nz
{
VertexComponent_Unused = -1,
// We limit to 16 components by vertex since it's the minimal number supported by the GPU
VertexComponent_InstanceData0,
VertexComponent_InstanceData1,
VertexComponent_InstanceData2,
VertexComponent_InstanceData3,
VertexComponent_InstanceData4,
VertexComponent_InstanceData5,
VertexComponent_Color,
VertexComponent_Normal,
VertexComponent_Position,
VertexComponent_Tangent,
VertexComponent_TexCoord,
VertexComponent_Userdata0,
VertexComponent_Userdata1,
VertexComponent_Userdata2,
VertexComponent_Userdata3,
VertexComponent_Userdata4,
VertexComponent_Userdata,
VertexComponent_FirstInstanceData = VertexComponent_InstanceData0,
VertexComponent_FirstVertexData = VertexComponent_Color,
VertexComponent_LastInstanceData = VertexComponent_InstanceData5,
VertexComponent_LastVertexData = VertexComponent_Userdata4,
VertexComponent_Max = VertexComponent_Userdata
};
VertexComponent_Max = VertexComponent_Userdata4
enum class VertexInputRate
{
Instance,
Vertex
};
enum VertexLayout
{
// Declarations meant for the rendering
// Predefined declarations for rendering
VertexLayout_XY,
VertexLayout_XY_Color,
VertexLayout_XY_UV,
@ -397,7 +387,7 @@ namespace Nz
VertexLayout_XYZ_Normal_UV_Tangent_Skinning,
VertexLayout_XYZ_UV,
// Declarations meant for the instancing
// Predefined declarations for instancing
VertexLayout_Matrix4,
VertexLayout_Max = VertexLayout_Matrix4

View File

@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@ -11,7 +11,7 @@
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <array>
@ -30,52 +30,57 @@ namespace Nz
friend class Utility;
public:
VertexDeclaration();
VertexDeclaration(const VertexDeclaration& declaration);
~VertexDeclaration();
struct Component;
struct ComponentEntry;
void DisableComponent(VertexComponent component);
void EnableComponent(VertexComponent component, ComponentType type, std::size_t offset);
VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components);
VertexDeclaration(const VertexDeclaration&) = delete;
VertexDeclaration(VertexDeclaration&&) noexcept = default;
~VertexDeclaration() = default;
void GetComponent(VertexComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const;
bool HasComponent(VertexComponent component) const;
template<typename T> bool HasComponentOfType(VertexComponent component) const;
std::size_t GetStride() const;
inline const Component* FindComponent(VertexComponent vertexComponent, std::size_t componentIndex) const;
void SetStride(std::size_t stride);
template<typename T> const Component* GetComponentByType(VertexComponent vertexComponent, std::size_t componentIndex = 0) const;
VertexDeclaration& operator=(const VertexDeclaration& declaration);
inline const Component& GetComponent(std::size_t componentIndex) const;
inline std::size_t GetComponentCount() const;
inline VertexInputRate GetInputRate() const;
inline std::size_t GetStride() const;
static VertexDeclaration* Get(VertexLayout layout);
inline bool HasComponent(VertexComponent component, std::size_t componentIndex = 0) const;
template<typename T> bool HasComponentOfType(VertexComponent vertexComponent, std::size_t componentIndex = 0) const;
VertexDeclaration& operator=(const VertexDeclaration&) = delete;
VertexDeclaration& operator=(VertexDeclaration&&) noexcept = default;
static const VertexDeclarationRef& Get(VertexLayout layout);
static bool IsTypeSupported(ComponentType type);
template<typename... Args> static VertexDeclarationRef New(Args&&... args);
// Signals:
NazaraSignal(OnVertexDeclarationRelease, const VertexDeclaration* /*vertexDeclaration*/);
struct Component
{
ComponentType type;
VertexComponent component;
std::size_t componentIndex;
std::size_t offset;
};
struct ComponentEntry
{
VertexComponent component;
ComponentType type;
std::size_t componentIndex;
};
private:
static bool Initialize();
static void Uninitialize();
struct Component
{
ComponentType type; // Le type de donnée
bool enabled = false; // Ce composant est-il activé ?/
std::size_t offset; // La position, en octets, de la première donnée
/*
** -Lynix:
** Il serait aussi possible de préciser le stride de façon indépendante, ce que je ne permets pas
** pour décomplexifier l'interface en enlevant quelque chose que je juge inutile.
** Si vous pensez que ça peut être utile, n'hésitez pas à me le faire savoir !
** PS: Même cas pour le diviseur (instancing)
*/
};
std::array<Component, VertexComponent_Max + 1> m_components;
std::vector<Component> m_components;
std::size_t m_stride;
VertexInputRate m_inputRate;
static std::array<VertexDeclaration, VertexLayout_Max + 1> s_declarations;
static std::array<VertexDeclarationRef, VertexLayout_Max + 1> s_declarations;
static VertexDeclarationLibrary::LibraryMap s_library;
};
}

View File

@ -1,32 +1,87 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/Algorithm.hpp>
#include <cassert>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
#include <Nazara/Utility/Algorithm.hpp>
namespace Nz
{
inline auto Nz::VertexDeclaration::FindComponent(VertexComponent vertexComponent, std::size_t componentIndex) const -> const Component*
{
assert(componentIndex == 0 || vertexComponent == VertexComponent_Userdata);
for (const Component& component : m_components)
{
if (component.component == vertexComponent && component.componentIndex == componentIndex)
return &component;
}
return nullptr;
}
inline auto VertexDeclaration::GetComponent(std::size_t componentIndex) const -> const Component&
{
return m_components[componentIndex];
}
inline std::size_t VertexDeclaration::GetComponentCount() const
{
return m_components.size();
}
inline VertexInputRate VertexDeclaration::GetInputRate() const
{
return m_inputRate;
}
inline std::size_t VertexDeclaration::GetStride() const
{
return m_stride;
}
inline bool VertexDeclaration::HasComponent(VertexComponent component, std::size_t componentIndex) const
{
return FindComponent(component, componentIndex) != nullptr;
}
template<typename T>
auto VertexDeclaration::GetComponentByType(VertexComponent vertexComponent, std::size_t componentIndex) const -> const Component*
{
NazaraAssert(componentIndex == 0 || vertexComponent == VertexComponent_Userdata, "Only userdata vertex component can have component indexes");
if (const Component* component = FindComponent(vertexComponent, componentIndex))
{
if (GetComponentTypeOf<T>() == component->type)
return component;
}
return nullptr;
}
template<typename T>
bool VertexDeclaration::HasComponentOfType(VertexComponent vertexComponent, std::size_t componentIndex) const
{
return GetComponentByType<T>(vertexComponent, componentIndex) != nullptr;
}
const VertexDeclarationRef& VertexDeclaration::Get(VertexLayout layout)
{
NazaraAssert(layout <= VertexLayout_Max, "Vertex layout out of enum");
return s_declarations[layout];
}
template<typename... Args>
VertexDeclarationRef VertexDeclaration::New(Args&&... args)
{
std::unique_ptr<VertexDeclaration> object(new VertexDeclaration(std::forward<Args>(args)...));
std::unique_ptr<VertexDeclaration> object = std::make_unique<VertexDeclaration>(std::forward<Args>(args)...);
object->SetPersistent(false);
return object.release();
}
template<typename T>
bool VertexDeclaration::HasComponentOfType(VertexComponent component) const
{
bool enabled;
Nz::ComponentType type;
GetComponent(component, &enabled, &type, nullptr);
return enabled && GetComponentTypeOf<T>() == type;
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Loader.hpp>
@ -18,6 +19,7 @@ namespace Nz
inline VkPolygonMode ToVulkan(FaceFilling faceFilling);
inline VkPrimitiveTopology ToVulkan(PrimitiveMode primitiveMode);
inline VkCompareOp ToVulkan(RendererComparison comparison);
inline VkShaderStageFlagBits ToVulkan(ShaderStageType stageType);
inline VkStencilOp ToVulkan(StencilOperation stencilOp);
NAZARA_VULKANRENDERER_API String TranslateVulkanError(VkResult code);
}

View File

@ -70,6 +70,18 @@ namespace Nz
return VK_COMPARE_OP_NEVER;
}
VkShaderStageFlagBits ToVulkan(ShaderStageType stageType)
{
switch (stageType)
{
case ShaderStageType::Fragment: return VK_SHADER_STAGE_FRAGMENT_BIT;
case ShaderStageType::Vertex: return VK_SHADER_STAGE_VERTEX_BIT;
}
NazaraError("Unhandled ShaderStageType 0x" + String::Number(static_cast<std::size_t>(stageType), 16));
return {};
}
VkStencilOp ToVulkan(StencilOperation stencilOp)
{
switch (stencilOp)

View File

@ -23,19 +23,37 @@ namespace Nz
VulkanRenderPipeline(Vk::DeviceHandle device, RenderPipelineInfo pipelineInfo);
~VulkanRenderPipeline() = default;
static std::vector<VkPipelineColorBlendAttachmentState> BuildColorBlendAttachmentState(const RenderPipelineInfo& pipelineInfo);
static std::vector<VkPipelineColorBlendAttachmentState> BuildColorBlendAttachmentStateList(const RenderPipelineInfo& pipelineInfo);
static VkPipelineColorBlendStateCreateInfo BuildColorBlendInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState);
static VkPipelineDepthStencilStateCreateInfo BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo);
static VkPipelineDynamicStateCreateInfo BuildDynamicStateInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkDynamicState>& dynamicStates);
static std::vector<VkDynamicState> BuildDynamicStateList(const RenderPipelineInfo& pipelineInfo);
static VkPipelineInputAssemblyStateCreateInfo BuildInputAssemblyInfo(const RenderPipelineInfo& pipelineInfo);
static VkPipelineRasterizationStateCreateInfo BuildRasterizationInfo(const RenderPipelineInfo& pipelineInfo);
static VkPipelineViewportStateCreateInfo BuildViewportInfo(const RenderPipelineInfo& pipelineInfo);
static VkStencilOpState BuildStencilOp(const RenderPipelineInfo& pipelineInfo, bool front);
static std::vector<VkPipelineShaderStageCreateInfo> BuildShaderStageInfo(const RenderPipelineInfo& pipelineInfo);
static CreateInfo BuildCreateInfo(const RenderPipelineInfo& pipelineInfo);
struct CreateInfo
{
struct StateData
{
VkPipelineVertexInputStateCreateInfo vertexInputState;
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState;
VkPipelineViewportStateCreateInfo viewportState;
VkPipelineRasterizationStateCreateInfo rasterizationState;
VkPipelineDepthStencilStateCreateInfo depthStencilState;
VkPipelineColorBlendStateCreateInfo colorBlendState;
VkPipelineDynamicStateCreateInfo dynamicState;
};
std::vector<VkPipelineColorBlendAttachmentState> colorBlendAttachmentState;
std::vector<VkDynamicState> dynamicStates;
std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
VkGraphicsPipelineCreateInfo createInfo;
std::unique_ptr<StateData> stateData;
VkGraphicsPipelineCreateInfo pipelineInfo;
};
private:

View File

@ -26,6 +26,7 @@ namespace Nz
bool Create(const Vk::DeviceHandle& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize);
inline const Vk::ShaderModule& GetHandle() const;
inline ShaderStageType GetStageType() const;
VulkanShaderStage& operator=(const VulkanShaderStage&) = delete;
VulkanShaderStage& operator=(VulkanShaderStage&&) noexcept = default;

View File

@ -11,6 +11,11 @@ namespace Nz
{
return m_shaderModule;
}
inline ShaderStageType VulkanShaderStage::GetStageType() const
{
return m_stage;
}
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>

View File

@ -211,7 +211,7 @@ namespace Nz
std::size_t Utility::ComponentStride[ComponentType_Max+1] =
{
4*sizeof(UInt8), // ComponentType_Color
4*sizeof(UInt8), // ComponentType_Color
1*sizeof(double), // ComponentType_Double1
2*sizeof(double), // ComponentType_Double2
3*sizeof(double), // ComponentType_Double3
@ -220,10 +220,10 @@ namespace Nz
2*sizeof(float), // ComponentType_Float2
3*sizeof(float), // ComponentType_Float3
4*sizeof(float), // ComponentType_Float4
1*sizeof(UInt32), // ComponentType_Int1
2*sizeof(UInt32), // ComponentType_Int2
3*sizeof(UInt32), // ComponentType_Int3
4*sizeof(UInt32), // ComponentType_Int4
1*sizeof(UInt32), // ComponentType_Int1
2*sizeof(UInt32), // ComponentType_Int2
3*sizeof(UInt32), // ComponentType_Int3
4*sizeof(UInt32), // ComponentType_Int4
4*sizeof(float) // ComponentType_Quaternion
};

View File

@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@ -14,144 +14,27 @@
namespace Nz
{
VertexDeclaration::VertexDeclaration() :
m_stride(0)
VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) :
m_inputRate(inputRate)
{
}
std::size_t offset = 0;
VertexDeclaration::VertexDeclaration(const VertexDeclaration& declaration) :
RefCounted(),
m_components(declaration.m_components),
m_stride(declaration.m_stride)
{
}
VertexDeclaration::~VertexDeclaration()
{
OnVertexDeclarationRelease(this);
}
void VertexDeclaration::DisableComponent(VertexComponent component)
{
#ifdef NAZARA_DEBUG
if (component > VertexComponent_Max)
m_components.reserve(components.size());
for (const ComponentEntry& entry : components)
{
NazaraError("Vertex component out of enum");
return;
}
#endif
auto& component = m_components.emplace_back();
component.component = entry.component;
component.componentIndex = entry.componentIndex;
component.offset = offset;
component.type = entry.type;
#if NAZARA_UTILITY_SAFE
if (component == VertexComponent_Unused)
{
NazaraError("Cannot disable \"unused\" component");
return;
}
#endif
NazaraAssert(IsTypeSupported(component.type), "Component type 0x" + String::Number(component.type, 16) + " is not supported by vertex declarations");
NazaraAssert(component.componentIndex == 0 || component.component == VertexComponent_Userdata, "Only userdata components can have non-zero component indexes");
Component& vertexComponent = m_components[component];
if (vertexComponent.enabled)
{
vertexComponent.enabled = false;
m_stride -= Utility::ComponentStride[vertexComponent.type];
}
}
void VertexDeclaration::EnableComponent(VertexComponent component, ComponentType type, std::size_t offset)
{
#ifdef NAZARA_DEBUG
if (component > VertexComponent_Max)
{
NazaraError("Vertex component out of enum");
return;
}
#endif
#if NAZARA_UTILITY_SAFE
if (!IsTypeSupported(type))
{
NazaraError("Component type 0x" + String::Number(type, 16) + " is not supported by vertex declarations");
return;
}
#endif
if (component != VertexComponent_Unused)
{
Component& vertexComponent = m_components[component];
if (vertexComponent.enabled)
m_stride -= Utility::ComponentStride[vertexComponent.type];
else
vertexComponent.enabled = true;
vertexComponent.offset = offset;
vertexComponent.type = type;
offset += Utility::ComponentStride[component.type];
}
m_stride += Utility::ComponentStride[type];
}
void VertexDeclaration::GetComponent(VertexComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const
{
#ifdef NAZARA_DEBUG
if (component > VertexComponent_Max)
{
NazaraError("Vertex component out of enum");
return;
}
#endif
#if NAZARA_UTILITY_SAFE
if (component == VertexComponent_Unused)
{
NazaraError("Cannot get \"unused\" component");
return;
}
#endif
const Component& vertexComponent = m_components[component];
if (enabled)
*enabled = vertexComponent.enabled;
if (type)
*type = vertexComponent.type;
if (offset)
*offset = vertexComponent.offset;
}
bool VertexDeclaration::HasComponent(VertexComponent component) const
{
bool enabled;
GetComponent(component, &enabled, nullptr, nullptr);
return enabled;
}
std::size_t VertexDeclaration::GetStride() const
{
return m_stride;
}
void VertexDeclaration::SetStride(std::size_t stride)
{
m_stride = stride;
}
VertexDeclaration& VertexDeclaration::operator=(const VertexDeclaration& declaration)
{
m_components = declaration.m_components;
m_stride = declaration.m_stride;
return *this;
}
VertexDeclaration* VertexDeclaration::Get(VertexLayout layout)
{
NazaraAssert(layout <= VertexLayout_Max, "Vertex layout out of enum");
return &s_declarations[layout];
m_stride = offset;
}
bool VertexDeclaration::IsTypeSupported(ComponentType type)
@ -193,22 +76,37 @@ namespace Nz
{
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowException);
// Layout : Type
VertexDeclaration* declaration;
auto NewDeclaration = [](VertexInputRate inputRate, std::initializer_list<ComponentEntry> components)
{
return New(inputRate, std::move(components));
};
// VertexLayout_XY : VertexStruct_XY
declaration = &s_declarations[VertexLayout_XY];
declaration->EnableComponent(VertexComponent_Position, ComponentType_Float2, NazaraOffsetOf(VertexStruct_XY, position));
s_declarations[VertexLayout_XY] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float2,
0
}
});
NazaraAssert(declaration->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout_XY");
NazaraAssert(s_declarations[VertexLayout_XY]->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout_XY");
// VertexLayout_XY_Color : VertexStruct_XY_Color
declaration = &s_declarations[VertexLayout_XY_Color];
declaration->EnableComponent(VertexComponent_Position, ComponentType_Float2, NazaraOffsetOf(VertexStruct_XY_Color, position));
declaration->EnableComponent(VertexComponent_Color, ComponentType_Color, NazaraOffsetOf(VertexStruct_XY_Color, color));
NazaraAssert(declaration->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout_XY_Color");
s_declarations[VertexLayout_XY_Color] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float2,
0
},
{
VertexComponent_Color,
ComponentType_Color,
0
},
});
NazaraAssert(s_declarations[VertexLayout_XY_Color]->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout_XY_Color");
/*
// VertexLayout_XY_UV : VertexStruct_XY_UV
declaration = &s_declarations[VertexLayout_XY_UV];
declaration->EnableComponent(VertexComponent_Position, ComponentType_Float2, NazaraOffsetOf(VertexStruct_XY_UV, position));
@ -287,7 +185,7 @@ namespace Nz
declaration->EnableComponent(VertexComponent_InstanceData2, ComponentType_Float4, NazaraOffsetOf(Matrix4f, m31));
declaration->EnableComponent(VertexComponent_InstanceData3, ComponentType_Float4, NazaraOffsetOf(Matrix4f, m41));
NazaraAssert(declaration->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout_Matrix4");
NazaraAssert(declaration->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout_Matrix4");*/
}
catch (const std::exception& e)
{
@ -301,8 +199,10 @@ namespace Nz
void VertexDeclaration::Uninitialize()
{
VertexDeclarationLibrary::Uninitialize();
s_declarations.fill(nullptr);
}
std::array<VertexDeclaration, VertexLayout_Max + 1> VertexDeclaration::s_declarations;
std::array<VertexDeclarationRef, VertexLayout_Max + 1> VertexDeclaration::s_declarations;
VertexDeclarationLibrary::LibraryMap VertexDeclaration::s_library;
}

View File

@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/VulkanRenderPipeline.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/VulkanRenderer/VulkanShaderStage.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <cassert>
#include <Nazara/VulkanRenderer/Debug.hpp>
@ -16,11 +17,13 @@ namespace Nz
{
}
/*VkPipelineColorBlendAttachmentState VulkanRenderPipeline::BuildColorBlendAttachmentState(const RenderPipelineInfo& pipelineInfo)
std::vector<VkPipelineColorBlendAttachmentState> VulkanRenderPipeline::BuildColorBlendAttachmentStateList(const RenderPipelineInfo& pipelineInfo)
{
VkPipelineColorBlendAttachmentState colorBlendStates;
colorBlendStates.blendEnable = pipelineInfo.blending;
colorBlendStates.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; //< TODO
std::vector<VkPipelineColorBlendAttachmentState> colorBlendStates;
VkPipelineColorBlendAttachmentState colorBlendState = colorBlendStates.emplace_back();
colorBlendState.blendEnable = pipelineInfo.blending;
colorBlendState.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; //< TODO
if (pipelineInfo.blending)
{
@ -29,18 +32,29 @@ namespace Nz
{
blendState.dstAlphaBlendFactor
}*/
/*}
}
else
{
colorBlendStates.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendStates.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendStates.colorBlendOp = VK_BLEND_OP_ADD;
colorBlendStates.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendStates.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendStates.alphaBlendOp = VK_BLEND_OP_ADD;
colorBlendState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendState.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendState.colorBlendOp = VK_BLEND_OP_ADD;
colorBlendState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendState.alphaBlendOp = VK_BLEND_OP_ADD;
}
return colorBlendStates;
}*/
}
VkPipelineColorBlendStateCreateInfo VulkanRenderPipeline::BuildColorBlendInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState)
{
VkPipelineColorBlendStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
createInfo.attachmentCount = std::uint32_t(attachmentState.size());
createInfo.pAttachments = attachmentState.data();
return createInfo;
}
VkPipelineDepthStencilStateCreateInfo VulkanRenderPipeline::BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo)
{
@ -56,6 +70,21 @@ namespace Nz
return createInfo;
}
VkPipelineDynamicStateCreateInfo VulkanRenderPipeline::BuildDynamicStateInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkDynamicState>& dynamicStates)
{
VkPipelineDynamicStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
createInfo.dynamicStateCount = std::uint32_t(dynamicStates.size());
createInfo.pDynamicStates = dynamicStates.data();
return createInfo;
}
std::vector<VkDynamicState> VulkanRenderPipeline::BuildDynamicStateList(const RenderPipelineInfo& pipelineInfo)
{
return { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
}
VkPipelineInputAssemblyStateCreateInfo VulkanRenderPipeline::BuildInputAssemblyInfo(const RenderPipelineInfo& pipelineInfo)
{
VkPipelineInputAssemblyStateCreateInfo createInfo = {};
@ -77,6 +106,15 @@ namespace Nz
return createInfo;
}
VkPipelineViewportStateCreateInfo VulkanRenderPipeline::BuildViewportInfo(const RenderPipelineInfo& pipelineInfo)
{
VkPipelineViewportStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
createInfo.scissorCount = createInfo.viewportCount = 1; //< TODO
return createInfo;
}
VkStencilOpState VulkanRenderPipeline::BuildStencilOp(const RenderPipelineInfo& pipelineInfo, bool front)
{
const auto& pipelineStencil = (front) ? pipelineInfo.stencilFront : pipelineInfo.stencilBack;
@ -99,10 +137,41 @@ namespace Nz
for (auto&& stagePtr : pipelineInfo.shaderStages)
{
Nz::VulkanShaderStage& vulkanStage = *static_cast<Nz::VulkanShaderStage*>(stagePtr.get());
VkPipelineShaderStageCreateInfo& createInfo = shaderStageCreateInfos.emplace_back();
//createInfo.
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
createInfo.module = vulkanStage.GetHandle();
createInfo.pName = "main";
createInfo.stage = ToVulkan(vulkanStage.GetStageType());
}
return shaderStageCreateInfos;
}
auto VulkanRenderPipeline::BuildCreateInfo(const RenderPipelineInfo& pipelineInfo) -> CreateInfo
{
CreateInfo createInfo = {};
createInfo.stateData = std::make_unique<CreateInfo::StateData>();
createInfo.colorBlendAttachmentState = BuildColorBlendAttachmentStateList(pipelineInfo);
createInfo.dynamicStates = BuildDynamicStateList(pipelineInfo);
createInfo.shaderStages = BuildShaderStageInfo(pipelineInfo);
createInfo.stateData->colorBlendState = BuildColorBlendInfo(pipelineInfo, createInfo.colorBlendAttachmentState);
createInfo.stateData->depthStencilState = BuildDepthStencilInfo(pipelineInfo);
createInfo.stateData->dynamicState = BuildDynamicStateInfo(pipelineInfo, createInfo.dynamicStates);
createInfo.stateData->inputAssemblyState = BuildInputAssemblyInfo(pipelineInfo);
createInfo.stateData->rasterizationState = BuildRasterizationInfo(pipelineInfo);
createInfo.stateData->viewportState = BuildViewportInfo(pipelineInfo);
createInfo.pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
createInfo.pipelineInfo.stageCount = std::uint32_t(createInfo.shaderStages.size());
createInfo.pipelineInfo.pStages = createInfo.shaderStages.data();
createInfo.pipelineInfo.pColorBlendState = createInfo.colorBlendAttachmentState.data();
createInfo.pipelineInfo.
return createInfo;
}
}