Some work on render pipelines

This commit is contained in:
Lynix 2020-02-27 23:12:29 +01:00
parent 2944d73586
commit 798425ce10
7 changed files with 104 additions and 30 deletions

View File

@ -347,39 +347,19 @@ int main()
attributeDescription.data() // const VkVertexInputAttributeDescription *pVertexAttributeDescriptions attributeDescription.data() // const VkVertexInputAttributeDescription *pVertexAttributeDescriptions
}; };
VkPipelineInputAssemblyStateCreateInfo input_assembly_state_create_info = {
VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType
nullptr, // const void *pNext
0, // VkPipelineInputAssemblyStateCreateFlags flags
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology
VK_FALSE // VkBool32 primitiveRestartEnable
};
VkPipelineViewportStateCreateInfo viewport_state_create_info = { VkPipelineViewportStateCreateInfo viewport_state_create_info = {
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType
nullptr, // const void *pNext nullptr, // const void *pNext
0, // VkPipelineViewportStateCreateFlags flags 0, // VkPipelineViewportStateCreateFlags flags
1, // uint32_t viewportCount 1, // uint32_t viewportCount
nullptr, // const VkViewport *pViewports nullptr, // const VkViewport *pViewports
1, // uint32_t scissorCount 1, // uint32_t scissorCount
nullptr // const VkRect2D *pScissors nullptr // const VkRect2D *pScissors
}; };
VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = { VkPipelineInputAssemblyStateCreateInfo input_assembly_state_create_info = Nz::VulkanRenderPipeline::BuildInputAssemblyInfo(pipelineInfo);
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = Nz::VulkanRenderPipeline::BuildRasterizationInfo(pipelineInfo);
nullptr, // const void *pNext VkPipelineDepthStencilStateCreateInfo depthStencilInfo = Nz::VulkanRenderPipeline::BuildDepthStencilInfo(pipelineInfo);
0, // VkPipelineRasterizationStateCreateFlags flags
VK_FALSE, // VkBool32 depthClampEnable
VK_FALSE, // VkBool32 rasterizerDiscardEnable
VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode
VK_CULL_MODE_NONE, // VkCullModeFlags cullMode
VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace
VK_FALSE, // VkBool32 depthBiasEnable
0.0f, // float depthBiasConstantFactor
0.0f, // float depthBiasClamp
0.0f, // float depthBiasSlopeFactor
1.0f // float lineWidth
};
VkPipelineMultisampleStateCreateInfo multisample_state_create_info = { VkPipelineMultisampleStateCreateInfo multisample_state_create_info = {
VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType
@ -429,8 +409,6 @@ int main()
dynamicStates.data() // const VkDynamicState* pDynamicStates; dynamicStates.data() // const VkDynamicState* pDynamicStates;
}; };
VkPipelineDepthStencilStateCreateInfo depthStencilInfo = Nz::VulkanRenderPipeline::BuildDepthStencilInfo(pipelineInfo);
VkGraphicsPipelineCreateInfo pipeline_create_info = { VkGraphicsPipelineCreateInfo pipeline_create_info = {
VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType
nullptr, // const void *pNext nullptr, // const void *pNext

View File

@ -19,6 +19,7 @@ namespace Nz
FaceFilling faceFilling = FaceFilling_Fill; FaceFilling faceFilling = FaceFilling_Fill;
FaceSide cullingSide = FaceSide_Back; FaceSide cullingSide = FaceSide_Back;
RendererComparison depthCompare = RendererComparison_Less; RendererComparison depthCompare = RendererComparison_Less;
PrimitiveMode primitiveMode = PrimitiveMode_TriangleList;
struct struct
{ {

View File

@ -123,6 +123,8 @@ namespace Nz
enum FaceSide enum FaceSide
{ {
FaceSide_None,
FaceSide_Back, FaceSide_Back,
FaceSide_Front, FaceSide_Front,
FaceSide_FrontAndBack, FaceSide_FrontAndBack,

View File

@ -14,6 +14,9 @@
namespace Nz namespace Nz
{ {
inline VkCullModeFlagBits ToVulkan(FaceSide faceSide);
inline VkPolygonMode ToVulkan(FaceFilling faceFilling);
inline VkPrimitiveTopology ToVulkan(PrimitiveMode primitiveMode);
inline VkCompareOp ToVulkan(RendererComparison comparison); inline VkCompareOp ToVulkan(RendererComparison comparison);
inline VkStencilOp ToVulkan(StencilOperation stencilOp); inline VkStencilOp ToVulkan(StencilOperation stencilOp);
NAZARA_VULKANRENDERER_API String TranslateVulkanError(VkResult code); NAZARA_VULKANRENDERER_API String TranslateVulkanError(VkResult code);

View File

@ -9,6 +9,49 @@
namespace Nz namespace Nz
{ {
VkCullModeFlagBits ToVulkan(FaceSide faceSide)
{
switch (faceSide)
{
case FaceSide_None: return VK_CULL_MODE_NONE;
case FaceSide_Back: return VK_CULL_MODE_BACK_BIT;
case FaceSide_Front: return VK_CULL_MODE_FRONT_BIT;
case FaceSide_FrontAndBack: return VK_CULL_MODE_FRONT_AND_BACK;
}
NazaraError("Unhandled FaceSide 0x" + String::Number(faceSide, 16));
return VK_CULL_MODE_BACK_BIT;
}
inline VkPolygonMode ToVulkan(FaceFilling faceFilling)
{
switch (faceFilling)
{
case FaceFilling_Fill: return VK_POLYGON_MODE_FILL;
case FaceFilling_Line: return VK_POLYGON_MODE_LINE;
case FaceFilling_Point: return VK_POLYGON_MODE_POINT;
}
NazaraError("Unhandled FaceFilling 0x" + String::Number(faceFilling, 16));
return VK_POLYGON_MODE_FILL;
}
VkPrimitiveTopology ToVulkan(PrimitiveMode primitiveMode)
{
switch (primitiveMode)
{
case PrimitiveMode_LineList: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
case PrimitiveMode_LineStrip: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
case PrimitiveMode_PointList: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
case PrimitiveMode_TriangleList: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
case PrimitiveMode_TriangleStrip: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
case PrimitiveMode_TriangleFan: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
}
NazaraError("Unhandled FaceFilling 0x" + String::Number(primitiveMode, 16));
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
}
inline VkCompareOp ToVulkan(RendererComparison comparison) inline VkCompareOp ToVulkan(RendererComparison comparison)
{ {
switch (comparison) switch (comparison)

View File

@ -20,7 +20,10 @@ namespace Nz
VulkanRenderPipeline(Vk::DeviceHandle device, RenderPipelineInfo pipelineInfo); VulkanRenderPipeline(Vk::DeviceHandle device, RenderPipelineInfo pipelineInfo);
~VulkanRenderPipeline() = default; ~VulkanRenderPipeline() = default;
static VkPipelineColorBlendAttachmentState BuildColorBlendState(const RenderPipelineInfo& pipelineInfo);
static VkPipelineDepthStencilStateCreateInfo BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo); static VkPipelineDepthStencilStateCreateInfo BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo);
static VkPipelineInputAssemblyStateCreateInfo BuildInputAssemblyInfo(const RenderPipelineInfo& pipelineInfo);
static VkPipelineRasterizationStateCreateInfo BuildRasterizationInfo(const RenderPipelineInfo& pipelineInfo);
static VkStencilOpState BuildStencilOp(const RenderPipelineInfo& pipelineInfo, bool front); static VkStencilOpState BuildStencilOp(const RenderPipelineInfo& pipelineInfo, bool front);
private: private:

View File

@ -16,16 +16,39 @@ namespace Nz
{ {
} }
VkPipelineColorBlendAttachmentState VulkanRenderPipeline::BuildColorBlendState(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
if (pipelineInfo.blending)
{
//TODO
/*switch (pipelineInfo.dstBlend)
{
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;
}
return colorBlendStates;
}
VkPipelineDepthStencilStateCreateInfo VulkanRenderPipeline::BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo) VkPipelineDepthStencilStateCreateInfo VulkanRenderPipeline::BuildDepthStencilInfo(const RenderPipelineInfo& pipelineInfo)
{ {
VkPipelineDepthStencilStateCreateInfo createInfo = {}; VkPipelineDepthStencilStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
createInfo.pNext = nullptr;
createInfo.flags = 0U;
createInfo.depthTestEnable = pipelineInfo.depthBuffer; createInfo.depthTestEnable = pipelineInfo.depthBuffer;
createInfo.depthWriteEnable = pipelineInfo.depthWrite; createInfo.depthWriteEnable = pipelineInfo.depthWrite;
createInfo.depthCompareOp = ToVulkan(pipelineInfo.depthCompare); createInfo.depthCompareOp = ToVulkan(pipelineInfo.depthCompare);
createInfo.depthBoundsTestEnable = VK_FALSE;
createInfo.stencilTestEnable = pipelineInfo.stencilTest; createInfo.stencilTestEnable = pipelineInfo.stencilTest;
createInfo.front = BuildStencilOp(pipelineInfo, true); createInfo.front = BuildStencilOp(pipelineInfo, true);
createInfo.back = BuildStencilOp(pipelineInfo, false); createInfo.back = BuildStencilOp(pipelineInfo, false);
@ -33,6 +56,27 @@ namespace Nz
return createInfo; return createInfo;
} }
VkPipelineInputAssemblyStateCreateInfo VulkanRenderPipeline::BuildInputAssemblyInfo(const RenderPipelineInfo& pipelineInfo)
{
VkPipelineInputAssemblyStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
createInfo.topology = ToVulkan(pipelineInfo.primitiveMode);
return createInfo;
}
VkPipelineRasterizationStateCreateInfo VulkanRenderPipeline::BuildRasterizationInfo(const RenderPipelineInfo& pipelineInfo)
{
VkPipelineRasterizationStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
createInfo.polygonMode = ToVulkan(pipelineInfo.faceFilling);
createInfo.cullMode = ToVulkan(pipelineInfo.cullingSide);
createInfo.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; //< TODO
createInfo.lineWidth = pipelineInfo.lineWidth;
return createInfo;
}
VkStencilOpState VulkanRenderPipeline::BuildStencilOp(const RenderPipelineInfo& pipelineInfo, bool front) VkStencilOpState VulkanRenderPipeline::BuildStencilOp(const RenderPipelineInfo& pipelineInfo, bool front)
{ {
const auto& pipelineStencil = (front) ? pipelineInfo.stencilFront : pipelineInfo.stencilBack; const auto& pipelineStencil = (front) ? pipelineInfo.stencilFront : pipelineInfo.stencilBack;