Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gpu/vk/astc_bc_policy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Which cards keep every large decoded ASTC texture as BC3, the finer blocks (UI, characters) too (vk_texture.cpp).
// tests/test_astc_bc_policy.py
#pragma once
#include <cstdint>

namespace astc_bc_policy {

// The VRAM the driver allows the process, in bytes: under 8.5 GB, every large ASTC texture as BC3 (a quarter of RGBA8).
// Issue 519 set it under 6 GB (an RTX 3050 Laptop, 3.3 GB allowed: 1.75 GB of decoded ASTC in Goron City, paged, 4 fps).
// 8 GB cards are allowed ~7-7.6 GB and fill up the same way: an RX 7700S (7.1 GB allowed) held 2.5 GB of decoded ASTC in
// Hyrule Castle Town's market with the VRAM at the limit; as BC3, 1.3 GB. 10 GB cards and up keep the finer ones as RGBA8
inline bool all_by_vram(uint64_t allowed) {
return allowed && allowed < (8704ull << 20);
}

} // namespace astc_bc_policy
5 changes: 3 additions & 2 deletions gpu/vk/vk_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "host_shaders/astc_decoder_comp_spv.h"
#include "host_shaders/bc_encoder_comp_spv.h"
#include "bc_levels.h"
#include "astc_bc_policy.h"
#include "host_shaders/block_linear_unswizzle_2d_comp_spv.h"
#include "vk_work.h" // (after the others: counts the commands that do GPU work, for full_barrier)

Expand Down Expand Up @@ -1482,11 +1483,11 @@ Texture* create(const Key& key, const nvn_tex* t, VkFormat vf, bool astc, int bw
static const uint64_t low = (uint64_t)(getenv("RX_VK_ASTC_BC_MB") ? atoi(getenv("RX_VK_ASTC_BC_MB")) : 2) << 20;
// (issue 519: on a card the driver gives under 6 GB, the finer ones too. An RTX 3050 Laptop (4 GB, 3.3 allowed)
// held 1.75 GB of decoded ASTC in Goron City, drawn every frame: 5.6 GB used of 3.3, paged, 4 fps. As BC3, a
// quarter. RX_VK_ASTC_BC_ALL=1 or 0 says so on any card)
// quarter. Now 8 GB cards too: astc_bc_policy.h. RX_VK_ASTC_BC_ALL=1 or 0 says so on any card)
static const bool all = [] {
if (const char* e = getenv("RX_VK_ASTC_BC_ALL")) return e[0] == '1';
uint64_t used = 0, allowed = 0;
const bool small = vram_usage(&used, &allowed) && allowed && allowed < (6ull << 30);
const bool small = vram_usage(&used, &allowed) && astc_bc_policy::all_by_vram(allowed);
if (small) logf("vk: %llu MB of VRAM allowed: all large ASTC textures kept as BC3", (unsigned long long)(allowed >> 20));
return small;
}();
Expand Down
1 change: 1 addition & 0 deletions tests/run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"nx2/test_draw_parameters.py": ["--headers", "{spirv_headers}", "--spirv-val", "{spirv_val}"],
"nx2/test_coop_spirv.py": ["--headers", "{spirv_headers}", "--spirv-val", "{spirv_val}"],
"nx2/test_spirv_struct_identity.py": ["--headers", "{spirv_headers}", "--spirv-val", "{spirv_val}"],
"tests/test_astc_bc_policy.py": ["--cxx", "g++"],
}

# Python packages some tests import (CI installs them; the runner itself needs none)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_astc_bc_policy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// astc_bc_policy::all_by_vram (gpu/vk/astc_bc_policy.h): the cards that keep every large ASTC texture as BC3.
// tests/test_astc_bc_policy.py
#include "../gpu/vk/astc_bc_policy.h"

#include <cstdio>
#include <cstdlib>

static int failures = 0;
static void expect(bool ok, const char* what) {
if (!ok) {
std::printf("FAIL: %s\n", what);
failures++;
}
}

int main() {
const uint64_t MB = 1ull << 20;
using astc_bc_policy::all_by_vram;
expect(!all_by_vram(0), "unknown: as before (the finer ones as RGBA8)");
expect(all_by_vram(3379 * MB), "a 4 GB laptop card (3.3 GB allowed, issue 519)");
expect(all_by_vram(5900 * MB), "a 6 GB card");
expect(all_by_vram(7133 * MB), "an 8 GB RX 7700S (7.1 GB allowed)");
expect(all_by_vram(7700 * MB), "an 8 GB card allowed more");
expect(!all_by_vram(9400 * MB), "a 10 GB card");
expect(!all_by_vram(11200 * MB), "a 12 GB card");
expect(!all_by_vram(15000 * MB), "a 16 GB card");
if (failures) return EXIT_FAILURE;
std::printf("astc bc policy: all checks passed\n");
return EXIT_SUCCESS;
}
32 changes: 32 additions & 0 deletions tests/test_astc_bc_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Compile and run the rule for the cards that keep every large ASTC texture as BC3 (gpu/vk/astc_bc_policy.h; no game/GPU)."""
import argparse
import subprocess
import tempfile
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def check_source():
"""The texture setup still asks the rule, and the switch that overrides it is still read"""
src = (ROOT / "gpu/vk/vk_texture.cpp").read_text(encoding="utf-8")
for needle in ('#include "astc_bc_policy.h"', "astc_bc_policy::all_by_vram(allowed)", 'getenv("RX_VK_ASTC_BC_ALL")',
"(bw * bh >= 36 || all) ? low : 64ull << 20"):
if needle not in src:
raise SystemExit("vk_texture.cpp no longer has: " + needle)


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--cxx", default="g++")
args = parser.parse_args()
check_source()
with tempfile.TemporaryDirectory(prefix="astc-bc-policy-") as tmp:
exe = Path(tmp) / "astc-bc-policy"
subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror",
str(ROOT / "tests/test_astc_bc_policy.cpp"), "-o", str(exe)], check=True)
subprocess.run([str(exe)], check=True)


if __name__ == "__main__":
main()
Loading