fix: preserve D3D texture addressing in native UI sampling

This commit is contained in:
shen
2026-10-18 03:49:11 -07:00
parent fe6e41dc8e
commit b61140b8f4
13 changed files with 94 additions and 9 deletions
+6 -3
View File
@@ -19,6 +19,7 @@
// and 2D UIRenderCommand stream + memory textures ("MTRA").
// - Version 5: adds per-draw fog color, mode, range and distance/density state.
// - Version 6: adds texture address and filtering state for both stages.
// - Version 11: adds D3D8 UI stage-0 U/V addressing; older UI captures retain clamp.
// - Version 7: adds two fixed-function lights and material color sources.
// - Version 8: eight lights, back-buffer clear entries, viewport MinZ/MaxZ, border color,
// TEXCOORDINDEX / TEXTURETRANSFORMFLAGS / D3DTS_TEXTUREn per stage, emissive
@@ -28,7 +29,7 @@
namespace native_draw_capture {
struct Capture {
std::uint32_t version = 10;
std::uint32_t version = 11;
std::vector<Render3DDraw> draws;
std::unordered_map<std::string, std::vector<std::uint8_t>> textures;
std::uint32_t ui_width = 960;
@@ -114,7 +115,7 @@ inline void write(
std::ofstream file(path, std::ios::binary | std::ios::trunc);
if (!file) throw std::runtime_error("cannot create native draw capture: " + path);
const std::uint32_t magic = 0x4d544452; // MTDR
const std::uint32_t version = 10;
const std::uint32_t version = 11;
const auto count = static_cast<std::uint32_t>(draws.size());
write_scalar(file, magic); write_scalar(file, version); write_scalar(file, count);
for (const auto& draw : draws) {
@@ -233,6 +234,7 @@ inline void write(
write_string(file, cmd.mask);
file.write(reinterpret_cast<const char*>(cmd.mu), sizeof(cmd.mu));
file.write(reinterpret_cast<const char*>(cmd.mv), sizeof(cmd.mv));
write_scalar(file,cmd.address_u);write_scalar(file,cmd.address_v);
}
if (!file) throw std::runtime_error("failed to write native draw capture: " + path);
}
@@ -242,7 +244,7 @@ inline Capture read_capture(const std::string& path) {
if (!file) throw std::runtime_error("cannot open native draw capture: " + path);
std::uint32_t magic = 0, version = 0, count = 0;
read_scalar(file, magic); read_scalar(file, version); read_scalar(file, count);
if (magic != 0x4d544452 || (version < 1 || version > 10) || count > 10'000)
if (magic != 0x4d544452 || (version < 1 || version > 11) || count > 10'000)
throw std::runtime_error("unsupported native draw capture format");
Capture capture;
capture.version = version;
@@ -404,6 +406,7 @@ inline Capture read_capture(const std::string& path) {
read_string(file, cmd.mask);
file.read(reinterpret_cast<char*>(cmd.mu), sizeof(cmd.mu));
file.read(reinterpret_cast<char*>(cmd.mv), sizeof(cmd.mv));
if(version>=11) {read_scalar(file,cmd.address_u);read_scalar(file,cmd.address_v);}
if (!file) throw std::runtime_error("truncated native draw capture UI command");
}
}
+1 -1
View File
@@ -154,7 +154,7 @@ void VulkanWindow::build_ui_batches(
? ((cmd.blend == 1 || cmd.blend == 2) ? 0x2A : (cmd.blend == 3 ? 0x31 : 1))
: 1;
const VkPipeline pipeline = get_pipeline(0, 0, blend_mode);
const VkDescriptorSet descriptor = get_ui_texture_descriptor(tex_name, mask_name, capture_textures, point);
const VkDescriptorSet descriptor = get_ui_texture_descriptor(tex_name, mask_name, capture_textures, point, cmd.address_u, cmd.address_v);
for (int k = 0; k < 4; ++k) {
Vertex& vert = vertices[v_count + k];
+14 -1
View File
@@ -195,7 +195,20 @@ VkDescriptorSet VulkanWindow::get_texture_descriptor(
VkDescriptorSet VulkanWindow::get_ui_texture_descriptor(
const std::string& texture0_name,
const std::string& mask_name,
const std::unordered_map<std::string, std::vector<std::uint8_t>>& capture_textures, bool point) {
const std::unordered_map<std::string, std::vector<std::uint8_t>>& capture_textures, bool point,
std::uint32_t address_u,std::uint32_t address_v) {
if(address_u!=3 || address_v!=3) {
// 40250 ExpandedImage uses the current D3D8 addressing state. Board backgrounds tile;
// clamping them stretches the edge texels into stripes. Reuse the existing sampler cache.
Render3DDraw state{};
state.address_u[0]=address_u; state.address_v[0]=address_v;
state.address_u[1]=state.address_v[1]=3;
for(int i=0;i<2;++i) {
state.min_filter[i]=state.mag_filter[i]=point?1:2;
state.mip_filter[i]=0; // UI remains at mip zero, including the HD archive.
}
return get_texture_descriptor(texture0_name,mask_name,capture_textures,state);
}
auto& tex0 = get_gpu_texture(texture0_name, capture_textures);
if (point && mask_name.empty() && tex0.view) {
if (!tex0.ui_point_descriptor)
+1 -1
View File
@@ -357,7 +357,7 @@ private:
const std::string& texture0_name,
const std::string& mask_name,
const std::unordered_map<std::string, std::vector<std::uint8_t>>& capture_textures,
bool point = false);
bool point = false, std::uint32_t address_u = 3, std::uint32_t address_v = 3);
void upload_texture(
std::uint32_t width,