VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
AttachmentsVk Struct Reference

#include <AttachmentsVk.h>

Public Member Functions

 AttachmentsVk (uint32_t w, uint32_t h, uint32_t multisample)
 
bool destroy ()
 
void createMultiViewColorDepthWithResolution ()
 

Public Attributes

uint32_t w
 
uint32_t h
 
uint32_t multiview = 2
 
uint32_t multisample
 
MIVSIvk color
 
union {
   struct {
      MIVvk   colorMS
 
      MIVvk   depthMS
 
      MIVvk   stencilMS
 
      MIVvk   depth
 
      MIVvk   stencil
 
   } 
 
   struct {
      MIVvk   member [5]
 
   } 
 
}; 
 

Detailed Description

Definition at line 14 of file AttachmentsVk.h.

Constructor & Destructor Documentation

◆ AttachmentsVk()

AttachmentsVk::AttachmentsVk ( uint32_t  w,
uint32_t  h,
uint32_t  multisample 
)

Definition at line 6 of file AttachmentsVk.cpp.

7 color = {};
8 for (int i = 0; i < 5; i++)member[i] = {};
9};
MIVvk member[5]
Definition: AttachmentsVk.h:32
uint32_t multisample
Definition: AttachmentsVk.h:18

Member Function Documentation

◆ createMultiViewColorDepthWithResolution()

void AttachmentsVk::createMultiViewColorDepthWithResolution ( )

VK_SAMPLE_COUNT_1_BIT;

Definition at line 16 of file AttachmentsVk.cpp.

16 {
17
18 const uint32_t multiviewLayerCount = 2;
19
20 log_ata("create MVColDepWithReso [%u %u] multisample %u \n", w, h,multisample);
21 {
22 VkImageCreateInfo imageCI = vka::plysm::imageCreateInfo();
23 imageCI.imageType = VK_IMAGE_TYPE_2D;
24 imageCI.format = $format.COLORFORMAT;
25 imageCI.extent = { w, h, 1 };
26 imageCI.mipLevels = 1;
27 imageCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
28 imageCI.arrayLayers = multiviewLayerCount;
29 imageCI.samples = (VkSampleCountFlagBits)multisample;
30 imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
31 imageCI.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
32 VK_CHECK_RESULT(vkCreateImage($device, &imageCI, nullptr, &colorMS.image));
33
34 VkMemoryRequirements memReqs;
35 vkGetImageMemoryRequirements($device, colorMS.image, &memReqs);
36
37 VkMemoryAllocateInfo memoryAllocInfo = vka::plysm::memoryAllocateInfo();
38 memoryAllocInfo.allocationSize = memReqs.size;
39 memoryAllocInfo.memoryTypeIndex = vka::shelve::getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,nullptr);
40 VK_CHECK_RESULT(vkAllocateMemory($device, &memoryAllocInfo, nullptr, &colorMS.memory));
41 VK_CHECK_RESULT(vkBindImageMemory($device, colorMS.image, colorMS.memory, 0));
42
43 VkImageViewCreateInfo imageViewCI = vka::plysm::imageViewCreateInfo();
44 imageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
45 imageViewCI.format = $format.COLORFORMAT;
46 imageViewCI.flags = 0;
47 imageViewCI.components.r = VK_COMPONENT_SWIZZLE_R;
48 imageViewCI.components.g = VK_COMPONENT_SWIZZLE_G;
49 imageViewCI.components.b = VK_COMPONENT_SWIZZLE_B;
50 imageViewCI.components.a = VK_COMPONENT_SWIZZLE_A;
51 imageViewCI.subresourceRange = {};
52 imageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
53 imageViewCI.subresourceRange.baseMipLevel = 0;
54 imageViewCI.subresourceRange.levelCount = 1;
55 imageViewCI.subresourceRange.baseArrayLayer = 0;
56 imageViewCI.subresourceRange.layerCount = multiviewLayerCount;
57 imageViewCI.image = colorMS.image;
58 VK_CHECK_RESULT(vkCreateImageView($device, &imageViewCI, nullptr, &colorMS.view));
59
60 }
61
62
63 {
64 VkImageCreateInfo imageCI = vka::plysm::imageCreateInfo();
65 imageCI.imageType = VK_IMAGE_TYPE_2D;
66 imageCI.format = $format.COLORFORMAT;
67 imageCI.extent = { w, h, 1 };
68 imageCI.mipLevels = 1;
69 imageCI.arrayLayers = multiviewLayerCount;
70 imageCI.samples = VK_SAMPLE_COUNT_1_BIT;
71 imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
72 imageCI.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
73 VK_CHECK_RESULT(vkCreateImage($device, &imageCI, nullptr, &color.image));
74
75 VkMemoryRequirements memReqs;
76 vkGetImageMemoryRequirements($device, color.image, &memReqs);
77
78 VkMemoryAllocateInfo memoryAllocInfo = vka::plysm::memoryAllocateInfo();
79 memoryAllocInfo.allocationSize = memReqs.size;
80 memoryAllocInfo.memoryTypeIndex = vka::shelve::getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,nullptr);
81 VK_CHECK_RESULT(vkAllocateMemory($device, &memoryAllocInfo, nullptr, &color.memory));
82 VK_CHECK_RESULT(vkBindImageMemory($device, color.image, color.memory, 0));
83
84 VkImageViewCreateInfo imageViewCI = vka::plysm::imageViewCreateInfo();
85 imageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
86 imageViewCI.format = $format.COLORFORMAT;
87 imageViewCI.flags = 0;
88 imageViewCI.subresourceRange = {};
89 imageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
90 imageViewCI.subresourceRange.baseMipLevel = 0;
91 imageViewCI.subresourceRange.levelCount = 1;
92 imageViewCI.subresourceRange.baseArrayLayer = 0;
93 imageViewCI.subresourceRange.layerCount = multiviewLayerCount;
94 imageViewCI.image = color.image;
95 VK_CHECK_RESULT(vkCreateImageView($device, &imageViewCI, nullptr, &color.view));
96
97 // Create sampler to sample from the attachment in the fragment shader
98 VkSamplerCreateInfo samplerCI = vka::plysm::samplerCreateInfo();
99 samplerCI.magFilter = VK_FILTER_NEAREST;
100 samplerCI.minFilter = VK_FILTER_NEAREST;
101 samplerCI.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
102 samplerCI.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
103 samplerCI.addressModeV = samplerCI.addressModeU;
104 samplerCI.addressModeW = samplerCI.addressModeU;
105 samplerCI.mipLodBias = 0.0f;
106 samplerCI.maxAnisotropy = 1.0f;
107 samplerCI.minLod = 0.0f;
108 samplerCI.maxLod = 1.0f;
109 samplerCI.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
110 VK_CHECK_RESULT(vkCreateSampler($device, &samplerCI, nullptr, &color.sampler));
111
112
113 color.Info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
114 color.Info.imageView = color.view;
115 color.Info.sampler = color.sampler;
116
117 }
118
119
120 {
121 VkImageCreateInfo imageCI = vka::plysm::imageCreateInfo();
122 imageCI.imageType = VK_IMAGE_TYPE_2D;
123 imageCI.format = $format.DEPTHFORMAT;
124 imageCI.extent = { w, h, 1 };
125 imageCI.mipLevels = 1;
126 imageCI.arrayLayers = multiviewLayerCount;
127 imageCI.samples = (VkSampleCountFlagBits)multisample;
128 imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
129 imageCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
130 imageCI.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
131 imageCI.flags = 0;
132 VK_CHECK_RESULT(vkCreateImage($device, &imageCI, nullptr, &depthMS.image));
133
134 VkMemoryRequirements memReqs;
135 vkGetImageMemoryRequirements($device, depthMS.image, &memReqs);
136
137 VkMemoryAllocateInfo memAllocInfo{};
138 memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
139 memAllocInfo.allocationSize = 0;
140 memAllocInfo.memoryTypeIndex = 0;
141
142 VkImageViewCreateInfo depthStencilView = {};
143 depthStencilView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
144 depthStencilView.pNext = NULL;
145 depthStencilView.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
146 depthStencilView.format = $format.DEPTHFORMAT;
147 depthStencilView.flags = 0;
148 depthStencilView.subresourceRange = {};
149 depthStencilView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
150 depthStencilView.subresourceRange.baseMipLevel = 0;
151 depthStencilView.subresourceRange.levelCount = 1;
152 depthStencilView.subresourceRange.baseArrayLayer = 0;
153 depthStencilView.subresourceRange.layerCount = multiviewLayerCount;
154 depthStencilView.image = depthMS.image;
155
156 memAllocInfo.allocationSize = memReqs.size;
157 memAllocInfo.memoryTypeIndex = vka::shelve::getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, nullptr);
158 VK_CHECK_RESULT(vkAllocateMemory($device, &memAllocInfo, nullptr, &depthMS.memory));
159 VK_CHECK_RESULT(vkBindImageMemory($device, depthMS.image, depthMS.memory, 0));
160 VK_CHECK_RESULT(vkCreateImageView($device, &depthStencilView, nullptr, &depthMS.view));
161
162 }
163
164
165 {
166 VkImageCreateInfo imageCI = vka::plysm::imageCreateInfo();
167 imageCI.imageType = VK_IMAGE_TYPE_2D;
168 imageCI.format = $format.DEPTHFORMAT;
169 imageCI.extent = { w, h, 1 };
170 imageCI.mipLevels = 1;
171 imageCI.arrayLayers = multiviewLayerCount;
172 imageCI.samples = VK_SAMPLE_COUNT_1_BIT;
173 imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
174 imageCI.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
175 imageCI.flags = 0;
176 VK_CHECK_RESULT(vkCreateImage($device, &imageCI, nullptr, &depth.image));
177
178 VkMemoryRequirements memReqs;
179 vkGetImageMemoryRequirements($device, depth.image, &memReqs);
180
181 VkMemoryAllocateInfo memAllocInfo{};
182 memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
183 memAllocInfo.allocationSize = 0;
184 memAllocInfo.memoryTypeIndex = 0;
185
186 VkImageViewCreateInfo depthStencilView = {};
187 depthStencilView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
188 depthStencilView.pNext = NULL;
189 depthStencilView.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
190 depthStencilView.format = $format.DEPTHFORMAT;
191 depthStencilView.flags = 0;
192 depthStencilView.subresourceRange = {};
193 depthStencilView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
194 depthStencilView.subresourceRange.baseMipLevel = 0;
195 depthStencilView.subresourceRange.levelCount = 1;
196 depthStencilView.subresourceRange.baseArrayLayer = 0;
197 depthStencilView.subresourceRange.layerCount = multiviewLayerCount;
198 depthStencilView.image = depth.image;
199
200 memAllocInfo.allocationSize = memReqs.size;
201 memAllocInfo.memoryTypeIndex = vka::shelve::getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, nullptr);
202 VK_CHECK_RESULT(vkAllocateMemory($device, &memAllocInfo, nullptr, &depth.memory));
203 VK_CHECK_RESULT(vkBindImageMemory($device, depth.image, depth.memory, 0));
204 VK_CHECK_RESULT(vkCreateImageView($device, &depthStencilView, nullptr, &depth.view));
205 }
206
207
208}
#define log_ata(...)
Definition: AttachmentsVk.h:11
VkDescriptorImageInfo Info
VkDeviceMemory memory
VkImageView view
VkImage image
VkSampler sampler
VkImage image
VkImageView view
VkDeviceMemory memory

◆ destroy()

bool AttachmentsVk::destroy ( )

Definition at line 11 of file AttachmentsVk.cpp.

11 {
12 for (int i = 0; i < 5; i++)member[i].dealloc();
13 color.dealloc();
14 return true;
15};
void dealloc()

Member Data Documentation

◆ 

union { ... } AttachmentsVk::@4

◆ color

MIVSIvk AttachmentsVk::color

Definition at line 20 of file AttachmentsVk.h.

◆ colorMS

MIVvk AttachmentsVk::colorMS

Definition at line 28 of file AttachmentsVk.h.

◆ depth

MIVvk AttachmentsVk::depth

Definition at line 29 of file AttachmentsVk.h.

◆ depthMS

MIVvk AttachmentsVk::depthMS

Definition at line 28 of file AttachmentsVk.h.

◆ h

uint32_t AttachmentsVk::h

Definition at line 16 of file AttachmentsVk.h.

◆ member

MIVvk AttachmentsVk::member[5]

Definition at line 32 of file AttachmentsVk.h.

◆ multisample

uint32_t AttachmentsVk::multisample

Definition at line 18 of file AttachmentsVk.h.

◆ multiview

uint32_t AttachmentsVk::multiview = 2

Definition at line 17 of file AttachmentsVk.h.

◆ stencil

MIVvk AttachmentsVk::stencil

Definition at line 29 of file AttachmentsVk.h.

◆ stencilMS

MIVvk AttachmentsVk::stencilMS

Definition at line 28 of file AttachmentsVk.h.

◆ w

uint32_t AttachmentsVk::w

Definition at line 16 of file AttachmentsVk.h.


The documentation for this struct was generated from the following files: