Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

High Fidelity Games: Real Examples, Best Practices ... | Oleksii Vasylenko

High Fidelity Games: Real Examples, Best Practices ... | Oleksii Vasylenko

  • Be the first to comment

  • Be the first to like this

High Fidelity Games: Real Examples, Best Practices ... | Oleksii Vasylenko

  1. 1. High Fidelity Games Real Examples, Best Practices, Vulkan Expertize & Excellences Oleksii Vasylenko Graphics Engineer Samsung Electronics
  2. 2. GameDev Team UK Ukraine USA Korea
  3. 3. Eternal battle Quality Performance
  4. 4. Push the limits!  More visual effects  More impressive graphics  Higher frame rate  Longer battery life
  5. 5. Push the limits!  More visual effects  More impressive graphics  Higher frame rate  Longer battery life
  6. 6. What is Vulkan? o An open-standard, cross-platform graphics+compute API • Compatibility break with OpenGL • Start from first principles o Goals • Clean, modern architecture • Multithread / multicore-friendly • Greatly reduced CPU overhead • Full support for both desktop and mobile GPU architectures • More predictable performance – no driver magic • Improved reliability and consistency between implementations
  7. 7. What is Vulkan? o An open-standard, cross-platform graphics+compute API • Compatibility break with OpenGL • Start from first principles o Goals • Clean, modern architecture • Multithread / multicore-friendly • Greatly reduced CPU overhead • Full support for both desktop and mobile GPU architectures • More predictable performance – no driver magic • Improved reliability and consistency between implementations
  8. 8. 1st demos
  9. 9. S7 Unpack: Protostar
  10. 10. 2016: next step First real Vulkan games
  11. 11. 2016: first real games • Vulkan gives consistent 60 FPS even in thermal throttling situation • Console quality graphics with cinematic post-processing in Mobile
  12. 12. 2017: more and more
  13. 13. Best practices
  14. 14. Best practices: command buffers Regular logic: 0 1 2 0 CB 0 CB 1 CB 2 CB 00 Fence 0 WAIT FOR RENDERING COMPLETION OF CB0 (FENCE 0) CB 1 1 1 SUBMIT SUBMIT SUBMIT SUBMIT SUBMIT ACQUIRE / PRESENT SWAPCHAIN IMAGES WAIT FOR FENCE 0
  15. 15. Best practices: command buffers Better solution: 0 1 2 0 CB 0 CB 1 CB 2 CB 00 Get Fence 0 signal next CB 1 1 SUBMIT SUBMIT SUBMIT SUBMIT SUBMIT ACQUIRE / PRESENT SWAPCHAIN IMAGES READY new CB 4 All CBs are not READY
  16. 16. Best practices: command buffers • Should use "FIFO" instead of "MAILBOX" for SwapChain creation on Android to get stable Queue/Dequeue based on vsync • Recommend to use 3 back buffers on Android • Avoid vkWaitForFences usage on acquire image • Recommend to minimize command buffers count per frame ExpectedError
  17. 17. Best practices: renderpasses • Use begin/end renderpass efficiently • Renderpass must match framebuffer • Reduce renderpass count where it’s possible • Recognize where function should be called: inside or outside renderpass
  18. 18. Pipeline - abstract scheme of how a unit of work is processed Best practices: pipeline barriers void vkCmdPipelineBarrier( VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32 memoryBarrierCount, constVkMemoryBarrier* pMemoryBarrier uint32 bufferMemoryBarrierCount, constVkMemoryBarrier* pBufferMemoryBarrier uint32 imageMemoryBarrierCount, constVkMemoryBarrier* pImageMemoryBarrier); VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT VK_PIPELINE_STAGE_VERTEX_INPUT_BIT VK_PIPELINE_STAGE_VERTEX_SHADER_BIT VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
  19. 19. Best practices: pipeline barriers Vertex Shader ... Fragment Shader Vertex Shader ... Fragment Shader Vertex Shader ... Fragment Shader - Change image layout to readable - Wrong stage mask: bubble! SRC: VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT DST: VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
  20. 20. Best practices: pipeline barriers Vertex Shader ... Fragment Shader Vertex Shader ... Fragment Shader Vertex Shader ... Fragment Shader - Change image layout to readable - Wrong stage mask: flickering! SRC: VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT DST: VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT ... ...
  21. 21. Best practices: pipeline barriers Vertex Shader ... Fragment Shader Vertex Shader ... Fragment Shader Vertex Shader ... Fragment Shader - Change image layout to readable - Correct stage mask SRC: VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT DST: VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
  22. 22. Best practices: pipeline barriers
  23. 23. Best practices: uniform buffers • Minimize vkUpdateDescriptorSets calls by using fixed uniform buffer for static objects • Use UniformBufferPool for dynamic objects • Minimize vkMapMemory, vkUnmapMemory calls for dynamic objects Vertex / Index Raw Data Staging VkBuffer VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT VK_MEMORY_PROPERTY_HOST_COHERENT_BIT VkBuffer / VkDeviceMemory VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT vkCmdCopyBuffer Vertex / Index Raw Data VkBuffer / VkDeviceMemory VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT VK_MEMORY_PROPERTY_HOST_COHERENT_BIT memcpy command process memcpy static dynamic
  24. 24. Best practices: other recommendations • Cache everything as much as you can • ‘std140’ layout for uniform buffers should be used at shader side • Avoid vkCmdSetXXX, vkCmdBindXXX duplications • Use deferred deletion for Vulkan related resources & objects • Use proper image layout for images (especially for presentation and copy!) • Consider VkPhysicalDeviceLimits before doing something!
  25. 25. Best practices: validation layers Log example: • Code 52 : At Draw time the active render pass (0xffffffff997f2024) is incompatible w/ gfx pipeline (0xffffffffc3b1f808) that was created w/ render pass (0xffffffffc43fac8c) due to: color a ttachments at index 0 of subpass index 0 are not compatible. • Code 56 : You cannot start a render pass using attachment 0 where the render pass initial layout is VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL and the previous known layo ut of the attachment is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL. The layouts must match, or the render pass initial layout for the attachment must be VK_IMAGE_LAYOUT _UNDEFINED • Code 6 : vkCmdDrawIndexed(): Cannot use image 0xffffffff97108908 with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the actual current lay out VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL. • Code 61 : Descriptor set 0xffffffffc321ee78 encountered the following validation error at vkCmdDrawIndexed() time: Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time descriptor is used. See previous error callback for specific details. CreateInstance() { … VkInstanceCreateInfo InstInfo; InstInfo.enabledLayerCount = enabledLayerCount; InstInfo.ppEnabledLayerNames = enabledLayers; … } SetupDebugLayerCallback() { VkDebugReportCallbackCreateInfoEXT CreateInfo; CreateInfo.pfnCallback = DebugReportFunction; vkCreateDebugReportCallbackEXT (Instance, &CreateInfo, nullptr, &MsgCallback); }
  26. 26. Complicated API? X
  27. 27. • Vulkan – solution for high fidelity games creation on mobile • The most popular game engines support Vulkan Samsung will keep go on supporting game developers and players! If you have any questions, offers or suggestions, please contact gamedev@samsung.com
  28. 28. Thank you!

×