Model preview: AVA2 render-target window on a Vulkan colour target

Port of AVA2's CRenderTarget / GrpRenderTargetTexture / renderTarget module.
The host gains an RGBA8 offscreen colour pass for D3D colour render targets;
mt_preview shows wearable items on every allowed race and monsters with
motions, reached by X+click in the inventory and shop and from the wiki.
Player races are created as TYPE_PC so their parts exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-16 04:48:07 +09:00
co-authored by Claude Opus 5.5
parent 32372c2a73
commit 84404cf1f1
25 changed files with 1602 additions and 34 deletions
+13 -6
View File
@@ -56,8 +56,9 @@ class VulkanWindow {
VkDescriptorSet set = VK_NULL_HANDLE;
std::uint64_t last_used_frame = 0;
};
// An offscreen D3D render-target texture (the 40250 character shadow map, "rt:<id>:<w>x<h>"):
// drawn by the frame's offscreen pass ahead of the back-buffer pass and sampled by that pass.
// An offscreen D3D render-target texture (the 40250 character shadow map, "rt:<id>:<w>x<h>", or a
// colour target such as the model preview, "rt:<id>:<w>x<h>:c"): drawn by the frame's offscreen pass
// ahead of the back-buffer pass and sampled by that pass.
// Between frames the colour image stays SHADER_READ_ONLY_OPTIMAL and the depth image
// DEPTH_STENCIL_ATTACHMENT_OPTIMAL; the render pass keeps (LOAD/STORE) both, like a D3D surface.
struct RenderTarget {
@@ -67,7 +68,9 @@ class VulkanWindow {
VkImageView depth_view = VK_NULL_HANDLE;
VkFramebuffer framebuffer = VK_NULL_HANDLE;
std::uint32_t width = 0, height = 0;
bool initialized = false; // cleared to white / depth 1 by the first frame that uses it
bool initialized = false; // cleared (shadow white, colour black) / depth 1 by the first frame that uses it
bool color = false; // RGBA8 drawn with offscreen_color_pass_; otherwise offscreen_format_
std::uint64_t last_used_frame = 0; // pruned with the textures once unused
};
struct PreparedDraw {
Geometry* geometry = nullptr;
@@ -223,7 +226,7 @@ private:
};
// Host copies of the swapchain image (--screenshot-out) and, with MT_DUMP_RT, of every render target.
struct Readback {
struct RtDump { VkBuffer buffer; VkDeviceMemory memory; std::uint32_t w, h; };
struct RtDump { VkBuffer buffer; VkDeviceMemory memory; std::uint32_t w, h, texel; };
bool screenshot = false; // the swapchain image is copied (a BMP or a frame sink wants it)
bool bmp = false; // --screenshot-out
std::vector<FrameSink> sinks;
@@ -297,7 +300,9 @@ private:
// The render pass of offscreen render-target textures: colour (R5G6B5 like the D3D surface when
// the device can render to it) + D32 depth, both loaded and stored, colour left shader-readable.
// PORT: plus offscreen_color_pass_, the same pass over RGBA8 for colour targets.
void create_offscreen_pass();
VkRenderPass make_offscreen_pass(VkFormat format);
// The reduced-resolution scene pass: pass_'s attachments (so pass_ pipelines draw in it) at
// scene_extent_, resolving into the sampled scene_texture_. Unsupported when the swapchain
@@ -322,9 +327,10 @@ private:
// the layouts offscreen_pass_ expects. Recorded outside any render pass.
void initialize_render_target(RenderTarget& target);
// offscreen: for offscreen_pass_ (single-sampled render-target texture) instead of pass_.
// offscreen: 1 for offscreen_pass_, 2 for offscreen_color_pass_ (single-sampled render-target
// texture) instead of pass_.
VkPipeline get_pipeline(std::uint8_t cull, std::uint8_t depth, std::uint8_t blend,
bool lines = false, std::uint8_t z_func = 4, bool offscreen = false,
bool lines = false, std::uint8_t z_func = 4, std::uint8_t offscreen = 0,
const Render3DDraw* draw = nullptr);
VkDescriptorSet allocate_texture_descriptor_set(VkImageView view0, VkImageView view1,
@@ -478,6 +484,7 @@ private:
std::unordered_map<std::string, PairedDescriptor> paired_descriptors_;
std::unordered_map<std::string, RenderTarget> render_targets_;
VkRenderPass offscreen_pass_ = VK_NULL_HANDLE;
VkRenderPass offscreen_color_pass_ = VK_NULL_HANDLE;
float render_scale_ = 1.0f;
bool scene_supported_ = false;
VkRenderPass scene_pass_ = VK_NULL_HANDLE;