Skip to content

Commit 3dd19b1

Browse files
authored
Merge pull request #75 from KTStephano/v0.10
V0.10
2 parents f9421a9 + c77c1b5 commit 3dd19b1

13 files changed

+577
-344
lines changed

Source/Engine/StratusGpuBuffer.cpp

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -584,142 +584,4 @@ namespace stratus {
584584
}
585585
return indices;
586586
}
587-
588-
GpuCommandBuffer::GpuCommandBuffer() {
589-
590-
}
591-
592-
void GpuCommandBuffer::RemoveCommandsAt(const std::unordered_set<size_t>& indices) {
593-
VerifyArraySizes_();
594-
if (indices.size() == 0) return;
595-
596-
// std::vector<uint64_t> newHandles;
597-
std::vector<uint32_t> newMaterialIndices;
598-
std::vector<glm::mat4> newPrevFrameModelTransforms;
599-
std::vector<glm::mat4> newModelTransforms;
600-
std::vector<GpuDrawElementsIndirectCommand> newIndirectDrawCommands;
601-
for (size_t i = 0; i < NumDrawCommands(); ++i) {
602-
if (indices.find(i) == indices.end()) {
603-
// handlesToIndicesMap.insert(std::make_pair(handles[i], newHandles.size()));
604-
// newHandles.push_back(handles[i]);
605-
newMaterialIndices.push_back(materialIndices[i]);
606-
newPrevFrameModelTransforms.push_back(prevFrameModelTransforms[i]);
607-
newModelTransforms.push_back(modelTransforms[i]);
608-
newIndirectDrawCommands.push_back(indirectDrawCommands[i]);
609-
}
610-
// else {
611-
// handlesToIndicesMap.erase(handles[i]);
612-
// }
613-
}
614-
615-
// handles = std::move(newHandles);
616-
materialIndices = std::move(newMaterialIndices);
617-
prevFrameModelTransforms = std::move(newPrevFrameModelTransforms);
618-
modelTransforms = std::move(newModelTransforms);
619-
indirectDrawCommands = std::move(newIndirectDrawCommands);
620-
}
621-
622-
size_t GpuCommandBuffer::NumDrawCommands() const {
623-
return indirectDrawCommands.size();
624-
}
625-
626-
void GpuCommandBuffer::UploadDataToGpu() {
627-
VerifyArraySizes_();
628-
629-
const size_t numElems = NumDrawCommands();
630-
if (numElems == 0) return;
631-
632-
if (indirectDrawCommands_ == GpuBuffer() || indirectDrawCommands_.SizeBytes() < (numElems * sizeof(GpuDrawElementsIndirectCommand))) {
633-
const Bitfield flags = GPU_DYNAMIC_DATA;
634-
635-
materialIndices_ = GpuBuffer((const void *)materialIndices.data(), numElems * sizeof(uint32_t), flags);
636-
prevFrameModelTransforms_ = GpuBuffer((const void*)prevFrameModelTransforms.data(), numElems * sizeof(glm::mat4), flags);
637-
modelTransforms_ = GpuBuffer((const void *)modelTransforms.data(), numElems * sizeof(glm::mat4), flags);
638-
indirectDrawCommands_ = GpuBuffer((const void *)indirectDrawCommands.data(), numElems * sizeof(GpuDrawElementsIndirectCommand), flags);
639-
if (aabbs.size() > 0) {
640-
aabbs_ = GpuBuffer((const void *)aabbs.data(), numElems * sizeof(GpuAABB), flags);
641-
}
642-
}
643-
else {
644-
materialIndices_.CopyDataToBuffer(0, numElems * sizeof(uint32_t), (const void *)materialIndices.data());
645-
prevFrameModelTransforms_.CopyDataToBuffer(0, numElems * sizeof(glm::mat4), (const void*)prevFrameModelTransforms.data());
646-
modelTransforms_.CopyDataToBuffer(0, numElems * sizeof(glm::mat4), (const void *)modelTransforms.data());
647-
indirectDrawCommands_.CopyDataToBuffer(0, numElems * sizeof(GpuDrawElementsIndirectCommand), (const void *)indirectDrawCommands.data());
648-
if (aabbs.size() > 0) {
649-
aabbs_.CopyDataToBuffer(0, numElems * sizeof(GpuAABB), (const void *)aabbs.data());
650-
}
651-
}
652-
}
653-
654-
void GpuCommandBuffer::BindMaterialIndicesBuffer(uint32_t index) {
655-
if (materialIndices_ == GpuBuffer()) {
656-
throw std::runtime_error("Null material indices GpuBuffer");
657-
}
658-
materialIndices_.BindBase(GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
659-
}
660-
661-
void GpuCommandBuffer::BindPrevFrameModelTransformBuffer(uint32_t index) {
662-
if (prevFrameModelTransforms_ == GpuBuffer()) {
663-
throw std::runtime_error("Null previous frame model transform GpuBuffer");
664-
}
665-
prevFrameModelTransforms_.BindBase(GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
666-
}
667-
668-
void GpuCommandBuffer::BindModelTransformBuffer(uint32_t index) {
669-
if (modelTransforms_ == GpuBuffer()) {
670-
throw std::runtime_error("Null model transform GpuBuffer");
671-
}
672-
modelTransforms_.BindBase(GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
673-
}
674-
675-
void GpuCommandBuffer::BindAabbBuffer(uint32_t index) {
676-
if (aabbs_ == GpuBuffer()) {
677-
throw std::runtime_error("Null aabb GpuBuffer");
678-
}
679-
aabbs_.BindBase(GpuBaseBindingPoint::SHADER_STORAGE_BUFFER, index);
680-
}
681-
682-
void GpuCommandBuffer::BindIndirectDrawCommands() {
683-
if (indirectDrawCommands_ == GpuBuffer()) {
684-
throw std::runtime_error("Null indirect draw command buffer");
685-
}
686-
indirectDrawCommands_.Bind(GpuBindingPoint::DRAW_INDIRECT_BUFFER);
687-
}
688-
689-
void GpuCommandBuffer::UnbindIndirectDrawCommands() {
690-
if (indirectDrawCommands_ == GpuBuffer()) {
691-
throw std::runtime_error("Null indirect draw command buffer");
692-
}
693-
indirectDrawCommands_.Unbind(GpuBindingPoint::DRAW_INDIRECT_BUFFER);
694-
}
695-
696-
void GpuCommandBuffer::VerifyArraySizes_() const {
697-
if (//materialIndices.size() == handlesToIndicesMap.size() &&
698-
//materialIndices.size() == handles.size() &&
699-
materialIndices.size() != prevFrameModelTransforms.size() ||
700-
materialIndices.size() != modelTransforms.size() ||
701-
materialIndices.size() != indirectDrawCommands.size()) {
702-
throw std::runtime_error("Sizes do not match up in GpuBuffer");
703-
}
704-
705-
if (aabbs.size() > 0) {
706-
assert(aabbs.size() == indirectDrawCommands.size());
707-
}
708-
}
709-
710-
const GpuBuffer& GpuCommandBuffer::GetIndirectDrawCommandsBuffer() const {
711-
return indirectDrawCommands_;
712-
}
713-
714-
GpuCommandBufferPtr GpuCommandBuffer::Copy() const {
715-
GpuCommandBufferPtr copy = GpuCommandBufferPtr(new GpuCommandBuffer());
716-
copy->materialIndices = materialIndices;
717-
copy->prevFrameModelTransforms = prevFrameModelTransforms;
718-
copy->modelTransforms = modelTransforms;
719-
copy->indirectDrawCommands = indirectDrawCommands;
720-
copy->aabbs = aabbs;
721-
722-
copy->UploadDataToGpu();
723-
return copy;
724-
}
725587
}

Source/Engine/StratusGpuBuffer.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ namespace stratus {
7373

7474
struct GpuBufferImpl;
7575
struct GpuArrayBufferImpl;
76-
struct GpuCommandBuffer;
77-
78-
typedef std::shared_ptr<GpuCommandBuffer> GpuCommandBufferPtr;
7976

8077
// A gpu buffer holds primitive data usually in the form of floats, ints and shorts
8178
// TODO: Look into use cases for things other than STATIC_DRAW
@@ -422,53 +419,4 @@ namespace stratus {
422419
static std::vector<_MeshData> freeIndices_;
423420
static bool initialized_;
424421
};
425-
426-
// Stores material indices, model transforms and indirect draw commands
427-
class GpuCommandBuffer final {
428-
GpuBuffer materialIndices_;
429-
GpuBuffer prevFrameModelTransforms_;
430-
GpuBuffer modelTransforms_;
431-
GpuBuffer indirectDrawCommands_;
432-
GpuBuffer aabbs_;
433-
434-
public:
435-
GpuCommandBuffer();
436-
437-
// This is to allow for 64-bit handles to be used to identify an object
438-
// with its location in the array
439-
// std::unordered_map<uint64_t, size_t> handlesToIndicesMap;
440-
// std::vector<uint64_t> handles;
441-
// CPU side of the data
442-
std::vector<uint32_t> materialIndices;
443-
// Model transform is defined as global transform * mesh transform
444-
std::vector<glm::mat4> prevFrameModelTransforms;
445-
std::vector<glm::mat4> modelTransforms;
446-
std::vector<GpuDrawElementsIndirectCommand> indirectDrawCommands;
447-
std::vector<GpuAABB> aabbs;
448-
449-
GpuCommandBuffer(GpuCommandBuffer&&) = default;
450-
GpuCommandBuffer(const GpuCommandBuffer&) = delete;
451-
452-
GpuCommandBuffer& operator=(GpuCommandBuffer&&) = delete;
453-
GpuCommandBuffer& operator=(const GpuCommandBuffer&) = delete;
454-
455-
void RemoveCommandsAt(const std::unordered_set<size_t>& indices);
456-
size_t NumDrawCommands() const;
457-
void UploadDataToGpu();
458-
459-
void BindMaterialIndicesBuffer(uint32_t index);
460-
void BindPrevFrameModelTransformBuffer(uint32_t index);
461-
void BindModelTransformBuffer(uint32_t index);
462-
void BindAabbBuffer(uint32_t index);
463-
464-
void BindIndirectDrawCommands();
465-
void UnbindIndirectDrawCommands();
466-
467-
const GpuBuffer& GetIndirectDrawCommandsBuffer() const;
468-
469-
GpuCommandBufferPtr Copy() const;
470-
471-
private:
472-
void VerifyArraySizes_() const;
473-
};
474422
}

0 commit comments

Comments
 (0)