Compare commits
No commits in common. "a87da63c9841d8d1ad46cc23c0b7d0a6f86626bc" and "cee0cad0bd2c8def28bbdb01a3e8f76b3c6e0406" have entirely different histories.
a87da63c98
...
cee0cad0bd
|
|
@ -9,12 +9,10 @@
|
|||
#include "physical_device.h"
|
||||
#include "window.h"
|
||||
|
||||
[[nodiscard]] vk::Extent2D GetExtent(const Window *window, vk::SurfaceCapabilitiesKHR *surfaceCapabilities);
|
||||
|
||||
Swapchain::Swapchain(const Window *window, const Device *device, NameString &&name)
|
||||
: m_Device(device)
|
||||
, m_Name(std::move(name))
|
||||
, m_Format(vk::Format::eUndefined)
|
||||
, m_Name(std::move(name))
|
||||
, m_Format(vk::Format::eUndefined)
|
||||
{
|
||||
this->Create(window);
|
||||
}
|
||||
|
|
@ -26,12 +24,12 @@ Swapchain::~Swapchain()
|
|||
|
||||
Swapchain::Swapchain(Swapchain &&other) noexcept
|
||||
: m_Device(other.m_Device)
|
||||
, m_Swapchain(Take(other.m_Swapchain))
|
||||
, m_Name(std::move(other.m_Name))
|
||||
, m_Extent(other.m_Extent)
|
||||
, m_Format(other.m_Format)
|
||||
, m_Images(std::move(other.m_Images))
|
||||
, m_ImageViews(std::move(other.m_ImageViews))
|
||||
, m_Swapchain(Take(other.m_Swapchain))
|
||||
, m_Name(std::move(other.m_Name))
|
||||
, m_Extent(other.m_Extent)
|
||||
, m_Format(other.m_Format)
|
||||
, m_Images(std::move(other.m_Images))
|
||||
, m_ImageViews(std::move(other.m_ImageViews))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -54,15 +52,6 @@ void
|
|||
Swapchain::Create(const Window *window)
|
||||
{
|
||||
auto surfaceCapabilities = GetSurfaceCapabilities(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
m_Extent = GetExtent(window, &surfaceCapabilities);
|
||||
|
||||
while (m_Extent.width == 0 || m_Extent.height == 0)
|
||||
{
|
||||
glfwWaitEvents();
|
||||
surfaceCapabilities = GetSurfaceCapabilities(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
m_Extent = GetExtent(window, &surfaceCapabilities);
|
||||
}
|
||||
|
||||
auto surfaceFormats = GetSurfaceFormats(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
auto presentModes = GetSurfacePresentModes(m_Device->m_PhysicalDevice, window->m_Surface);
|
||||
|
||||
|
|
@ -94,6 +83,20 @@ Swapchain::Create(const Window *window)
|
|||
}
|
||||
}
|
||||
|
||||
if (surfaceCapabilities.currentExtent.width != MaxValue<u32>)
|
||||
{
|
||||
m_Extent = surfaceCapabilities.currentExtent;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto [width, height] = window->GetSize();
|
||||
auto [minWidth, minHeight] = surfaceCapabilities.minImageExtent;
|
||||
auto [maxWidth, maxHeight] = surfaceCapabilities.maxImageExtent;
|
||||
|
||||
m_Extent.width = glm::clamp(width, minWidth, maxWidth);
|
||||
m_Extent.height = glm::clamp(height, minHeight, maxHeight);
|
||||
}
|
||||
|
||||
u32 swapchainImageCount = 3;
|
||||
if (surfaceCapabilities.maxImageCount > 0)
|
||||
{
|
||||
|
|
@ -203,22 +206,4 @@ Swapchain::Cleanup()
|
|||
m_Swapchain = nullptr;
|
||||
DEBUG("Swapchain '{}' destroyed.", m_Name);
|
||||
}
|
||||
}
|
||||
|
||||
vk::Extent2D
|
||||
GetExtent(const Window *window, vk::SurfaceCapabilitiesKHR *surfaceCapabilities)
|
||||
{
|
||||
if (surfaceCapabilities->currentExtent.width != MaxValue<u32>)
|
||||
{
|
||||
return surfaceCapabilities->currentExtent;
|
||||
}
|
||||
|
||||
auto [width, height] = window->GetSize();
|
||||
auto [minWidth, minHeight] = surfaceCapabilities->minImageExtent;
|
||||
auto [maxWidth, maxHeight] = surfaceCapabilities->maxImageExtent;
|
||||
|
||||
return {
|
||||
.width = glm::clamp(width, minWidth, maxWidth),
|
||||
.height = glm::clamp(height, minHeight, maxHeight),
|
||||
};
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ Window::GetSize() const
|
|||
{
|
||||
int width;
|
||||
int height;
|
||||
glfwGetFramebufferSize(m_Window, &width, &height);
|
||||
glfwGetWindowSize(m_Window, &width, &height);
|
||||
return {Cast<u32>(width), Cast<u32>(height)};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ struct Window final
|
|||
|
||||
void SetWindowSize(const vk::Extent2D &extent) const noexcept;
|
||||
void SetWindowSize(u32 width, u32 height) const noexcept;
|
||||
/// Actual size of the framebuffer being used for the window render.
|
||||
[[nodiscard]] vk::Extent2D GetSize() const;
|
||||
|
||||
// Ctor/Dtor
|
||||
|
|
|
|||
|
|
@ -513,7 +513,6 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
}
|
||||
|
||||
Nodes nodes;
|
||||
nodes.Add(mat4{1.0f}, -1);
|
||||
{
|
||||
if (model.defaultScene >= 0)
|
||||
{
|
||||
|
|
@ -534,7 +533,6 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
}
|
||||
if (node->scale.size() == 3)
|
||||
{
|
||||
// We don't handle the scale 0 special case yet.
|
||||
nodeScale = glm::make_vec3(node->scale.data());
|
||||
}
|
||||
if (node->matrix.size() == 16)
|
||||
|
|
@ -544,14 +542,14 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
const mat4 transform =
|
||||
translate(mat4(1.0f), nodeTranslation) * mat4_cast(nodeRotation) * scale(mat4(1.0f), nodeScale) * nodeMatrix;
|
||||
|
||||
const i32 nodeArrayIndex = Cast<i32>(nodes.Add(transform, parent));
|
||||
const u32 nodeArrayIndex = nodes.Add(transform, parent);
|
||||
if (node->mesh >= 0)
|
||||
{
|
||||
auto [start, count] = meshPrimRanges[node->mesh];
|
||||
const auto end = start + count;
|
||||
for (usize i = start; i != end; ++i)
|
||||
{
|
||||
meshPrimitives[i].m_TransformIdx = nodeArrayIndex;
|
||||
meshPrimitives[i].m_TransformIdx = Cast<i32>(nodeArrayIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -563,7 +561,7 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
auto *scene = &model.scenes[model.defaultScene];
|
||||
for (i32 rootNodeIdx : scene->nodes)
|
||||
{
|
||||
processNode(rootNodeIdx, 0);
|
||||
processNode(rootNodeIdx, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -662,6 +660,8 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
buffer.Destroy(pDevice);
|
||||
}
|
||||
|
||||
nodes.Update();
|
||||
|
||||
return Model{m_ResourceManager, std::move(textureHandles), std::move(nodes),
|
||||
materialsHandle, positionBufferHandle, normalBufferHandle,
|
||||
texCoord0BufferHandle, color0Handle, indexBuffer, meshPrimitives, nodeHandle};
|
||||
|
|
@ -711,24 +711,12 @@ Model::operator=(Model &&other) noexcept
|
|||
m_NormalHandle = other.m_NormalHandle;
|
||||
m_TexCoord0Handle = other.m_TexCoord0Handle;
|
||||
m_VertexColorHandle = other.m_VertexColorHandle;
|
||||
m_NodeHandle = other.m_NodeHandle;
|
||||
m_NodeHandle = std::move(other.m_NodeHandle);
|
||||
m_IndexBuffer = other.m_IndexBuffer;
|
||||
m_MeshPrimitives = std::move(other.m_MeshPrimitives);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const mat4 &
|
||||
Model::GetModelTransform() const
|
||||
{
|
||||
return m_Nodes[0];
|
||||
}
|
||||
|
||||
void
|
||||
Model::SetModelTransform(const mat4 &transform)
|
||||
{
|
||||
m_Nodes.Set(0, transform);
|
||||
}
|
||||
|
||||
Model::~Model()
|
||||
{
|
||||
if (!m_ResourceManager)
|
||||
|
|
@ -747,22 +735,12 @@ Model::~Model()
|
|||
m_ResourceManager->Release(m_MaterialsHandle);
|
||||
}
|
||||
|
||||
void
|
||||
Model::Update()
|
||||
{
|
||||
if (m_Nodes.Update())
|
||||
{
|
||||
m_ResourceManager->Write(m_NodeHandle, 0, m_Nodes.GetGlobalTransformByteSize(),
|
||||
m_Nodes.GetGlobalTransformPtr());
|
||||
}
|
||||
}
|
||||
|
||||
ModelLoader::ModelLoader(GpuResourceManager *resourceManager, vk::Queue transferQueue, u32 transferQueueIndex,
|
||||
u32 graphicsQueueIndex)
|
||||
: m_ResourceManager(resourceManager)
|
||||
, m_TransferQueue(transferQueue)
|
||||
, m_TransferQueueIndex(transferQueueIndex)
|
||||
, m_GraphicsQueueIndex(graphicsQueueIndex)
|
||||
, m_TransferQueue(transferQueue)
|
||||
, m_TransferQueueIndex(transferQueueIndex)
|
||||
, m_GraphicsQueueIndex(graphicsQueueIndex)
|
||||
{
|
||||
const Device *pDevice = resourceManager->m_Device;
|
||||
const vk::CommandPoolCreateInfo poolCreateInfo = {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "buffer.h"
|
||||
#include "global.h"
|
||||
#include "image.h"
|
||||
|
||||
#include "render_resource_manager.h"
|
||||
|
||||
|
|
@ -33,7 +34,6 @@ struct Nodes
|
|||
{
|
||||
eastl::vector<mat4> m_Transforms;
|
||||
eastl::vector<mat4> m_GlobalTransforms;
|
||||
/// Parents are also used for bookkeeping
|
||||
eastl::vector<u32> m_Parents_;
|
||||
bool m_Dirty = true;
|
||||
|
||||
|
|
@ -42,10 +42,10 @@ struct Nodes
|
|||
constexpr static u32 PARENT_MASK = ~(ROOT_BIT | DIRTY_BIT);
|
||||
|
||||
u32
|
||||
Add(const mat4& transform, const i32 parent = -1)
|
||||
Add(const mat4& transform, i32 parent = -1)
|
||||
{
|
||||
m_Dirty = true;
|
||||
const u32 index = Count();
|
||||
u32 index = Count();
|
||||
m_Transforms.push_back(transform);
|
||||
m_GlobalTransforms.push_back(transform);
|
||||
const u32 parentVal = (parent < 0 ? ROOT_BIT : parent & PARENT_MASK) | DIRTY_BIT;
|
||||
|
|
@ -91,20 +91,20 @@ struct Nodes
|
|||
[[nodiscard]] usize
|
||||
GetGlobalTransformByteSize() const
|
||||
{
|
||||
return m_GlobalTransforms.size() * sizeof m_GlobalTransforms[0];
|
||||
return m_Transforms.size() * sizeof m_Transforms[0];
|
||||
}
|
||||
|
||||
[[nodiscard]] const mat4 *
|
||||
GetGlobalTransformPtr() const
|
||||
{
|
||||
return m_GlobalTransforms.data();
|
||||
return m_Transforms.data();
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
Update()
|
||||
{
|
||||
if (!m_Dirty)
|
||||
return false;
|
||||
return;
|
||||
|
||||
auto transformIter = m_Transforms.begin();
|
||||
auto globalTransformIter = m_GlobalTransforms.begin();
|
||||
|
|
@ -113,41 +113,23 @@ struct Nodes
|
|||
|
||||
while (parentIter != parentEnd)
|
||||
{
|
||||
const bool isRoot = *parentIter & ROOT_BIT;
|
||||
const bool isDirty = *parentIter & DIRTY_BIT;
|
||||
|
||||
if (isRoot)
|
||||
if (!(*parentIter & ROOT_BIT) && *parentIter & DIRTY_BIT)
|
||||
{
|
||||
if (isDirty)
|
||||
{
|
||||
// Copy-update if the root is dirty.
|
||||
*globalTransformIter = *transformIter;
|
||||
}
|
||||
u32 parent = *parentIter & PARENT_MASK;
|
||||
*globalTransformIter = m_GlobalTransforms[parent] * *transformIter;
|
||||
}
|
||||
else
|
||||
{
|
||||
const u32 parentIdx = *parentIter & PARENT_MASK;
|
||||
const bool isParentDirty = m_Parents_[parentIdx] & DIRTY_BIT;
|
||||
if (isDirty || isParentDirty)
|
||||
{
|
||||
// Update w.r.t parent if either local or parent transforms updated.
|
||||
*globalTransformIter = m_GlobalTransforms[parentIdx] * *transformIter;
|
||||
m_Parents_[parentIdx] |= DIRTY_BIT; // Set dirty to propagate the update.
|
||||
}
|
||||
*globalTransformIter = *transformIter;
|
||||
}
|
||||
*parentIter &= ~DIRTY_BIT;
|
||||
|
||||
++parentIter;
|
||||
++globalTransformIter;
|
||||
++transformIter;
|
||||
}
|
||||
|
||||
for (u32 &parentValue : m_Parents_)
|
||||
{
|
||||
parentValue &= ~DIRTY_BIT; // Unset dirty.
|
||||
}
|
||||
|
||||
m_Dirty = false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -181,16 +163,13 @@ struct Model
|
|||
IndexBuffer m_IndexBuffer;
|
||||
eastl::vector<MeshPrimitive> m_MeshPrimitives;
|
||||
|
||||
[[nodiscard]] const mat4 &GetModelTransform() const;
|
||||
void SetModelTransform(const mat4 &transform);
|
||||
void Update();
|
||||
|
||||
Model(GpuResourceManager *resourceManager, eastl::vector<TextureHandle> &&textureHandles, Nodes&& nodes,
|
||||
BufferHandle materialsHandle, BufferHandle vertexPosHandle, BufferHandle normalHandle, BufferHandle uv0Handle, BufferHandle vertexColor,
|
||||
const IndexBuffer &indexBuffer, const eastl::vector<MeshPrimitive> &meshPrimitives, BufferHandle nodeHandle);
|
||||
|
||||
Model(Model &&other) noexcept;
|
||||
Model &operator=(Model &&other) noexcept;
|
||||
|
||||
~Model();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Model);
|
||||
|
|
|
|||
|
|
@ -236,9 +236,7 @@ main(int, char **)
|
|||
{
|
||||
Time::Update();
|
||||
|
||||
model.SetModelTransform(
|
||||
rotate(model.GetModelTransform(), Cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f)));
|
||||
model.Update();
|
||||
camera.m_Model *= rotate(mat4{1.0f}, Cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f));
|
||||
ubo.Write(&device, 0, sizeof camera, &camera);
|
||||
|
||||
Frame *currentFrame = frameManager.GetNextFrame(&swapchain, &window);
|
||||
|
|
|
|||
|
|
@ -215,12 +215,6 @@ GpuResourceManager::Commit(StorageBuffer *storageBuffer)
|
|||
return handle;
|
||||
}
|
||||
|
||||
void
|
||||
GpuResourceManager::Write(const BufferHandle handle, const usize offset, const usize size, const void *data)
|
||||
{
|
||||
m_BufferManager.Fetch(handle)->Write(m_Device, offset, size, data);
|
||||
}
|
||||
|
||||
void
|
||||
GpuResourceManager::EraseWrites(u32 handleIndex, HandleType handleType)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ public:
|
|||
vk::DescriptorSet m_DescriptorSet;
|
||||
|
||||
BufferHandle Commit(StorageBuffer *storageBuffer);
|
||||
void Write(BufferHandle handle, usize offset, usize size, const void *data);
|
||||
void Release(BufferHandle handle);
|
||||
TextureHandle Commit(Texture *texture);
|
||||
void Release(TextureHandle handle);
|
||||
|
|
|
|||
Loading…
Reference in New Issue