mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 20:33: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
|
|
@ -309,7 +309,7 @@ internal class TexWidget : IDataWindowWidget
|
||||||
conf.QueueSave();
|
conf.QueueSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ImGui.BeginTable("##table", 5))
|
if (!ImGui.BeginTable("##table", 6))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int numIcons = 1;
|
const int numIcons = 1;
|
||||||
|
|
@ -318,12 +318,21 @@ internal class TexWidget : IDataWindowWidget
|
||||||
iconWidths = ImGui.CalcTextSize(FontAwesomeIcon.Save.ToIconString()).X;
|
iconWidths = ImGui.CalcTextSize(FontAwesomeIcon.Save.ToIconString()).X;
|
||||||
|
|
||||||
ImGui.TableSetupScrollFreeze(0, 1);
|
ImGui.TableSetupScrollFreeze(0, 1);
|
||||||
ImGui.TableSetupColumn("Size", ImGuiTableColumnFlags.WidthFixed, ImGui.CalcTextSize("00000x00000").X);
|
ImGui.TableSetupColumn(
|
||||||
|
"Dimensions",
|
||||||
|
ImGuiTableColumnFlags.WidthFixed,
|
||||||
|
ImGui.CalcTextSize("00000x00000").X);
|
||||||
ImGui.TableSetupColumn(
|
ImGui.TableSetupColumn(
|
||||||
"Format",
|
"Format",
|
||||||
ImGuiTableColumnFlags.WidthFixed,
|
ImGuiTableColumnFlags.WidthFixed,
|
||||||
ImGui.CalcTextSize("R32G32B32A32_TYPELESS").X);
|
ImGui.CalcTextSize("R32G32B32A32_TYPELESS").X);
|
||||||
ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.WidthStretch);
|
ImGui.TableSetupColumn(
|
||||||
|
"Size",
|
||||||
|
ImGuiTableColumnFlags.WidthFixed,
|
||||||
|
ImGui.CalcTextSize("123.45 MB").X);
|
||||||
|
ImGui.TableSetupColumn(
|
||||||
|
"Name",
|
||||||
|
ImGuiTableColumnFlags.WidthStretch);
|
||||||
ImGui.TableSetupColumn(
|
ImGui.TableSetupColumn(
|
||||||
"Actions",
|
"Actions",
|
||||||
ImGuiTableColumnFlags.WidthFixed,
|
ImGuiTableColumnFlags.WidthFixed,
|
||||||
|
|
@ -353,6 +362,11 @@ internal class TexWidget : IDataWindowWidget
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
ImGui.TextUnformatted(Enum.GetName(wrap.Format)?[12..] ?? wrap.Format.ToString());
|
ImGui.TextUnformatted(Enum.GetName(wrap.Format)?[12..] ?? wrap.Format.ToString());
|
||||||
|
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
var rawSpec = new RawImageSpecification(wrap.Width, wrap.Height, (int)wrap.Format, 0);
|
||||||
|
var bytes = rawSpec.EstimatedBytes;
|
||||||
|
ImGui.TextUnformatted(bytes < 0 ? "-" : Util.FormatBytes(bytes));
|
||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
ImGui.TextUnformatted(wrap.Name);
|
ImGui.TextUnformatted(wrap.Name);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -485,7 +485,7 @@ internal sealed partial class TextureManager
|
||||||
IReadOnlyDictionary<string, object>? props = null,
|
IReadOnlyDictionary<string, object>? props = null,
|
||||||
CancellationToken cancellationToken = default)
|
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.");
|
throw new NotSupportedException("DXGI_FORMAT from specs is not supported by WIC.");
|
||||||
|
|
||||||
using var encoder = default(ComPtr<IWICBitmapEncoder>);
|
using var encoder = default(ComPtr<IWICBitmapEncoder>);
|
||||||
|
|
@ -494,7 +494,7 @@ internal sealed partial class TextureManager
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
// See: DirectXTK/Src/ScreenGrab.cpp
|
// 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_R32G32B32A32_FLOAT => GUID.GUID_WICPixelFormat128bppRGBAFloat,
|
||||||
DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT when !this.wicFactory2.IsEmpty() =>
|
DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT when !this.wicFactory2.IsEmpty() =>
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,7 @@ internal sealed partial class TextureManager
|
||||||
Height = (uint)specs.Height,
|
Height = (uint)specs.Height,
|
||||||
MipLevels = 1,
|
MipLevels = 1,
|
||||||
ArraySize = 1,
|
ArraySize = 1,
|
||||||
Format = (DXGI_FORMAT)specs.DxgiFormat,
|
Format = specs.Format,
|
||||||
SampleDesc = new(1, 0),
|
SampleDesc = new(1, 0),
|
||||||
Usage = D3D11_USAGE.D3D11_USAGE_IMMUTABLE,
|
Usage = D3D11_USAGE.D3D11_USAGE_IMMUTABLE,
|
||||||
BindFlags = (uint)D3D11_BIND_FLAG.D3D11_BIND_SHADER_RESOURCE,
|
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>
|
/// <summary>Gets the number of bits per pixel.</summary>
|
||||||
/// <exception cref="NotSupportedException">Thrown if <see cref="DxgiFormat"/> is not supported.</exception>
|
/// <exception cref="NotSupportedException">Thrown if <see cref="DxgiFormat"/> is not supported.</exception>
|
||||||
public int BitsPerPixel =>
|
public int BitsPerPixel =>
|
||||||
GetFormatInfo((DXGI_FORMAT)this.DxgiFormat, out var bitsPerPixel, out _)
|
GetFormatInfo(this.Format, out var bitsPerPixel, out _)
|
||||||
? bitsPerPixel
|
? bitsPerPixel
|
||||||
: throw new NotSupportedException(FormatNotSupportedMessage);
|
: 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>
|
/// <summary>
|
||||||
/// Creates a new instance of <see cref="RawImageSpecification"/> record using the given resolution,
|
/// Creates a new instance of <see cref="RawImageSpecification"/> record using the given resolution,
|
||||||
/// in B8G8R8A8(BGRA32) UNorm pixel format.
|
/// in B8G8R8A8(BGRA32) UNorm pixel format.
|
||||||
|
|
@ -230,7 +247,7 @@ public record struct RawImageSpecification
|
||||||
case DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM:
|
case DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM:
|
||||||
bitsPerPixel = 16;
|
bitsPerPixel = 16;
|
||||||
isBlockCompression = true;
|
isBlockCompression = true;
|
||||||
return false;
|
return true;
|
||||||
default:
|
default:
|
||||||
bitsPerPixel = 0;
|
bitsPerPixel = 0;
|
||||||
isBlockCompression = false;
|
isBlockCompression = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue