blurrypiano / littleVulkanEngine

Code repo for video tutorial series teaching Vulkan and computer graphics
MIT License
829 stars 147 forks source link

Whole screen renders red #3

Closed junglie85 closed 3 years ago

junglie85 commented 3 years ago

Great series. I'm following it on YouTube and implementing in Python.

I've got to the end of Command Buffers Overview but when I run the application my whole window is filled with red. There are no errors and no validation layer errors until I close the window.

I don't know enough Vulkan to understand why this would be the case and wondered if you had any advice on why this might be the case or how to approach debugging it?

Jtaim commented 3 years ago

do you have a repository to share your code?

junglie85 commented 3 years ago

https://github.com/ambye85/pylve/blob/main/examples/example_05b.py

junglie85 commented 3 years ago

I realised I committed half an attempt at fixing/debugging, which was broken. I've just reverted those changes and pushed.

blurrypiano commented 3 years ago

So I would suspect what's happening is the triangle is filling the entire screen. You could try changing the output color in the fragment shader to confirm.

Then I'd check to make sure the width and height of the viewport are reasonable values https://github.com/ambye85/pylve/blob/895fac120972bdb3a035bfb3053288bee55abf99/examples/example_05b.py#L494

Jtaim commented 3 years ago

@ambye85 list of validation errors I am getting with your code. redo forgot to compile the frag and vert files. now I got a green triangle with red background. with following errors.

DEBUG: Validation Validation Error: [ VUID-vkDestroyImageView-imageView-01026 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x63ac21f0 | Cannot call vkDestroyImageView on VkImageView 0xa540ac0000000009[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to imageView must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroyImageView-imageView-01026) DEBUG: Validation Validation Error: [ VUID-vkDestroyImageView-imageView-01026 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x63ac21f0 | Cannot call vkDestroyImageView on VkImageView 0x1f91b40000000011[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to imageView must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroyImageView-imageView-01026) DEBUG: Validation Validation Error: [ VUID-vkDestroyImage-image-01000 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xf2d29b5a | Cannot call vkDestroyImage on VkImage 0xc6ac6a000000000f[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to image, either directly or via a VkImageView, must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroyImage-image-01000) DEBUG: Validation Validation Error: [ VUID-vkFreeMemory-memory-00677 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x485c8ea2 | Cannot call vkFreeMemory on VkDeviceMemory 0xedbd50000000010[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to memory (via images or buffers) must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkFreeMemory-memory-00677) DEBUG: Validation Validation Error: [ VUID-vkDestroyFramebuffer-framebuffer-00892 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xdb308312 | Cannot call vkDestroyFramebuffer on VkFramebuffer 0x3047930000000016[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to framebuffer must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroyFramebuffer-framebuffer-00892) DEBUG: Validation Validation Error: [ VUID-vkDestroyRenderPass-renderPass-00873 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x473619ad | Cannot call vkDestroyRenderPass on VkRenderPass 0x83d4ee000000000b[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to renderPass must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroyRenderPass-renderPass-00873) DEBUG: Validation Validation Error: [ VUID-vkDestroySemaphore-semaphore-01137 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xa1569838 | Cannot call vkDestroySemaphore on VkSemaphore 0xcc0459000000001c[] that is currently in use by a command buffer. The Vulkan spec states: All submitted batches that refer to semaphore must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroySemaphore-semaphore-01137) DEBUG: Validation Validation Error: [ VUID-vkDestroyFence-fence-01120 ] Object 0: handle = 0xdcba38000000001d, type = VK_OBJECT_TYPE_FENCE; | MessageID = 0x5d296248 | VkFence 0xdcba38000000001d[] is in use. The Vulkan spec states: All queue submission commands that refer to fence must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroyFence-fence-01120) DEBUG: Validation Validation Error: [ VUID-vkDestroyPipeline-pipeline-00765 ] Object 0: handle = 0x2da5bc30298, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bdce5fd | Cannot call vkDestroyPipeline on VkPipeline 0x41ab840000000021[] that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to pipeline must have completed execution (https://vulkan.lunarg.com/doc/view/1.2.170.0/windows/1.2-extensions/vkspec.html#VUID-vkDestroyPipeline-pipeline-00765)

blurrypiano commented 3 years ago

I think those errors would just be because at the end of the run function there's a missing vkWaitDeviceIdle but shouldn't be what's affecting the whole screen being a single color.

@ambye85 - if you want to join the discord https://discord.gg/fahfeTFe and post in the debugging-help I'm usually a lot better at responding there.

junglie85 commented 3 years ago

Thanks for your help with this. I'm still not getting a triangle, only the red screen. I've added the vkWaitDevieIdle call to the end of my run method and those debug messages do go.

I've added a GLFW example from the Python Vulkan package that draws a multi-coloured triangle, which works on my machine. I'm trying to go through the painstaking exercise of comparing the two for possible typo's/errors on my part. I'm not sure why @Jtaim is able to get this to render with no changes - FWIW, I'm on macOS but it looks like the LVE videos are also.

I'll try and drop into the discord.

blurrypiano commented 3 years ago

clear value was being only set for color attachment, unioned depth value would overwrite color value on certain compilers resulting in entire screen being red.

Correct method below

clear_values = vk.ffi.new(
                'VkClearValue[]', [vk.VkClearValue(color=[[0.1, 0.1, 0.1, 1.0]]), vk.VkClearValue(depthStencil=[1.0, 0])])

            render_pass_info = vk.VkRenderPassBeginInfo(
                sType=vk.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
                renderPass=self._swap_chain.render_pass,
                framebuffer=self._swap_chain.framebuffer(i),
                renderArea=[[0, 0], self._swap_chain.swap_chain_extent],
                clearValueCount=2,
                pClearValues=clear_values,
            )