Fixes and updates to graphics api

This commit is contained in:
Wojtek Figat
2026-02-20 23:49:49 +01:00
parent 08d9ae0ae6
commit 6fd58c418e
9 changed files with 67 additions and 29 deletions

View File

@@ -101,6 +101,19 @@ void GPUContext::Draw(GPUTexture* dst, GPUTexture* src)
DrawFullscreenTriangle();
}
void GPUContext::Draw(GPUTexture* dst, GPUTextureView* src)
{
ASSERT_LOW_LAYER(dst && src);
ResetRenderTarget();
const float width = (float)dst->Width();
const float height = (float)dst->Height();
SetViewport(width, height);
SetRenderTarget(dst->View());
BindSR(0, src);
SetState(_device->GetCopyLinearPS());
DrawFullscreenTriangle();
}
void GPUContext::Draw(GPUTexture* rt)
{
ASSERT_LOW_LAYER(rt);

View File

@@ -489,6 +489,13 @@ public:
/// <param name="src">The source texture.</param>
API_FUNCTION() void Draw(GPUTexture* dst, GPUTexture* src);
/// <summary>
/// Draws the specified source texture view to destination render target (using fullscreen triangle). Copies contents with resizing and format conversion support. Uses linear texture sampling.
/// </summary>
/// <param name="dst">The destination texture.</param>
/// <param name="src">The source texture view.</param>
API_FUNCTION() void Draw(GPUTexture* dst, GPUTextureView* src);
/// <summary>
/// Draws the specified texture to render target (using fullscreen triangle). Copies contents with resizing and format conversion support. Uses linear texture sampling.
/// </summary>

View File

@@ -176,7 +176,7 @@ DECLARE_ENUM_OPERATORS(FormatSupport);
/// <summary>
/// The features exposed for a particular format.
/// </summary>
API_STRUCT() struct FormatFeatures
API_STRUCT(NoDefault) struct FormatFeatures
{
DECLARE_SCRIPTING_TYPE_MINIMAL(FormatFeatures);
@@ -196,11 +196,23 @@ API_STRUCT() struct FormatFeatures
/// <summary>
/// Initializes a new instance of the <see cref="FeaturesPerFormat"/> struct.
/// [Deprecated in v1.12]
/// </summary>
/// <param name="format">The format.</param>
/// <param name="msaaLevelMax">The MSAA level maximum.</param>
/// <param name="formatSupport">The format support.</param>
FormatFeatures(const PixelFormat format, MSAALevel msaaLevelMax, FormatSupport formatSupport)
DEPRECATED("Skip format argument as it's unsued.") FormatFeatures(const PixelFormat format, MSAALevel msaaLevelMax, FormatSupport formatSupport)
: MSAALevelMax(msaaLevelMax)
, Support(formatSupport)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FeaturesPerFormat"/> struct.
/// </summary>
/// <param name="msaaLevelMax">The MSAA level maximum.</param>
/// <param name="formatSupport">The format support.</param>
FormatFeatures(MSAALevel msaaLevelMax, FormatSupport formatSupport)
: MSAALevelMax(msaaLevelMax)
, Support(formatSupport)
{
@@ -210,59 +222,59 @@ API_STRUCT() struct FormatFeatures
/// <summary>
/// Graphics Device limits and constraints descriptor.
/// </summary>
API_STRUCT() struct GPULimits
API_STRUCT(NoDefault) struct GPULimits
{
DECLARE_SCRIPTING_TYPE_MINIMAL(GPULimits);
/// <summary>
/// True if device supports Compute shaders.
/// </summary>
API_FIELD() bool HasCompute;
API_FIELD() bool HasCompute = false;
/// <summary>
/// True if device supports Tessellation shaders (domain and hull shaders).
/// </summary>
API_FIELD() bool HasTessellation;
API_FIELD() bool HasTessellation = false;
/// <summary>
/// True if device supports Geometry shaders.
/// </summary>
API_FIELD() bool HasGeometryShaders;
API_FIELD() bool HasGeometryShaders = false;
/// <summary>
/// True if device supports hardware geometry instancing.
/// </summary>
API_FIELD() bool HasInstancing;
API_FIELD() bool HasInstancing = false;
/// <summary>
/// True if device supports rendering to volume textures using Geometry shaders.
/// </summary>
API_FIELD() bool HasVolumeTextureRendering;
API_FIELD() bool HasVolumeTextureRendering = false;
/// <summary>
/// True if device supports indirect drawing (including pixel shader write to UAV).
/// </summary>
API_FIELD() bool HasDrawIndirect;
API_FIELD() bool HasDrawIndirect = false;
/// <summary>
/// True if device supports append/consume buffers with counters.
/// </summary>
API_FIELD() bool HasAppendConsumeBuffers;
API_FIELD() bool HasAppendConsumeBuffers = false;
/// <summary>
/// True if device supports separate render target blending states.
/// </summary>
API_FIELD() bool HasSeparateRenderTargetBlendState;
API_FIELD() bool HasSeparateRenderTargetBlendState = false;
/// <summary>
/// True if device supports depth buffer texture as a shader resource view.
/// </summary>
API_FIELD() bool HasDepthAsSRV;
API_FIELD() bool HasDepthAsSRV = false;
/// <summary>
/// True if device supports depth buffer clipping (see GPUPipelineState::Description::DepthClipEnable).
/// </summary>
API_FIELD() bool HasDepthClip;
API_FIELD() bool HasDepthClip = false;
/// <summary>
/// True if device supports depth buffer bounds testing (see GPUPipelineState::Description::DepthBoundsEnable and GPUContext::SetDepthBounds).
@@ -272,55 +284,55 @@ API_STRUCT() struct GPULimits
/// <summary>
/// True if device supports depth buffer texture as a readonly depth buffer (can be sampled in the shader while performing depth-test).
/// </summary>
API_FIELD() bool HasReadOnlyDepth;
API_FIELD() bool HasReadOnlyDepth = false;
/// <summary>
/// True if device supports multisampled depth buffer texture as a shader resource view.
/// </summary>
API_FIELD() bool HasMultisampleDepthAsSRV;
API_FIELD() bool HasMultisampleDepthAsSRV = false;
/// <summary>
/// True if device supports reading from typed UAV in shader (common types such as R32G32B32A32, R16G16B16A16, R16, R8). This doesn't apply to single-component 32-bit formats.
/// </summary>
API_FIELD() bool HasTypedUAVLoad;
API_FIELD() bool HasTypedUAVLoad = false;
/// <summary>
/// The maximum amount of texture mip levels.
/// </summary>
API_FIELD() int32 MaximumMipLevelsCount;
API_FIELD() int32 MaximumMipLevelsCount = 1;
/// <summary>
/// The maximum size of the 1D texture.
/// </summary>
API_FIELD() int32 MaximumTexture1DSize;
API_FIELD() int32 MaximumTexture1DSize = 0;
/// <summary>
/// The maximum length of 1D textures array.
/// </summary>
API_FIELD() int32 MaximumTexture1DArraySize;
API_FIELD() int32 MaximumTexture1DArraySize = 0;
/// <summary>
/// The maximum size of the 2D texture.
/// </summary>
API_FIELD() int32 MaximumTexture2DSize;
API_FIELD() int32 MaximumTexture2DSize = 0;
/// <summary>
/// The maximum length of 2D textures array.
/// </summary>
API_FIELD() int32 MaximumTexture2DArraySize;
API_FIELD() int32 MaximumTexture2DArraySize = 0;
/// <summary>
/// The maximum size of the 3D texture.
/// </summary>
API_FIELD() int32 MaximumTexture3DSize;
API_FIELD() int32 MaximumTexture3DSize = 0;
/// <summary>
/// The maximum size of the cube texture (both width and height).
/// </summary>
API_FIELD() int32 MaximumTextureCubeSize;
API_FIELD() int32 MaximumTextureCubeSize = 0;
/// <summary>
/// The maximum degree of anisotropic filtering used for texture sampling.
/// </summary>
API_FIELD() float MaximumSamplerAnisotropy;
API_FIELD() float MaximumSamplerAnisotropy = 0.0f;
};

View File

@@ -1,6 +1,7 @@
// Copyright (c) Wojciech Figat. All rights reserved.
#include "GPUSwapChain.h"
#include "GPUContext.h"
#include "GPUDevice.h"
#include "Textures/GPUTexture.h"
#include "Engine/Core/Log.h"
@@ -42,6 +43,11 @@ GPUSwapChain::GPUSwapChain()
#endif
}
void GPUSwapChain::CopyBackbuffer(GPUContext* context, GPUTexture* dst)
{
context->Draw(dst, GetBackBufferView());
}
Task* GPUSwapChain::DownloadDataAsync(TextureData& result)
{
if (_downloadTask)

View File

@@ -106,7 +106,7 @@ public:
/// </summary>
/// <param name="context">The GPU commands context.</param>
/// <param name="dst">The destination texture. It must match the output dimensions and format. No staging texture support.</param>
virtual void CopyBackbuffer(GPUContext* context, GPUTexture* dst) = 0;
virtual void CopyBackbuffer(GPUContext* context, GPUTexture* dst);
/// <summary>
/// Checks if task is ready to render.

View File

@@ -658,7 +658,7 @@ bool GPUDeviceDX11::Init()
}
UINT formatSupport = 0;
_device->CheckFormatSupport(dxgiFormat, &formatSupport);
FeaturesPerFormat[i] = FormatFeatures(format, static_cast<MSAALevel>(maxCount), (FormatSupport)formatSupport);
FeaturesPerFormat[i] = FormatFeatures((MSAALevel)maxCount, (FormatSupport)formatSupport);
}
// Driver extensions support

View File

@@ -786,7 +786,7 @@ bool GPUDeviceDX12::Init()
if (FAILED(_device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatInfo, sizeof(formatInfo))))
formatInfo.Support1 = D3D12_FORMAT_SUPPORT1_NONE;
const MSAALevel maximumMultisampleCount = GetMaximumMultisampleCount(_device, dxgiFormat);
FeaturesPerFormat[i] = FormatFeatures(format, maximumMultisampleCount, (FormatSupport)formatInfo.Support1);
FeaturesPerFormat[i] = FormatFeatures(maximumMultisampleCount, (FormatSupport)formatInfo.Support1);
}
D3D12_FEATURE_DATA_D3D12_OPTIONS2 options2 = {};

View File

@@ -62,7 +62,7 @@ bool GPUDeviceNull::Init()
limits.MaximumTextureCubeSize = 16384;
limits.MaximumSamplerAnisotropy = 1;
for (int32 i = 0; i < static_cast<int32>(PixelFormat::MAX); i++)
FeaturesPerFormat[i] = FormatFeatures(static_cast<PixelFormat>(i), MSAALevel::None, FormatSupport::None);
FeaturesPerFormat[i] = FormatFeatures(MSAALevel::None, FormatSupport::None);
}
// Create main context

View File

@@ -1807,7 +1807,7 @@ bool GPUDeviceVulkan::Init()
msaa = maxMsaa;
}
FeaturesPerFormat[i] = FormatFeatures(format, msaa, support);
FeaturesPerFormat[i] = FormatFeatures(msaa, support);
}
}