Vulkan Tutorial 2016 Khronos Seoul DevU SAMSUNG Electronics Hyokuen Lee Senior Graphics Engineer (hk75.lee@samsung.com) Minwook Kim Senior Graphics Engineer (minw83.kim@samsung.com)
Who I am Graphics R&D Group, MCD, SAMSUNG Electronics. Hyokeun Lee (hk75.lee@samsung.com)
목차 소개 개발환경 초기화 ( 준비작업 ) 삼각형그리기 사각형그리기 회전및 3차원투영 텍스처입히기 Standard Validation Layer
소개 Vulkan - Low CPU overhead, 멀티플랫폼지원하는 3D graphics, computing API
Vulkan 특징 Low CPU Overhead - 저수준 API 로써불필요한 CPU overhead 제거 출처 : GDC 2015 Khronos Vulkan Session 자료
Vulkan 특징 Multi-Core 효율성 - Multi-threading 기반 multi-command queue 방식으로병렬처리가능
Vulkan 특징 Layer 구조 - 여러개의 layer 구조로구성되어있으며개발자가 layer 를선택, 추가하여활성화가능 (API 최소한의부하를위해기본적인에러체크, 의존성체크등생략 )
Vulkan 특징 SPIR-V - Standard Portable Intermediate Representation - Binary shading language - Run-time shader 컴파일이필요없으며미리컴파일된 shader 를사용
개발환경 개발환경설치 Vulkan SDK 빌드 Visual Studio 환경설정
개발환경설치 설치항목 - Vulkan SDK 설치 (https://vulkan.lunarg.com/app/download ) - Cmake 설치 (https://cmake.org/download/ ) - Python 3 설치 (https://www.python.org/downloads/ ) - GLM library 설치 (http://glm.g-truc.net/0.9.8/index.html ) - Vulkan Graphic Driver 설치 : Nvdia (https://developer.nvidia.com/vulkan-driver ) : AMD (http://www.amd.com/en-us/innovations/softwaretechnologies/technologies-gaming/vulkan )
Vulkan SDK 빌드 Vulkan SDK 빌드 (Visual Studio 2015, 64-bit computer 기준 ) - go to C:\VulkanSDK\1.0.17.0\glslang\build : cmake G Visual Studio 14 Win64.. : project 를열어 Debug/Release x64 full build - go to C:\VulkanSDK\1.0.17.0\spirv-tools\build : cmake G Visual Studio 14 Win64.. : project 를열어 Debug/Release x64 full build build 폴더는직접생성해야함 - go to C:\VulkanSDK\1.0.17.0\Samples\build : cmake G Visual Studio 14 Win64.. : project 를열어 Debug/Release x64 full build
Visual Studio 환경설정 Vulkan / GLM header path 설정
Visual Studio 환경설정 Vulkan library path 설정
Visual Studio 환경설정 Vulkan library
초기화 ( 준비작업 ) Instance Device (Physical Device / Logical Device) Queue / Queue Family
API Naming Convention Standard Prefixes VK : Define / Vk : Type structure / vk : Function p / PFN / pfn : 포인터및함수포인터 vkcmd : command buffer 에저장할 command Extension 1) Type structure / 함수 VkSurfaceFormatKHR / vkdestorysurfacekhr( ) 2) Define VK_KHR_mirror_clamp_to_edge / VK_EXT_debug_marker
Instance Instance - Vulkan 과 application 간 connection 역할수행 - 간단한 application 정보들과, instance layer, instance extension 정보들로구성 Creating an Instance 1) Enable instance layer / extension - Instance layer 지원여부체크 - Instance extension 지원여부체크 2) Create instance - Application 정보설정 - Instance layer / extension 정보설정
Instance Create Destroy
createinstance()
checkerror()
destroyinstance()
Device Physical Device - Instance 를통하여 physical device 를선택 - System 내의사용가능한 GPU 를의미 - Vulkan 에서는사용가능한 GPU 중사용목적에따라여러개의 GPU 를사용가능 Logical Device - Physical device 를통하여 logical device 를생성 - Vulkan program 과 GPU 간의 logical connection (Vulkan API 사용시 main handle) - Physical device 로부터여러개의 logical device 생성가능
Queue / Queue Family Queue - Vulkan 에서는대부분의명령어를 (drawing, texturing, memory transfer 등 ) command buffer 에저장하고 queue 에 submit 하여사용한다 Queue Family - 서로다른 queue type 별로 queue family 구분 - 각각의 queue family 는특정명령어 type 을허용한다예 ) drawing command 와 computing command 용 queue family 0 memory transfer 용 queue family 1
Physical Device Selecting Physical Device - 사용할 GPU 를선택 - Graphics 처리용으로 graphics queue family 지원 GPU 선택 1) System 내사용가능한 physical device(gpu) 열거 2) Graphics queue family 지원여부확인 - VK_QUEUE_GRAPHICS_BIT flag 체크 3) GPU 의 properties 및 features 체크
Physical Device Create Destroy Physical device 는사용할 GPU 를선택하는 것이므로별도의 destroy 처리가필요없음
selectphysicaldevice() Graphics queue family 지원여부확인
isdevicesuitable() Graphics queue family 지원여부확인
findqueuefamilies() #1 참고 : Present Queue Family 확장 version VK_QUEUE_GRAPHICS_BIT flag 가있는지확인
Logical Device Creating Logical Device - Vulkan program 과 GPU 간의 logical connection (Vulkan API 사용시 main handle) - Logical device 생성과정 1) 사용할 queue 명시 (queue family 로부터생성 ) 2) 사용할 device extension 명시 3) 사용할 device feature 명시 4) Logical device 생성
Logical Device Create Destroy
createlogicaldevice() - 사용할 Queue 정보 - 사용할 device extension 정보 - 사용할 device feature 정보 Logical device 생성시생성된 queue 의 handle 을얻어온다
destroylogicaldevice()
Who I am Graphics R&D Group, MCD, SAMSUNG Electronics. Minwook Kim (minw83.kim@samsung.com)
삼각형그리기 Window System / Surface Present Queue Swapchain / Framebuffer Command Buffer Render Pass Graphics Pipeline Shader (SPIR-V) Swapchain Recreation
삼각형그리기 VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image Submit CMD Buffer Submit CMD Buffer Submit CMD Buffer BeginCommandBuffer Begin RenderPass Bind GraphicsPipeline Draw End RenderPass EndCommandBuffer
Window System / Surface Window Surface - Vulkan 은 platform 중립적 (agnostic) API 이므로각 platform 의 window system 에직접접근불가 - Rendering 된이미지를화면에표시하기위해 WSI (Window System Integration) 사용 - Platform 별 rendering target surface 필요 Device Extension for Presentation - VK_KHR_surface : Vulkan 과 window system 을연결해주는 WSI - VK_KHR_win32_surface : Win32 system 의 window 를사용할수있도록지원하는 extension VK_KHR_xcb_surface(Linux) / VK_KHR_android_surface(android)
Window System / Surface Create Destroy
Creating the Surface Surface 생성 - VkSurfaceKHR surface 객체생성 - Platform 별로 VkSurfaceKHR 객체를생성하는별도의함수를사용 Win32 : vkcreatewin32surfacekhr( ) Android : vkcreateandroidsurfacekhr( ) Linux : vkcreatexcbsurfacekhr( )
Creating the Surface Create Destroy
Present Queue VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image Submit CMD Buffer Submit CMD Buffer Submit CMD Buffer BeginCommandBuffer Begin RenderPass Bind GraphicsPipeline Draw End RenderPass EndCommandBuffer
Present Queue Present Queue - Vulkan 은화면에 rendering 결과를표시하기위하여 present queue 를사용 - Rendering 된 image 를 present queue 에 submit 하여 surface 에전달 Present Queue Family - Graphics queue family 와동일한 queue 일수도, 아닐수도있음 - vkgetphysicaldevicesurfacesupportkhr( ) 로 present queue family 체크
findqueuefamilies() #2 참고 : Graphics Queue Family version
Swapchain VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image BeginCommandBuffer EndCommandBuffer Swapchain CMD Buffer ImageView ( VKImageView ) Begin Framebuffer RenderPass Bind GraphicPipeline End RenderPass Submit Draw Submit CMD Swapchain Buffer ImageView ( VKImageView ) Framebuffer Submit CMD Buffer Swapchain ImageView ( VKImageView ) Framebuffer
Swapchain Swapchain - 출력장치에연속으로표시할수있는하나이상의 image collection - Refresh rate sync 에맞춰서 rendering 된결과들을화면에출력하는역할 - Swapchain 에연결된 image 에 graphics queue 에기록된 operation 들로 rendering 을수행하고 present queue 에 submit
Swapchain Swapchain Image - Swapchain 에연결되는실제 image resource Swapchain Image View - Swapchain 에대한추가적인 meta data 예 ) RGBA component, view type(2d/3d), surface format, mipmap, image array
Querying for Swapchain Support Querying for Swapchain Support - Swapchain 을만들기위해서 instance, device 정보외에 3 가지추가정보필요 1. Surface capabilities 2. Surface format 3. Presentation Mode
Choosing Swapchain Support 1/3 Surface Capabilities (VkSurfaceCapabilitiesKHR) - Capability 값들중 extent 값을사용 - Surface capability 예시
Choosing Swapchain Support 2/3 Surface Format (VkSurfaceFormatKHR) 1) format (VkFormat) - VK_FORMAT_B8G8R8A8_UNORM 2) colorspace (VkColorSpaceKHR) - VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
Choosing Swapchain Support 3/3 Presentation Mode - 화면에이미지를표시하는조건을설정 1) VK_PRESENT_MODE_IMMEDIATE_KHR 2) VK_PRESENT_MODE_FIFO_KHR (wait when queue full) 3) VK_PRESENT_MODE_FIFO_RELAXED_KHR (no wait when queue empty) 4) VK_PRESENT_MODE_MAILBOX_KHR (no wait when queue full)
Swapchain Create Destroy
createswapchain() #1
createswapchain() #2
createswapchain() #3 destroyswapchain()
Swapchain Image View VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image BeginCommandBuffer EndCommandBuffer Swapchain CMD Buffer ImageView ( VKImageView ) Begin Framebuffer RenderPass Bind GraphicPipeline End RenderPass Submit Draw Submit CMD Swapchain Buffer ImageView ( VKImageView ) Framebuffer Submit CMD Buffer Swapchain ImageView ( VKImageView ) Framebuffer
Swapchain Image View Create Destroy
createimageviews()
Framebuffer VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image BeginCommandBuffer EndCommandBuffer Swapchain CMD Buffer ImageView ( VKImageView ) Begin Framebuffer RenderPass Bind GraphicPipeline End RenderPass Submit Draw Submit CMD Swapchain Buffer ImageView ( VKImageView ) Framebuffer Submit CMD Buffer Swapchain ImageView ( VKImageView ) Framebuffer
Framebuffer Framebuffer - Color, depth, stencil target 이되는 buffer - 각 swapchain image view 를연결하여 frame buffer 를생성 Framebuffer 생성시필요한정보 - 연결할 swapchain image view (color, depth, stencil image view) - Frame buffer attachment type 을명시한 render pass 객체 - 기타정보 (swapchain extent 정보, swapchain 개수등 )
Framebuffer Create Destroy
createframebuffers() / destroyframebuffers()
Command Buffer VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image Submit CMD Buffer Submit CMD Buffer Submit CMD Buffer BeginCommandBuffer Begin RenderPass Bind GraphicsPipeline Draw End RenderPass EndCommandBuffer
Command Buffer Command Buffer - Vulkan 은명령어를 queue 에 submit 하여실행 - Command buffer 로묶어처리하여여러 CPU 에서 multi-thread 처리가가능 - Command buffer 에기록된 command 들은재사용가능 Command Pool - Command buffer 를할당하기위하여 memory 를관리 - Command buffer 는 command pool 을통하여할당
Command Pool Create Destroy
createcommandpool() / destroycommandpool()
Command Buffer Create Destroy Command buffer 는사용한 command pool 소멸시자동으로소멸되므로별도의 destroy 처리를할필요없음
createcommandbuffers()
Render Pass VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image Submit CMD Buffer Submit CMD Buffer Submit CMD Buffer BeginCommandBuffer Begin RenderPass Bind GraphicsPipeline Draw End RenderPass EndCommandBuffer
Render Pass Render Pass - Rendering 에사용될 framebuffer attachment type 에대해명시 : Framebuffer attachment 정보 (color buffer, depth buffer, multisampling.. ) : Subpass 정보 ( 연속적인 rendering) Render Pass 생성순서 1) Attachment description 2) Subpass description / dependency 3) Render pass create info 4) Render pass 생성
Render Pass Create Destroy
createrenderpass() #1 LOAD_OP_LOAD : LOAD_OP_CLEAR : LOAD_OP_DONT_CARE : STORE_OP_STORE : STORE_OP_DONT_CARE :
createrenderpass() #2
Graphics Pipeline VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image Submit CMD Buffer Submit CMD Buffer Submit CMD Buffer BeginCommandBuffer Begin RenderPass Bind GraphicsPipeline Draw End RenderPass EndCommandBuffer
Graphics Pipeline Graphics Pipeline - 3 차원이미지를 2 차원 raster 이미지로 표현하기위한일련의단계 Index, vertex Buffer Input assembler Vertex Shader Tessellation - Vulkan 은 graphics pipeline 의각단계를 명시적으로코드로작성 Geometry Shader ViewPort / Scissor Rasterization Fragment Shader Framebuffer Color Blending
Shader / SPIR-V Vertex shader / Fragment shader - GLSL 를 glslang complier 를통한변환 SPIR-V - Pre-compiled bytecode format - Intermediate language for parallel compute and graphics - Vulkan 은 GL_KHR_vulkan_glsl extension 을따르는 GLSL shader 를 SPIR-V 로 compile 하여사용
Vertex Shader (shader.vert) 참고 : Vertex buffer version Vertex attributes - coordinate - color
Fragment Shader (shader.frag) Shader Compile C:/VulkanSDK/1.0.17.0/Bin32/glslangValidator.exe V shader.vert shader.frag => vert.spv / frag.spv
createshadermodule()
Graphics Pipeline Create Destroy
creategraphicspipeline() #1
Graphics Pipeline Index, vertex Buffer Input assembler Vertex Shader Done Tessellation Skip Geometry Shader Skip ViewPort / Scissor Rasterization Fragment Shader Done Framebuffer Color Blending
creategraphicspipeline() #2
creategraphicspipeline() #3
creategraphicspipeline() #4
creategraphicspipeline() #5
creategraphicspipeline() #6
Recording Command Buffer BeginCommandBuffer Begin RenderPass Bind GraphicsPipeline Draw End RenderPass EndCommandBuffer ONE_TIME_SUBMIT_BIT RENDER_PASS_CONTINUE_BIT SIMULTANEOUS_USE_BIT 커맨드버퍼재사용가능
recordingcommandbuffers()
Recording Command Buffer Create Destroy
Drawing Frame VkSurface (WSI) PresentQueue Swapchain Image 0 Swapchain 1 Swapchain N Image Image Submit Submit Submit 3 CMD Buffer CMD Buffer vkacquirenextimagekhr CMD Buffer 2 1 1 st Semaphore vkqueuesubmit 2nd Semaphore vkqueuepresentkhr
Semaphore 동기화객체 - Semaphore : Queue 내부또는 queue 간 command sync 처리 - Fence : CPU side 에서 GPU ready 를기다림 ( 일반적으로, GPU 동작과상관없이 program level 에서 queue 명령어의완료를체크하는데사용 ) Semaphore - Drawing 동작을처리하기위해두종류의 semaphore 를사용 1) Swapchain 의실제 image 를얻기위한 semaphore (Rendering 준비동작 ) 2) Rendering 이완료되었음을알리기위한 semaphore
Semaphore Create Destroy
createsemaphores() / destroysemaphores()
drawframe()
Swapchain Recreation Swapchain Recreation - Window surface 크기가바뀔때 swapchain 갱신필요 - 화면의회전, Pause/Resume, 확대 / 축소시에도 swapchain 갱신
Swapchain Recreation ( 화면크기변경 ) Swapchain Dependency Surface Changed Swapchain - Window 변경 > Surface 변경 > Swapchain 갱신 Buffers Render Pass - Surface format 변경 > Render pass 갱신 Graphics Pipeline - Window/surface resolution 변경 > Buffer 갱신 (framebuffer/depth buffer/command buffer) - Viewport, scissor 영역변경 > Graphics pipeline 갱신
reinitswapchain()
createswapchain()
Swapchain Recreation Create Destroy Recreate
삼각형그리기 Window System / Surface Present Queue Swapchain / Framebuffer Command Buffer Render Pass Graphics Pipeline Shader (SPIR-V) Swapchain Recreation
사각형그리기 Vertex Buffer Staging Buffer Index Buffer
Vertex Buffer Vertex Buffer - Vertex shader 에 vertex attribute 전달 (coordinate, color, texture coordinate 등 ) Vertex Buffer 적용순서 - Vertex shader 수정 - Vertex data 정의 - Vertex binding description 설정 - Vertex attribute description 설정 - Vulkan graphics pipeline 에 vertex binding / attribute description 설정 - Vertex buffer 생성 - Vertex buffer 를이용하여 drawing
Vertex Shader 수정 Vertex Shader - Vertex attribute 는 program(vertex buffer) 으로부터 vertex 단위데이터를입력받음 - Vertex buffer 로부터 attribute 를전달받기위해서 in keyword 를사용 - Vertex shader 수정후 shader 재컴파일수행
Vertex Shader (shader.vert) 참고 : Fixed version Vertex attributes - coordinate - color
Vertex Data 정의 Vertex Data - GLM library 사용 (vector, matrix type 등의 linear algebra 사용 ) GLM shader 의 vector type (vec2, vec3 등 ) 과호환이가능한 C++ type 을제공
Vertex data 정의
Vertex Binding/Attribute Description Vertex Binding Description - 데이터배열에서하나의데이터단위에대한정보전달 (instance rendering 의경우 instance 단위 ) - VkVertexInputBindingDescription Vertex Attribute Description - 구성하는데이터 ( 좌표, color 등 ) 의 binding index, location, format, offset 정보등을명시 - VkVertexInputAttributeDescription
Vertex Binding/Attribute Description
Vertex Data 정의 Create Destroy
creategraphicspipeline()
Vertex Buffer 생성 Vulkan Buffer - 임의의데이터를저장할수있는 GPU memory 공간 - 사용자가 memory 를명시적으로할당 Vertex Buffer 생성 1) Vertex buffer 생성 2) Memory requirement 확인 3) Memory 할당 (CPU accessible) 4) Vertex buffer 에 memory binding 5) Vertex buffer 에 vertex data 복사
Vertex Buffer 생성 Create Destroy
createvertexbuffer()
findmemorytype()
destroyvertexbuffer()
Vertex Buffer 로그리기 Drawing with the Vulkan Buffer - Drawing command 실행전, vertex buffer binding 수행
Vertex Buffer 로그리기 Create Destroy
recordcommandbuffers()
Staging Buffer Memory 성능최적화 - CPU 접근가능한 vertex buffer 성능에최적화 memory type 이아님 - 성능에최적화된 memory type : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT flag 속성 (CPU 접근불가 ) Staging Buffer 사용 1) Staging buffer 생성 (GPU memory, CPU accessible) 2) Vertex data 를 staging buffer 에복사 3) Staging buffer 를최종 vertex buffer 에복사 (GPU memory, CPU not accessible)
createbuffer() / destroybuffer()
copybuffer() 1 회용 command buffer 생성 Buffer 복사 command buffer submit / 1 회용 command buffer 정리
createvertexbuffer()
Index Buffer Index 데이터 - Vertex data 만사용 vertex 데이터중복문제 - Index 데이터를사용하여 vertex 데이터중복문제해결
Index data 정의
Index Buffer Create Destroy
createindexbuffer()
destroyindexbuffer()
Index Buffer 로그리기 Create Destroy
recordcommandbuffers()
사각형그리기 Vertex Buffer Staging Buffer Index Buffer
회전및 3 차원투영 Resource Descriptor Descriptor Set / Descriptor Set Layout Uniform Buffer Object (UBO)
Resource Descriptor Resource Descriptor - Vulkan 에서사용하는 resource 를명시 - Resource descriptor 를사용하여 shader 에서 buffer, image 등의 resource 를사용 대표적인 Resource Descriptor - UBO (Uniform Buffer Object) : Shader 변경없이 drawing time 에값전달예 ) transformation matrix(vertex shader) - Texture image
Descriptor Set / Descriptor Set Layout Descriptor Set Layout - Pipeline 에서, access 할 resource type 및 binding number, pipeline stage 정보등을명시 Descriptor Pool - 사용할 descriptor 객체수에대한정보를가짐 - Descriptor pool 로부터 descriptor set 객체를할당 Descriptor Set - Resource descriptor 에 bound 될실제 resource 에대해서명시 - Descriptor set layout, descriptor pool 로부터생성
Descriptor Set / Descriptor Set Layout Descriptor 사용순서 1) Graphics pipeline 생성이전 : descriptor set layout 생성 2) Graphics pipeline 생성시점 : descriptor set layout 명시 3) Graphics pipeline 생성이후 : uniform buffer object 및 descriptor pool/descriptor set 생성 4) Rendering 시점 : descriptor binding
Resource Descriptor Create Descriptor set layout 생성 Descriptor set layout 명시 Uniform Buffer Object 생성 Descriptor pool / descriptor set 생성 Descriptor set binding
Vertex Shader 수정 Vertex Shader - Vertex shader 에 uniform 추가 (MVP matrix) - gl_position 에 MVP transformation 적용 (Model-View-Projection : 회전및 3 차원 projection)
Vertex Shader (shader.vert) Uniform (MVP matrix) (binding = 0) : Descriptor set layout 에서 index 로참조 MVP transformation
Uniform Data 정의 Uniform Data - GLM library 를사용하여 matrix type 사용
Uniform data 정의
Descriptor Set Layout 생성 Descriptor Set Layout - 사용하려는 resource 의구성정보 예 ) binding 정보, resource type(uniform, texture 등 ), 사용시점 (pipeline stage) Descriptor Set Layout 생성순서 1) Resource type 별로 descriptor set layout binding 정보설정 (VkDescriptorSetLayoutBinding) 2) Descriptor set layout 생성정보설정 (VkDescriptorSetLayoutCreateInfo) 3) Descriptor set layout 생성 4) Graphics pipeline 에 descriptor set layout 정보설정
Descriptor Set Layout 생성
Descriptor Set Layout 생성 Create Destroy
createdescriptorsetlayout() destroydescriptorsetlayout()
Descriptor Set Layout 명시 Create Destroy
creategraphicspipeline()
Uniform Buffer Object 생성 Uniform Buffer Object (UBO) - 매 frame, uniform (MVP transformation) 정보갱신 - Vulkan buffer (VkBuffer) 를사용하여 program 에서 shader 로 uniform 전달 - Uniform buffer 생성과정은 vertex buffer, index buffer 생성과정과유사 매 frame 마다변경되는 uniform 값을 UBO 에복사하여 shader 에전달
Uniform Buffer Object 생성 Create Destroy
createstaginguniformbuffer() destroystaginguniformbuffer()
createuniformbuffer() destroyuniformbuffer()
updateuniformbuffer() 매 frame 마다, drawframe() 이전에호출
creategraphicspipeline() Invert Y-coordinate
Descriptor Pool 생성 Descriptor Pool - Resource type 별로 descriptor pool 을생성 - Descriptor type, descriptor 수등의정보를가지고생성
Descriptor Pool 생성 Create Destroy
createdescriptorpool() destroydescriptorpool()
Descriptor Set 생성 Descriptor Set - 준비된 descriptor set layout 및 descriptor pool 로부터 descriptor set 생성 - Descriptor set 생성후 buffer 를할당
Descriptor Set 생성 Create Destroy Descriptor set 은 descriptor pool 소멸시 같이소멸되므로별도의 destroy 처리를할 필요없음
createdescriptorset()
Descriptor Set Binding Descriptor Set Binding - Rendering 시점에 descriptor set binding - Render pass 내에서 drawing 명령어이전에 binding 명령어 submit
Descriptor Set Binding Create Destroy
recordcommandbuffers()
회전및 3 차원투영 Resource Descriptor Descriptor Set / Descriptor Set Layout Uniform Buffer Object (UBO)
텍스처입히기 Texture Image Sampler Texture Descriptor Set
Fragment Shader 수정 Fragment Shader - Program(vertex buffer) 으로부터 fragment 단위데이터를입력받음 - Texture 적용을위한 sampler 및 texture 좌표를전달
Fragment Shader (shader.frag)
Texture Data 정의 Vertex Data - Vertex 데이터에 texture 좌표정보추가
Texture data 정의
Texture Image Texture Image 생성 - Texture image 생성과정은 vertex buffer 생성과정과유사 : VkImage Image 객체에대한 handle : VkDeviceMemory 실제 image 데이터를저장하고있는 memory 객체 Texture Image 생성순서 1) Image 파일로부터데이터를읽음 2) Texture image 객체생성 3) Image 파일로부터읽어온데이터를 texture image 객체에저장
Texture Image Texture Image 와 Vertex buffer 생성비교
createimage()
destroyimage()
copyimage()
beginsinglecommandbuffer() / endsinglecommandbuffer()
Texture Image Image Layout - Vulkan image 객체는사용할용도에따라최적화된 layout 을설정하여사용 - Image layout 변경시 barrier 객체를사용하여동기화 Pipeline barrier - Resource 의 read/write 동기화에사용 - VK_SHARING_MODE_EXCLUSIVE 모드일때, Image layout transition, queue family ownership transfer 등에도사용 - Image memory barrier (VkImageMemoryBarrier) : image layout transition 시사용 Buffer memory barrier (VkBufferMemoryBarrier) : buffer 동기화시사용
transitionimagelayout() #1 Layout transition Queue family ownership transfer
transitionimagelayout() #2
Texture Image Create Destroy
createtextureimage() #1
createtextureimage() #2
createtextureimage() #3
Texture Image View Image View - Texture image 객체및추가적인정보를가지는객체 (Texture view type, format, mipmap, texture array 등의추가정보저장 ) - Texture image 객체대신 texture image view 객체를 handle 로사용한다
Texture Image View Create Destroy
createtextureimageview() destroytextureimageviews()
createimageview()
Sampler Sampler - Shader 는 sampler 객체를통해서 texture access - Sampler 는 texture filter, mipmap, wrap mode 등에대한처리를지원
Sampler Create Destroy
createtexturesampler() destroytexturesampler()
Texture Descriptor Set Texture Descriptor Set - Texture image view 및 sampler 를 shader 에전달하기위해 descriptor set 사용 Descriptor 사용순서 1) Graphics pipeline 생성이전 : descriptor set layout 생성 2) Graphics pipeline 생성시점 : descriptor set layout 명시 3) Graphics pipeline 생성이후 : texture image view/sampler 및 descriptor pool/descriptor set 생성 4) Rendering 시점 : descriptor binding
Resource Descriptor Create Descriptor set layout 생성 Descriptor set layout 명시 Texture image view / sampler 생성 Descriptor pool / descriptor set 생성 Descriptor set binding
createdescriptorsetlayout()
creategraphicspipeline()
Descriptor Pool 생성 Descriptor Pool - 새로운 descriptor type (texture image) 을 descriptor pool 에추가
Descriptor Pool 생성 Create Destroy
createdescriptorpool()
Descriptor Set 생성 Descriptor Set - Texture type 의 descriptor set 추가
Descriptor Set 생성 Create Destroy Descriptor set 은 descriptor pool 소멸시같이 소멸되므로별도의 destroy 처리를할필요없음
createdescriptorset()
Descriptor Set Binding Descriptor Set Binding - Rendering 시점에 descriptor set binding - Render pass 내에서 drawing 명령어이전에 binding 명령어 submit
Descriptor Set Binding Create Destroy
recordcommandbuffers()
텍스처입히기 Texture Image Sampler Texture Descriptor Set
Standard Validation Layer 적용 Vulkan Design Concept - Driver 에서처리해야하는일을최소화 (Minimal driver overhead) - 사용자가명시적으로모든것을처리 - 기본적인 error check 최소화 Validation Layer - Vulkan API 를 hooking 하여여러부가적인기능및서비스를제공 - 일반적으로 debug mode 에서 enable, release mode 일때 disable 후배포
Vulkan API Hooking Example 실제 vkcreateinstance( ) 를호출하기전에 error 체크를수행 실제 vkcreateinstance( ) 를호출뒤후처리수행
Standard Validation Layer - LunarG Vulkan SDK 에 open source 로 standard validation layer 를제공 - 개발자들이별도의 customizing 된 validation layer 를개발, 제공할수있음
Standard Validation Layer 적용 Create Destroy Instance 생성전에 validation layer 관련정보설정 Instance 생성시관련정보를전달
setupvalidationlayers() Instance 생성시전달할정보설정 - instance layer - instance extension - debug report callback 정보 Device Layer : deprecated (SDK ver. 1.0.13.0) VK_EXT_debug_report 사용자정의 callback 함수
createinstance() setupvalidationlayers( ) 에서정보설정 - instance layer - instance extension - debug report callback 정보
checkinstancelayersupport()
checkinstanceextensionsupport()
Debug Report Callback 설정 Debug Report Callback - 활성화한 validation layer 에의해 error detection 된경우 error report 를받도록별도로설정
Debug Report Callback 설정 Create Destroy
createdebugreportcallback() / destroydebugreportcallback() - Error report callback 함수는명시적으로생성 / 소멸처리해야한다 - vkcreatedebugreportcallbackext( ), vkdestorydebugreportcallbackext( ) 함수사용 - 이함수들은 extension 함수이기때문에자동으로 loading 되지않으므로, vkgetinstanceprocaddr() 로함수주소를가져와사용한다
VulkanDebugCallback() VkDebugReportCallbackCreateInfoEXT 에등록
참고자료 Vulkan API Specification https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html Vulkan SDK 에포함된 sample project build 방법 https://www.youtube.com/watch?v=wht5wcxipce (Tutorial 0) Vulkan Validation Layers http://gpuopen.com/using-the-vulkan-validation-layers/