From 00e14ab6eafca3802d6184a7ce694e4749c36488 Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 2 Dec 2022 20:02:01 +0100 Subject: [PATCH] change shader container architecture --- src/GraphicsPipeline.hs | 27 ++++++++++++++++++++------- src/Init.hs | 4 ++-- src/Types.hs | 4 ++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/GraphicsPipeline.hs b/src/GraphicsPipeline.hs index 7d3c7b1..b2e6fa4 100644 --- a/src/GraphicsPipeline.hs +++ b/src/GraphicsPipeline.hs @@ -170,13 +170,26 @@ createGraphicsPipelines = do let pipelineStagesCreateInfos = V.fromList $ map Vk.SomeStruct - [ createShaderStageCreateInfo - Vk.SHADER_STAGE_VERTEX_BIT + ( maybe + [] + (\shader -> + [ createShaderStageCreateInfo + Vk.SHADER_STAGE_VERTEX_BIT + shader + ] + ) (containedVertexShader shaderContainer) - , createShaderStageCreateInfo - Vk.SHADER_STAGE_FRAGMENT_BIT + ++ + maybe + [] + (\shader -> + [ createShaderStageCreateInfo + Vk.SHADER_STAGE_FRAGMENT_BIT + shader + ] + ) (containedFragmentShader shaderContainer) - ] + ) dynamicStates = V.fromList [ Vk.DYNAMIC_STATE_VIEWPORT @@ -231,7 +244,7 @@ createGraphicsPipelines Just $ createVertexInputAssemblyStateCreateInfo VK.PRIMITIVE_TOPOLOGY_TRIANGLE_LIST , Vk.viewportState = Just $ Vk.SomeStruct pipelineViewportStateCreateInfo , Vk.rasterizationState = Just $ createRasterizationStateCreateInfo Vk.POLYGON_MODE_FILL - , Vk.multisampleState = Just $ createMultisampleStateCreateInfo + , Vk.multisampleState = Just createMultisampleStateCreateInfo , Vk.colorBlendState = Just $ Vk.SomeStruct pipelineColorBlendStateCreateInfo , Vk.dynamicState = Just pipelineDynamicStateCreateInfo , Vk.layout = pipelineLayout @@ -249,7 +262,7 @@ createGraphicsPipelines (V.replicate number (Vk.SomeStruct pipelineCreateInfo)) Nothing unless (result == Vk.SUCCESS) $ - error "createGraphicsPiepelines: Failed creating pipelines" + error "createGraphicsPipelines: Failed creating pipelines" return pipelines ) (\pipelines -> do diff --git a/src/Init.hs b/src/Init.hs index e710eb0..e782a68 100644 --- a/src/Init.hs +++ b/src/Init.hs @@ -90,8 +90,8 @@ initVulkan window = do rainbowFragmentShader <- loadShader vulkanLogicalDevice "shadersrc/rainbow.frag" "frag" renderPass <- createRenderPass vulkanLogicalDevice (Khr.format surfaceFormat) pipelineLayout <- createPipelineLayout vulkanLogicalDevice - let redContainer = ShaderContainer redVertexShader redFragmentShader - let rainbowContainer = ShaderContainer rainbowVertexShader rainbowFragmentShader + let redContainer = ShaderContainer (Just redVertexShader) (Just redFragmentShader) + let rainbowContainer = ShaderContainer (Just rainbowVertexShader) (Just rainbowFragmentShader) redPipelines <- createGraphicsPipelines vulkanLogicalDevice diff --git a/src/Types.hs b/src/Types.hs index 4edba10..46ffe25 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -10,8 +10,8 @@ import qualified Vulkan as Vk import qualified VulkanMemoryAllocator as VMA data ShaderContainer = ShaderContainer - { containedVertexShader :: Vk.ShaderModule - , containedFragmentShader :: Vk.ShaderModule + { containedVertexShader :: Maybe Vk.ShaderModule + , containedFragmentShader :: Maybe Vk.ShaderModule } deriving (Show)