mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 12:57:06 +01:00
3b9d8b2fa3
- The bounding radius, offset() and MaxY() read the positions of a chunk alone (Positions(), geometry_bank::positions()): on Vulkan the compact streams are no longer decoded into basic_vertex and kept for the life of the bank as every model loads, so the host memory of EU07M models stays below that of E3D. What still needs whole vertices (the editor, the picking, the export) decodes them on first use as before. - A COMPACT_VERTEX variant which doesn't compile is told once in the log and the banks of EU07M models go back to basic_vertex (compact_layout_failed()), those built already when they are drawn next, instead of the models being left out for the session. - The shader validator compiles the vk14 shaders which have COMPACT_VERTEX with it, alone and with MODEL_DRAWS, as the renderer makes the variants.
134 lines
6.0 KiB
C++
134 lines
6.0 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
// the geometry banks of the vulkan renderer (stage D1 of the plan): the chunks of a bank in three device buffers of the bank
|
|
// (vertices, their user data, 32 bit indices), made the first time the bank is drawn after its chunks changed. a chunk replaced
|
|
// with the same size is copied in place, otherwise the buffers are made anew and the old ones go once the gpu is done with them.
|
|
// the data stays in memory as well (gfx::geometry_bank), the simulation reads it back. the primitives are the values of opengl
|
|
// the program gives them with; a line loop is drawn as a strip which goes back to its first vertex
|
|
|
|
#pragma once
|
|
|
|
#include "rendering/geometrybank.h"
|
|
#include "rendering/vulkan14/vulkan14common.h"
|
|
#include "rendering/vulkan14/vulkan14memory.h"
|
|
|
|
#include <chrono>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string_view>
|
|
|
|
namespace vk14
|
|
{
|
|
|
|
struct resources;
|
|
|
|
// where the data of a chunk is in the buffers of its bank
|
|
struct chunk_source
|
|
{
|
|
// basic_vertex, or for a bank of the compact layout the positions alone (12 bytes a vertex)
|
|
VkBuffer vertices{VK_NULL_HANDLE};
|
|
VkBuffer userdata{VK_NULL_HANDLE};
|
|
// the compact layout: the tangent quaternions and the texture coordinates (gfx::compact_attributes), drawn with the
|
|
// vertex_kind::scene_compact variant of the program; null for basic_vertex
|
|
VkBuffer attributes{VK_NULL_HANDLE};
|
|
bool compact{false};
|
|
VkBuffer indices{VK_NULL_HANDLE}; // null for a chunk without indices
|
|
std::uint32_t count{0}; // vertices, or indices
|
|
std::uint32_t first{0}; // first index, or vertex
|
|
std::int32_t basevertex{0};
|
|
VkPrimitiveTopology topology{VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST};
|
|
// for the ray tracing: the vertices of the chunk in the buffer of the bank, the device addresses of the buffers (0 without the ray
|
|
// tracing), and the number the data of the chunk on the gpu has: another one when the buffers were made anew or the chunk changed
|
|
std::uint32_t vertexfirst{0};
|
|
std::uint32_t vertexcount{0};
|
|
VkDeviceAddress vertex_address{0};
|
|
VkDeviceAddress attribute_address{0}; // the compact layout
|
|
VkDeviceAddress index_address{0};
|
|
std::uint64_t generation{0};
|
|
};
|
|
|
|
// the vulkan primitive of a primitive of opengl (GL_TRIANGLES ...)
|
|
VkPrimitiveTopology topology_of(unsigned int Type);
|
|
|
|
// a variant of a scene program for the compact layout didn't compile: the banks of EU07M models are made of basic_vertex
|
|
// from then on, those made already when they are drawn next, so the models stay in sight. told once in the log
|
|
void compact_layout_failed(std::string_view Program);
|
|
// false once compact_layout_failed() was called
|
|
bool compact_layout_usable();
|
|
|
|
class vulkan14_geometrybank : public gfx::geometry_bank
|
|
{
|
|
public:
|
|
explicit vulkan14_geometrybank(resources const &Resources) : m_resources(Resources) {}
|
|
~vulkan14_geometrybank() override;
|
|
|
|
// the chunk with its data on the gpu: uploaded now when it changed since the last time. false: nothing to draw.
|
|
// gfx::geometrybank_manager::indirect_source() calls it too (which marks the bank as used). any thread walking the passes (M2);
|
|
// what changes the chunks is made while none of them draws (gfx::walk_sync)
|
|
bool source(gfx::geometry_handle const &Geometry, chunk_source &Source);
|
|
// the bytes on the gpu, for the debug panel
|
|
VkDeviceSize gpu_bytes() const
|
|
{
|
|
return m_bytes;
|
|
}
|
|
|
|
private:
|
|
struct chunk_place
|
|
{
|
|
std::uint32_t vertexfirst{0};
|
|
std::uint32_t vertexcount{0}; // on the gpu: one more than the chunk for a line loop
|
|
std::uint32_t indexfirst{0};
|
|
std::uint32_t indexcount{0};
|
|
bool dirty{true};
|
|
std::uint64_t generation{0}; // of its data on the gpu, for the ray tracing (chunk_source::generation)
|
|
};
|
|
|
|
void create_(gfx::geometry_handle const &Geometry) override;
|
|
void replace_(gfx::geometry_handle const &Geometry) override;
|
|
std::size_t draw_(gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams) override
|
|
{
|
|
return 0;
|
|
}
|
|
bool indirect_source_(gfx::geometry_handle const &Geometry, gfx::indirect_source &Source) override;
|
|
void release_() override;
|
|
// the buffers made anew for all the chunks
|
|
bool build();
|
|
// the chunks changed in place copied to the buffers
|
|
void update();
|
|
// the vertices of a chunk as they go to the gpu
|
|
void gpu_vertices(geometry_chunk const &Chunk, std::vector<gfx::basic_vertex> &Vertices, std::vector<gfx::vertex_userdata> &Userdata) const;
|
|
// the same for a chunk of the compact layout
|
|
static void gpu_compact(geometry_chunk const &Chunk, gfx::position_array &Positions, gfx::compact_array &Attributes, std::vector<gfx::vertex_userdata> &Userdata);
|
|
// the user data of a chunk as it goes to the gpu, for its first Count vertices
|
|
static void gpu_userdata(geometry_chunk const &Chunk, std::size_t Count, std::vector<gfx::vertex_userdata> &Userdata);
|
|
// the vertex streams of the gpu made of the chunks, in place of the buffers made before
|
|
bool make_buffers(void const *Vertices, VkDeviceSize VertexBytes, std::vector<gfx::vertex_userdata> const &Userdata, gfx::compact_array const *Attributes, std::vector<gfx::basic_index> const &Indices);
|
|
|
|
resources const &m_resources;
|
|
// basic_vertex, or the positions of the compact layout
|
|
std::shared_ptr<buffer> m_vertices;
|
|
std::shared_ptr<buffer> m_userdata;
|
|
// the compact layout (every chunk of the bank made with create_compact()): the tangent quaternions and the texture coordinates
|
|
std::shared_ptr<buffer> m_attributes;
|
|
bool m_compact{false};
|
|
std::shared_ptr<buffer> m_indices;
|
|
std::vector<chunk_place> m_places;
|
|
bool m_layoutdirty{true}; // the buffers have to be made anew
|
|
bool m_chunksdirty{false}; // some chunks have to be copied
|
|
// the buffers couldn't be made (no memory for them), and when: made again after a while
|
|
bool m_failed{false};
|
|
std::chrono::steady_clock::time_point m_failedat{};
|
|
VkDeviceSize m_bytes{0};
|
|
// the buffers made or updated by one of the threads drawing from the bank at a time
|
|
std::mutex m_mutex;
|
|
};
|
|
|
|
} // namespace vk14
|