Merge remote-tracking branch 'origin/master' into sdl_platform

This commit is contained in:
2025-10-14 01:08:57 +03:00
292 changed files with 4020 additions and 1770 deletions

View File

@@ -1388,7 +1388,7 @@ void GPUContextVulkan::UpdateBuffer(GPUBuffer* buffer, const void* data, uint32
}
else
{
auto allocation = _device->UploadBuffer.Upload(data, size, 4);
auto allocation = _device->UploadBuffer.Upload(data, size, PLATFORM_MEMORY_ALIGNMENT);
VkBufferCopy region;
region.size = size;

View File

@@ -11,7 +11,7 @@
#include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Scripting/Enums.h"
void GPUTextureViewVulkan::Init(GPUDeviceVulkan* device, ResourceOwnerVulkan* owner, VkImage image, int32 totalMipLevels, PixelFormat format, MSAALevel msaa, VkExtent3D extent, VkImageViewType viewType, int32 mipLevels, int32 firstMipIndex, int32 arraySize, int32 firstArraySlice, bool readOnlyDepth)
void GPUTextureViewVulkan::Init(GPUDeviceVulkan* device, ResourceOwnerVulkan* owner, VkImage image, int32 totalMipLevels, PixelFormat format, MSAALevel msaa, VkExtent3D extent, VkImageViewType viewType, int32 mipLevels, int32 firstMipIndex, int32 arraySize, int32 firstArraySlice, bool readOnlyDepth, bool stencilView)
{
ASSERT(View == VK_NULL_HANDLE);
@@ -57,7 +57,13 @@ void GPUTextureViewVulkan::Init(GPUDeviceVulkan* device, ResourceOwnerVulkan* ow
SubresourceIndex = RenderTools::CalcSubresourceIndex(firstMipIndex, firstArraySlice, totalMipLevels);
}
if (PixelFormatExtensions::IsDepthStencil(format))
if (stencilView)
{
range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
LayoutRTV = readOnlyDepth ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
LayoutSRV = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
}
else if (PixelFormatExtensions::IsDepthStencil(format))
{
range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
#if 0
@@ -157,13 +163,23 @@ void GPUTextureViewVulkan::DescriptorAsImage(GPUContextVulkan* context, VkImageV
imageView = View;
layout = LayoutSRV;
const VkImageAspectFlags aspectMask = Info.subresourceRange.aspectMask;
if (aspectMask == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))
if (aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))
{
// Transition depth-only when binding depth buffer with stencil
// Transition depth-only when binding depth buffer with stencil (or stencil-only without depth)
if (ViewSRV == VK_NULL_HANDLE)
{
VkImageViewCreateInfo createInfo = Info;
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
if (aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT)
{
// Stencil
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
createInfo.components.g = VK_COMPONENT_SWIZZLE_R; // Map .g component in shader to .r of stencil plane
}
else
{
// Depth
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
}
VALIDATE_VULKAN_RESULT(vkCreateImageView(Device->Device, &createInfo, nullptr, &ViewSRV));
}
imageView = ViewSRV;
@@ -434,6 +450,26 @@ void GPUTextureVulkan::initHandles()
{
_handleReadOnlyDepth.Init(_device, this, _image, mipLevels, format, msaa, extent, VK_IMAGE_VIEW_TYPE_2D, mipLevels, 0, 1, 0, true);
}
// Stencil view
if (IsDepthStencil() && IsShaderResource() && PixelFormatExtensions::HasStencil(format))
{
PixelFormat stencilFormat;
switch (format)
{
case PixelFormat::D24_UNorm_S8_UInt:
case PixelFormat::R24_UNorm_X8_Typeless:
case PixelFormat::R24G8_Typeless:
stencilFormat = PixelFormat::X24_Typeless_G8_UInt;
break;
case PixelFormat::D32_Float_S8X24_UInt:
case PixelFormat::R32_Float_X8X24_Typeless:
case PixelFormat::R32G8X24_Typeless:
stencilFormat = PixelFormat::X32_Typeless_G8X24_UInt;
break;
}
_handleStencil.Init(_device, this, _image, mipLevels, stencilFormat, msaa, extent, VK_IMAGE_VIEW_TYPE_2D, mipLevels, 0, 1, 0, true, true);
}
}
void GPUTextureVulkan::OnResidentMipsChanged()
@@ -457,6 +493,7 @@ void GPUTextureVulkan::OnReleaseGPU()
_handleVolume.Release();
_handleUAV.Release();
_handleReadOnlyDepth.Release();
_handleStencil.Release();
for (int32 i = 0; i < _handlesPerMip.Count(); i++)
{
for (int32 j = 0; j < _handlesPerMip[i].Count(); j++)

View File

@@ -45,7 +45,7 @@ public:
#endif
public:
void Init(GPUDeviceVulkan* device, ResourceOwnerVulkan* owner, VkImage image, int32 totalMipLevels, PixelFormat format, MSAALevel msaa, VkExtent3D extent, VkImageViewType viewType, int32 mipLevels = 1, int32 firstMipIndex = 0, int32 arraySize = 1, int32 firstArraySlice = 0, bool readOnlyDepth = false);
void Init(GPUDeviceVulkan* device, ResourceOwnerVulkan* owner, VkImage image, int32 totalMipLevels, PixelFormat format, MSAALevel msaa, VkExtent3D extent, VkImageViewType viewType, int32 mipLevels = 1, int32 firstMipIndex = 0, int32 arraySize = 1, int32 firstArraySlice = 0, bool readOnlyDepth = false, bool stencilView = false);
VkImageView GetFramebufferView();
@@ -79,6 +79,7 @@ private:
GPUTextureViewVulkan _handleVolume;
GPUTextureViewVulkan _handleUAV;
GPUTextureViewVulkan _handleReadOnlyDepth;
GPUTextureViewVulkan _handleStencil;
Array<GPUTextureViewVulkan> _handlesPerSlice; // [slice]
Array<Array<GPUTextureViewVulkan>> _handlesPerMip; // [slice][mip]
@@ -140,6 +141,11 @@ public:
ASSERT(_desc.Flags & GPUTextureFlags::ReadOnlyDepthView);
return (GPUTextureView*)&_handleReadOnlyDepth;
}
GPUTextureView* ViewStencil() const override
{
ASSERT(_desc.Flags & GPUTextureFlags::DepthStencil);
return (GPUTextureView*)&_handleStencil;
}
void* GetNativePtr() const override
{
return (void*)_image;

View File

@@ -111,6 +111,7 @@ UploadBufferVulkan::Allocation UploadBufferVulkan::Allocate(uint64 size, uint64
// Move within a page
_currentOffset += size;
ASSERT_LOW_LAYER(_currentOffset <= _currentPage->Size);
return result;
}