[WIP] Box moved to 'new API' pending fixes.
This commit is contained in:
parent
63282c3587
commit
3a7a2b4ab7
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
namespace systems
|
namespace systems
|
||||||
{
|
{
|
||||||
|
class Device;
|
||||||
|
|
||||||
class CommitManager
|
class CommitManager
|
||||||
{
|
{
|
||||||
|
|
@ -286,6 +287,11 @@ class CommitManager
|
||||||
return *m_Instance;
|
return *m_Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsInit()
|
||||||
|
{
|
||||||
|
return static_cast<bool>(m_Instance);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vk::DescriptorPool m_DescriptorPool;
|
vk::DescriptorPool m_DescriptorPool;
|
||||||
vk::DescriptorSetLayout m_SetLayout;
|
vk::DescriptorSetLayout m_SetLayout;
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@
|
||||||
#include "aster/core/size.h"
|
#include "aster/core/size.h"
|
||||||
#include "aster/core/swapchain.h"
|
#include "aster/core/swapchain.h"
|
||||||
|
|
||||||
|
#include "EASTL/deque.h"
|
||||||
#include <EASTL/hash_map.h>
|
#include <EASTL/hash_map.h>
|
||||||
#include <EASTL/optional.h>
|
#include <EASTL/optional.h>
|
||||||
#include "EASTL/deque.h"
|
|
||||||
|
|
||||||
#include <slang-com-ptr.h>
|
#include <slang-com-ptr.h>
|
||||||
#include <slang.h>
|
#include <slang.h>
|
||||||
|
|
@ -371,6 +371,7 @@ struct DeviceCreateInfo
|
||||||
PhysicalDeviceSelectorFn m_PhysicalDeviceSelector = DefaultPhysicalDeviceSelector;
|
PhysicalDeviceSelectorFn m_PhysicalDeviceSelector = DefaultPhysicalDeviceSelector;
|
||||||
std::span<u8> m_PipelineCacheData = {};
|
std::span<u8> m_PipelineCacheData = {};
|
||||||
eastl::vector<cstr> m_ShaderSearchPaths;
|
eastl::vector<cstr> m_ShaderSearchPaths;
|
||||||
|
bool m_UseBindless = true;
|
||||||
cstr m_Name = "Primary";
|
cstr m_Name = "Primary";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -401,7 +402,7 @@ struct Frame;
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
vk::CommandBuffer m_Cmd;
|
vk::CommandBuffer m_Cmd;
|
||||||
|
|
||||||
friend Device;
|
friend Device;
|
||||||
|
|
@ -505,6 +506,14 @@ struct Frame
|
||||||
GraphicsContext CreateGraphicsContext();
|
GraphicsContext CreateGraphicsContext();
|
||||||
TransferContext CreateTransferContext();
|
TransferContext CreateTransferContext();
|
||||||
void WaitUntilReady();
|
void WaitUntilReady();
|
||||||
|
|
||||||
|
Frame() = default;
|
||||||
|
Frame(Device &device, u32 primaryQueueFamily, u32 frameIndex);
|
||||||
|
Frame(Frame &&other) noexcept;
|
||||||
|
|
||||||
|
Frame &operator=(Frame &&other) noexcept;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(Frame);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Device final
|
class Device final
|
||||||
|
|
@ -515,6 +524,7 @@ class Device final
|
||||||
Surface m_Surface;
|
Surface m_Surface;
|
||||||
::Device m_Device;
|
::Device m_Device;
|
||||||
Swapchain m_Swapchain;
|
Swapchain m_Swapchain;
|
||||||
|
std::unique_ptr<CommitManager> m_CommitManager;
|
||||||
|
|
||||||
// TODO: This is single-threaded.
|
// TODO: This is single-threaded.
|
||||||
vk::Queue m_GraphicsQueue;
|
vk::Queue m_GraphicsQueue;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "EASTL/array.h"
|
#include "EASTL/array.h"
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
#include "core/image_view.h"
|
#include "core/image_view.h"
|
||||||
|
#include "systems/device.h"
|
||||||
|
|
||||||
using namespace systems;
|
using namespace systems;
|
||||||
|
|
||||||
|
|
@ -44,7 +45,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
|
||||||
.poolSizeCount = static_cast<u32>(poolSizes.size()),
|
.poolSizeCount = static_cast<u32>(poolSizes.size()),
|
||||||
.pPoolSizes = poolSizes.data(),
|
.pPoolSizes = poolSizes.data(),
|
||||||
};
|
};
|
||||||
AbortIfFailed(device->m_Device.createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool));
|
AbortIfFailed(device->m_Device->createDescriptorPool(&poolCreateInfo, nullptr, &m_DescriptorPool));
|
||||||
|
|
||||||
eastl::array descriptorLayoutBindings = {
|
eastl::array descriptorLayoutBindings = {
|
||||||
vk::DescriptorSetLayoutBinding{
|
vk::DescriptorSetLayoutBinding{
|
||||||
|
|
@ -85,7 +86,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
|
||||||
.bindingCount = static_cast<u32>(descriptorLayoutBindings.size()),
|
.bindingCount = static_cast<u32>(descriptorLayoutBindings.size()),
|
||||||
.pBindings = descriptorLayoutBindings.data(),
|
.pBindings = descriptorLayoutBindings.data(),
|
||||||
};
|
};
|
||||||
AbortIfFailed(device->m_Device.createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout));
|
AbortIfFailed(device->m_Device->createDescriptorSetLayout(&descriptorSetLayoutCreateInfo, nullptr, &m_SetLayout));
|
||||||
|
|
||||||
// One descriptor is enough. Updating it at any time is safe. (Update until submit, data held when pending)
|
// One descriptor is enough. Updating it at any time is safe. (Update until submit, data held when pending)
|
||||||
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_descriptor_indexing.html
|
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_descriptor_indexing.html
|
||||||
|
|
@ -95,7 +96,7 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
|
||||||
.descriptorSetCount = 1,
|
.descriptorSetCount = 1,
|
||||||
.pSetLayouts = &m_SetLayout,
|
.pSetLayouts = &m_SetLayout,
|
||||||
};
|
};
|
||||||
AbortIfFailed(device->m_Device.allocateDescriptorSets(&descriptorSetAllocateInfo, &m_DescriptorSet));
|
AbortIfFailed(device->m_Device->allocateDescriptorSets(&descriptorSetAllocateInfo, &m_DescriptorSet));
|
||||||
|
|
||||||
device->SetName(m_SetLayout, "Bindless Layout");
|
device->SetName(m_SetLayout, "Bindless Layout");
|
||||||
device->SetName(m_DescriptorPool, "Bindless Pool");
|
device->SetName(m_DescriptorPool, "Bindless Pool");
|
||||||
|
|
@ -106,8 +107,8 @@ CommitManager::CommitManager(const Device *device, const u32 maxBuffers, const u
|
||||||
|
|
||||||
CommitManager::~CommitManager()
|
CommitManager::~CommitManager()
|
||||||
{
|
{
|
||||||
m_Device->m_Device.destroy(m_SetLayout, nullptr);
|
m_Device->m_Device->destroy(m_SetLayout, nullptr);
|
||||||
m_Device->m_Device.destroy(m_DescriptorPool, nullptr);
|
m_Device->m_Device->destroy(m_DescriptorPool, nullptr);
|
||||||
|
|
||||||
#if !defined(ASTER_NDEBUG)
|
#if !defined(ASTER_NDEBUG)
|
||||||
u32 bufferCount = 0;
|
u32 bufferCount = 0;
|
||||||
|
|
@ -227,7 +228,7 @@ CommitManager::Update()
|
||||||
// Descriptor Updates
|
// Descriptor Updates
|
||||||
if (!m_Writes.empty())
|
if (!m_Writes.empty())
|
||||||
{
|
{
|
||||||
m_Device->m_Device.updateDescriptorSets(static_cast<u32>(m_Writes.size()), m_Writes.data(), 0, nullptr);
|
m_Device->m_Device->updateDescriptorSets(static_cast<u32>(m_Writes.size()), m_Writes.data(), 0, nullptr);
|
||||||
|
|
||||||
m_Writes.clear();
|
m_Writes.clear();
|
||||||
m_WriteInfos.clear();
|
m_WriteInfos.clear();
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "aster/systems/sync_server.h"
|
#include "aster/systems/sync_server.h"
|
||||||
#include "aster/util/files.h"
|
#include "aster/util/files.h"
|
||||||
|
#include "systems/commit_manager.h"
|
||||||
|
|
||||||
#include <EASTL/vector_map.h>
|
#include <EASTL/vector_map.h>
|
||||||
#include <fmt/ranges.h>
|
#include <fmt/ranges.h>
|
||||||
|
|
@ -615,8 +616,9 @@ systems::Device::CreatePipeline(Pipeline &pipelineOut, const GraphicsPipelineCre
|
||||||
.sampleShadingEnable = false,
|
.sampleShadingEnable = false,
|
||||||
};
|
};
|
||||||
vk::PipelineDepthStencilStateCreateInfo depthStencilStateCreateInfo = {
|
vk::PipelineDepthStencilStateCreateInfo depthStencilStateCreateInfo = {
|
||||||
.depthTestEnable = false,
|
.depthTestEnable = true,
|
||||||
.depthWriteEnable = false,
|
.depthWriteEnable = true,
|
||||||
|
.depthCompareOp = vk::CompareOp::eLess,
|
||||||
};
|
};
|
||||||
vk::PipelineColorBlendAttachmentState colorBlendAttachmentState = {
|
vk::PipelineColorBlendAttachmentState colorBlendAttachmentState = {
|
||||||
.blendEnable = false,
|
.blendEnable = false,
|
||||||
|
|
@ -919,11 +921,29 @@ systems::Device::CreatePipelineLayout(vk::PipelineLayout &pipelineLayout,
|
||||||
|
|
||||||
// TODO: Reflect to create the push constants and descriptor sets.
|
// TODO: Reflect to create the push constants and descriptor sets.
|
||||||
|
|
||||||
|
// TODO: Hackery. To FIX.
|
||||||
|
vk::PushConstantRange pcr{
|
||||||
|
.stageFlags = vk::ShaderStageFlagBits::eAllGraphics,
|
||||||
|
.offset = 0,
|
||||||
|
.size = 24,
|
||||||
|
};
|
||||||
|
|
||||||
|
u32 setLayoutCount = 0;
|
||||||
|
const vk::DescriptorSetLayout *setLayout = nullptr;
|
||||||
|
|
||||||
|
if (m_CommitManager)
|
||||||
|
{
|
||||||
|
setLayoutCount = 1;
|
||||||
|
setLayout = &m_CommitManager->GetDescriptorSetLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: END EXPERIMENT
|
||||||
|
|
||||||
const vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = {
|
const vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo = {
|
||||||
.setLayoutCount = 0,
|
.setLayoutCount = setLayoutCount,
|
||||||
.pSetLayouts = nullptr,
|
.pSetLayouts = setLayout,
|
||||||
.pushConstantRangeCount = 0,
|
.pushConstantRangeCount = 1,
|
||||||
.pPushConstantRanges = nullptr,
|
.pPushConstantRanges = &pcr,
|
||||||
};
|
};
|
||||||
vk::Result result = m_Device->createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &pipelineLayout);
|
vk::Result result = m_Device->createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &pipelineLayout);
|
||||||
if (Failed(result))
|
if (Failed(result))
|
||||||
|
|
@ -1043,6 +1063,11 @@ systems::Device::Device(const DeviceCreateInfo &createInfo)
|
||||||
|
|
||||||
m_Swapchain = Swapchain{m_Surface, m_Device, m_Window.get().GetSize()};
|
m_Swapchain = Swapchain{m_Surface, m_Device, m_Window.get().GetSize()};
|
||||||
|
|
||||||
|
if (createInfo.m_UseBindless)
|
||||||
|
{
|
||||||
|
m_CommitManager = std::make_unique<CommitManager>(this, 1000, 1000, 1000, CreateSampler({}));
|
||||||
|
}
|
||||||
|
|
||||||
const vk::CommandPoolCreateInfo transferPoolCreateInfo = {
|
const vk::CommandPoolCreateInfo transferPoolCreateInfo = {
|
||||||
.flags = vk::CommandPoolCreateFlagBits::eTransient | vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
.flags = vk::CommandPoolCreateFlagBits::eTransient | vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
||||||
.queueFamilyIndex = m_TransferQueueFamily,
|
.queueFamilyIndex = m_TransferQueueFamily,
|
||||||
|
|
@ -1057,11 +1082,24 @@ systems::Device::Device(const DeviceCreateInfo &createInfo)
|
||||||
.name = slang::CompilerOptionName::VulkanUseEntryPointName,
|
.name = slang::CompilerOptionName::VulkanUseEntryPointName,
|
||||||
.value = slang::CompilerOptionValue{.kind = slang::CompilerOptionValueKind::Int, .intValue0 = 1},
|
.value = slang::CompilerOptionValue{.kind = slang::CompilerOptionValueKind::Int, .intValue0 = 1},
|
||||||
};
|
};
|
||||||
|
slang::CompilerOptionEntry bindlessSpaceIndex = {
|
||||||
|
.name = slang::CompilerOptionName::BindlessSpaceIndex,
|
||||||
|
.value = slang::CompilerOptionValue{.kind = slang::CompilerOptionValueKind::Int, .intValue0 = 100},
|
||||||
|
};
|
||||||
|
slang::CompilerOptionEntry scalarLayout = {
|
||||||
|
.name = slang::CompilerOptionName::GLSLForceScalarLayout,
|
||||||
|
.value = slang::CompilerOptionValue{.kind = slang::CompilerOptionValueKind::Int, .intValue0 = 1},
|
||||||
|
};
|
||||||
|
std::array compilerOptions = {
|
||||||
|
useOriginalEntrypointNames,
|
||||||
|
bindlessSpaceIndex,
|
||||||
|
};
|
||||||
|
|
||||||
const slang::TargetDesc spirvTargetDesc = {
|
const slang::TargetDesc spirvTargetDesc = {
|
||||||
.format = SLANG_SPIRV,
|
.format = SLANG_SPIRV,
|
||||||
.profile = m_GlobalSlangSession->findProfile("glsl_450"),
|
.profile = m_GlobalSlangSession->findProfile("glsl_450"),
|
||||||
.compilerOptionEntries = &useOriginalEntrypointNames,
|
.compilerOptionEntries = compilerOptions.data(),
|
||||||
.compilerOptionEntryCount = 1,
|
.compilerOptionEntryCount = static_cast<u32>(compilerOptions.size()),
|
||||||
};
|
};
|
||||||
const slang::SessionDesc sessionDesc = {
|
const slang::SessionDesc sessionDesc = {
|
||||||
.targets = &spirvTargetDesc,
|
.targets = &spirvTargetDesc,
|
||||||
|
|
@ -1075,7 +1113,7 @@ systems::Device::Device(const DeviceCreateInfo &createInfo)
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
for (auto &frame : m_Frames)
|
for (auto &frame : m_Frames)
|
||||||
{
|
{
|
||||||
frame = CreateFrame(index++);
|
frame = Frame(*this, m_PrimaryQueueFamily, index++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1097,51 +1135,6 @@ systems::Device::~Device()
|
||||||
#pragma region Frames
|
#pragma region Frames
|
||||||
// ====================================================================================================
|
// ====================================================================================================
|
||||||
|
|
||||||
systems::Frame
|
|
||||||
systems::Device::CreateFrame(u32 frameIndex)
|
|
||||||
{
|
|
||||||
vk::CommandPool pool;
|
|
||||||
vk::Fence fence;
|
|
||||||
vk::Semaphore acquire;
|
|
||||||
vk::Semaphore finished;
|
|
||||||
|
|
||||||
NameString name = "Frame ";
|
|
||||||
name += static_cast<char>(frameIndex + '0');
|
|
||||||
|
|
||||||
const vk::CommandPoolCreateInfo commandPoolCreateInfo = {
|
|
||||||
.flags = vk::CommandPoolCreateFlagBits::eTransient,
|
|
||||||
.queueFamilyIndex = m_PrimaryQueueFamily,
|
|
||||||
};
|
|
||||||
AbortIfFailedMV(m_Device->createCommandPool(&commandPoolCreateInfo, nullptr, &pool),
|
|
||||||
"Could not command pool for frame {}", frameIndex);
|
|
||||||
|
|
||||||
constexpr vk::FenceCreateInfo fenceCreateInfo = {.flags = vk::FenceCreateFlagBits::eSignaled};
|
|
||||||
AbortIfFailedMV(m_Device->createFence(&fenceCreateInfo, nullptr, &fence),
|
|
||||||
"Could not create a fence for frame {}", frameIndex);
|
|
||||||
|
|
||||||
constexpr vk::SemaphoreCreateInfo semaphoreCreateInfo = {};
|
|
||||||
AbortIfFailedMV(m_Device->createSemaphore(&semaphoreCreateInfo, nullptr, &acquire),
|
|
||||||
"Could not create IA semaphore for frame {}.", frameIndex);
|
|
||||||
AbortIfFailedMV(m_Device->createSemaphore(&semaphoreCreateInfo, nullptr, &finished),
|
|
||||||
"Could not create RF semaphore for frame {}.", frameIndex);
|
|
||||||
|
|
||||||
m_Device.SetName(pool, name.c_str());
|
|
||||||
m_Device.SetName(fence, name.c_str());
|
|
||||||
m_Device.SetName(acquire, name.c_str());
|
|
||||||
m_Device.SetName(finished, name.c_str());
|
|
||||||
|
|
||||||
DEBUG("Frame {} created successfully.", frameIndex);
|
|
||||||
|
|
||||||
return Frame{
|
|
||||||
.m_Device = this,
|
|
||||||
.m_Pool = pool,
|
|
||||||
.m_FrameAvailableFence = fence,
|
|
||||||
.m_ImageAcquireSem = acquire,
|
|
||||||
.m_RenderFinishSem = finished,
|
|
||||||
.m_FrameIdx = frameIndex,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
systems::Frame &
|
systems::Frame &
|
||||||
systems::Device::GetNextFrame()
|
systems::Device::GetNextFrame()
|
||||||
{
|
{
|
||||||
|
|
@ -1156,8 +1149,8 @@ systems::Device::GetNextFrame()
|
||||||
bool imageAcquired = false;
|
bool imageAcquired = false;
|
||||||
while (!imageAcquired)
|
while (!imageAcquired)
|
||||||
{
|
{
|
||||||
switch (auto result = m_Device->acquireNextImageKHR(
|
switch (auto result = m_Device->acquireNextImageKHR(m_Swapchain.m_Swapchain, MaxValue<u64>,
|
||||||
m_Swapchain.m_Swapchain, MaxValue<u64>, currentFrame.m_ImageAcquireSem, nullptr, &imageIndex))
|
currentFrame.m_ImageAcquireSem, nullptr, &imageIndex))
|
||||||
{
|
{
|
||||||
case vk::Result::eSuccess:
|
case vk::Result::eSuccess:
|
||||||
case vk::Result::eSuboptimalKHR: // Suboptimal can still render. Better to let this go for semaphores etc.
|
case vk::Result::eSuboptimalKHR: // Suboptimal can still render. Better to let this go for semaphores etc.
|
||||||
|
|
@ -1350,6 +1343,75 @@ systems::Frame::WaitUntilReady()
|
||||||
"Waiting for fence {} failed.", m_FrameIdx);
|
"Waiting for fence {} failed.", m_FrameIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
systems::Frame::Frame(Device &device, u32 primaryQueueFamily, u32 frameIndex)
|
||||||
|
: m_Device{&device}
|
||||||
|
, m_FrameIdx{frameIndex}
|
||||||
|
, m_ImageIdx{0}
|
||||||
|
{
|
||||||
|
NameString name = "Frame ";
|
||||||
|
name += static_cast<char>(frameIndex + '0');
|
||||||
|
|
||||||
|
const vk::CommandPoolCreateInfo commandPoolCreateInfo = {
|
||||||
|
.flags = vk::CommandPoolCreateFlagBits::eTransient,
|
||||||
|
.queueFamilyIndex = primaryQueueFamily,
|
||||||
|
};
|
||||||
|
AbortIfFailedMV(device.m_Device->createCommandPool(&commandPoolCreateInfo, nullptr, &m_Pool),
|
||||||
|
"Could not command pool for frame {}", frameIndex);
|
||||||
|
|
||||||
|
constexpr vk::FenceCreateInfo fenceCreateInfo = {.flags = vk::FenceCreateFlagBits::eSignaled};
|
||||||
|
AbortIfFailedMV(device.m_Device->createFence(&fenceCreateInfo, nullptr, &m_FrameAvailableFence),
|
||||||
|
"Could not create a fence for frame {}", frameIndex);
|
||||||
|
|
||||||
|
constexpr vk::SemaphoreCreateInfo semaphoreCreateInfo = {};
|
||||||
|
AbortIfFailedMV(device.m_Device->createSemaphore(&semaphoreCreateInfo, nullptr, &m_ImageAcquireSem),
|
||||||
|
"Could not create IA semaphore for frame {}.", frameIndex);
|
||||||
|
AbortIfFailedMV(device.m_Device->createSemaphore(&semaphoreCreateInfo, nullptr, &m_RenderFinishSem),
|
||||||
|
"Could not create RF semaphore for frame {}.", frameIndex);
|
||||||
|
|
||||||
|
m_Device->SetName(m_Pool, name.c_str());
|
||||||
|
m_Device->SetName(m_FrameAvailableFence, name.c_str());
|
||||||
|
m_Device->SetName(m_ImageAcquireSem, name.c_str());
|
||||||
|
m_Device->SetName(m_RenderFinishSem, name.c_str());
|
||||||
|
|
||||||
|
DEBUG("Frame {} created successfully.", frameIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
systems::Frame &
|
||||||
|
systems::Frame::operator=(Frame &&other) noexcept
|
||||||
|
{
|
||||||
|
if (this == &other)
|
||||||
|
return *this;
|
||||||
|
m_Device = other.m_Device;
|
||||||
|
m_Pool = Take(other.m_Pool);
|
||||||
|
m_FrameAvailableFence = Take(other.m_FrameAvailableFence);
|
||||||
|
m_ImageAcquireSem = Take(other.m_ImageAcquireSem);
|
||||||
|
m_RenderFinishSem = Take(other.m_RenderFinishSem);
|
||||||
|
m_FrameIdx = other.m_FrameIdx;
|
||||||
|
m_CommandBuffers = Take(other.m_CommandBuffers);
|
||||||
|
m_SwapchainImage = Take(other.m_SwapchainImage);
|
||||||
|
m_SwapchainImageView = Take(other.m_SwapchainImageView);
|
||||||
|
m_SwapchainSize = Take(other.m_SwapchainSize);
|
||||||
|
m_ImageIdx = other.m_ImageIdx;
|
||||||
|
m_CommandBuffersAllocated = other.m_CommandBuffersAllocated;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
systems::Frame::Frame(Frame &&other) noexcept
|
||||||
|
: m_Device{Take(other.m_Device)}
|
||||||
|
, m_Pool{Take(other.m_Pool)}
|
||||||
|
, m_FrameAvailableFence{Take(other.m_FrameAvailableFence)}
|
||||||
|
, m_ImageAcquireSem{Take(other.m_ImageAcquireSem)}
|
||||||
|
, m_RenderFinishSem{Take(other.m_RenderFinishSem)}
|
||||||
|
, m_FrameIdx{other.m_FrameIdx}
|
||||||
|
, m_CommandBuffers{Take(other.m_CommandBuffers)}
|
||||||
|
, m_SwapchainImage{Take(other.m_SwapchainImage)}
|
||||||
|
, m_SwapchainImageView{Take(other.m_SwapchainImageView)}
|
||||||
|
, m_SwapchainSize{Take(other.m_SwapchainSize)}
|
||||||
|
, m_ImageIdx{other.m_ImageIdx}
|
||||||
|
, m_CommandBuffersAllocated{other.m_CommandBuffersAllocated}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
// ====================================================================================================
|
// ====================================================================================================
|
||||||
|
|
@ -1397,6 +1459,14 @@ void
|
||||||
systems::GraphicsContext::BindPipeline(const Pipeline &pipeline)
|
systems::GraphicsContext::BindPipeline(const Pipeline &pipeline)
|
||||||
{
|
{
|
||||||
m_Cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.m_Pipeline);
|
m_Cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.m_Pipeline);
|
||||||
|
|
||||||
|
// TODO: Maybe find a smarter place to host this.
|
||||||
|
if (CommitManager::IsInit())
|
||||||
|
{
|
||||||
|
m_Cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1,
|
||||||
|
&CommitManager::Instance().GetDescriptorSet(), 0, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
m_PipelineInUse = &pipeline;
|
m_PipelineInUse = &pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,12 @@ main(int, char **)
|
||||||
.m_Vulkan13Features = {.synchronization2 = true, .dynamicRendering = true}},
|
.m_Vulkan13Features = {.synchronization2 = true, .dynamicRendering = true}},
|
||||||
.m_AppName = "Triangle",
|
.m_AppName = "Triangle",
|
||||||
.m_ShaderSearchPaths = {"shader/"},
|
.m_ShaderSearchPaths = {"shader/"},
|
||||||
|
.m_UseBindless = false,
|
||||||
.m_Name = "Primary",
|
.m_Name = "Primary",
|
||||||
}};
|
}};
|
||||||
|
|
||||||
Pipeline pipeline;
|
Pipeline pipeline;
|
||||||
auto pipelineError = device.CreatePipeline(
|
auto pipelineError = device.CreatePipeline(pipeline, {
|
||||||
pipeline, {
|
|
||||||
.m_VertexInputs = {{
|
.m_VertexInputs = {{
|
||||||
.m_Attribute = Vertex::GetAttributes(),
|
.m_Attribute = Vertex::GetAttributes(),
|
||||||
.m_Stride = sizeof(Vertex),
|
.m_Stride = sizeof(Vertex),
|
||||||
|
|
@ -83,7 +83,6 @@ main(int, char **)
|
||||||
auto vbo = device.CreateVertexBuffer(vertices.size() * sizeof vertices[0], "VBO");
|
auto vbo = device.CreateVertexBuffer(vertices.size() * sizeof vertices[0], "VBO");
|
||||||
vbo->Write(0, vertices.size() * sizeof vertices[0], vertices.data());
|
vbo->Write(0, vertices.size() * sizeof vertices[0], vertices.data());
|
||||||
|
|
||||||
|
|
||||||
// Persistent variables
|
// Persistent variables
|
||||||
|
|
||||||
vk::ImageSubresourceRange subresourceRange = {
|
vk::ImageSubresourceRange subresourceRange = {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ add_shader(box "shader/box.vert.glsl")
|
||||||
add_shader(box "shader/box.frag.glsl")
|
add_shader(box "shader/box.frag.glsl")
|
||||||
add_shader(box "shader/box.vs.hlsl")
|
add_shader(box "shader/box.vs.hlsl")
|
||||||
add_shader(box "shader/box.ps.hlsl")
|
add_shader(box "shader/box.ps.hlsl")
|
||||||
|
add_shader(box "shader/triangle.slang")
|
||||||
add_resource_dir(box "shader/")
|
add_resource_dir(box "shader/")
|
||||||
|
|
||||||
target_link_libraries(box PRIVATE aster_core)
|
target_link_libraries(box PRIVATE aster_core)
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,6 @@ main(int, char **)
|
||||||
.m_ShaderSearchPaths = {"shader/"},
|
.m_ShaderSearchPaths = {"shader/"},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// TODO: Device in CommitManager.
|
|
||||||
systems::CommitManager commitManager{&device.m_Device, 12, 12, 12, device.CreateSampler({})};
|
|
||||||
|
|
||||||
Pipeline pipeline;
|
Pipeline pipeline;
|
||||||
auto pipelineResult =
|
auto pipelineResult =
|
||||||
device.CreatePipeline(pipeline, {.m_Shaders = {
|
device.CreatePipeline(pipeline, {.m_Shaders = {
|
||||||
|
|
@ -325,16 +322,23 @@ main(int, char **)
|
||||||
initDepthImages(extent);
|
initDepthImages(extent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: Move to 64bit handles.
|
||||||
struct PCB
|
struct PCB
|
||||||
{
|
{
|
||||||
systems::ResId<Buffer> m_Camera;
|
|
||||||
systems::ResId<Buffer> m_VertexBuffer;
|
systems::ResId<Buffer> m_VertexBuffer;
|
||||||
|
u32 m_Pad0 = 0;
|
||||||
|
systems::ResId<Buffer> m_Camera;
|
||||||
|
u32 m_Pad1 = 0;
|
||||||
systems::ResId<TextureView> m_Texture;
|
systems::ResId<TextureView> m_Texture;
|
||||||
|
u32 m_Pad2 = 0;
|
||||||
};
|
};
|
||||||
|
static_assert(sizeof(PCB) == 24);
|
||||||
|
|
||||||
|
auto &commitManager = systems::CommitManager::Instance();
|
||||||
|
|
||||||
PCB pcb = {
|
PCB pcb = {
|
||||||
.m_Camera = commitManager.CommitBuffer(ubo),
|
|
||||||
.m_VertexBuffer = commitManager.CommitBuffer(vbo),
|
.m_VertexBuffer = commitManager.CommitBuffer(vbo),
|
||||||
|
.m_Camera = commitManager.CommitBuffer(ubo),
|
||||||
.m_Texture = commitManager.CommitTexture(crate),
|
.m_Texture = commitManager.CommitTexture(crate),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -351,7 +355,7 @@ main(int, char **)
|
||||||
camera.m_Model *= rotate(mat4{1.0f}, static_cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f));
|
camera.m_Model *= rotate(mat4{1.0f}, static_cast<f32>(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f));
|
||||||
ubo->Write(0, sizeof camera, &camera);
|
ubo->Write(0, sizeof camera, &camera);
|
||||||
|
|
||||||
auto currentFrame = device.GetNextFrame();
|
auto& currentFrame = device.GetNextFrame();
|
||||||
|
|
||||||
prevSwapchainSize = swapchainSize;
|
prevSwapchainSize = swapchainSize;
|
||||||
swapchainSize = currentFrame.m_SwapchainSize;
|
swapchainSize = currentFrame.m_SwapchainSize;
|
||||||
|
|
@ -420,10 +424,8 @@ main(int, char **)
|
||||||
|
|
||||||
context.SetViewport(viewport);
|
context.SetViewport(viewport);
|
||||||
context.BindPipeline(pipeline);
|
context.BindPipeline(pipeline);
|
||||||
/*cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline.m_Layout, 0, 1,
|
context.PushConstantBlock(pcb);
|
||||||
&commitManager.GetDescriptorSet(), 0, nullptr);*/
|
context.Draw(vertices.size());
|
||||||
//context.PushConstantBlock(pcb);
|
|
||||||
context.Draw(3);
|
|
||||||
|
|
||||||
context.EndRendering();
|
context.EndRendering();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
[vk::binding(0, 0)] __DynamicResource<__DynamicResourceKind.General> gBuffers[];
|
||||||
|
[vk::binding(1, 0)] __DynamicResource<__DynamicResourceKind.Sampler> gSamplers[];
|
||||||
|
[vk::binding(2, 0)] __DynamicResource<__DynamicResourceKind.General> gStorageTextures[];
|
||||||
|
|
||||||
|
export T getDescriptorFromHandle<T>(DescriptorHandle<T> handle) where T : IOpaqueDescriptor
|
||||||
|
{
|
||||||
|
__target_switch
|
||||||
|
{
|
||||||
|
case spirv:
|
||||||
|
switch (T.kind) {
|
||||||
|
case DescriptorKind.Buffer:
|
||||||
|
return gBuffers[((uint2)handle).x].asOpaqueDescriptor<T>();
|
||||||
|
case DescriptorKind.CombinedTextureSampler:
|
||||||
|
return gSamplers[((uint2)handle).x].asOpaqueDescriptor<T>();
|
||||||
|
case DescriptorKind.Texture:
|
||||||
|
return gStorageTextures[((uint2)handle).x].asOpaqueDescriptor<T>();
|
||||||
|
default:
|
||||||
|
return defaultGetDescriptorFromHandle(handle);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return defaultGetDescriptorFromHandle(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,46 +1,59 @@
|
||||||
|
import bindless;
|
||||||
|
|
||||||
struct Vertex {
|
struct VertexData
|
||||||
float3 point;
|
{
|
||||||
float3 color;
|
float4 position;
|
||||||
|
float2 texCoord0;
|
||||||
|
float2 _pad0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CameraData
|
||||||
|
{
|
||||||
|
float4x4 model;
|
||||||
|
float4x4 view;
|
||||||
|
float4x4 projection;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PCB {
|
||||||
|
DescriptorHandle<StructuredBuffer<VertexData>> vertexBuffer;
|
||||||
|
DescriptorHandle<StructuredBuffer<CameraData>> cameraBuffer;
|
||||||
|
DescriptorHandle<Sampler2D> texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
//uniform CameraData camera;
|
||||||
|
[vk::push_constant]
|
||||||
|
uniform PCB pcb;
|
||||||
|
|
||||||
struct VSIn {
|
struct VSIn {
|
||||||
uint VertexIndex : SV_VertexID;
|
uint vertexIndex : SV_VertexID;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VSOut
|
struct VSOut
|
||||||
{
|
{
|
||||||
float4 Pos : SV_POSITION;
|
float4 position : SV_POSITION;
|
||||||
float3 Color : COLOR0;
|
float2 texCoord0 : TEXCOORD0;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const float3 points[] = {
|
|
||||||
float3(-0.5f, -0.5f, 0.5f),
|
|
||||||
float3(0.5f, -0.5f, 0.5f),
|
|
||||||
float3(0.0f, 0.5f, 0.5f),
|
|
||||||
};
|
|
||||||
static const float3 colors[] = {
|
|
||||||
float3(1.0f, 0.0f, 0.0f),
|
|
||||||
float3(0.0f, 1.0f, 0.0f),
|
|
||||||
float3(0.0f, 0.0f, 1.0f),
|
|
||||||
};
|
|
||||||
|
|
||||||
[shader("vertex")]
|
|
||||||
VSOut vsmain(VSIn input) {
|
|
||||||
VSOut output;
|
|
||||||
output.Pos = float4(points[input.VertexIndex], 1.0f);
|
|
||||||
output.Color = colors[input.VertexIndex];
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FSOut {
|
struct FSOut {
|
||||||
float4 Color;
|
float4 Color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
func vsmain(VSIn input) -> VSOut {
|
||||||
|
VSOut output;
|
||||||
|
|
||||||
|
VertexData vd = pcb.vertexBuffer[input.vertexIndex];
|
||||||
|
|
||||||
|
output.position = mul(mul(mul(float4(vd.position.xyz, 1.0f), pcb.cameraBuffer[0].model), pcb.cameraBuffer[0].view), pcb.cameraBuffer[0].projection);
|
||||||
|
output.texCoord0 = vd.texCoord0;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
[shader("fragment")]
|
[shader("fragment")]
|
||||||
FSOut fsmain(VSOut input) {
|
func fsmain(VSOut input) -> FSOut {
|
||||||
FSOut outp;
|
FSOut outp;
|
||||||
outp.Color = float4(input.Color, 1.0);
|
outp.Color = pcb.vertexBuffer[0].position.rgba;
|
||||||
|
outp.Color = float4(pcb.texture.Sample(input.texCoord0).rgb, 1.0);
|
||||||
return outp;
|
return outp;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue