Some work on render pipelines
This commit is contained in:
parent
2944d73586
commit
798425ce10
|
|
@ -347,14 +347,6 @@ int main()
|
|||
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 = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
|
|
@ -365,21 +357,9 @@ int main()
|
|||
nullptr // const VkRect2D *pScissors
|
||||
};
|
||||
|
||||
VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
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
|
||||
};
|
||||
VkPipelineInputAssemblyStateCreateInfo input_assembly_state_create_info = Nz::VulkanRenderPipeline::BuildInputAssemblyInfo(pipelineInfo);
|
||||
VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = Nz::VulkanRenderPipeline::BuildRasterizationInfo(pipelineInfo);
|
||||
VkPipelineDepthStencilStateCreateInfo depthStencilInfo = Nz::VulkanRenderPipeline::BuildDepthStencilInfo(pipelineInfo);
|
||||
|
||||
VkPipelineMultisampleStateCreateInfo multisample_state_create_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType
|
||||
|
|
@ -429,8 +409,6 @@ int main()
|
|||
dynamicStates.data() // const VkDynamicState* pDynamicStates;
|
||||
};
|
||||
|
||||
VkPipelineDepthStencilStateCreateInfo depthStencilInfo = Nz::VulkanRenderPipeline::BuildDepthStencilInfo(pipelineInfo);
|
||||
|
||||
VkGraphicsPipelineCreateInfo pipeline_create_info = {
|
||||
VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void *pNext
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace Nz
|
|||
FaceFilling faceFilling = FaceFilling_Fill;
|
||||
FaceSide cullingSide = FaceSide_Back;
|
||||
RendererComparison depthCompare = RendererComparison_Less;
|
||||
PrimitiveMode primitiveMode = PrimitiveMode_TriangleList;
|
||||
|
||||
struct
|
||||
{
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ namespace Nz
|
|||
|
||||
enum FaceSide
|
||||
{
|
||||
FaceSide_None,
|
||||
|
||||
FaceSide_Back,
|
||||
FaceSide_Front,
|
||||
FaceSide_FrontAndBack,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
inline VkCullModeFlagBits ToVulkan(FaceSide faceSide);
|
||||
inline VkPolygonMode ToVulkan(FaceFilling faceFilling);
|
||||
inline VkPrimitiveTopology ToVulkan(PrimitiveMode primitiveMode);
|
||||
inline VkCompareOp ToVulkan(RendererComparison comparison);
|
||||
inline VkStencilOp ToVulkan(StencilOperation stencilOp);
|
||||
NAZARA_VULKANRENDERER_API String TranslateVulkanError(VkResult code);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,49 @@
|
|||
|
||||
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)
|
||||
{
|
||||
switch (comparison)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@ namespace Nz
|
|||
VulkanRenderPipeline(Vk::DeviceHandle device, RenderPipelineInfo pipelineInfo);
|
||||
~VulkanRenderPipeline() = default;
|
||||
|
||||
static VkPipelineColorBlendAttachmentState BuildColorBlendState(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);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -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 createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||
createInfo.pNext = nullptr;
|
||||
createInfo.flags = 0U;
|
||||
createInfo.depthTestEnable = pipelineInfo.depthBuffer;
|
||||
createInfo.depthWriteEnable = pipelineInfo.depthWrite;
|
||||
createInfo.depthCompareOp = ToVulkan(pipelineInfo.depthCompare);
|
||||
createInfo.depthBoundsTestEnable = VK_FALSE;
|
||||
createInfo.stencilTestEnable = pipelineInfo.stencilTest;
|
||||
createInfo.front = BuildStencilOp(pipelineInfo, true);
|
||||
createInfo.back = BuildStencilOp(pipelineInfo, false);
|
||||
|
|
@ -33,6 +56,27 @@ namespace Nz
|
|||
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)
|
||||
{
|
||||
const auto& pipelineStencil = (front) ? pipelineInfo.stencilFront : pipelineInfo.stencilBack;
|
||||
|
|
|
|||
Loading…
Reference in New Issue