mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 00:22:42 +01:00
6c7ec65825
The skinning of stage 4 moved the vertices on the CPU and replaced the geometry of each instance. The Vulkan renderer moves them in a compute shader now; GL 4.6 stays on the CPU. - gfx::skin_cache: the walks only work out the palette of the joints; flush(), before the walks of the next frame, moves the vertices of the instances whose pose changed: through the new GfxRenderer->Skin_Geometry() where the renderer can, else on the CPU with Replace / Replace_Indexed as before. A chunk made or emptied makes the buffers of the bank anew from the vertices the CPU holds, so every instance skinned on the GPU is moved again then. - Vulkan (rendering/vulkan14/vulkan14skinning.cpp, shaders/vk14/skin.comp): the bind pose with the weights of a skinned part goes to the GPU once, the palette in the ring of the frame; the kernel writes the moved vertices over those of the chunk of the instance in the buffer of its bank (gfx::basic_vertex), with barriers against the copies of the uploads and the draws of the frames before, and before the draws of the frame. The vertex buffers of the plain banks get the storage usage. The kernel is made the first time a part is skinned; without it the CPU moves them. - eu07.ini: gfx.skinning.gpu (default yes); no moves them on the CPU in Vulkan too. Both give the same picture. Checked in Vulkan: a tube of two joints turned by 60 degrees, GPU against CPU, with gfx.gpucull 0 and 1: no pixel differs, and the log shows the kernel ran. Two instances, the second posed later: the first keeps its pose through the rebuild of the bank, the same as on the CPU. A clip moving the tube every frame. GL 4.6 after the change of the cache: both instances bent as before (time let run in the editor for the tests only). Unit tests 1200/1200. Not measured on a large scene, not built with GCC here.
80 lines
2.6 KiB
C++
80 lines
2.6 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/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "model/skinning.h"
|
|
#include "rendering/geometrybank.h"
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
class TModel3d;
|
|
class TSubModel;
|
|
|
|
namespace gfx
|
|
{
|
|
|
|
// the skinned submodels of the instances drawn (EU07M skins), moved by the pose of the joints of each instance. the walks of the passes
|
|
// work out the palette of the joints once a frame for each instance and submodel; flush(), before the walks of the next frame, moves
|
|
// the vertices of those whose pose changed: in a compute shader where the renderer can (Skin_Geometry(), gfx.skinning.gpu), else on
|
|
// the CPU, replacing their geometry, as nothing the walks draw may change while they draw (gfx::walk_sync). so the vertices drawn
|
|
// follow the joints a frame late, and the first frame an instance is seen it's drawn in the bind pose
|
|
class skin_cache
|
|
{
|
|
public:
|
|
static skin_cache &instance();
|
|
// in a walk: the geometry to draw the skinned Submodel of Model with, for the instance drawn (TSubModel::iInstance). the bind
|
|
// pose of the submodel while its joints stay in it, or till its own geometry is made
|
|
geometry_handle geometry(TSubModel &Submodel, TModel3d const &Model, unsigned int Frame);
|
|
// on the main thread, before the walks of a frame: the vertices worked out go to the renderer, the instances not drawn for a while
|
|
// let go of theirs
|
|
void flush(unsigned int Frame);
|
|
// the entries kept and the geometry made, for the statistics
|
|
std::size_t size() const;
|
|
|
|
private:
|
|
struct key
|
|
{
|
|
std::uintptr_t owner{0};
|
|
TSubModel const *submodel{nullptr};
|
|
bool operator==(key const &) const = default;
|
|
};
|
|
struct key_hash
|
|
{
|
|
std::size_t operator()(key const &Key) const noexcept;
|
|
};
|
|
struct entry
|
|
{
|
|
std::shared_ptr<skinning::skinned_geometry const> source;
|
|
int type{0};
|
|
unsigned int frame{0}; // the frame the pose was worked out in
|
|
std::vector<glm::mat4> palette;
|
|
gfx::vertex_array vertices;
|
|
bool posed{false}; // the joints aren't in the bind pose
|
|
bool pending{false}; // the vertices are to be moved
|
|
bool gpu{false}; // moved by the renderer on the gpu the last time
|
|
geometry_handle handle{};
|
|
};
|
|
|
|
// the geometry of the instance, in the bind pose
|
|
void make(entry &Cached);
|
|
// the vertices of the instance moved by its palette, on the gpu or the cpu
|
|
void move(entry &Cached);
|
|
|
|
mutable std::mutex m_mutex;
|
|
std::unordered_map<key, entry, key_hash> m_entries;
|
|
geometrybank_handle m_bank{};
|
|
};
|
|
|
|
} // namespace gfx
|