parent
870b18b1fa
commit
1302d26217
|
|
@ -57,26 +57,22 @@ Recast(TFrom &&in)
|
|||
return reinterpret_cast<TType>(std::forward<TFrom>(in));
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_deg(long double degrees)
|
||||
constexpr f32 operator""_deg(long double degrees)
|
||||
{
|
||||
return glm::radians<f32>(Cast<f32>(degrees));
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_deg(unsigned long long int degrees)
|
||||
constexpr f32 operator""_deg(unsigned long long int degrees)
|
||||
{
|
||||
return glm::radians<f32>(Cast<f32>(degrees));
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_rad(long double rads)
|
||||
constexpr f32 operator""_rad(long double rads)
|
||||
{
|
||||
return Cast<f32>(rads);
|
||||
}
|
||||
|
||||
constexpr f32
|
||||
operator""_rad(unsigned long long int rads)
|
||||
constexpr f32 operator""_rad(unsigned long long int rads)
|
||||
{
|
||||
return Cast<f32>(rads);
|
||||
}
|
||||
|
|
@ -84,10 +80,10 @@ operator""_rad(unsigned long long int rads)
|
|||
using glm::ivec2;
|
||||
using glm::ivec3;
|
||||
using glm::ivec4;
|
||||
using glm::quat;
|
||||
using glm::vec2;
|
||||
using glm::vec3;
|
||||
using glm::vec4;
|
||||
using glm::quat;
|
||||
|
||||
using glm::mat2;
|
||||
using glm::mat3;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
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 +26,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))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ TextureHandle
|
|||
TextureManager::Commit(Texture *texture)
|
||||
{
|
||||
ERROR_IF(!texture->IsValid() || !texture->IsOwned(), "Buffer must be valid and owned for commital")
|
||||
THEN_ABORT(-1);
|
||||
THEN_ABORT(-1);
|
||||
|
||||
if (m_FreeHead != GpuResourceHandle::INVALID_HANDLE)
|
||||
{
|
||||
|
|
@ -165,7 +165,7 @@ BufferManager::Release(const Device *device, const BufferHandle handle)
|
|||
void
|
||||
BufferManager::Destroy(const Device *device)
|
||||
{
|
||||
for (auto& buffer : m_Buffers)
|
||||
for (auto &buffer : m_Buffers)
|
||||
{
|
||||
buffer.Destroy(device);
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ GpuResourceManager::Release(TextureHandle handle)
|
|||
}
|
||||
|
||||
TextureHandle
|
||||
GpuResourceManager::Commit(Texture* texture)
|
||||
GpuResourceManager::Commit(Texture *texture)
|
||||
{
|
||||
TextureHandle handle = m_TextureManager.Commit(texture);
|
||||
|
||||
|
|
@ -338,7 +338,7 @@ GpuResourceManager::GpuResourceManager(const Device *device, u16 maxSize)
|
|||
.maxAnisotropy = properties.limits.maxSamplerAnisotropy,
|
||||
.compareEnable = false,
|
||||
.minLod = 0,
|
||||
.maxLod = vk::LodClampNone,
|
||||
.maxLod = VK_LOD_CLAMP_NONE,
|
||||
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
|
||||
.unnormalizedCoordinates = false,
|
||||
};
|
||||
|
|
@ -368,6 +368,18 @@ GpuResourceManager::GpuResourceManager(const Device *device, u16 maxSize)
|
|||
};
|
||||
AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool));
|
||||
|
||||
vk::DescriptorBindingFlags bindingFlags =
|
||||
vk::DescriptorBindingFlagBits::ePartiallyBound | vk::DescriptorBindingFlagBits::eUpdateAfterBind;
|
||||
eastl::array layoutBindingFlags = {
|
||||
bindingFlags,
|
||||
bindingFlags,
|
||||
};
|
||||
|
||||
vk::DescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsCreateInfo = {
|
||||
.bindingCount = Cast<u32>(layoutBindingFlags.size()),
|
||||
.pBindingFlags = layoutBindingFlags.data(),
|
||||
};
|
||||
|
||||
eastl::vector immutableSamplers(texturesCount, m_ImmutableSampler);
|
||||
eastl::array descriptorLayoutBindings = {
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
|
|
@ -384,7 +396,9 @@ GpuResourceManager::GpuResourceManager(const Device *device, u16 maxSize)
|
|||
.pImmutableSamplers = immutableSamplers.data(),
|
||||
},
|
||||
};
|
||||
static_assert(layoutBindingFlags.size() == descriptorLayoutBindings.size());
|
||||
const vk::DescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = {
|
||||
.pNext = &bindingFlagsCreateInfo,
|
||||
.flags = vk::DescriptorSetLayoutCreateFlagBits::eUpdateAfterBindPool,
|
||||
.bindingCount = Cast<u32>(descriptorLayoutBindings.size()),
|
||||
.pBindings = descriptorLayoutBindings.data(),
|
||||
|
|
@ -420,18 +434,18 @@ GpuResourceManager::~GpuResourceManager()
|
|||
}
|
||||
|
||||
GpuResourceManager::GpuResourceManager(GpuResourceManager &&other) noexcept
|
||||
: m_WriteInfos(std::move(other.m_WriteInfos)),
|
||||
m_Writes(std::move(other.m_Writes)),
|
||||
m_WriteOwner(std::move(other.m_WriteOwner)),
|
||||
m_ImmutableSampler(other.m_ImmutableSampler),
|
||||
m_BufferManager(std::move(other.m_BufferManager)),
|
||||
m_TextureManager(std::move(other.m_TextureManager)),
|
||||
m_Device(Take(other.m_Device)),
|
||||
m_DescriptorPool(other.m_DescriptorPool),
|
||||
m_SetLayout(other.m_SetLayout),
|
||||
m_DescriptorSet(other.m_DescriptorSet),
|
||||
m_CommitedBufferCount(other.m_CommitedBufferCount),
|
||||
m_CommitedTextureCount(other.m_CommitedTextureCount)
|
||||
: m_WriteInfos(std::move(other.m_WriteInfos))
|
||||
, m_Writes(std::move(other.m_Writes))
|
||||
, m_WriteOwner(std::move(other.m_WriteOwner))
|
||||
, m_ImmutableSampler(other.m_ImmutableSampler)
|
||||
, m_BufferManager(std::move(other.m_BufferManager))
|
||||
, m_TextureManager(std::move(other.m_TextureManager))
|
||||
, m_Device(Take(other.m_Device))
|
||||
, m_DescriptorPool(other.m_DescriptorPool)
|
||||
, m_SetLayout(other.m_SetLayout)
|
||||
, m_DescriptorSet(other.m_DescriptorSet)
|
||||
, m_CommitedBufferCount(other.m_CommitedBufferCount)
|
||||
, m_CommitedTextureCount(other.m_CommitedTextureCount)
|
||||
{
|
||||
assert(!other.m_Device);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,7 @@ struct TextureManager
|
|||
u32 m_MaxCapacity;
|
||||
u32 m_FreeHead;
|
||||
|
||||
void
|
||||
Init(u32 maxCapacity);
|
||||
void Init(u32 maxCapacity);
|
||||
TextureHandle Commit(Texture *texture);
|
||||
Texture *Fetch(TextureHandle handle);
|
||||
void Release(const Device *device, TextureHandle handle);
|
||||
|
|
@ -63,9 +62,8 @@ struct BufferManager
|
|||
|
||||
struct GpuResourceManager
|
||||
{
|
||||
private:
|
||||
union WriteInfo
|
||||
{
|
||||
private:
|
||||
union WriteInfo {
|
||||
vk::DescriptorBufferInfo uBufferInfo;
|
||||
vk::DescriptorImageInfo uImageInfo;
|
||||
vk::BufferView uBufferView;
|
||||
|
|
@ -98,7 +96,7 @@ private:
|
|||
|
||||
void EraseWrites(u32 handleIndex, HandleType handleType);
|
||||
|
||||
public:
|
||||
public:
|
||||
const Device *m_Device;
|
||||
|
||||
constexpr static u32 BUFFER_BINDING_INDEX = 0;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ struct Light
|
|||
vec3 um_Position;
|
||||
vec3 um_Direction;
|
||||
};
|
||||
f32 m_Range; // < 0.0 for invalid
|
||||
u32 m_Color_; // LSB is used for flags. (R G B Flags)
|
||||
f32 m_Range; // < 0.0 for invalid
|
||||
u32 m_Color_; // LSB is used for flags. (R G B Flags)
|
||||
f32 m_Intensity;
|
||||
|
||||
constexpr static u32 MAX_GEN = 0x40;
|
||||
|
|
@ -150,7 +150,7 @@ LightManager::AddDirectional(const vec3 &direction, const vec3 &color)
|
|||
m_Lights.push_back();
|
||||
m_Lights.push_back();
|
||||
|
||||
if (m_MetaInfo.m_PointLightMaxCount > 0) // Edge Case: nullptr at size 0
|
||||
if (m_MetaInfo.m_PointLightMaxCount > 0) // Edge Case: nullptr at size 0
|
||||
{
|
||||
Light *oldPointStart = m_Lights.data() + oldPointLightOffset;
|
||||
Light *newPointStart = oldPointStart + 2;
|
||||
|
|
@ -175,7 +175,7 @@ LightManager::AddDirectional(const vec3 &direction, const vec3 &color)
|
|||
}
|
||||
|
||||
LightHandle
|
||||
LightManager::AddPoint(const vec3 & position, const vec3 &color, const f32 radius)
|
||||
LightManager::AddPoint(const vec3 &position, const vec3 &color, const f32 radius)
|
||||
{
|
||||
assert(m_PointLightCount <= m_MetaInfo.m_PointLightMaxCount);
|
||||
assert(radius >= 0.0f);
|
||||
|
|
@ -206,7 +206,7 @@ LightManager::AddPoint(const vec3 & position, const vec3 &color, const f32 radiu
|
|||
const u16 index = m_PointLightCount;
|
||||
|
||||
Light *light = &m_Lights[index + m_MetaInfo.m_PointLightOffset];
|
||||
constexpr u8 gen = 0; // New light
|
||||
constexpr u8 gen = 0; // New light
|
||||
|
||||
light->m_Color_ = (ToColor32(color) & Light::COLOR_MASK) | Light::TYPE_POINT | gen;
|
||||
light->m_Range = radius;
|
||||
|
|
@ -244,7 +244,6 @@ LightManager::RemoveLight(const LightHandle handle)
|
|||
{
|
||||
const u8 handleGen = handle.m_Generation;
|
||||
|
||||
|
||||
if (handle.m_Type == Light::TYPE_DIRECTIONAL)
|
||||
{
|
||||
Light *lightSlot = &m_Lights[handle.m_Index];
|
||||
|
|
|
|||
|
|
@ -44,11 +44,11 @@ struct LightManager
|
|||
// We can use that with Offset = 0, and point light at further offsets.
|
||||
// This way we don't need to move point lights often.
|
||||
|
||||
BufferHandle m_LightBuffer; // 04 04
|
||||
u16 m_PointLightMaxCount; // 02 06
|
||||
u16 m_PointLightOffset; // 02 08
|
||||
u16 m_DirectionalLightMaxCount; // 02 10
|
||||
u16 m_UnusedPadding0 = 0; // 02 12
|
||||
BufferHandle m_LightBuffer; // 04 04
|
||||
u16 m_PointLightMaxCount; // 02 06
|
||||
u16 m_PointLightOffset; // 02 08
|
||||
u16 m_DirectionalLightMaxCount; // 02 10
|
||||
u16 m_UnusedPadding0 = 0; // 02 12
|
||||
};
|
||||
|
||||
GpuResourceManager *m_ResourceManager;
|
||||
|
|
@ -69,7 +69,7 @@ struct LightManager
|
|||
constexpr static u16 CAPACITY_MASK = ~(UPDATE_REQUIRED_BIT);
|
||||
|
||||
LightHandle AddDirectional(const vec3 &direction, const vec3 &color);
|
||||
LightHandle AddPoint(const vec3& position, const vec3 &color, f32 radius);
|
||||
LightHandle AddPoint(const vec3 &position, const vec3 &color, f32 radius);
|
||||
void Update();
|
||||
void RemoveLight(LightHandle handle);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
#include "buffer.h"
|
||||
#include "device.h"
|
||||
#include "gpu_resource_manager.h"
|
||||
#include "helpers.h"
|
||||
#include "image.h"
|
||||
#include "gpu_resource_manager.h"
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <EASTL/array.h>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
vec4
|
||||
VectorToVec4(const std::vector<double> &vec)
|
||||
|
|
@ -46,8 +46,7 @@ VectorToVec3(const std::vector<double> &vec)
|
|||
}
|
||||
|
||||
TextureHandle
|
||||
ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer,
|
||||
tinygltf::Image *image) const
|
||||
ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer, tinygltf::Image *image) const
|
||||
{
|
||||
assert(image->component == 4);
|
||||
|
||||
|
|
@ -64,17 +63,17 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu
|
|||
.dstAccessMask = vk::AccessFlagBits::eTransferWrite,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eTransferDstOptimal,
|
||||
.srcQueueFamilyIndex = vk::QueueFamilyIgnored,
|
||||
.dstQueueFamilyIndex = vk::QueueFamilyIgnored,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = texture.m_Image,
|
||||
.subresourceRange =
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = texture.GetMipLevels(),
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = texture.GetMipLevels(),
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
vk::ImageMemoryBarrier nextMipBarrier = {
|
||||
|
|
@ -82,17 +81,17 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu
|
|||
.dstAccessMask = vk::AccessFlagBits::eTransferRead,
|
||||
.oldLayout = vk::ImageLayout::eTransferDstOptimal,
|
||||
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
|
||||
.srcQueueFamilyIndex = vk::QueueFamilyIgnored,
|
||||
.dstQueueFamilyIndex = vk::QueueFamilyIgnored,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = texture.m_Image,
|
||||
.subresourceRange =
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
vk::ImageMemoryBarrier imageReadyBarrier = {
|
||||
|
|
@ -104,13 +103,13 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu
|
|||
.dstQueueFamilyIndex = m_GraphicsQueueIndex,
|
||||
.image = texture.m_Image,
|
||||
.subresourceRange =
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = texture.GetMipLevels(),
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = texture.GetMipLevels(),
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
vk::BufferImageCopy imageCopy = {
|
||||
|
|
@ -118,12 +117,12 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu
|
|||
.bufferRowLength = Cast<u32>(image->width),
|
||||
.bufferImageHeight = Cast<u32>(image->height),
|
||||
.imageSubresource =
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.mipLevel = 0,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.mipLevel = 0,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.imageOffset = {},
|
||||
.imageExtent = texture.m_Extent,
|
||||
};
|
||||
|
|
@ -135,9 +134,7 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu
|
|||
commandBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, 0,
|
||||
nullptr, 0, nullptr, 1, &nextMipBarrier);
|
||||
|
||||
auto calcNextMip = [](i32 prev) {
|
||||
return eastl::max(prev / 2, 1);
|
||||
};
|
||||
auto calcNextMip = [](i32 prev) { return eastl::max(prev / 2, 1); };
|
||||
|
||||
i32 prevMipWidth = Cast<i32>(texture.m_Extent.width);
|
||||
i32 prevMipHeight = Cast<i32>(texture.m_Extent.height);
|
||||
|
|
@ -151,27 +148,29 @@ ModelLoader::LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBu
|
|||
|
||||
vk::ImageBlit blitRegion = {
|
||||
.srcSubresource =
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.mipLevel = prevMipLevel,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.srcOffsets = std::array{
|
||||
vk::Offset3D{0, 0, 0},
|
||||
vk::Offset3D{prevMipWidth, prevMipHeight, 1},
|
||||
},
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.mipLevel = prevMipLevel,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.srcOffsets =
|
||||
std::array{
|
||||
vk::Offset3D{0, 0, 0},
|
||||
vk::Offset3D{prevMipWidth, prevMipHeight, 1},
|
||||
},
|
||||
.dstSubresource =
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.mipLevel = currentMipLevel,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.dstOffsets = std::array{
|
||||
vk::Offset3D{0, 0, 0},
|
||||
vk::Offset3D{currentMipWidth, currentMipHeight, 1},
|
||||
},
|
||||
{
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.mipLevel = currentMipLevel,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.dstOffsets =
|
||||
std::array{
|
||||
vk::Offset3D{0, 0, 0},
|
||||
vk::Offset3D{currentMipWidth, currentMipHeight, 1},
|
||||
},
|
||||
};
|
||||
|
||||
nextMipBarrier.subresourceRange.baseMipLevel = currentMipLevel;
|
||||
|
|
@ -407,7 +406,7 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
usize byteOffset = (uvAccessor->byteOffset + uvBufferView->byteOffset);
|
||||
|
||||
assert(uvAccessor->type == TINYGLTF_TYPE_VEC2 &&
|
||||
uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT);
|
||||
uvAccessor->componentType == TINYGLTF_COMPONENT_TYPE_FLOAT);
|
||||
{
|
||||
vec2 *data = Recast<vec2 *>(uvBuffer->data.data() + byteOffset);
|
||||
vec2 *end = data + vertexCount;
|
||||
|
|
@ -513,7 +512,8 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
{
|
||||
if (model.defaultScene >= 0)
|
||||
{
|
||||
eastl::function<void(i32,i32)> processNode = [&processNode, &model, &nodes, &meshPrimRanges, &meshPrimitives](i32 idx, i32 parent) -> void {
|
||||
eastl::function<void(i32, i32)> processNode = [&processNode, &model, &nodes, &meshPrimRanges,
|
||||
&meshPrimitives](i32 idx, i32 parent) -> void {
|
||||
const auto *node = &model.nodes[idx];
|
||||
|
||||
vec3 nodeTranslation = vec3{0.0f};
|
||||
|
|
@ -537,8 +537,8 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
{
|
||||
nodeMatrix = glm::make_mat4(node->matrix.data());
|
||||
}
|
||||
const mat4 transform =
|
||||
translate(mat4(1.0f), nodeTranslation) * mat4_cast(nodeRotation) * scale(mat4(1.0f), nodeScale) * nodeMatrix;
|
||||
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));
|
||||
if (node->mesh >= 0)
|
||||
|
|
@ -633,12 +633,14 @@ ModelLoader::LoadModel(cstr path, cstr name, bool batched)
|
|||
.m_NodeHandle = nodeHandle,
|
||||
};
|
||||
|
||||
return Model{m_ResourceManager, std::move(textureHandles), std::move(nodes),
|
||||
handles, indexBuffer, meshPrimitives, };
|
||||
return Model{
|
||||
m_ResourceManager, std::move(textureHandles), std::move(nodes), handles, indexBuffer, meshPrimitives,
|
||||
};
|
||||
}
|
||||
|
||||
Model::Model(GpuResourceManager *resourceManager, eastl::vector<TextureHandle> &&textureHandles, Nodes &&nodes,
|
||||
const ModelHandles &handles, const IndexBuffer &indexBuffer, const eastl::vector<MeshPrimitive> &meshPrimitives)
|
||||
const ModelHandles &handles, const IndexBuffer &indexBuffer,
|
||||
const eastl::vector<MeshPrimitive> &meshPrimitives)
|
||||
: m_ResourceManager(resourceManager)
|
||||
, m_TextureHandles(std::move(textureHandles))
|
||||
, m_Nodes(std::move(nodes))
|
||||
|
|
@ -741,12 +743,13 @@ ModelLoader::~ModelLoader()
|
|||
}
|
||||
}
|
||||
|
||||
ModelLoader::ModelLoader(ModelLoader &&other) noexcept: m_ResourceManager(Take(other.m_ResourceManager)),
|
||||
m_CommandPool(other.m_CommandPool),
|
||||
m_CommandBuffer(other.m_CommandBuffer),
|
||||
m_TransferQueue(other.m_TransferQueue),
|
||||
m_TransferQueueIndex(other.m_TransferQueueIndex),
|
||||
m_GraphicsQueueIndex(other.m_GraphicsQueueIndex)
|
||||
ModelLoader::ModelLoader(ModelLoader &&other) noexcept
|
||||
: m_ResourceManager(Take(other.m_ResourceManager))
|
||||
, m_CommandPool(other.m_CommandPool)
|
||||
, m_CommandBuffer(other.m_CommandBuffer)
|
||||
, m_TransferQueue(other.m_TransferQueue)
|
||||
, m_TransferQueueIndex(other.m_TransferQueueIndex)
|
||||
, m_GraphicsQueueIndex(other.m_GraphicsQueueIndex)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ struct MeshPrimitive
|
|||
|
||||
struct Material
|
||||
{
|
||||
vec4 m_AlbedoFactor; // 16 16
|
||||
vec3 m_EmissionFactor; // 12 28
|
||||
f32 m_MetalFactor; // 04 32
|
||||
f32 m_RoughFactor; // 04 36
|
||||
TextureHandle m_AlbedoTex; // 04 40
|
||||
TextureHandle m_NormalTex; // 04 44
|
||||
TextureHandle m_MetalRoughTex; // 04 48
|
||||
TextureHandle m_OcclusionTex; // 04 52
|
||||
TextureHandle m_EmissionTex; // 04 56
|
||||
vec4 m_AlbedoFactor; // 16 16
|
||||
vec3 m_EmissionFactor; // 12 28
|
||||
f32 m_MetalFactor; // 04 32
|
||||
f32 m_RoughFactor; // 04 36
|
||||
TextureHandle m_AlbedoTex; // 04 40
|
||||
TextureHandle m_NormalTex; // 04 44
|
||||
TextureHandle m_MetalRoughTex; // 04 48
|
||||
TextureHandle m_OcclusionTex; // 04 52
|
||||
TextureHandle m_EmissionTex; // 04 56
|
||||
};
|
||||
|
||||
struct VertexData
|
||||
|
|
@ -72,7 +72,8 @@ struct Model
|
|||
void Update();
|
||||
|
||||
Model(GpuResourceManager *resourceManager, eastl::vector<TextureHandle> &&textureHandles, Nodes &&nodes,
|
||||
const ModelHandles& handles, const IndexBuffer &indexBuffer, const eastl::vector<MeshPrimitive> &meshPrimitives);
|
||||
const ModelHandles &handles, const IndexBuffer &indexBuffer,
|
||||
const eastl::vector<MeshPrimitive> &meshPrimitives);
|
||||
~Model();
|
||||
|
||||
Model(Model &&other) noexcept;
|
||||
|
|
@ -91,8 +92,8 @@ struct ModelLoader
|
|||
u32 m_TransferQueueIndex;
|
||||
u32 m_GraphicsQueueIndex;
|
||||
|
||||
TextureHandle LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer,
|
||||
tinygltf::Image *image) const;
|
||||
TextureHandle
|
||||
LoadImage(vk::CommandBuffer commandBuffer, StagingBuffer *stagingBuffer, tinygltf::Image *image) const;
|
||||
Model LoadModel(cstr path, cstr name = nullptr, bool batched = false);
|
||||
|
||||
constexpr static auto ANormal = "NORMAL";
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
#include "helpers.h"
|
||||
#include "light_manager.h"
|
||||
|
||||
#include "gpu_resource_manager.h"
|
||||
#include "model_loader.h"
|
||||
#include "pipeline_utils.h"
|
||||
#include "gpu_resource_manager.h"
|
||||
|
||||
#include <EASTL/array.h>
|
||||
#include <stb_image.h>
|
||||
|
|
@ -53,18 +53,18 @@ main(int, char **)
|
|||
Features enabledDeviceFeatures = {
|
||||
.m_Vulkan10Features = {.samplerAnisotropy = true},
|
||||
.m_Vulkan12Features =
|
||||
{
|
||||
.descriptorIndexing = true,
|
||||
.shaderSampledImageArrayNonUniformIndexing = true,
|
||||
.shaderStorageBufferArrayNonUniformIndexing = true,
|
||||
.shaderStorageImageArrayNonUniformIndexing = true,
|
||||
.descriptorBindingUniformBufferUpdateAfterBind = true, // Not related to Bindless
|
||||
.descriptorBindingSampledImageUpdateAfterBind = true,
|
||||
.descriptorBindingStorageImageUpdateAfterBind = true,
|
||||
.descriptorBindingStorageBufferUpdateAfterBind = true,
|
||||
.descriptorBindingPartiallyBound = true,
|
||||
.runtimeDescriptorArray = true,
|
||||
},
|
||||
{
|
||||
.descriptorIndexing = true,
|
||||
.shaderSampledImageArrayNonUniformIndexing = true,
|
||||
.shaderStorageBufferArrayNonUniformIndexing = true,
|
||||
.shaderStorageImageArrayNonUniformIndexing = true,
|
||||
.descriptorBindingUniformBufferUpdateAfterBind = true, // Not related to Bindless
|
||||
.descriptorBindingSampledImageUpdateAfterBind = true,
|
||||
.descriptorBindingStorageImageUpdateAfterBind = true,
|
||||
.descriptorBindingStorageBufferUpdateAfterBind = true,
|
||||
.descriptorBindingPartiallyBound = true,
|
||||
.runtimeDescriptorArray = true,
|
||||
},
|
||||
.m_Vulkan13Features = {.dynamicRendering = true},
|
||||
};
|
||||
|
||||
|
|
@ -285,11 +285,11 @@ main(int, char **)
|
|||
|
||||
for (auto &prim : model.m_MeshPrimitives)
|
||||
{
|
||||
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset,
|
||||
sizeof prim.m_MaterialIdx, &prim.m_MaterialIdx);
|
||||
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset, sizeof prim.m_MaterialIdx,
|
||||
&prim.m_MaterialIdx);
|
||||
pcbOffset += sizeof prim.m_MaterialIdx;
|
||||
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset,
|
||||
sizeof prim.m_TransformIdx, &prim.m_TransformIdx);
|
||||
cmd.pushConstants(pipeline.m_Layout, vk::ShaderStageFlagBits::eAll, pcbOffset, sizeof prim.m_TransformIdx,
|
||||
&prim.m_TransformIdx);
|
||||
pcbOffset += sizeof prim.m_TransformIdx;
|
||||
cmd.drawIndexed(prim.m_IndexCount, 1, prim.m_FirstIndex, Cast<i32>(prim.m_VertexOffset), 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#include "pipeline_utils.h"
|
||||
|
||||
#include "device.h"
|
||||
#include "helpers.h"
|
||||
#include "gpu_resource_manager.h"
|
||||
#include "helpers.h"
|
||||
#include "swapchain.h"
|
||||
|
||||
#include <EASTL/array.h>
|
||||
|
|
|
|||
Loading…
Reference in New Issue