Mercurial > games > semicongine
annotate semiconginev2/old/vulkan/image.nim @ 1221:000befd9479f compiletime-tests
did: remove support for git, for now
author | sam <sam@basx.dev> |
---|---|
date | Wed, 17 Jul 2024 21:05:47 +0700 |
parents | 56781cc0fc7c |
children |
rev | line source |
---|---|
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import std/strformat |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 import std/tables |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/logging |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 import ../core |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 import ./device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 import ./physicaldevice |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 import ./buffer |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 import ./memory |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 import ./commandbuffer |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 type |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 PixelDepth = 1 .. 4 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 VulkanImage* = object |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 device*: Device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 vk*: VkImage |
959
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
958
diff
changeset
|
17 width*: uint32 # pixel |
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
958
diff
changeset
|
18 height*: uint32 # pixel |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 depth*: PixelDepth |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 format*: VkFormat |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 usage*: seq[VkImageUsageFlagBits] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 case memoryAllocated*: bool |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 of false: discard |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 of true: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 memory*: DeviceMemory |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 VulkanSampler* = object |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 device*: Device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 vk*: VkSampler |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 ImageView* = object |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 vk*: VkImageView |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 image*: VulkanImage |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 VulkanTexture* = object |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 image*: VulkanImage |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 imageView*: ImageView |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 sampler*: VulkanSampler |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 const DEPTH_FORMAT_MAP = { |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
38 PixelDepth(1): [VK_FORMAT_R8_SRGB, VK_FORMAT_R8_UNORM], |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
39 PixelDepth(2): [VK_FORMAT_R8G8_SRGB, VK_FORMAT_R8G8_UNORM], |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
40 PixelDepth(3): [VK_FORMAT_R8G8B8_SRGB, VK_FORMAT_R8G8B8_UNORM], |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
41 PixelDepth(4): [VK_FORMAT_R8G8B8A8_SRGB, VK_FORMAT_R8G8B8A8_UNORM], |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 }.toTable |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
44 const LINEAR_FORMATS = [ |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
45 VK_FORMAT_R8_UNORM, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
46 VK_FORMAT_R8G8_UNORM, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
47 VK_FORMAT_R8G8B8_UNORM, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
48 VK_FORMAT_R8G8B8A8_UNORM, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
49 ] |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
50 |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
51 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
52 proc requirements(image: VulkanImage): MemoryRequirements = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
53 assert image.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
54 assert image.device.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
55 var req: VkMemoryRequirements |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 image.device.vk.vkGetImageMemoryRequirements(image.vk, addr req) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
57 result.size = req.size |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
58 result.alignment = req.alignment |
1138 | 59 let memorytypes = image.device.physicaldevice.vk.GetMemoryProperties().types |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
60 for i in 0 ..< sizeof(req.memoryTypeBits) * 8: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
61 if ((req.memoryTypeBits shr i) and 1) == 1: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
62 result.memoryTypes.add memorytypes[i] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
63 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 proc allocateMemory(image: var VulkanImage, requireMappable: bool, preferVRAM: bool, preferAutoFlush: bool) = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
65 assert image.device.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 assert image.memoryAllocated == false |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
67 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
68 let requirements = image.requirements() |
1138 | 69 let memoryType = requirements.memoryTypes.SelectBestMemoryType( |
902 | 70 requireMappable = requireMappable, |
71 preferVRAM = preferVRAM, | |
72 preferAutoFlush = preferAutoFlush | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
75 debug "Allocating memory for image: ", image.width, "x", image.height, "x", image.depth, ", ", requirements.size, " bytes of type ", memoryType |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 image = VulkanImage( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 device: image.device, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
78 vk: image.vk, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
79 width: image.width, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
80 height: image.height, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
81 depth: image.depth, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
82 format: image.format, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
83 usage: image.usage, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
84 memoryAllocated: true, |
1138 | 85 memory: image.device.Allocate(requirements.size, memoryType), |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
86 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
87 checkVkResult image.device.vk.vkBindImageMemory(image.vk, image.memory.vk, VkDeviceSize(0)) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
88 |
943
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
89 proc transitionImageLayout(image: VulkanImage, queue: Queue, oldLayout, newLayout: VkImageLayout) = |
945
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
90 var |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
91 barrier = VkImageMemoryBarrier( |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
92 sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, |
943
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
93 oldLayout: oldLayout, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
94 newLayout: newLayout, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
95 srcQueueFamilyIndex: VK_QUEUE_FAMILY_IGNORED, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
96 dstQueueFamilyIndex: VK_QUEUE_FAMILY_IGNORED, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
97 image: image.vk, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
98 subresourceRange: VkImageSubresourceRange( |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
99 aspectMask: toBits [VK_IMAGE_ASPECT_COLOR_BIT], |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
100 baseMipLevel: 0, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
101 levelCount: 1, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
102 baseArrayLayer: 0, |
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
103 layerCount: 1, |
945
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
104 ), |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
105 ) |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
106 srcStage: VkPipelineStageFlagBits |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
107 dstStage: VkPipelineStageFlagBits |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
108 if oldLayout == VK_IMAGE_LAYOUT_UNDEFINED and newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: |
945
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
109 srcStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
110 barrier.srcAccessMask = VkAccessFlags(0) |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
111 dstStage = VK_PIPELINE_STAGE_TRANSFER_BIT |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
112 barrier.dstAccessMask = [VK_ACCESS_TRANSFER_WRITE_BIT].toBits |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
113 elif oldLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL and newLayout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
945
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
114 srcStage = VK_PIPELINE_STAGE_TRANSFER_BIT |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
115 barrier.srcAccessMask = [VK_ACCESS_TRANSFER_WRITE_BIT].toBits |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
116 dstStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
b65068f5f246
del: do not use vulkan 1.3 functions to support older hardware
sam <sam@basx.dev>
parents:
943
diff
changeset
|
117 barrier.dstAccessMask = [VK_ACCESS_SHADER_READ_BIT].toBits |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
118 else: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
119 raise newException(Exception, "Unsupported layout transition!") |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
120 |
1138 | 121 WithSingleUseCommandBuffer(image.device, queue, commandBuffer): |
122 commandBuffer.PipelineBarrier([srcStage], [dstStage], imageBarriers = [barrier]) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
123 |
1138 | 124 proc Copy*(src: Buffer, dst: VulkanImage, queue: Queue) = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
125 assert src.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
126 assert dst.device.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
127 assert src.device == dst.device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
128 assert VK_BUFFER_USAGE_TRANSFER_SRC_BIT in src.usage |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
129 assert VK_IMAGE_USAGE_TRANSFER_DST_BIT in dst.usage |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
130 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
131 var region = VkBufferImageCopy( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
132 bufferOffset: 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
133 bufferRowLength: 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
134 bufferImageHeight: 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
135 imageSubresource: VkImageSubresourceLayers( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
136 aspectMask: toBits [VK_IMAGE_ASPECT_COLOR_BIT], |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
137 mipLevel: 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
138 baseArrayLayer: 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
139 layerCount: 1, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
140 ), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
141 imageOffset: VkOffset3D(x: 0, y: 0, z: 0), |
959
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
958
diff
changeset
|
142 imageExtent: VkExtent3D(width: dst.width, height: dst.height, depth: 1) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
143 ) |
1138 | 144 WithSingleUseCommandBuffer(src.device, queue, commandBuffer): |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
145 commandBuffer.vkCmdCopyBufferToImage( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
146 src.vk, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
147 dst.vk, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
148 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
149 1, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
150 addr region |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
151 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
152 |
1167 | 153 proc CreateImage*(device: Device, width, height, depth: uint32, format: VkFormat, samples: VkSampleCountFlagBits, usage: openArray[VkImageUsageFlagBits]): VulkanImage = |
154 assert device.vk.Valid | |
155 assert width > 0 | |
156 assert height > 0 | |
157 | |
158 result.device = device | |
159 result.usage = @usage | |
160 | |
161 | |
162 result.width = width | |
163 result.height = height | |
164 result.depth = depth | |
165 result.format = format | |
166 | |
167 var imageInfo = VkImageCreateInfo( | |
168 sType: VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, | |
169 imageType: VK_IMAGE_TYPE_2D, | |
170 extent: VkExtent3D(width: uint32(width), height: uint32(height), depth: 1), | |
171 mipLevels: 1, | |
172 arrayLayers: 1, | |
173 format: result.format, | |
174 tiling: VK_IMAGE_TILING_OPTIMAL, | |
175 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, | |
176 usage: toBits result.usage, | |
177 sharingMode: VK_SHARING_MODE_EXCLUSIVE, | |
178 samples: samples, | |
179 ) | |
180 checkVkResult device.vk.vkCreateImage(addr imageInfo, nil, addr result.vk) | |
181 result.allocateMemory(requireMappable = false, preferVRAM = true, preferAutoFlush = false) | |
182 | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
183 # currently only usable for texture access from shader |
1167 | 184 proc createTextureImage[T](device: Device, queue: Queue, width, height: uint32, depth: PixelDepth, image: Image[T]): VulkanImage = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
185 assert device.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
186 assert width > 0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
187 assert height > 0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
188 assert depth != 2 |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
189 |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
190 result.device = device |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
191 result.usage = @[VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_USAGE_SAMPLED_BIT] |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
192 |
959
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
958
diff
changeset
|
193 let size: uint64 = width * height * uint32(depth) |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
194 let usageBits = toBits result.usage |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
195 var formatList = DEPTH_FORMAT_MAP[depth] |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
196 var selectedFormat: VkFormat |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
197 var formatProperties = VkImageFormatProperties2(sType: VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2) |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
198 |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
199 for format in formatList: |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
200 var formatInfo = VkPhysicalDeviceImageFormatInfo2( |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
201 sType: VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
202 format: format, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
203 thetype: VK_IMAGE_TYPE_2D, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
204 tiling: VK_IMAGE_TILING_OPTIMAL, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
205 usage: usageBits, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
206 ) |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
207 let formatCheck = device.physicalDevice.vk.vkGetPhysicalDeviceImageFormatProperties2( |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
208 addr formatInfo, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
209 addr formatProperties, |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
210 ) |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
211 if formatCheck == VK_SUCCESS: # found suitable format |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
212 selectedFormat = format |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
213 break |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
214 elif formatCheck == VK_ERROR_FORMAT_NOT_SUPPORTED: # nope, try to find other format |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
215 continue |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
216 else: # raise error |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
217 checkVkResult formatCheck |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
218 |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
219 # assumption: images comes in sRGB color space |
979 | 220 # convert to linear space if there is not support for sRGB |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
221 var data = addr image.imagedata[0] |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
222 if selectedFormat in LINEAR_FORMATS: |
1137 | 223 let linearImage = image.AsLinear() |
979 | 224 data = addr linearImage.imagedata[0] |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
225 |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
226 assert size <= uint64(formatProperties.imageFormatProperties.maxResourceSize) |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
227 assert width <= uint64(formatProperties.imageFormatProperties.maxExtent.width) |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
228 assert height <= uint64(formatProperties.imageFormatProperties.maxExtent.height) |
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
229 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
230 result.width = width |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
231 result.height = height |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
232 result.depth = depth |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
233 result.format = selectedFormat |
959
c104dbf5bbb8
did: adjust integer sizes to match vulkan API (more) directly
sam <sam@basx.dev>
parents:
958
diff
changeset
|
234 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
235 var imageInfo = VkImageCreateInfo( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
236 sType: VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
237 imageType: VK_IMAGE_TYPE_2D, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
238 extent: VkExtent3D(width: uint32(width), height: uint32(height), depth: 1), |
958 | 239 mipLevels: min(1'u32, formatProperties.imageFormatProperties.maxMipLevels), |
240 arrayLayers: min(1'u32, formatProperties.imageFormatProperties.maxArrayLayers), | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
241 format: result.format, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
242 tiling: VK_IMAGE_TILING_OPTIMAL, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
243 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, |
962
7855746f2d13
add: support for color space conversion, convert color space if srgb is not available for images
sam <sam@basx.dev>
parents:
960
diff
changeset
|
244 usage: usageBits, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
245 sharingMode: VK_SHARING_MODE_EXCLUSIVE, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
246 samples: VK_SAMPLE_COUNT_1_BIT, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
247 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
248 checkVkResult device.vk.vkCreateImage(addr imageInfo, nil, addr result.vk) |
902 | 249 result.allocateMemory(requireMappable = false, preferVRAM = true, preferAutoFlush = false) |
943
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
250 result.transitionImageLayout(queue, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
251 |
1138 | 252 var stagingBuffer = device.CreateBuffer(size = size, usage = [VK_BUFFER_USAGE_TRANSFER_SRC_BIT], requireMappable = true, preferVRAM = false, preferAutoFlush = true) |
253 stagingBuffer.SetData(queue, src = data, size = size) | |
254 stagingBuffer.Copy(result, queue) | |
943
925197a1ec95
add: some sync (not finished), simplify renderpass af
sam <sam@basx.dev>
parents:
940
diff
changeset
|
255 result.transitionImageLayout(queue, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) |
1138 | 256 stagingBuffer.Destroy() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
257 |
1138 | 258 proc Destroy*(image: var VulkanImage) = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
259 assert image.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
260 assert image.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
261 image.device.vk.vkDestroyImage(image.vk, nil) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
262 if image.memoryAllocated: |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
263 assert image.memory.vk.Valid |
1138 | 264 image.memory.Free() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
265 image = VulkanImage( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
266 device: image.device, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
267 vk: image.vk, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
268 width: image.width, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
269 height: image.height, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
270 depth: image.depth, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
271 format: image.format, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
272 usage: image.usage, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
273 memoryAllocated: false, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
274 ) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
275 image.vk.Reset |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
276 |
1138 | 277 proc CreateSampler*(device: Device, sampler: Sampler): VulkanSampler = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
278 assert device.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
279 var samplerInfo = VkSamplerCreateInfo( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
280 sType: VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
281 magFilter: sampler.magnification, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
282 minFilter: sampler.minification, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
283 addressModeU: sampler.wrapModeS, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
284 addressModeV: sampler.wrapModeT, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
285 addressModeW: VK_SAMPLER_ADDRESS_MODE_REPEAT, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
286 anisotropyEnable: device.enabledFeatures.samplerAnisotropy, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
287 maxAnisotropy: device.physicalDevice.properties.limits.maxSamplerAnisotropy, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
288 borderColor: VK_BORDER_COLOR_INT_OPAQUE_BLACK, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
289 unnormalizedCoordinates: VK_FALSE, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
290 compareEnable: VK_FALSE, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
291 compareOp: VK_COMPARE_OP_ALWAYS, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
292 mipmapMode: VK_SAMPLER_MIPMAP_MODE_LINEAR, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
293 mipLodBias: 0, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
294 minLod: 0, |
940
459066429a72
fix: last commit was actually only relevant for ARM, also adjust validation outputs
sam <sam@basx.dev>
parents:
939
diff
changeset
|
295 maxLod: 0, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
296 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
297 result.device = device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
298 checkVkResult device.vk.vkCreateSampler(addr samplerInfo, nil, addr result.vk) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
299 |
1138 | 300 proc Destroy*(sampler: var VulkanSampler) = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
301 assert sampler.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
302 assert sampler.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
303 sampler.device.vk.vkDestroySampler(sampler.vk, nil) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
304 sampler.vk.Reset |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
305 |
1138 | 306 proc CreateImageView*( |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
307 image: VulkanImage, |
902 | 308 imageviewtype = VK_IMAGE_VIEW_TYPE_2D, |
309 baseMipLevel = 0'u32, | |
310 levelCount = 1'u32, | |
311 baseArrayLayer = 0'u32, | |
312 layerCount = 1'u32 | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
313 ): ImageView = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
314 assert image.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
315 assert image.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
316 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
317 var createInfo = VkImageViewCreateInfo( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
318 sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
319 image: image.vk, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
320 viewType: imageviewtype, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
321 format: image.format, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
322 components: VkComponentMapping( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
323 r: VK_COMPONENT_SWIZZLE_IDENTITY, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
324 g: VK_COMPONENT_SWIZZLE_IDENTITY, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
325 b: VK_COMPONENT_SWIZZLE_IDENTITY, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
326 a: VK_COMPONENT_SWIZZLE_IDENTITY, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
327 ), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
328 subresourceRange: VkImageSubresourceRange( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
329 aspectMask: VkImageAspectFlags(VK_IMAGE_ASPECT_COLOR_BIT), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
330 baseMipLevel: baseMipLevel, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
331 levelCount: levelCount, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
332 baseArrayLayer: baseArrayLayer, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
333 layerCount: layerCount, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
334 ), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
335 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
336 result.image = image |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
337 checkVkResult image.device.vk.vkCreateImageView(addr(createInfo), nil, addr(result.vk)) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
338 |
1138 | 339 proc Destroy*(imageview: var ImageView) = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
340 assert imageview.image.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
341 assert imageview.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
342 imageview.image.device.vk.vkDestroyImageView(imageview.vk, nil) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
343 imageview.vk.Reset() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
344 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
345 func `$`*(texture: VulkanTexture): string = |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
346 &"VulkanTexture({texture.image.width}x{texture.image.height})" |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
347 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
348 |
1138 | 349 proc UploadTexture*(device: Device, queue: Queue, texture: Texture): VulkanTexture = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
350 assert device.vk.Valid |
872
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
840
diff
changeset
|
351 if texture.isGrayscale: |
1167 | 352 result.image = createTextureImage(device = device, queue = queue, width = texture.grayImage.width, height = texture.grayImage.height, depth = 1, image = texture.grayImage) |
872
1ee397815b0b
did: image & font refactoring, add texture-atlas-packing
Sam <sam@basx.dev>
parents:
840
diff
changeset
|
353 else: |
1167 | 354 result.image = createTextureImage(device = device, queue = queue, width = texture.colorImage.width, height = texture.colorImage.height, depth = 4, image = texture.colorImage) |
1138 | 355 result.imageView = result.image.CreateImageView() |
356 result.sampler = result.image.device.CreateSampler(texture.sampler) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
357 |
1138 | 358 proc Destroy*(texture: var VulkanTexture) = |
359 texture.image.Destroy() | |
360 texture.imageView.Destroy() | |
361 texture.sampler.Destroy() |