Skip to content

Commit 77f20a5

Browse files
committed
resolve code review advise
1 parent 7c00578 commit 77f20a5

4 files changed

Lines changed: 80 additions & 282 deletions

File tree

src/Assets/FSceneLoader.cpp

Lines changed: 79 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -430,241 +430,85 @@ namespace Assets
430430
}
431431

432432

433-
// Load skeletons
434-
435-
436-
for (const auto& skin : model.skins)
437-
438-
439-
{
440-
441-
442-
Assets::Skeleton skeleton;
443-
444-
445-
skeleton.Name = skin.name;
446-
447-
448-
skeleton.RootJointIndex = -1; // TODO: find root? usually 0 or logic derived
449-
450-
451-
452-
453-
454-
std::vector<glm::mat4> ibms;
455-
456-
457-
if (skin.inverseBindMatrices != -1)
458-
459-
460-
{
461-
462-
463-
const auto& accessor = model.accessors[skin.inverseBindMatrices];
464-
465-
466-
const auto& bufferView = model.bufferViews[accessor.bufferView];
467-
468-
469-
const auto& buffer = model.buffers[bufferView.buffer];
470-
471-
472-
int stride = accessor.ByteStride(bufferView);
473-
474-
475-
476-
477-
478-
ibms.resize(accessor.count);
479-
480-
481-
const unsigned char* dataPtr = buffer.data.data() + bufferView.byteOffset + accessor.byteOffset;
482-
483-
484-
485-
486-
487-
for(size_t i=0; i<accessor.count; ++i)
488-
489-
490-
{
491-
492-
493-
const float* m = reinterpret_cast<const float*>(dataPtr + i * stride);
494-
495-
496-
ibms[i] = glm::make_mat4(m);
497-
498-
499-
}
500-
501-
502-
}
503-
504-
505-
506-
507-
508-
std::map<int, int> nodeToJointIndex;
509-
510-
511-
for(size_t i=0; i<skin.joints.size(); ++i)
512-
513-
514-
{
515-
516-
517-
nodeToJointIndex[skin.joints[i]] = static_cast<int>(i);
518-
519-
520-
}
521-
522-
523-
524-
525-
526-
for (size_t i = 0; i < skin.joints.size(); ++i)
527-
528-
529-
{
530-
531-
532-
int nodeIdx = skin.joints[i];
533-
534-
535-
auto& node = model.nodes[nodeIdx];
536-
537-
538-
539-
540-
541-
Assets::Joint joint;
542-
543-
544-
joint.Name = node.name;
545-
546-
547-
if (i < ibms.size())
548-
549-
550-
{
551-
552-
553-
joint.InverseBindMatrix = ibms[i];
554-
555-
556-
}
557-
558-
559-
560-
561-
562-
if (!node.matrix.empty())
563-
564-
565-
{
566-
567-
568-
glm::dmat4 dmat = glm::make_mat4(node.matrix.data());
569-
570-
571-
glm::mat4 mat = glm::mat4(dmat);
572-
573-
574-
glm::vec3 skew;
575-
576-
577-
glm::vec4 perspective;
578-
579-
580-
glm::decompose(mat, joint.Scale, joint.Rotation, joint.Translation, skew, perspective);
581-
582-
583-
}
584-
585-
586-
else
587-
588-
589-
{
590-
591-
592-
joint.Translation = node.translation.empty() ? glm::vec3(0) : glm::vec3(node.translation[0], node.translation[1], node.translation[2]);
593-
594-
595-
joint.Scale = node.scale.empty() ? glm::vec3(1) : glm::vec3(node.scale[0], node.scale[1], node.scale[2]);
596-
597-
598-
joint.Rotation = node.rotation.empty() ? glm::quat(1, 0, 0, 0) : glm::quat(static_cast<float>(node.rotation[3]), static_cast<float>(node.rotation[0]), static_cast<float>(node.rotation[1]), static_cast<float>(node.rotation[2]));
599-
600-
601-
}
602-
603-
604-
605-
606-
607-
skeleton.Joints.push_back(joint);
608-
609-
610-
}
611-
612-
613-
614-
615-
616-
// Hierarchy
617-
618-
619-
for(size_t i=0; i<skin.joints.size(); ++i)
620-
621-
622-
{
623-
624-
625-
int nodeIdx = skin.joints[i];
626-
627-
628-
auto& node = model.nodes[nodeIdx];
629-
630-
631-
for (int child : node.children)
632-
633-
634-
{
635-
636-
637-
if (nodeToJointIndex.find(child) != nodeToJointIndex.end())
638-
639-
640-
{
641-
642-
643-
int childIdx = nodeToJointIndex[child];
644-
645-
646-
skeleton.Joints[childIdx].ParentIndex = static_cast<int>(i);
647-
648-
649-
skeleton.Joints[i].Children.push_back(childIdx);
650-
651-
652-
}
653-
654-
655-
}
656-
657-
658-
}
659-
660-
661-
662-
663-
664-
skeletons.push_back(skeleton);
665-
666-
667-
}
433+
// Load skeletons
434+
for (const auto& skin : model.skins)
435+
{
436+
Assets::Skeleton skeleton;
437+
skeleton.Name = skin.name;
438+
skeleton.RootJointIndex = 0;
439+
440+
std::vector<glm::mat4> ibms;
441+
if (skin.inverseBindMatrices != -1)
442+
{
443+
const auto& accessor = model.accessors[skin.inverseBindMatrices];
444+
const auto& bufferView = model.bufferViews[accessor.bufferView];
445+
const auto& buffer = model.buffers[bufferView.buffer];
446+
int stride = accessor.ByteStride(bufferView);
447+
448+
ibms.resize(accessor.count);
449+
const unsigned char* dataPtr = buffer.data.data() + bufferView.byteOffset + accessor.byteOffset;
450+
451+
for(size_t i=0; i<accessor.count; ++i)
452+
{
453+
const float* m = reinterpret_cast<const float*>(dataPtr + i * stride);
454+
ibms[i] = glm::make_mat4(m);
455+
}
456+
}
457+
458+
std::map<int, int> nodeToJointIndex;
459+
for(size_t i=0; i<skin.joints.size(); ++i)
460+
{
461+
nodeToJointIndex[skin.joints[i]] = static_cast<int>(i);
462+
}
463+
464+
for (size_t i = 0; i < skin.joints.size(); ++i)
465+
{
466+
int nodeIdx = skin.joints[i];
467+
auto& node = model.nodes[nodeIdx];
468+
469+
Assets::Joint joint;
470+
joint.Name = node.name;
471+
if (i < ibms.size())
472+
{
473+
joint.InverseBindMatrix = ibms[i];
474+
}
475+
476+
if (!node.matrix.empty())
477+
{
478+
glm::dmat4 dmat = glm::make_mat4(node.matrix.data());
479+
glm::mat4 mat = glm::mat4(dmat);
480+
glm::vec3 skew;
481+
glm::vec4 perspective;
482+
glm::decompose(mat, joint.Scale, joint.Rotation, joint.Translation, skew, perspective);
483+
}
484+
else
485+
{
486+
joint.Translation = node.translation.empty() ? glm::vec3(0) : glm::vec3(node.translation[0], node.translation[1], node.translation[2]);
487+
joint.Scale = node.scale.empty() ? glm::vec3(1) : glm::vec3(node.scale[0], node.scale[1], node.scale[2]);
488+
joint.Rotation = node.rotation.empty() ? glm::quat(1, 0, 0, 0) : glm::quat(static_cast<float>(node.rotation[3]), static_cast<float>(node.rotation[0]), static_cast<float>(node.rotation[1]), static_cast<float>(node.rotation[2]));
489+
}
490+
491+
skeleton.Joints.push_back(joint);
492+
}
493+
494+
// Hierarchy
495+
for(size_t i=0; i<skin.joints.size(); ++i)
496+
{
497+
int nodeIdx = skin.joints[i];
498+
auto& node = model.nodes[nodeIdx];
499+
for (int child : node.children)
500+
{
501+
if (nodeToJointIndex.find(child) != nodeToJointIndex.end())
502+
{
503+
int childIdx = nodeToJointIndex[child];
504+
skeleton.Joints[childIdx].ParentIndex = static_cast<int>(i);
505+
skeleton.Joints[i].Children.push_back(childIdx);
506+
}
507+
}
508+
}
509+
510+
skeletons.push_back(skeleton);
511+
}
668512

669513

670514

src/Rendering/PipelineCommon/CommonComputePipeline.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,47 +80,6 @@ namespace Vulkan::PipelineCommon
8080
0, sizeof(Assets::GPUScene), &(scene.FetchGPUScene(imageIndex)));
8181
}
8282

83-
struct GPUScene1
84-
{
85-
uint64_t Camera;
86-
uint64_t Nodes;
87-
88-
uint64_t Reorders;
89-
uint64_t VerticesSimple;
90-
91-
uint64_t Vertices;
92-
uint64_t Indices;
93-
94-
uint64_t Materials;
95-
uint64_t Offsets;
96-
97-
uint64_t Cubes;
98-
uint64_t Voxels;
99-
100-
uint64_t Pages;
101-
uint64_t HDRSHs;
102-
103-
uint64_t Lights;
104-
uint64_t IndirectDrawCommands;
105-
106-
uint64_t GPUDrivenStats;
107-
uint64_t TLAS;
108-
109-
uint64_t SkinWeights;
110-
uint64_t SkinJoints;
111-
112-
uint64_t SkinnedVertices;
113-
uint64_t JointMatrices;
114-
115-
uint64_t SkinnedVerticesSimple;
116-
uint64_t Reserved;
117-
118-
uint32_t SwapChainIndex;
119-
uint32_t custom_data_0;
120-
uint32_t custom_data_1;
121-
uint32_t custom_data_2;
122-
};
123-
12483
ZeroBindPipeline::ZeroBindPipeline(const SwapChain& swapChain, const char* shaderfile):PipelineBase(swapChain)
12584
{
12685
// Create descriptor pool/sets.

src/Rendering/RayTraceBaseRenderer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ namespace Vulkan::RayTracing
109109
CreateTopLevelStructures(commandBuffer);
110110
});
111111

112-
//topScratchBuffer_.reset();
113-
//topScratchBufferMemory_.reset();
114-
//bottomScratchBuffer_.reset();
115-
//bottomScratchBufferMemory_.reset();
116-
117112
const auto elapsed = std::chrono::duration<float, std::chrono::seconds::period>(
118113
std::chrono::high_resolution_clock::now() - timer).count();
119114
SPDLOG_INFO("- built acceleration structures in {:.2f}ms", elapsed * 1000.f);

src/Rendering/VulkanBaseRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ namespace Vulkan
829829
skinnedBufferBarrier.size = VK_WHOLE_SIZE;
830830

831831
vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
832-
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &skinnedBufferBarrier, 0, nullptr);
832+
VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, 0, 0, nullptr, 1, &skinnedBufferBarrier, 0, nullptr);
833833
}
834834
}
835835

0 commit comments

Comments
 (0)