@@ -40,6 +40,8 @@ import qualified FIR.Pipeline
4040
4141import qualified Data.Linear.Alias as Alias
4242
43+ import qualified Data.IntMap.Strict as IM
44+
4345import Ghengin.Core.Render.Property
4446import Ghengin.Core.Shader.Pipeline ( ShaderPipeline )
4547import Data.Unique
@@ -58,7 +60,7 @@ data RenderPipeline info tys where
5860
5961 RenderPipeline :: RendererPipeline Graphics -- ^ The graphics pipeline underlying this render pipeline. Can a graphics pipeline be shared amongst Render Pipelines such that this field needs to be ref counted?
6062 ⊸ Alias RenderPass -- ^ A reference counted reference to a render pass, since we might share render passes amongst pipelines
61- ⊸ (Alias DescriptorSet , Alias ResourceMap , Alias DescriptorPool ) -- A descriptor set per frame; currently we are screwing up drawing multiple frames. Descriptor Set for the render properties.
63+ ⊸ (Alias DescriptorSet , Alias ResourceMap , Ur DescriptorSetMap , Alias DescriptorPool ) -- A descriptor set per frame; currently we are screwing up drawing multiple frames. Descriptor Set for the render properties.
6264 ⊸ ShaderPipeline info
6365 -> Unique
6466 -> RenderPipeline info '[]
@@ -77,9 +79,9 @@ data SomePipeline = ∀ α β. SomePipeline (RenderPipeline α β)
7779-- Shader pipeline and buffers are only be created once and reused across
7880-- render packets that use the same one (Note that render packets store
7981-- references to these things).
80- -- TODO: Currently we assume all our descriptor sets are Uniform buffers and
81- -- our buffers too but eventually Uniform will be just a constructor of a more
82- -- general Buffer and we should select the correct type of buffer individually.
82+ -- TODO: Currently we assume all our descriptor sets are Uniform or Storage buffers
83+ -- and our buffers too but eventually Uniform & Storage will be just a constructor of
84+ -- a more general Buffer and we should select the correct type of buffer individually.
8385makeRenderPipeline :: forall τ info tops descs strides
8486 . ( PipelineConstraints info tops descs strides
8587 , CompatiblePipeline τ info
@@ -105,7 +107,7 @@ makeRenderPipelineWith gps renderPass shaderPipeline props0 = Linear.do
105107 -- Create the descriptor sets and graphics pipeline based on the shader
106108 -- pipeline
107109 --
108- -- (1) Create the uniform buffers and the mapped memory
110+ -- (1) Create the uniform/storage buffers and the mapped memory
109111 -- (2) Create the descriptor sets from the descriptor set layout
110112 -- (3) Update the descriptor sets with the buffers information
111113 --
@@ -122,8 +124,10 @@ makeRenderPipelineWith gps renderPass shaderPipeline props0 = Linear.do
122124 -- properties.
123125 -- Each Material and Mesh then allocates additional descriptor sets from this pool on creation.
124126
127+ (Ur descSetMap) <- pure $ createDescriptorSetBindingsMap shaderPipeline
128+
125129 logT " Creating descriptor pool"
126- dpool0 <- createDescriptorPool shaderPipeline
130+ dpool0 <- createDescriptorPool descSetMap
127131
128132 -- Allocate descriptor set #0 to be used by this render pipeline's
129133 -- render properties
@@ -135,7 +139,7 @@ makeRenderPipelineWith gps renderPass shaderPipeline props0 = Linear.do
135139
136140 -- Make the resource map for this render pipeline using the dummyRP
137141 logT " Making resources"
138- (resources0, props1) <- makeResources props0
142+ (resources0, props1) <- makeResources ((fromMaybe ( error " DescriptorSetMap doesn't contain shader pipeline descriptors. " ) ( IM. lookup 0 descSetMap))) props0
139143
140144 -- Bind resources to descriptor set
141145 logT " Updating descriptor set"
@@ -161,7 +165,7 @@ makeRenderPipelineWith gps renderPass shaderPipeline props0 = Linear.do
161165 -- Make the unique identifier for this pipeline reference
162166 Ur uniq <- liftSystemIOU newUnique
163167
164- pure $ mkRP (RenderPipeline pipeline renderPass (dset2, resources2, dpool5) shaderPipeline uniq) props1
168+ pure $ mkRP (RenderPipeline pipeline renderPass (dset2, resources2, ( Ur descSetMap), dpool5) shaderPipeline uniq) props1
165169 where
166170 mkRP :: ∀ info (b :: [Type ]). RenderPipeline info '[] ⊸ PropertyBindings b ⊸ RenderPipeline info b
167171 mkRP x GHNil = x
@@ -182,9 +186,9 @@ instance HasProperties (RenderPipeline π) where
182186
183187 descriptors :: RenderPipeline π α ⊸ Renderer (Alias DescriptorSet , Alias ResourceMap , RenderPipeline π α )
184188 descriptors = \ case
185- RenderPipeline gpip rpass (dset0, rmap0, dpool) spip uq -> Linear. do
189+ RenderPipeline gpip rpass (dset0, rmap0, dmap, dpool) spip uq -> Linear. do
186190 ((dset1, rmap1), (dset2, rmap2)) <- Alias. share (dset0, rmap0)
187- pure (dset1, rmap1, RenderPipeline gpip rpass (dset2, rmap2, dpool) spip uq)
191+ pure (dset1, rmap1, RenderPipeline gpip rpass (dset2, rmap2, dmap, dpool) spip uq)
188192 RenderProperty p xs -> Linear. do
189193 (dset, rmap, mat') <- descriptors xs
190194 pure (dset, rmap, RenderProperty p mat')
@@ -197,7 +201,7 @@ destroyRenderPipeline :: RenderPipeline α τ ⊸ Renderer ()
197201destroyRenderPipeline (RenderProperty b rp) = enterD " Destroying render pipeline" Linear. do
198202 Alias. forget b
199203 destroyRenderPipeline rp
200- destroyRenderPipeline (RenderPipeline gp rp (a,b,c) _ _) = enterD " Destroying render pipeline" Linear. do
204+ destroyRenderPipeline (RenderPipeline gp rp (a,b,( Ur _), c) _ _) = enterD " Destroying render pipeline" Linear. do
201205 Alias. forget a >> Alias. forget b >> Alias. forget c
202206 Alias. forget rp
203207 destroyPipeline gp
0 commit comments