### Create Fence Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Demonstrates creating a fence, with an option to start it in a signaled state. Remember to destroy the fence when done. ```go fence, err := device.CreateFence(true) if err != nil { panic(err) } defer device.DestroyFence(fence) ``` -------------------------------- ### Install Dependencies Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Install project dependencies using either the make command or Go's module tools. 'make install' is recommended for a complete setup. ```bash make install ``` ```bash go mod download && go mod tidy ``` -------------------------------- ### Buffer Usage Examples in Go Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/constants.md Examples showing how to assign buffer usage flags. ```go stagingBuf := vk.BufferUsageTransferSrc deviceLocalBuf := vk.BufferUsageTransferDst | vk.BufferUsageVertexBuffer uniformBuf := vk.BufferUsageUniformBuffer ``` -------------------------------- ### Install vulkan-go Source: https://github.com/christerso/vulkan-go/blob/main/README.md Use 'go get' to install the vulkan-go package. ```go go get github.com/christerso/vulkan-go ``` -------------------------------- ### Image Usage Examples in Go Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/constants.md Examples demonstrating how to create images with specific usage flags. ```go colorImg := device.CreateImage2D(pd, fmt, extent, vk.ImageUsageColorAttachment) textureImg := device.CreateImage2D(pd, fmt, extent, vk.ImageUsageTransferDst | vk.ImageUsageSampled) ``` -------------------------------- ### Setup Development Tools Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Run the make dev-setup command to configure your development environment with necessary tools. ```bash make dev-setup ``` -------------------------------- ### Run flythrough example Source: https://github.com/christerso/vulkan-go/blob/main/README.md Execute the flythrough example from the command line. This example renders a procedural terrain and measures performance metrics. ```bash go run ./examples/flythrough ``` ```bash go run ./examples/flythrough -frames 3000 -n 768 ``` -------------------------------- ### Go Test Structure Example Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Illustrates a standard Go test function structure using table-driven tests for a `Device_CreateBuffer` method. Includes setup for test cases with varying inputs and expected outcomes. ```go func TestDevice_CreateBuffer(t *testing.T) { tests := []struct { name string createInfo BufferCreateInfo expectError bool }{ { name: "valid buffer", createInfo: BufferCreateInfo{ Size: 1024, Usage: BufferUsageVertexBuffer, }, expectError: false, }, { name: "zero size buffer", createInfo: BufferCreateInfo{ Size: 0, Usage: BufferUsageVertexBuffer, }, expectError: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Test implementation... }) } } ``` -------------------------------- ### Create Semaphore Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Demonstrates how to create a binary semaphore. Ensure to destroy the semaphore when it's no longer needed. ```go sem, err := device.CreateSemaphore() if err != nil { panic(err) } defer device.DestroySemaphore(sem) ``` -------------------------------- ### Go Buffer Creation Example Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Example of creating a Vulkan buffer using the Device.CreateBuffer method. This function handles memory allocation and binding, and includes validation. ```go // CreateBuffer creates a Vulkan buffer with the specified parameters. // It automatically handles memory allocation and binding. // // See: https://registry.khronos.org/vulkan/specs/1.3/html/chap12.html#VkBuffer func (d *Device) CreateBuffer(createInfo BufferCreateInfo) (*Buffer, error) { if err := validateBufferCreateInfo(createInfo); err != nil { return nil, fmt.Errorf("invalid buffer create info: %w", err) } buffer := &Buffer{ device: d, size: createInfo.Size, usage: createInfo.Usage, } // Implementation... return buffer, nil } ``` -------------------------------- ### CommandBuffer.Begin Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/command-buffer.md Starts recording commands into a command buffer. Requires appropriate usage flags. ```APIDOC ## CommandBuffer.Begin ### Description Starts recording into a command buffer. flags is a VkCommandBufferUsageFlags value. ### Method func (c CommandBuffer) Begin(flags uint32) error ### Parameters #### Path Parameters - **flags** (uint32) - Required - Usage flags (e.g., CommandBufferOneTimeSubmit). ### Returns - error: Error if recording cannot begin. ### Example ```go err := cmdBuffer.Begin(vk.CommandBufferOneTimeSubmit) if err != nil { panic(err) } ``` ``` -------------------------------- ### Verify Development Setup Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Run the make test command to ensure your development environment is set up correctly and all tests pass. ```bash make test ``` -------------------------------- ### Destroy Fence Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Shows how to destroy a previously created fence. ```go device.DestroyFence(fence) ``` -------------------------------- ### Initialize Vulkan Instance Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Loads Vulkan library and creates an instance. Ensure Vulkan is installed and accessible. Use vk.ValidationLayer for debugging. ```go vk.Load() // Opens libvulkan and resolves global commands instance, _ := vk.CreateInstance(vk.InstanceConfig{ ApplicationName: "MyApp", Layers: []string{vk.ValidationLayer}, Extensions: []string{surfaceExt}, }) defer instance.Destroy() ``` -------------------------------- ### Destroy Semaphore Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Shows how to destroy a previously created semaphore. ```go device.DestroySemaphore(semaphore) ``` -------------------------------- ### Vulkan Device Creation Workflow Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/device.md A comprehensive example demonstrating the typical workflow for creating a Vulkan logical device. This includes enumerating physical devices, selecting one, finding a suitable graphics queue family, and finally creating the logical device with necessary extensions. ```go // Enumerate devices devices, err := instance.EnumeratePhysicalDevices() if err != nil { panic(err) } // Select first device physicalDevice := devices[0] info := physicalDevice.Info() fmt.Printf("Selected: %s\n", info.Name) // Find graphics queue family graphicsFamily, err := physicalDevice.GraphicsFamily() if err != nil { panic(err) } // Create logical device device, queue, err := physicalDevice.CreateDevice(vk.DeviceConfig{ GraphicsFamily: graphicsFamily, Extensions: []string{"VK_KHR_swapchain"}, }) if err != nil { panic(err) } deffer device.Destroy() ``` -------------------------------- ### Begin Command Buffer Recording Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/command-buffer.md Starts recording commands into a command buffer. Use appropriate usage flags, such as CommandBufferOneTimeSubmit. ```go func (c CommandBuffer) Begin(flags uint32) error ``` ```go err := cmdBuffer.Begin(vk.CommandBufferOneTimeSubmit) if err != nil { panic(err) } ``` -------------------------------- ### Create Vulkan Instance with Debugging Enabled Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/debug.md Example of creating a Vulkan instance with the necessary layers and extensions for debugging. Ensure the debug utils extension and validation layer are included. ```go instance, err := vk.CreateInstance(vk.InstanceConfig{ ApplicationName: "MyApp", Layers: []string{vk.ValidationLayer}, Extensions: []string{vk.ExtDebugUtils}, }) if err != nil { panic(err) } ``` -------------------------------- ### Wait for Device Idle Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Blocks execution until all commands submitted to the device have completed. Useful for ensuring all work is finished before proceeding. ```go err := device.WaitIdle() if err != nil { panic(err) } ``` -------------------------------- ### Submit Command Buffer Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Submits a command buffer for execution on a queue. This can include waiting on semaphores and signaling others upon completion, optionally with a fence. ```go err := queue.Submit(vk.SubmitConfig{ Wait: acquireSem, WaitStage: vk.StageColorAttachmentOutput, Command: cmdBuffer, Signal: presentSem, Fence: frameFence, }) if err != nil { panic(err) } ``` -------------------------------- ### Vulkan-Go Frame Loop Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md This snippet demonstrates a typical frame loop in Vulkan-Go, including acquiring the next swapchain image, submitting rendering commands, and presenting the image. It shows how to handle the `ErrorOutOfDateKHR` error by breaking the loop to recreate the swapchain. ```go // Acquire next image imageIndex, acqResult := device.AcquireNextImage(swapchain, acquireSem, math.MaxUint64) if acqResult == vk.ErrorOutOfDateKHR { // Recreate swapchain break } // Submit rendering work queue.Submit(vk.SubmitConfig{ Wait: acquireSem, WaitStage: vk.StageColorAttachmentOutput, Command: cmdBuffer, Signal: presentSem, Fence: frameFence, }) // Present presResult := queue.Present(swapchain, imageIndex, presentSem) if presResult == vk.ErrorOutOfDateKHR { // Recreate swapchain break } ``` -------------------------------- ### Wait for Fence Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Waits for a specific fence to be signaled within a given timeout in nanoseconds. Handles potential errors or timeouts. ```go err := device.WaitFence(fence, 1000000000) // 1 second if err != nil { panic(err) } ``` -------------------------------- ### Wait for Queue Idle Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Blocks execution until all commands submitted to a specific queue have completed. Use this to ensure a particular queue is finished. ```go err := queue.WaitIdle() if err != nil { panic(err) } ``` -------------------------------- ### Instance.CreateDebugMessenger Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/debug.md Installs a debug messenger that reports validation warnings and errors to stderr. The instance must have been created with the debug utils extension (VK_EXT_debug_utils) enabled. ```APIDOC ## Instance.CreateDebugMessenger ### Description Installs a debug messenger that reports validation warnings and errors to stderr. The instance must have been created with the debug utils extension (VK_EXT_debug_utils) enabled. ### Method Go Function ### Parameters This function does not take any parameters. ### Returns - **DebugMessenger**: Debug messenger handle. - **error**: Non-nil if messenger creation fails. ### Example ```go instance, err := vk.CreateInstance(vk.InstanceConfig{ ApplicationName: "MyApp", Layers: []string{vk.ValidationLayer}, Extensions: []string{vk.ExtDebugUtils}, }) if err != nil { panic(err) } messenger, err := instance.CreateDebugMessenger() if err != nil { panic(err) } defer messenger.Destroy() ``` ``` -------------------------------- ### Create and Defer Destroy Debug Messenger Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/debug.md Installs a debug messenger to report validation warnings and errors. The instance must have the debug utils extension enabled. The messenger should be destroyed when no longer needed. ```go messenger, err := instance.CreateDebugMessenger() if err != nil { panic(err) } defer messenger.Destroy() ``` -------------------------------- ### Get Supported Vulkan Surface Formats Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Retrieves a list of supported Vulkan surface formats, including pixel format and colorspace. Use this to determine compatible formats for swapchain creation. ```go formats, err := physicalDevice.SurfaceFormats(surface) if err != nil { panic(err) } for _, fmt := range formats { fmt.Printf("%d (%d)\n", fmt.Format, fmt.ColorSpace) } ``` -------------------------------- ### Bind Multiple Vertex Buffers Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/command-buffer.md Binds multiple vertex buffers starting from a specified binding index. The number of offsets provided must match the number of buffers. ```go cmdBuffer.BindVertexBuffers(0, []vk.Buffer{buf1.Buffer, buf2.Buffer}, []vk.DeviceSize{0, 0}) ``` -------------------------------- ### Basic Vulkan Instance and Device Enumeration Source: https://github.com/christerso/vulkan-go/blob/main/README.md This Go code snippet demonstrates how to load the Vulkan library, create an instance, and enumerate physical devices. Ensure the Vulkan loader is available at runtime. ```go package main import ( "fmt" "github.com/christerso/vulkan-go/vk" ) func main() { if err := vk.Load(); err != nil { panic(err) } instance, err := vk.CreateInstance(vk.InstanceConfig{ApplicationName: "app"}) if err != nil { panic(err) } defer instance.Destroy() devices, _ := instance.EnumeratePhysicalDevices() for _, pd := range devices { info := pd.Info() fmt.Printf("%s (%s)\n", info.Name, info.Type) } } ``` -------------------------------- ### Reset Fence Example Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Resets a fence to its unsignaled state. This is typically done after a fence has been signaled and waited upon. ```go err := device.ResetFence(fence) if err != nil { panic(err) } ``` -------------------------------- ### Running Vulkan-Go Tests and Benchmarks Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Provides common Make commands for executing tests, generating coverage reports, and running benchmarks within the Vulkan-Go project. Also shows how to run a specific Go test file. ```bash # Run all tests make test ``` ```bash # Run tests with coverage make test-coverage ``` ```bash # Run benchmarks make bench ``` ```bash # Run specific test go test -run TestDevice_CreateBuffer ./pkg/vk ``` -------------------------------- ### Create Feature Branch Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Use this command to create a new branch for feature development, starting from the 'develop' branch. ```bash git checkout develop git pull upstream develop git checkout -b feature/your-feature-name ``` -------------------------------- ### Define FenceCreateSignaled Constant Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Defines flags for fence creation, specifically indicating if a fence should start in a signaled state. ```go const ( FenceCreateSignaled uint32 = 0x00000001 ) ``` -------------------------------- ### Device.Map Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/memory.md Maps device memory and returns a pointer to the start of the mapped region. This allows CPU access to device memory. ```APIDOC ## Device.Map ### Description Maps device memory and returns a pointer to the start. ### Method func (d Device) Map(mem DeviceMemory, size DeviceSize) (unsafe.Pointer, error) ### Parameters #### Path Parameters - mem (DeviceMemory) - Required - Device memory to map. - size (DeviceSize) - Required - Size to map in bytes. ### Response #### Success Response (200) - unsafe.Pointer: Pointer to mapped memory. - error: Non-nil on map failure. ### Example ```go ptr, err := device.Map(mem, size) if err != nil { panic(err) } defer device.Unmap(mem) ``` ``` -------------------------------- ### Create and Bind Graphics Pipeline Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Sets up shaders, pipeline layout, render pass, and graphics pipeline. Requires a created Vulkan device and SPIR-V shader modules. ```go shaderVert, _ := device.CreateShaderModule(vertSpirv) shaderFrag, _ := device.CreateShaderModule(fragSpirv) defer device.DestroyShaderModule(shaderVert) defer device.DestroyShaderModule(shaderFrag) layout, _ := device.CreatePipelineLayout(nil, 0, 0) defer device.DestroyPipelineLayout(layout) renderPass, _ := device.CreateColorDepthRenderPass(vk.FormatB8G8R8A8Srgb, vk.FormatD32Sfloat) defer device.DestroyRenderPass(renderPass) pipeline, _ := device.CreateGraphicsPipeline(vk.GraphicsPipelineConfig{ Layout: layout, RenderPass: renderPass, VertexShader: shaderVert, FragShader: shaderFrag, Topology: vk.TopologyTriangleList, PolygonMode: vk.PolygonFill, CullMode: vk.CullBack, FrontFace: vk.FrontFaceCounterClockwise, DepthTest: true, DepthWrite: true, }) defer device.DestroyPipeline(pipeline) ``` -------------------------------- ### Create Logical Device and Graphics Queue Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/device.md Creates a logical Vulkan device and obtains a handle to a graphics queue. Specify desired extensions like VK_KHR_swapchain for graphics capabilities. Ensure to destroy the device when no longer needed. ```go device, queue, err := physicalDevice.CreateDevice(vk.DeviceConfig{ GraphicsFamily: graphicsFamily, Extensions: []string{"VK_KHR_swapchain"}, }) if err != nil { panic(err) } defer device.Destroy() ``` -------------------------------- ### Create Vulkan Instance Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/instance.md Creates a Vulkan instance with the specified configuration, including layers and extensions. Ensure vk.Load() has been called prior to this. The instance handle must be destroyed when no longer needed. ```go instance, err := vk.CreateInstance(vk.InstanceConfig{ ApplicationName: "MyApp", APIVersion: vk.APIVersion13, Layers: []string{"VK_LAYER_KHRONOS_validation"}, Extensions: []string{"VK_KHR_surface", "VK_KHR_xcb_surface"}, }) if err != nil { panic(err) } defer instance.Destroy() ``` -------------------------------- ### Get Vulkan Swapchain Images Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Retrieves the images currently owned by a Vulkan swapchain. This is useful for accessing the individual image buffers that can be rendered to. ```go images, err := device.SwapchainImages(swapchain) if err != nil { panic(err) } fmt.Printf("%d images\n", len(images)) ``` -------------------------------- ### Initialization Functions Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Functions for initializing the Vulkan environment and creating core objects. ```APIDOC ## Load ### Description Loads the Vulkan library. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## CreateInstance ### Description Creates a Vulkan instance. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## CreateDebugMessenger ### Description Creates a debug messenger for Vulkan validation layers. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ``` -------------------------------- ### Get Queue Family Properties Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/device.md Retrieves all queue family properties for a given physical device. Use this to inspect available queues and their capabilities. ```go families := physicalDevice.QueueFamilies() for i, fam := range families { fmt.Printf("Family %d: %d queues\n", i, fam.QueueCount) } ``` -------------------------------- ### CommandBuffer.BindVertexBuffers Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/command-buffer.md Binds multiple vertex buffers starting from a specified binding index. Ensures that the number of offsets provided matches the number of buffers. ```APIDOC ## CommandBuffer.BindVertexBuffers ### Description Binds multiple vertex buffers starting at firstBinding. The offsets slice must match buffers in length. ### Method Go Function Signature ### Parameters #### Path Parameters - **firstBinding** (uint32) - Required - First binding index. - **buffers** ([]Buffer) - Required - Slice of buffers to bind. - **offsets** ([]DeviceSize) - Required - Slice of offsets (same length as buffers). ### Request Example ```go cmdBuffer.BindVertexBuffers(0, []vk.Buffer{buf1.Buffer, buf2.Buffer}, []vk.DeviceSize{0, 0}) ``` ### Response This method does not return a value. ``` -------------------------------- ### Create Sampler with Default Configuration Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/texture.md Creates a sampler using default linear filtering and repeat addressing mode. Handles potential creation errors. ```go // Linear filtering, repeat addressing sampler, err := device.CreateSampler(vk.SamplerConfig{}) if err != nil { panic(err) } ``` -------------------------------- ### vk.CreateInstance Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/instance.md Creates a Vulkan instance with the given configuration. The `Load` function must be called prior to this operation. ```APIDOC ## CreateInstance ### Description Creates a Vulkan instance with the given configuration. Load must be called first. ### Parameters #### Path Parameters * **cfg** (InstanceConfig) - Required - Instance configuration including layers and extensions. ### Returns - Instance: Valid Vulkan instance handle. - error: Non-nil if instance creation fails (e.g., extension not present, initialization failed). ### Example ```go instance, err := vk.CreateInstance(vk.InstanceConfig{ ApplicationName: "MyApp", APIVersion: vk.APIVersion13, Layers: []string{"VK_LAYER_KHRONOS_validation"}, Extensions: []string{"VK_KHR_surface", "VK_KHR_xcb_surface"}, }) if err != nil { panic(err) } def instance.Destroy() ``` ``` -------------------------------- ### Get Vulkan Surface Capabilities Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Retrieves the surface capabilities for a given Vulkan surface. This includes information like minimum and maximum image counts. ```go caps, err := physicalDevice.SurfaceCapabilities(surface) if err != nil { panic(err) } fmt.Printf("Image count: %d-%d\n", caps.MinImageCount, caps.MaxImageCount) ``` -------------------------------- ### Instance Management Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md APIs for managing Vulkan instances, including loading the Vulkan library, creating and destroying instances, enumerating physical devices, and retrieving device information. ```APIDOC ## Instance Management ### Description APIs for managing Vulkan instances, including loading the Vulkan library, creating and destroying instances, enumerating physical devices, and retrieving device information. ### Functions - `Load()`: Loads the Vulkan library. - `CreateInstance(config InstanceConfig)`: Creates a Vulkan instance. - `Destroy(instance Instance)`: Destroys a Vulkan instance. - `EnumeratePhysicalDevices(instance Instance)`: Enumerates available physical devices. - `Info(device PhysicalDevice)`: Retrieves information about a physical device. - `GraphicsFamily(device PhysicalDevice)`: Gets the graphics queue family index for a physical device. ### Types - `Instance`: Represents a Vulkan instance. - `InstanceConfig`: Configuration for instance creation. - `PhysicalDeviceType`: Enum for physical device types. - `DeviceInfo`: Structure containing physical device information. ### Version Utilities - `MakeAPIVersion(major, minor, patch uint8)`: Creates an API version. - `VersionMajor(version uint32)`: Extracts the major version. - `VersionMinor(version uint32)`: Extracts the minor version. - `VersionPatch(version uint32)`: Extracts the patch version. ``` -------------------------------- ### Create Sampler with Custom Configuration Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/texture.md Creates a sampler with custom filtering and addressing modes, such as nearest neighbor and clamp to edge. Handles potential creation errors. ```go // Nearest neighbor, clamp to edge sampler, err = device.CreateSampler(vk.SamplerConfig{ MagFilter: vk.FilterNearest, MinFilter: vk.FilterNearest, AddressModeU: vk.SamplerAddressModeClampToEdge, AddressModeV: vk.SamplerAddressModeClampToEdge, AddressModeW: vk.SamplerAddressModeClampToEdge, }) ``` -------------------------------- ### Get Supported Vulkan Present Modes Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Retrieves a list of supported present modes for a Vulkan surface. This is important for controlling presentation behavior, such as latency and tearing. ```go modes, err := physicalDevice.SurfacePresentModes(surface) if err != nil { panic(err) } // Look for mailbox mode for low-latency presentation for _, m := range modes { if m == vk.PresentModeMailbox { fmt.Println("Mailbox supported") } } ``` -------------------------------- ### Get Physical Device Information Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/instance.md Fetches the properties of a physical device, including its name, type, and API version. This information is crucial for understanding device capabilities. ```go info := physicalDevice.Info() fmt.Printf("GPU: %s\n", info.Name) fmt.Printf("Type: %s\n", info.Type.String()) fmt.Printf("API Version: %d.%d.%d\n", vk.VersionMajor(info.APIVersion), vk.VersionMinor(info.APIVersion), vk.VersionPatch(info.APIVersion)) ``` -------------------------------- ### Create Vulkan Device Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Enumerates physical devices and creates a logical device with specified features and extensions. Requires a valid Vulkan instance. ```go devices, _ := instance.EnumeratePhysicalDevices() physicalDevice := devices[0] family, _ := physicalDevice.GraphicsFamily() device, queue, _ := physicalDevice.CreateDevice(vk.DeviceConfig{ GraphicsFamily: family, Extensions: []string{"VK_KHR_swapchain"}, }) defer device.Destroy() ``` -------------------------------- ### Get Human-Readable Result Name Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/errors.md The String() method provides a human-readable string representation of the Result code, such as "VK_SUCCESS" or "VK_ERROR_...". ```go func (r Result) String() string ``` -------------------------------- ### Create Device-Local Buffer with Data Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/memory.md Uploads data to a new device-local buffer. It uses a host-visible staging buffer and a one-time command submission for efficiency. ```go vertexData := []float32{0, 0.5, 0.5, -0.5, -0.5, -0.5} buf, err := device.CreateDeviceLocalBuffer( physicalDevice, queue, pool, unsafe.Slice((*byte)(unsafe.Pointer(&vertexData[0])), len(vertexData)*4), vk.BufferUsageVertexBuffer) if err != nil { panic(err) } ``` -------------------------------- ### Get Physical Device Type String Representation Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/instance.md The String() method for PhysicalDeviceType returns a human-readable string representation of the device type. This is useful for displaying device information. ```go func (t PhysicalDeviceType) String() string { switch t { case PhysicalDeviceTypeIntegratedGpu: return "Integrated GPU" case PhysicalDeviceTypeDiscreteGpu: return "Discrete GPU" case PhysicalDeviceTypeVirtualGpu: return "Virtual GPU" case PhysicalDeviceTypeCpu: return "CPU" case PhysicalDeviceTypeOther: return "Other" default: return "Unknown" } } ``` ```go fmt.Println(device.Type.String()) // Output: "Discrete GPU" ``` -------------------------------- ### Create Graphics Pipeline Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/pipeline.md Builds a graphics pipeline with dynamic viewport and scissor settings. Configure vertex shaders, fragment shaders, input bindings, and rasterization states. ```go pipeline, err := device.CreateGraphicsPipeline(vk.GraphicsPipelineConfig{ Layout: pipelineLayout, RenderPass: renderPass, VertexShader: vertexModule, FragShader: fragModule, Bindings: []vk.VertexInputBinding{ {Binding: 0, Stride: 12, InputRate: vk.VertexInputRateVertex}, }, Attributes: []vk.VertexInputAttribute{ {Location: 0, Binding: 0, Format: vk.FormatR32G32B32Sfloat, Offset: 0}, }, Topology: vk.TopologyTriangleList, PolygonMode: vk.PolygonFill, CullMode: vk.CullBack, FrontFace: vk.FrontFaceCounterClockwise, DepthTest: true, DepthWrite: true, Blend: false, }) if err != nil { panic(err) } ``` -------------------------------- ### Create Vulkan Swapchain Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Creates a swapchain for color attachment output. Ensure surface capabilities and formats are queried beforehand. The swapchain configuration requires details like the surface, image count, format, color space, extent, and present mode. ```go caps, _ := physicalDevice.SurfaceCapabilities(surface) formats, _ := physicalDevice.SurfaceFormats(surface) swapchain, err := device.CreateSwapchain(vk.SwapchainConfig{ Surface: surface, MinImageCount: caps.MinImageCount + 1, Format: formats[0].Format, ColorSpace: formats[0].ColorSpace, Extent: caps.CurrentExtent, PresentMode: vk.PresentModeMailbox, PreTransform: vk.SurfaceTransformIdentity, Old: 0, }) if err != nil { panic(err) } ``` -------------------------------- ### Check Vulkan Surface Presentation Support Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Reports whether a specific queue family can present to a Vulkan surface. This is crucial for swapchain creation. ```go if physicalDevice.SurfaceSupport(graphicsFamily, surface) { fmt.Println("Queue family can present") } ``` -------------------------------- ### Run Development Build and Tests Source: https://github.com/christerso/vulkan-go/blob/main/CONTRIBUTING.md Execute this command to perform a full development build that includes running all tests. Ensure this passes before committing changes. ```bash make dev ``` -------------------------------- ### Create Vulkan Buffer Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/memory.md Creates a buffer, allocates associated memory, and binds them. Use BufferConfig to specify size, usage, and memory properties. ```go buf, err := device.CreateBuffer(physicalDevice, vk.BufferConfig{ Size: vk.DeviceSize(1024), Usage: vk.BufferUsageVertexBuffer, Properties: vk.MemoryDeviceLocal, Map: false, }) if err != nil { panic(err) } defer device.DestroyBuffer(buf) ``` -------------------------------- ### Device.CreateBuffer Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/memory.md Creates a buffer, allocates memory, and binds them together. This is a convenience function for setting up buffers. ```APIDOC ## Device.CreateBuffer ### Description Creates a buffer, allocates memory, and binds them together. ### Method func (d Device) CreateBuffer(pd PhysicalDevice, cfg BufferConfig) (AllocBuffer, error) ### Parameters #### Path Parameters - pd (PhysicalDevice) - Required - Physical device for memory type selection. - cfg (BufferConfig) - Required - Buffer configuration. ### Response #### Success Response (200) - AllocBuffer: Buffer with allocated memory and optional persistent mapping. - error: Non-nil on creation failure. ### Example ```go buf, err := device.CreateBuffer(physicalDevice, vk.BufferConfig{ Size: vk.DeviceSize(1024), Usage: vk.BufferUsageVertexBuffer, Properties: vk.MemoryDeviceLocal, Map: false, }) if err != nil { panic(err) } defer device.DestroyBuffer(buf) ``` ``` -------------------------------- ### PresentMode Enumeration Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Enumerates the available presentation modes for swapchains. ```go type PresentMode uint32 const ( PresentModeImmediate PresentMode = 0 PresentModeMailbox PresentMode = 1 PresentModeFIFO PresentMode = 2 PresentModeFIFORelaxed PresentMode = 3 ) ``` -------------------------------- ### Transition Image Layout Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/texture.md Records a pipeline barrier to transition an image from one layout to another. Use this for single-step layout changes. ```go func (c CommandBuffer) ImageBarrier(img Image, oldLayout, newLayout ImageLayout, srcStage, dstStage, srcAccess, dstAccess uint32, aspect uint32) ``` -------------------------------- ### Instance and Device Management Functions Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Functions for enumerating physical devices, querying device properties, and creating logical devices. ```APIDOC ## EnumeratePhysicalDevices ### Description Enumerates all available physical Vulkan devices. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## GraphicsFamily ### Description Finds the graphics queue family index for a given physical device. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## Info ### Description Retrieves information about a physical device. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## QueueFamilies ### Description Retrieves all queue family properties for a physical device. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## CreateDevice ### Description Creates a logical Vulkan device. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## SurfaceSupport ### Description Checks if a queue family supports presentation to a surface. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## SurfaceCapabilities ### Description Retrieves the capabilities of a surface. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## SurfaceFormats ### Description Retrieves the supported formats of a surface. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## SurfacePresentModes ### Description Retrieves the supported present modes of a surface. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## PresentFamily ### Description Finds the queue family index that supports presentation to a surface. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ``` -------------------------------- ### Device Configuration Structure Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/types.md Specifies configuration for creating a logical Vulkan device, including the graphics queue family index and a list of device extensions. ```go type DeviceConfig struct { GraphicsFamily uint32 Extensions []string } ``` -------------------------------- ### Create Clear Values Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/types.md Demonstrates creating color and depth/stencil clear values using helper functions. These are used to clear buffers during rendering. ```go clears := []vk.ClearValue{ vk.ClearColor(0, 0, 0, 1), vk.ClearDepthStencil(1, 0), } ``` -------------------------------- ### Record and Submit Commands Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Records drawing commands into a command buffer, then submits it for execution. Requires a command pool, allocated buffers, pipeline, and render targets. ```go pool, _ := device.CreateCommandPool(graphicsFamily) buffers, _ := device.AllocateCommandBuffers(pool, 1) cmd := buffers[0] cmd.Begin(vk.CommandBufferOneTimeSubmit) cmd.BeginRenderPass(renderPass, framebuffer, area, clears) cmd.BindPipeline(pipeline) cmd.SetViewport(viewport) cmd.SetScissor(scissor) cmd.BindVertexBuffer(vertexBuf.Buffer, 0) cmd.BindIndexBuffer(indexBuf.Buffer, 0, vk.IndexTypeUint32) cmd.DrawIndexed(indexCount, 1, 0, 0, 0) cmd.EndRenderPass() cmd.End() sem, _ := device.CreateSemaphore() fence, _ := device.CreateFence(true) queue.Submit(vk.SubmitConfig{Command: cmd, Signal: sem, Fence: fence}) device.WaitFence(fence, 1e9) ``` -------------------------------- ### Create Vulkan Texture Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Creates a 2D texture image, view, and sampler, then updates a descriptor set. Requires a device, queue, command pool, and image data. ```go img, view, _ := device.CreateTexture2D(physicalDevice, queue, pool, width, height, rgbaData) sampler, _ := device.CreateSampler(vk.SamplerConfig{}) device.UpdateImageDescriptor(descriptorSet, 0, view, sampler) ``` -------------------------------- ### Device.CreateGraphicsPipeline Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/pipeline.md Builds a graphics pipeline with dynamic viewport and scissor configurations. ```APIDOC ## Device.CreateGraphicsPipeline ### Description Builds a graphics pipeline with dynamic viewport and scissor. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **cfg** (GraphicsPipelineConfig) - Required - Pipeline configuration object containing details like layout, shaders, vertex input, topology, polygon mode, cull mode, front face, depth test, depth write, and blend settings. ### Request Example ```go pipeline, err := device.CreateGraphicsPipeline(vk.GraphicsPipelineConfig{ Layout: pipelineLayout, RenderPass: renderPass, VertexShader: vertexModule, FragShader: fragModule, Bindings: []vk.VertexInputBinding{ {Binding: 0, Stride: 12, InputRate: vk.VertexInputRateVertex}, }, Attributes: []vk.VertexInputAttribute{ {Location: 0, Binding: 0, Format: vk.FormatR32G32B32Sfloat, Offset: 0}, }, Topology: vk.TopologyTriangleList, PolygonMode: vk.PolygonFill, CullMode: vk.CullBack, FrontFace: vk.FrontFaceCounterClockwise, DepthTest: true, DepthWrite: true, Blend: false, }) if err != nil { panic(err) } ``` ### Response #### Success Response (200) - **Pipeline**: Valid pipeline handle. - **error**: nil on success. #### Response Example ```json { "Pipeline": "" } ``` #### Error Response - **error**: Non-nil on creation failure. ``` -------------------------------- ### Queue.Present Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Submits an image from the swapchain for presentation to the display, optionally waiting on a semaphore. ```APIDOC ## Queue.Present ### Description Queues the image for presentation, waiting on sem. ### Method (Implicitly POST or similar, as it submits a request for action) ### Endpoint (Not applicable for SDK functions) ### Parameters #### Path Parameters (Not applicable for SDK functions) #### Query Parameters (Not applicable for SDK functions) #### Request Body - **sc** (SwapchainKHR) - Required - The swapchain containing the image to present. - **imageIndex** (uint32) - Required - The index of the image to present, obtained from AcquireNextImage. - **wait** (Semaphore) - Required - The semaphore to wait on before presenting (use 0 for no semaphore). ### Request Example ```go result := queue.Present(swapchain, imageIndex, presentSem) if result == vk.ErrorOutOfDateKHR { // Recreate swapchain } ``` ### Response #### Success Response - **Result**: VK_SUCCESS indicating the presentation was queued successfully. #### Response Example (No explicit response body example provided, but the Go function returns a Result code) ERROR HANDLING: - Returns VK_SUBOPTIMAL_KHR or VK_ERROR_OUT_OF_DATE_KHR if the swapchain is suboptimal or out of date, respectively. ``` -------------------------------- ### Instance.EnumeratePhysicalDevices Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/instance.md Retrieves a list of all physical devices available on the Vulkan instance. ```APIDOC ## Instance.EnumeratePhysicalDevices ### Description Returns all physical devices available on the instance. ### Returns - []PhysicalDevice: Slice of available physical device handles. - error: Non-nil if enumeration fails. ### Example ```go devices, err := instance.EnumeratePhysicalDevices() if err != nil { panic(err) } for _, pd := range devices { info := pd.Info() fmt.Printf("%s (%s)\n", info.Name, info.Type) } ``` ``` -------------------------------- ### Device.CreateFence Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/sync.md Creates a fence for GPU-CPU synchronization. The fence can be created in a signaled or unsignaled state. ```APIDOC ## Device.CreateFence ### Description Creates a fence. If signaled is true, the fence starts in signaled state. ### Method func (d Device) CreateFence(signaled bool) (Fence, error) ### Parameters #### Path Parameters - **signaled** (bool) - Required - Initial state: true for signaled, false for unsignaled. ### Returns - Fence: Valid fence handle. - error: Non-nil on creation failure. ### Example ```go fence, err := device.CreateFence(true) if err != nil { panic(err) } def device.DestroyFence(fence) ``` ``` -------------------------------- ### Swapchain Creation Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md This section details the configuration required to create a new swapchain. It outlines the necessary parameters such as the surface, image count, format, extent, and presentation mode. ```APIDOC ## Swapchain Creation ### Description Configuration for swapchain creation. This includes specifying the target surface, desired image count, pixel format, color space, extent (resolution), presentation mode, and pre-transform. ### Struct: SwapchainConfig #### Fields - **Surface** (SurfaceKHR) - Required - The window surface to present rendered images to. - **MinImageCount** (uint32) - Required - The minimum number of images the swapchain should have, as determined by `SurfaceCapabilities`. - **Format** (Format) - Required - The pixel format of the images in the swapchain. - **ColorSpace** (uint32) - Required - The color space associated with the image format. - **Extent** (Extent2D) - Required - The resolution (width and height) of the swapchain images. - **PresentMode** (PresentMode) - Required - The presentation mode to use for displaying images. - **PreTransform** (uint32) - Required - The transform to apply to images before presentation (e.g., `SurfaceTransformIdentity`). - **Old** (SwapchainKHR) - Optional - A handle to a previous swapchain that is being replaced. If this is a new swapchain, this should be 0. ``` -------------------------------- ### Device.CreateTexture2DMipmapped Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/texture.md Creates a 2D image with a full mip chain, uploads the base level, and generates the rest on the GPU. It returns the image, a view spanning all levels, and the mip count. ```APIDOC ## Device.CreateTexture2DMipmapped ### Description Creates a device-local, sampled 2D image with a full mip chain, uploads level 0, and generates remaining levels on the GPU with vkCmdBlitImage (LINEAR filter). Returns the image, an image view spanning all mip levels, and the mip count. The whole image ends in SHADER_READ_ONLY_OPTIMAL. rgba must hold width*height*4 bytes. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method Signature ```go func (d Device) CreateTexture2DMipmapped(pd PhysicalDevice, q Queue, pool CommandPool, width, height uint32, rgba []byte) (AllocImage, ImageView, uint32, error) ``` ### Parameters - **pd** (PhysicalDevice) - Physical device. - **q** (Queue) - Queue. - **pool** (CommandPool) - Command pool. - **width** (uint32) - Texture width. - **height** (uint32) - Texture height. - **rgba** ([]byte) - RGBA data for level 0 (width*height*4 bytes). ### Returns - **AllocImage**: Image with full mip chain. - **ImageView**: View covering all levels. - **uint32**: Number of mip levels. - **error**: Non-nil on failure. ### Example ```go img, view, levels, err := device.CreateTexture2DMipmapped( physicalDevice, queue, pool, 512, 512, rgba) if err != nil { panic(err) } // Sampler MaxLod should be set to float32(levels)-1 for full range sampler, _ := device.CreateSampler(vk.SamplerConfig{ MaxLod: float32(levels) - 1, }) ``` ``` -------------------------------- ### Create Command Pool Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/command-buffer.md Creates a command pool that allows individual command buffer resets. Ensure to destroy the pool when no longer needed. ```go func (d Device) CreateCommandPool(family uint32) (CommandPool, error) ``` ```go pool, err := device.CreateCommandPool(graphicsFamily) if err != nil { panic(err) } defer device.DestroyCommandPool(pool) ``` -------------------------------- ### Handle Swapchain Recreation in Go Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/errors.md Implement logic to handle swapchain recreation, particularly when `AcquireNextImage` returns `vk.ErrorOutOfDateKHR`. This ensures the application can adapt to window resizing or other surface changes. ```go imageIndex, result := device.AcquireNextImage(swapchain, sem, 1e9) if result == vk.ErrorOutOfDateKHR { // Recreate swapchain and framebuffers rebuildSwapchain() continue } ``` -------------------------------- ### Device Management Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md APIs for creating and managing logical Vulkan devices and their associated queue families. ```APIDOC ## Device Management ### Description APIs for creating and managing logical Vulkan devices and their associated queue families. ### Functions - `QueueFamilies(device PhysicalDevice)`: Retrieves properties of queue families for a physical device. - `CreateDevice(physicalDevice PhysicalDevice, config DeviceConfig)`: Creates a logical device. - `Destroy(device Device)`: Destroys a logical device. ### Types - `Device`: Represents a logical Vulkan device. - `Queue`: Represents a queue on a logical device. - `DeviceConfig`: Configuration for logical device creation. - `QueueFamilyProperties`: Structure containing queue family properties. ``` -------------------------------- ### Create 2D Texture with Vulkan-Go Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/texture.md Creates a device-local, sampled 2D image from RGBA bytes. The data is uploaded via a staging buffer and a command buffer. Ensure rgba data is correctly formatted (width*height*4 bytes). ```go func (d Device) CreateTexture2D(pd PhysicalDevice, q Queue, pool CommandPool, width, height uint32, rgba []byte) (AllocImage, ImageView, error) ``` ```go // Create 512x512 RGBA texture rgba := make([]byte, 512*512*4) // ... fill rgba with pixel data ... img, view, err := device.CreateTexture2D(physicalDevice, queue, pool, 512, 512, rgba) if err != nil { panic(err) } def device.DestroyImage(img) def device.DestroyImageView(view) ``` -------------------------------- ### InstanceConfig Structure Definition Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/instance.md Defines the InstanceConfig structure used for configuring Vulkan instance creation. It includes application and engine names, API version, and lists of layers and extensions. ```go type InstanceConfig struct { ApplicationName string EngineName string APIVersion uint32 Layers []string Extensions []string } ``` -------------------------------- ### PhysicalDevice.SurfaceSupport Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/surface-swapchain.md Reports whether a specific queue family on a physical device supports presenting to a given Vulkan surface. This is crucial for determining if a queue can be used for rendering to a display. ```APIDOC ## PhysicalDevice.SurfaceSupport ### Description Reports whether the queue family can present to the surface. ### Signature ```go func (pd PhysicalDevice) SurfaceSupport(family uint32, s SurfaceKHR) bool ``` ### Parameters - **family** (uint32) - Required - Queue family index. - **s** (SurfaceKHR) - Required - Surface. ### Returns - bool: True if the queue family supports presentation to this surface, false otherwise. ### Example ```go if physicalDevice.SurfaceSupport(graphicsFamily, surface) { fmt.Println("Queue family can present") } ``` ``` -------------------------------- ### Create Pipeline Layout Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/pipeline.md Creates a pipeline layout from descriptor set layouts and an optional push constant range. Use when defining the binding points for resources like uniform buffers and samplers. ```go layout, err := device.CreatePipelineLayout( []vk.DescriptorSetLayout{dsLayout}, vk.ShaderStageVertex, 64) if err != nil { panic(err) } ``` -------------------------------- ### Surface and Swapchain Functions Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/INDEX.md Functions for managing Vulkan surfaces and swapchains for presentation. ```APIDOC ## DestroySurface ### Description Destroys a Vulkan surface. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## CreateSwapchain ### Description Creates a Vulkan swapchain. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## DestroySwapchain ### Description Destroys a Vulkan swapchain. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## SwapchainImages ### Description Retrieves the images associated with a swapchain. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ## AcquireNextImage ### Description Acquires the next available image from the swapchain. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ``` -------------------------------- ### Transition Image Layout for Sampling Source: https://github.com/christerso/vulkan-go/blob/main/_autodocs/api-reference/texture.md Transitions an image from transfer-destination optimal to shader-readable optimal layout for sampling. This is done after data has been uploaded. ```go // Later: transition from transfer-dst to shader-read for sampling cmdBuffer.ImageBarrier(img, vk.LayoutTransferDstOptimal, vk.LayoutShaderReadOnlyOptimal, vk.StageTransfer, vk.StageFragmentShader, vk.AccessTransferWrite, vk.AccessShaderRead, vk.AspectColor) ```