change shader container architecture

This commit is contained in:
nek0 2022-12-02 20:02:01 +01:00
parent 2219355483
commit 00e14ab6ea
3 changed files with 24 additions and 11 deletions

View file

@ -170,13 +170,26 @@ createGraphicsPipelines
= do = do
let pipelineStagesCreateInfos = let pipelineStagesCreateInfos =
V.fromList $ map Vk.SomeStruct V.fromList $ map Vk.SomeStruct
( maybe
[]
(\shader ->
[ createShaderStageCreateInfo [ createShaderStageCreateInfo
Vk.SHADER_STAGE_VERTEX_BIT Vk.SHADER_STAGE_VERTEX_BIT
(containedVertexShader shaderContainer) shader
, createShaderStageCreateInfo
Vk.SHADER_STAGE_FRAGMENT_BIT
(containedFragmentShader shaderContainer)
] ]
)
(containedVertexShader shaderContainer)
++
maybe
[]
(\shader ->
[ createShaderStageCreateInfo
Vk.SHADER_STAGE_FRAGMENT_BIT
shader
]
)
(containedFragmentShader shaderContainer)
)
dynamicStates = dynamicStates =
V.fromList V.fromList
[ Vk.DYNAMIC_STATE_VIEWPORT [ Vk.DYNAMIC_STATE_VIEWPORT
@ -231,7 +244,7 @@ createGraphicsPipelines
Just $ createVertexInputAssemblyStateCreateInfo VK.PRIMITIVE_TOPOLOGY_TRIANGLE_LIST Just $ createVertexInputAssemblyStateCreateInfo VK.PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
, Vk.viewportState = Just $ Vk.SomeStruct pipelineViewportStateCreateInfo , Vk.viewportState = Just $ Vk.SomeStruct pipelineViewportStateCreateInfo
, Vk.rasterizationState = Just $ createRasterizationStateCreateInfo Vk.POLYGON_MODE_FILL , Vk.rasterizationState = Just $ createRasterizationStateCreateInfo Vk.POLYGON_MODE_FILL
, Vk.multisampleState = Just $ createMultisampleStateCreateInfo , Vk.multisampleState = Just createMultisampleStateCreateInfo
, Vk.colorBlendState = Just $ Vk.SomeStruct pipelineColorBlendStateCreateInfo , Vk.colorBlendState = Just $ Vk.SomeStruct pipelineColorBlendStateCreateInfo
, Vk.dynamicState = Just pipelineDynamicStateCreateInfo , Vk.dynamicState = Just pipelineDynamicStateCreateInfo
, Vk.layout = pipelineLayout , Vk.layout = pipelineLayout
@ -249,7 +262,7 @@ createGraphicsPipelines
(V.replicate number (Vk.SomeStruct pipelineCreateInfo)) (V.replicate number (Vk.SomeStruct pipelineCreateInfo))
Nothing Nothing
unless (result == Vk.SUCCESS) $ unless (result == Vk.SUCCESS) $
error "createGraphicsPiepelines: Failed creating pipelines" error "createGraphicsPipelines: Failed creating pipelines"
return pipelines return pipelines
) )
(\pipelines -> do (\pipelines -> do

View file

@ -90,8 +90,8 @@ initVulkan window = do
rainbowFragmentShader <- loadShader vulkanLogicalDevice "shadersrc/rainbow.frag" "frag" rainbowFragmentShader <- loadShader vulkanLogicalDevice "shadersrc/rainbow.frag" "frag"
renderPass <- createRenderPass vulkanLogicalDevice (Khr.format surfaceFormat) renderPass <- createRenderPass vulkanLogicalDevice (Khr.format surfaceFormat)
pipelineLayout <- createPipelineLayout vulkanLogicalDevice pipelineLayout <- createPipelineLayout vulkanLogicalDevice
let redContainer = ShaderContainer redVertexShader redFragmentShader let redContainer = ShaderContainer (Just redVertexShader) (Just redFragmentShader)
let rainbowContainer = ShaderContainer rainbowVertexShader rainbowFragmentShader let rainbowContainer = ShaderContainer (Just rainbowVertexShader) (Just rainbowFragmentShader)
redPipelines <- redPipelines <-
createGraphicsPipelines createGraphicsPipelines
vulkanLogicalDevice vulkanLogicalDevice

View file

@ -10,8 +10,8 @@ import qualified Vulkan as Vk
import qualified VulkanMemoryAllocator as VMA import qualified VulkanMemoryAllocator as VMA
data ShaderContainer = ShaderContainer data ShaderContainer = ShaderContainer
{ containedVertexShader :: Vk.ShaderModule { containedVertexShader :: Maybe Vk.ShaderModule
, containedFragmentShader :: Vk.ShaderModule , containedFragmentShader :: Maybe Vk.ShaderModule
} }
deriving (Show) deriving (Show)