MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnInit

Method OnInit

Source/Engine/GraphicsDevice/Vulkan/GPUTextureVulkan.cpp:242–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242bool GPUTextureVulkan::OnInit()
243{
244 // Check if texture should have optimal CPU read/write access
245 if (IsStaging())
246 {
247 // TODO: rowAlign/sliceAlign on Vulkan texture ???
248 const int32 totalSize = ComputeBufferTotalSize(1, 1);
249 StagingBuffer = (GPUBufferVulkan*)_device->CreateBuffer(TEXT("Texture.StagingBuffer"));
250 if (StagingBuffer->Init(GPUBufferDescription::Buffer(totalSize, GPUBufferFlags::None, PixelFormat::Unknown, nullptr, 0, _desc.Usage)))
251 {
252 Delete(StagingBuffer);
253 return true;
254 }
255 _memoryUsage = 1;
256 initResource(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, _desc.MipLevels, _desc.ArraySize, false);
257 return false;
258 }
259
260 const bool useSRV = IsShaderResource();
261 const bool useDSV = IsDepthStencil();
262 const bool useRTV = IsRenderTarget();
263 const bool useUAV = IsUnorderedAccess();
264
265 const bool optimalTiling = true;
266 PixelFormat format = _desc.Format;
267 if (useDSV)
268 format = PixelFormatExtensions::FindDepthStencilFormat(format);
269 _desc.Format = _device->GetClosestSupportedPixelFormat(format, _desc.Flags, optimalTiling);
270 if (_desc.Format == PixelFormat::Unknown)
271 {
272 LOG(Error, "Unsupported texture format {0}.", ScriptingEnum::ToString(format));
273 return true;
274 }
275
276 // Setup texture description
277 VkImageCreateInfo imageInfo;
278 RenderToolsVulkan::ZeroStruct(imageInfo, VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
279 imageInfo.imageType = IsVolume() ? VK_IMAGE_TYPE_3D : VK_IMAGE_TYPE_2D;
280 imageInfo.format = RenderToolsVulkan::ToVulkanFormat(Format());
281 imageInfo.mipLevels = MipLevels();
282 imageInfo.arrayLayers = ArraySize();
283 imageInfo.extent.width = Width();
284 imageInfo.extent.height = Height();
285 imageInfo.extent.depth = Depth();
286 imageInfo.flags = IsCubeMap() ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0;
287 if (IsSRGB())
288 imageInfo.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
289#if VK_KHR_maintenance1
290 if (_device->OptionalDeviceExtensions.HasKHRMaintenance1 && imageInfo.imageType == VK_IMAGE_TYPE_3D)
291 imageInfo.flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR;
292#endif
293 imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
294 if (useSRV)
295 imageInfo.usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
296 if (useDSV)
297 imageInfo.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
298 if (useRTV)
299 imageInfo.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

Callers

nothing calls this directly

Calls 15

DeleteFunction · 0.85
MipLevelsFunction · 0.85
ArraySizeFunction · 0.85
IsSRGBFunction · 0.85
MultiSampleLevelFunction · 0.85
vmaCreateImageFunction · 0.85
HasStencilFunction · 0.85
IsRegularTextureFunction · 0.85
ToStringFunction · 0.70
BufferClass · 0.50
IsShaderResourceFunction · 0.50

Tested by

no test coverage detected