mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 14:23:40 +01:00
Add texture vram usage estimation
This commit is contained in:
parent
e9b903b2a7
commit
9ba0a297c9
4 changed files with 39 additions and 8 deletions
|
|
@ -485,7 +485,7 @@ internal sealed partial class TextureManager
|
|||
IReadOnlyDictionary<string, object>? props = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (!GetCorrespondingWicPixelFormat((DXGI_FORMAT)specs.DxgiFormat, out var inPixelFormat, out var srgb))
|
||||
if (!GetCorrespondingWicPixelFormat(specs.Format, out var inPixelFormat, out var srgb))
|
||||
throw new NotSupportedException("DXGI_FORMAT from specs is not supported by WIC.");
|
||||
|
||||
using var encoder = default(ComPtr<IWICBitmapEncoder>);
|
||||
|
|
@ -494,7 +494,7 @@ internal sealed partial class TextureManager
|
|||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// See: DirectXTK/Src/ScreenGrab.cpp
|
||||
var outPixelFormat = (DXGI_FORMAT)specs.DxgiFormat switch
|
||||
var outPixelFormat = specs.Format switch
|
||||
{
|
||||
DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT => GUID.GUID_WICPixelFormat128bppRGBAFloat,
|
||||
DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT when !this.wicFactory2.IsEmpty() =>
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ internal sealed partial class TextureManager
|
|||
Height = (uint)specs.Height,
|
||||
MipLevels = 1,
|
||||
ArraySize = 1,
|
||||
Format = (DXGI_FORMAT)specs.DxgiFormat,
|
||||
Format = specs.Format,
|
||||
SampleDesc = new(1, 0),
|
||||
Usage = D3D11_USAGE.D3D11_USAGE_IMMUTABLE,
|
||||
BindFlags = (uint)D3D11_BIND_FLAG.D3D11_BIND_SHADER_RESOURCE,
|
||||
|
|
|
|||
|
|
@ -51,10 +51,27 @@ public record struct RawImageSpecification
|
|||
/// <summary>Gets the number of bits per pixel.</summary>
|
||||
/// <exception cref="NotSupportedException">Thrown if <see cref="DxgiFormat"/> is not supported.</exception>
|
||||
public int BitsPerPixel =>
|
||||
GetFormatInfo((DXGI_FORMAT)this.DxgiFormat, out var bitsPerPixel, out _)
|
||||
GetFormatInfo(this.Format, out var bitsPerPixel, out _)
|
||||
? bitsPerPixel
|
||||
: throw new NotSupportedException(FormatNotSupportedMessage);
|
||||
|
||||
/// <summary>Gets or sets the format (typed).</summary>
|
||||
internal DXGI_FORMAT Format
|
||||
{
|
||||
get => (DXGI_FORMAT)this.DxgiFormat;
|
||||
set => this.DxgiFormat = (int)value;
|
||||
}
|
||||
|
||||
/// <summary>Gets the estimated number of bytes.</summary>
|
||||
/// <remarks><c>-1</c> if failed.</remarks>
|
||||
internal int EstimatedBytes =>
|
||||
GetFormatInfo(this.Format, out var bitsPerPixel, out var isBlockCompression)
|
||||
? isBlockCompression
|
||||
? (((Math.Max(1, (this.Width + 3) / 4) * 2 * bitsPerPixel) + 63) / 64) * 64 *
|
||||
Math.Max(1, (this.Height + 3) / 4)
|
||||
: (((((bitsPerPixel * this.Width) + 7) / 8) + 63) / 64) * 64 * this.Height
|
||||
: -1;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="RawImageSpecification"/> record using the given resolution,
|
||||
/// in B8G8R8A8(BGRA32) UNorm pixel format.
|
||||
|
|
@ -230,7 +247,7 @@ public record struct RawImageSpecification
|
|||
case DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM:
|
||||
bitsPerPixel = 16;
|
||||
isBlockCompression = true;
|
||||
return false;
|
||||
return true;
|
||||
default:
|
||||
bitsPerPixel = 0;
|
||||
isBlockCompression = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue