Add capybara

This commit is contained in:
2026-06-21 22:38:11 +02:00
parent d534e57ad2
commit 7e5536a02f
10 changed files with 153 additions and 45 deletions
+12 -2
View File
@@ -62,7 +62,17 @@ void Animator::addClip(std::shared_ptr<SkeletalAnimation> clip) {
void Animator::play(const std::string& name, float blendTime) {
auto it = m_clips.find(name);
if (it == m_clips.end()) return;
if (it == m_clips.end()) {
spdlog::warn("Animator::play failed. Clip '{}' not found.", name);
spdlog::info("Available clips:");
for (const auto& [clipName, _] : m_clips)
spdlog::info(" - '{}'", clipName);
return;
}
spdlog::info("Animator playing clip '{}'", name);
if (m_current.clip && blendTime > 0.f) {
m_previous = m_current;
@@ -73,7 +83,7 @@ void Animator::play(const std::string& name, float blendTime) {
m_blendT = 1.f;
}
m_current = { it->second.get(), 0.f, 1.f };
m_current = { it->second.get(), 0.f, 1.f };
m_currentClipName = name;
}
@@ -4,6 +4,12 @@
#include "destrum/Graphics/MeshCache.h"
#include "destrum/Graphics/MeshDrawCommand.h"
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <stdexcept>
void SkinningPipeline::init(GfxDevice& gfxDevice) {
const auto& device = gfxDevice.getDevice();
@@ -17,15 +23,13 @@ void SkinningPipeline::init(GfxDevice& gfxDevice) {
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.pushConstantRangeCount = 1;
pipelineLayoutInfo.pPushConstantRanges = pushConstants.data();
if (vkCreatePipelineLayout(gfxDevice.getDevice().device, &pipelineLayoutInfo, nullptr, &m_pipelineLayout) != VK_SUCCESS) {
throw std::runtime_error("Could not make pipleine layout");
if (vkCreatePipelineLayout(device.device, &pipelineLayoutInfo, nullptr, &m_pipelineLayout) != VK_SUCCESS) {
throw std::runtime_error("Could not make pipeline layout");
}
ComputePipelineConfigInfo pipelineConfig{};
pipelineConfig.name = "skinning compute pipeline";
pipelineConfig.pipelineLayout = m_pipelineLayout;
@@ -38,7 +42,6 @@ void SkinningPipeline::init(GfxDevice& gfxDevice) {
pipelineConfig
);
for (std::size_t i = 0; i < FRAMES_IN_FLIGHT; ++i) {
auto& jointMatricesBuffer = framesData[i].jointMatricesBuffer;
jointMatricesBuffer.capacity = MAX_JOINT_MATRICES;
@@ -52,12 +55,15 @@ void SkinningPipeline::cleanup(GfxDevice& gfxDevice) {
for (auto& frame : framesData) {
gfxDevice.destroyBuffer(frame.jointMatricesBuffer.buffer);
}
vkDestroyPipelineLayout(gfxDevice.getDevice().device, m_pipelineLayout, nullptr);
skinningPipeline.reset();
}
void SkinningPipeline::doSkinning(VkCommandBuffer cmd, std::size_t frameIndex, const MeshCache& meshCache, const MeshDrawCommand& dc) {
void SkinningPipeline::doSkinning(VkCommandBuffer cmd,
std::size_t frameIndex,
const MeshCache& meshCache,
const MeshDrawCommand& dc) {
skinningPipeline->bind(cmd);
const auto& mesh = meshCache.getMesh(dc.meshId);
@@ -66,27 +72,55 @@ void SkinningPipeline::doSkinning(VkCommandBuffer cmd, std::size_t frameIndex, c
const auto cs = PushConstants{
.jointMatricesBuffer = getCurrentFrameData(frameIndex).jointMatricesBuffer.buffer.address,
.jointMatricesStartIndex = static_cast<std::uint32_t>(dc.jointMatricesStartIndex), // explicit cast
.jointMatricesStartIndex = static_cast<std::uint32_t>(dc.jointMatricesStartIndex),
.numVertices = mesh.numVertices,
.inputBuffer = mesh.vertexBuffer.address,
.skinningData = mesh.skinningDataBuffer.address,
.outputBuffer = dc.skinnedMesh->skinnedVertexBuffer.address,
};
vkCmdPushConstants(cmd, m_pipelineLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(PushConstants), &cs);
static const auto workgroupSize = 256;
// const auto groupSizeX = (std::uint32_t)std::ceil(mesh.numVertices / (float)workgroupSize);
const auto groupSizeX = static_cast<std::uint32_t>(
std::ceil(mesh.numVertices / (float)workgroupSize));
vkCmdPushConstants(cmd,
m_pipelineLayout,
VK_SHADER_STAGE_COMPUTE_BIT,
0,
sizeof(PushConstants),
&cs);
constexpr std::uint32_t workgroupSize = 256;
const auto groupSizeX = static_cast<std::uint32_t>((mesh.numVertices + workgroupSize - 1) / workgroupSize);
if (groupSizeX == 0) {
return;
}
vkCmdDispatch(cmd, groupSizeX, 1, 1);
// Required before the graphics pass reads skinnedVertexBuffer as a vertex buffer.
// Without this, the draw can see stale/partial data from before the compute dispatch.
VkBufferMemoryBarrier skinnedVertexBarrier{};
skinnedVertexBarrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
skinnedVertexBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
skinnedVertexBarrier.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
skinnedVertexBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
skinnedVertexBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
skinnedVertexBarrier.buffer = dc.skinnedMesh->skinnedVertexBuffer.buffer;
skinnedVertexBarrier.offset = 0;
skinnedVertexBarrier.size = VK_WHOLE_SIZE;
vkCmdPipelineBarrier(cmd,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_VERTEX_INPUT_BIT,
0,
0, nullptr,
1, &skinnedVertexBarrier,
0, nullptr);
}
void SkinningPipeline::beginDrawing(std::size_t frameIndex) {
getCurrentFrameData(frameIndex).jointMatricesBuffer.clear();
}
std::size_t SkinningPipeline::appendJointMatrices(std::span<const glm::mat4> jointMatrices, std::size_t frameIndex) {
std::size_t SkinningPipeline::appendJointMatrices(std::span<const glm::mat4> jointMatrices,
std::size_t frameIndex) {
auto& jointMatricesBuffer = getCurrentFrameData(frameIndex).jointMatricesBuffer;
const auto startIndex = jointMatricesBuffer.size;
jointMatricesBuffer.append(jointMatrices);