Esempio n. 1
0
 public override void TransitionToFinalLayout(VkCommandBuffer cb)
 {
     foreach (FramebufferAttachment ca in ColorTargets)
     {
         VkTexture vkTex = Util.AssertSubtype <Texture, VkTexture>(ca.Target);
         vkTex.SetImageLayout(ca.MipLevel, ca.ArrayLayer, VkImageLayout.ColorAttachmentOptimal);
         if ((vkTex.Usage & TextureUsage.Sampled) != 0)
         {
             vkTex.TransitionImageLayout(
                 cb,
                 ca.MipLevel, 1,
                 ca.ArrayLayer, 1,
                 VkImageLayout.ShaderReadOnlyOptimal);
         }
     }
     if (DepthTarget != null)
     {
         VkTexture vkTex = Util.AssertSubtype <Texture, VkTexture>(DepthTarget.Value.Target);
         vkTex.SetImageLayout(
             DepthTarget.Value.MipLevel,
             DepthTarget.Value.ArrayLayer,
             VkImageLayout.DepthStencilAttachmentOptimal);
         if ((vkTex.Usage & TextureUsage.Sampled) != 0)
         {
             vkTex.TransitionImageLayout(
                 cb,
                 DepthTarget.Value.MipLevel, 1,
                 DepthTarget.Value.ArrayLayer, 1,
                 VkImageLayout.ShaderReadOnlyOptimal);
         }
     }
 }
Esempio n. 2
0
 public override void TransitionToIntermediateLayout(VkCommandBuffer cb)
 {
     foreach (FramebufferAttachment ca in ColorTargets)
     {
         VkTexture vkTex = Util.AssertSubtype <Texture, VkTexture>(ca.Target);
         vkTex.SetImageLayout(0, ca.ArrayLayer, VkImageLayout.ColorAttachmentOptimal);
     }
 }
Esempio n. 3
0
 public override void TransitionToIntermediateLayout(VkCommandBuffer cb)
 {
     for (int i = 0; i < ColorTargets.Count; i++)
     {
         FramebufferAttachment ca    = ColorTargets[i];
         VkTexture             vkTex = Util.AssertSubtype <Texture, VkTexture>(ca.Target);
         vkTex.SetImageLayout(0, ca.ArrayLayer, VkImageLayout.ColorAttachmentOptimal);
     }
 }
Esempio n. 4
0
 public override void TransitionToFinalLayout(VkCommandBuffer cb)
 {
     foreach (FramebufferAttachment ca in ColorTargets)
     {
         VkTexture vkTex = Util.AssertSubtype <Texture, VkTexture>(ca.Target);
         vkTex.SetImageLayout(0, ca.ArrayLayer, VkImageLayout.ColorAttachmentOptimal);
         vkTex.TransitionImageLayout(cb, 0, 1, ca.ArrayLayer, 1, VkImageLayout.PresentSrcKHR);
     }
 }
Esempio n. 5
0
 public override void TransitionToIntermediateLayout(VkCommandBuffer cb)
 {
     foreach (FramebufferAttachment ca in ColorTargets)
     {
         VkTexture vkTex = Util.AssertSubtype <Texture, VkTexture>(ca.Target);
         vkTex.SetImageLayout(ca.MipLevel, ca.ArrayLayer, VkImageLayout.ColorAttachmentOptimal);
     }
     if (DepthTarget != null)
     {
         VkTexture vkTex = Util.AssertSubtype <Texture, VkTexture>(DepthTarget.Value.Target);
         vkTex.SetImageLayout(
             DepthTarget.Value.MipLevel,
             DepthTarget.Value.ArrayLayer,
             VkImageLayout.DepthStencilAttachmentOptimal);
     }
 }
Esempio n. 6
0
        private void BeginCurrentRenderPass()
        {
            Debug.Assert(_activeRenderPass == VkRenderPass.Null);
            Debug.Assert(_currentFramebuffer != null);
            _currentFramebufferEverActive = true;

            uint attachmentCount    = _currentFramebuffer.AttachmentCount;
            bool haveAnyAttachments = _framebuffer.ColorTargets.Count > 0 || _framebuffer.DepthTarget != null;
            bool haveAllClearValues = _depthClearValue.HasValue || _framebuffer.DepthTarget == null;
            bool haveAnyClearValues = _depthClearValue.HasValue;

            for (int i = 0; i < _currentFramebuffer.ColorTargets.Count; i++)
            {
                if (!_validColorClearValues[i])
                {
                    haveAllClearValues = false;
                    haveAnyClearValues = true;
                }
                else
                {
                    haveAnyClearValues = true;
                }
            }

            VkRenderPassBeginInfo renderPassBI = VkRenderPassBeginInfo.New();

            renderPassBI.renderArea  = new VkRect2D(_currentFramebuffer.RenderableWidth, _currentFramebuffer.RenderableHeight);
            renderPassBI.framebuffer = _currentFramebuffer.CurrentFramebuffer;

            if (!haveAnyAttachments || !haveAllClearValues)
            {
                renderPassBI.renderPass = _currentFramebuffer.RenderPassNoClear;
                vkCmdBeginRenderPass(_cb, ref renderPassBI, VkSubpassContents.Inline);
                _activeRenderPass = _currentFramebuffer.RenderPassNoClear;

                if (haveAnyClearValues)
                {
                    if (_depthClearValue.HasValue)
                    {
                        ClearDepthStencil(_depthClearValue.Value.depthStencil.depth, (byte)_depthClearValue.Value.depthStencil.stencil);
                        _depthClearValue = null;
                    }

                    for (uint i = 0; i < _currentFramebuffer.ColorTargets.Count; i++)
                    {
                        if (_validColorClearValues[i])
                        {
                            _validColorClearValues[i] = false;
                            VkClearValue vkClearValue = _clearValues[i];
                            RgbaFloat    clearColor   = new RgbaFloat(
                                vkClearValue.color.float32_0,
                                vkClearValue.color.float32_1,
                                vkClearValue.color.float32_2,
                                vkClearValue.color.float32_3);
                            ClearColorTarget(i, clearColor);
                        }
                    }
                }
            }
            else
            {
                // We have clear values for every attachment.
                renderPassBI.renderPass = _currentFramebuffer.RenderPassClear;
                fixed(VkClearValue *clearValuesPtr = &_clearValues[0])
                {
                    renderPassBI.clearValueCount = attachmentCount;
                    renderPassBI.pClearValues    = clearValuesPtr;
                    if (_depthClearValue.HasValue)
                    {
                        _clearValues[_currentFramebuffer.ColorTargets.Count] = _depthClearValue.Value;
                    }
                    vkCmdBeginRenderPass(_cb, ref renderPassBI, VkSubpassContents.Inline);
                    _activeRenderPass = _currentFramebuffer.RenderPassClear;
                    Util.ClearArray(_validColorClearValues);
                }
            }

            // Set new image layouts
            foreach (FramebufferAttachment colorTarget in _currentFramebuffer.ColorTargets)
            {
                VkTexture     vkTex  = Util.AssertSubtype <Texture, VkTexture>(colorTarget.Target);
                VkImageLayout layout = (vkTex.Usage & TextureUsage.Sampled) != 0
                    ? VkImageLayout.ShaderReadOnlyOptimal
                    : VkImageLayout.ColorAttachmentOptimal;
                vkTex.SetImageLayout(colorTarget.ArrayLayer, layout);
            }

            if (_currentFramebuffer.DepthTarget != null)
            {
                VkTexture     vkDepthTex = Util.AssertSubtype <Texture, VkTexture>(_currentFramebuffer.DepthTarget.Value.Target);
                VkImageLayout layout     = (vkDepthTex.Usage & TextureUsage.Sampled) != 0
                    ? VkImageLayout.ShaderReadOnlyOptimal
                    : VkImageLayout.DepthStencilAttachmentOptimal;

                vkDepthTex.SetImageLayout(_currentFramebuffer.DepthTarget.Value.ArrayLayer, layout);
            }
        }