Compare commits
No commits in common. "1a8f113323133f5769a727091869d7ce542f7aaf" and "363259a52ebc17d95482915ba89a6e1c48d2b1a9" have entirely different histories.
1a8f113323
...
363259a52e
|
|
@ -13,7 +13,7 @@ if (MSVC)
|
||||||
add_compile_definitions(_HAS_EXCEPTIONS=1)
|
add_compile_definitions(_HAS_EXCEPTIONS=1)
|
||||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||||
else ()
|
else ()
|
||||||
set(CMAKE_CXX_FLAGS "-Wall -g -fno-rtti -fno-exceptions")
|
set(CMAKE_CXX_FLAGS "-Wall -fno-rtti -fno-exceptions")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
include(add_shader.cmake)
|
include(add_shader.cmake)
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
#include <ranges>
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Buffer::Destroy(const Device *device)
|
Buffer::Destroy(const Device *device)
|
||||||
{
|
{
|
||||||
|
|
@ -18,91 +16,28 @@ Buffer::Destroy(const Device *device)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Buffer::Allocate(const Device *device, usize size, vk::BufferUsageFlags bufferUsage,
|
UniformBuffer::Init(const Device *device, usize size, cstr name)
|
||||||
VmaAllocationCreateFlags allocationFlags, VmaMemoryUsage memoryUsage, cstr name)
|
|
||||||
{
|
{
|
||||||
assert(size <= SIZE_MASK);
|
|
||||||
|
|
||||||
vk::BufferCreateInfo bufferCreateInfo = {
|
vk::BufferCreateInfo bufferCreateInfo = {
|
||||||
.size = size,
|
.size = size,
|
||||||
.usage = bufferUsage,
|
.usage = vk::BufferUsageFlagBits::eUniformBuffer,
|
||||||
.sharingMode = vk::SharingMode::eExclusive,
|
.sharingMode = vk::SharingMode::eExclusive,
|
||||||
};
|
};
|
||||||
const VmaAllocationCreateInfo allocationCreateInfo = {
|
constexpr VmaAllocationCreateInfo allocationCreateInfo = {
|
||||||
.flags = allocationFlags,
|
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
|
||||||
.usage = memoryUsage,
|
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT,
|
||||||
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
};
|
};
|
||||||
|
|
||||||
VkBuffer buffer;
|
VkBuffer buffer;
|
||||||
VmaAllocation allocation;
|
VmaAllocation allocation;
|
||||||
VmaAllocationInfo allocationInfo;
|
|
||||||
auto result = Cast<vk::Result>(vmaCreateBuffer(device->m_Allocator, Recast<VkBufferCreateInfo *>(&bufferCreateInfo),
|
auto result = Cast<vk::Result>(vmaCreateBuffer(device->m_Allocator, Recast<VkBufferCreateInfo *>(&bufferCreateInfo),
|
||||||
&allocationCreateInfo, &buffer, &allocation, &allocationInfo));
|
&allocationCreateInfo, &buffer, &allocation, nullptr));
|
||||||
ERROR_IF(Failed(result), "Could not allocate buffer. Cause: {}", result) THEN_ABORT(result);
|
ERROR_IF(Failed(result), "Could not allocate buffer. Cause: {}", result) THEN_ABORT(result);
|
||||||
|
|
||||||
m_Buffer = buffer;
|
m_Buffer = buffer;
|
||||||
m_Size = size & SIZE_MASK;
|
m_Size = size;
|
||||||
m_Allocation = allocation;
|
m_Allocation = allocation;
|
||||||
m_Mapped = allocationInfo.pMappedData;
|
|
||||||
|
|
||||||
vk::MemoryPropertyFlags memoryPropertyFlags;
|
|
||||||
vmaGetAllocationMemoryProperties(device->m_Allocator, allocation,
|
|
||||||
Recast<VkMemoryPropertyFlags *>(&memoryPropertyFlags));
|
|
||||||
if (memoryPropertyFlags & vk::MemoryPropertyFlagBits::eHostVisible)
|
|
||||||
{
|
|
||||||
m_Size |= HOST_ACCESSIBLE_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
device->SetName(m_Buffer, name);
|
device->SetName(m_Buffer, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Buffer::Write(const Device *device, usize offset, usize size, void *data)
|
|
||||||
{
|
|
||||||
assert(IsHostVisible());
|
|
||||||
|
|
||||||
if (!IsMapped())
|
|
||||||
{
|
|
||||||
auto result = Cast<vk::Result>(vmaMapMemory(device->m_Allocator, m_Allocation, &m_Mapped));
|
|
||||||
ERROR_IF(Failed(result), "Memory mapping failed. Cause: {}", result);
|
|
||||||
if (!Failed(result))
|
|
||||||
{
|
|
||||||
memcpy(m_Mapped, data, size);
|
|
||||||
|
|
||||||
vmaUnmapMemory(device->m_Allocator, m_Allocation);
|
|
||||||
m_Mapped = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(m_Mapped, data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Debug this.
|
|
||||||
// auto result = Cast<vk::Result>(vmaCopyMemoryToAllocation(device->m_Allocator, &data, m_Allocation, 0, size));
|
|
||||||
// ERROR_IF(Failed(result), "Writing to buffer failed. Cause: {}", result) THEN_ABORT(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
UniformBuffer::Init(const Device *device, const usize size, const cstr name)
|
|
||||||
{
|
|
||||||
Allocate(device, size, vk::BufferUsageFlagBits::eUniformBuffer,
|
|
||||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
|
|
||||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT,
|
|
||||||
VMA_MEMORY_USAGE_AUTO, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
VertexBuffer::Init(const Device *device, usize size, cstr name)
|
|
||||||
{
|
|
||||||
Allocate(device, size, vk::BufferUsageFlagBits::eVertexBuffer | vk::BufferUsageFlagBits::eTransferDst,
|
|
||||||
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, VMA_MEMORY_USAGE_AUTO, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
StagingBuffer::Init(const Device *device, usize size, cstr name)
|
|
||||||
{
|
|
||||||
Allocate(device, size, vk::BufferUsageFlagBits::eTransferSrc,
|
|
||||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT,
|
|
||||||
VMA_MEMORY_USAGE_AUTO, name);
|
|
||||||
}
|
|
||||||
|
|
@ -14,55 +14,12 @@ struct Buffer
|
||||||
{
|
{
|
||||||
vk::Buffer m_Buffer = nullptr;
|
vk::Buffer m_Buffer = nullptr;
|
||||||
VmaAllocation m_Allocation = nullptr;
|
VmaAllocation m_Allocation = nullptr;
|
||||||
void *m_Mapped = nullptr;
|
|
||||||
|
|
||||||
[[nodiscard]] usize GetSize() const;
|
|
||||||
[[nodiscard]] bool IsHostVisible() const;
|
|
||||||
[[nodiscard]] bool IsMapped() const;
|
|
||||||
|
|
||||||
void Destroy(const Device *device);
|
|
||||||
void Write(const Device *device, usize offset, usize size, void *data);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void Allocate(const Device *device, usize size, vk::BufferUsageFlags bufferUsage,
|
|
||||||
VmaAllocationCreateFlags allocationFlags, VmaMemoryUsage memoryUsage, cstr name);
|
|
||||||
|
|
||||||
usize m_Size = 0;
|
usize m_Size = 0;
|
||||||
|
|
||||||
constexpr static usize HOST_ACCESSIBLE_BIT = 1llu << 63;
|
void Destroy(const Device *device);
|
||||||
constexpr static usize SIZE_MASK = ~HOST_ACCESSIBLE_BIT;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UniformBuffer : Buffer
|
struct UniformBuffer : Buffer
|
||||||
{
|
{
|
||||||
void Init(const Device *device, usize size, cstr name = nullptr);
|
void Init(const Device *device, usize size, cstr name = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexBuffer : Buffer
|
|
||||||
{
|
|
||||||
void Init(const Device *device, usize size, cstr name = nullptr);
|
|
||||||
void Write(const Device *device, void *data, usize size, usize offset) const = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct StagingBuffer : Buffer
|
|
||||||
{
|
|
||||||
void Init(const Device *device, usize size, cstr name = nullptr);
|
|
||||||
};
|
|
||||||
|
|
||||||
inline usize
|
|
||||||
Buffer::GetSize() const
|
|
||||||
{
|
|
||||||
return m_Size & SIZE_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
Buffer::IsHostVisible() const
|
|
||||||
{
|
|
||||||
return m_Size & HOST_ACCESSIBLE_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
Buffer::IsMapped() const
|
|
||||||
{
|
|
||||||
return m_Mapped;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,14 @@ struct Device final
|
||||||
~Device();
|
~Device();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires vk::isVulkanHandleType<T>::value void SetName(const T &object, cstr name) const;
|
requires vk::isVulkanHandleType<T>::value
|
||||||
|
void SetName(const T &object, cstr name) const;
|
||||||
[[nodiscard]] vk::Queue GetQueue(u32 familyIndex, u32 queueIndex) const;
|
[[nodiscard]] vk::Queue GetQueue(u32 familyIndex, u32 queueIndex) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires vk::isVulkanHandleType<T>::value void
|
requires vk::isVulkanHandleType<T>::value
|
||||||
|
void
|
||||||
Device::SetName(const T &object, cstr name) const
|
Device::SetName(const T &object, cstr name) const
|
||||||
{
|
{
|
||||||
if (!name)
|
if (!name)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
#include <vulkan/vulkan.hpp>
|
#include <vulkan/vulkan.hpp>
|
||||||
|
|
||||||
constexpr u32 ASTER_API_VERSION = VK_API_VERSION_1_3;
|
constexpr u32 ASTER_API_VERSION = vk::ApiVersion13;
|
||||||
|
|
||||||
#define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__)
|
#define CODE_LOC " @ " __FILE__ ":" VULKAN_HPP_STRINGIFY(__LINE__)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
add_executable(triangle "triangle.cpp")
|
add_executable(triangle "triangle.cpp")
|
||||||
add_shader(triangle shader/triangle.vert.glsl)
|
add_shader(triangle shader/triangle.vs.hlsl)
|
||||||
add_shader(triangle shader/triangle.frag.glsl)
|
add_shader(triangle shader/triangle.frag.glsl)
|
||||||
|
|
||||||
target_link_libraries(triangle PRIVATE aster_core)
|
target_link_libraries(triangle PRIVATE aster_core)
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
#version 450
|
|
||||||
#pragma shader_stage(vertex)
|
|
||||||
|
|
||||||
layout(location=0) in vec4 position;
|
|
||||||
layout(location=1) in vec4 color;
|
|
||||||
|
|
||||||
layout(location=0) out vec3 outColor;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
/*
|
|
||||||
vec3 points[] = {
|
|
||||||
vec3(-0.5f, -0.5f, 0.0f),
|
|
||||||
vec3(0.5f, -0.5f, 0.0f),
|
|
||||||
vec3(0.0f, 0.5f, 0.0f)
|
|
||||||
};
|
|
||||||
vec3 colors[] = {
|
|
||||||
vec3( 1.0f, 0.0f, 0.0f ),
|
|
||||||
vec3( 0.0f, 1.0f, 0.0f ),
|
|
||||||
vec3( 0.0f, 0.0f, 1.0f ),
|
|
||||||
};
|
|
||||||
|
|
||||||
gl_Position = vec4(points[gl_VertexIndex], 1.0f);
|
|
||||||
outColor = vec3(colors[gl_VertexIndex]); //*/
|
|
||||||
//*
|
|
||||||
gl_Position = vec4(position.xyz, 1.0f);
|
|
||||||
outColor = vec3(color.rgb); //*/
|
|
||||||
}
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
// Copyright (c) 2020-2024 Anish Bhobe
|
// Copyright (c) 2020-2024 Anish Bhobe
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|
||||||
#include "buffer.h"
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
@ -19,43 +18,12 @@
|
||||||
#include <EASTL/array.h>
|
#include <EASTL/array.h>
|
||||||
|
|
||||||
constexpr u32 MAX_FRAMES_IN_FLIGHT = 3;
|
constexpr u32 MAX_FRAMES_IN_FLIGHT = 3;
|
||||||
constexpr auto VERTEX_SHADER_FILE = "shader/triangle.vert.glsl.spv";
|
constexpr auto VERTEX_SHADER_FILE = "shader/triangle.vs.hlsl.spv";
|
||||||
constexpr auto FRAGMENT_SHADER_FILE = "shader/triangle.frag.glsl.spv";
|
constexpr auto FRAGMENT_SHADER_FILE = "shader/triangle.frag.glsl.spv";
|
||||||
|
|
||||||
vk::ShaderModule CreateShader(const Device *device, cstr shaderFile);
|
vk::ShaderModule CreateShader(const Device *device, cstr shaderFile);
|
||||||
Pipeline CreatePipeline(const Device *device, const Swapchain *swapchain);
|
Pipeline CreatePipeline(const Device *device, const Swapchain *swapchain);
|
||||||
|
|
||||||
struct Vertex
|
|
||||||
{
|
|
||||||
float m_Position[4];
|
|
||||||
float m_Color[4];
|
|
||||||
|
|
||||||
constexpr static vk::VertexInputBindingDescription
|
|
||||||
GetBinding(const u32 binding)
|
|
||||||
{
|
|
||||||
return {.binding = binding, .stride = sizeof(Vertex), .inputRate = vk::VertexInputRate::eVertex};
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr static eastl::array<vk::VertexInputAttributeDescription, 2>
|
|
||||||
GetAttributes(const u32 binding)
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
vk::VertexInputAttributeDescription{
|
|
||||||
.location = 0,
|
|
||||||
.binding = binding,
|
|
||||||
.format = vk::Format::eR32G32B32A32Sfloat,
|
|
||||||
.offset = offsetof(Vertex, m_Position),
|
|
||||||
},
|
|
||||||
vk::VertexInputAttributeDescription{
|
|
||||||
.location = 1,
|
|
||||||
.binding = binding,
|
|
||||||
.format = vk::Format::eR32G32B32A32Sfloat,
|
|
||||||
.offset = offsetof(Vertex, m_Color),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Frame
|
struct Frame
|
||||||
{
|
{
|
||||||
const Device *m_Device;
|
const Device *m_Device;
|
||||||
|
|
@ -83,80 +51,16 @@ main(int, char **)
|
||||||
|
|
||||||
INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data());
|
INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data());
|
||||||
|
|
||||||
Features enabledDeviceFeatures = {.m_Vulkan13Features = {.dynamicRendering = true}};
|
Features enabledDeviceFeatures = {.m_Vulkan13Features = {.dynamicRendering = vk::True}};
|
||||||
QueueAllocation queueAllocation = FindAppropriateQueueAllocation(&deviceToUse);
|
QueueAllocation queueAllocation = FindAppropriateQueueAllocation(&deviceToUse);
|
||||||
Device device = {&context, &deviceToUse, &enabledDeviceFeatures, {queueAllocation}, "Primary Device"};
|
Device device = {&context, &deviceToUse, &enabledDeviceFeatures, {queueAllocation}, "Primary Device"};
|
||||||
|
|
||||||
vk::Queue commandQueue = device.GetQueue(queueAllocation.m_Family, 0);
|
vk::Queue commandQueue = device.GetQueue(queueAllocation.m_Family, 1);
|
||||||
|
|
||||||
Swapchain swapchain = {&window, &device, "Primary Chain"};
|
Swapchain swapchain = {&window, &device, "Primary Chain"};
|
||||||
|
|
||||||
Pipeline pipeline = CreatePipeline(&device, &swapchain);
|
Pipeline pipeline = CreatePipeline(&device, &swapchain);
|
||||||
|
|
||||||
vk::CommandPool copyPool;
|
|
||||||
vk::CommandBuffer copyBuffer;
|
|
||||||
{
|
|
||||||
vk::CommandPoolCreateInfo poolCreateInfo = {
|
|
||||||
.flags = vk::CommandPoolCreateFlagBits::eTransient,
|
|
||||||
.queueFamilyIndex = queueAllocation.m_Family,
|
|
||||||
};
|
|
||||||
auto result = device.m_Device.createCommandPool(&poolCreateInfo, nullptr, ©Pool);
|
|
||||||
ERROR_IF(Failed(result), "Copy command pool creation failed. Cause: {}", result) THEN_ABORT(result);
|
|
||||||
vk::CommandBufferAllocateInfo bufferAllocateInfo = {
|
|
||||||
.commandPool = copyPool,
|
|
||||||
.level = vk::CommandBufferLevel::ePrimary,
|
|
||||||
.commandBufferCount = 1,
|
|
||||||
};
|
|
||||||
result = device.m_Device.allocateCommandBuffers(&bufferAllocateInfo, ©Buffer);
|
|
||||||
ERROR_IF(Failed(result), "Copy command buffer allocation failed. Cause: {}", result) THEN_ABORT(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// eastl::array<Vertex, 3> vertices{};
|
|
||||||
eastl::array vertices = {
|
|
||||||
Vertex{.m_Position = {-0.5f, -0.5f, 0.0f, 1.0f}, .m_Color = {1.0f, 0.0f, 0.0f, 1.0f}},
|
|
||||||
Vertex{.m_Position = {0.5f, -0.5f, 0.0f, 1.0f}, .m_Color = {0.0f, 1.0f, 0.0f, 1.0f}},
|
|
||||||
Vertex{.m_Position = {0.0f, 0.5f, 0.0f, 1.0f}, .m_Color = {0.0f, 0.0f, 1.0f, 1.0f}},
|
|
||||||
};
|
|
||||||
VertexBuffer vbo;
|
|
||||||
vbo.Init(&device, vertices.size() * sizeof vertices[0], "VBO");
|
|
||||||
{
|
|
||||||
StagingBuffer staging;
|
|
||||||
staging.Init(&device, vertices.size() * sizeof vertices[0], "Staging");
|
|
||||||
staging.Write(&device, 0, vertices.size() * sizeof vertices[0], vertices.data());
|
|
||||||
|
|
||||||
vk::Fence fence;
|
|
||||||
vk::FenceCreateInfo fenceCreateInfo = {};
|
|
||||||
auto result = device.m_Device.createFence(&fenceCreateInfo, nullptr, &fence);
|
|
||||||
ERROR_IF(Failed(result), "Fence creation failed. Cause: {}", result) THEN_ABORT(result);
|
|
||||||
|
|
||||||
vk::CommandBufferBeginInfo beginInfo = {.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit};
|
|
||||||
result = copyBuffer.begin(&beginInfo);
|
|
||||||
ERROR_IF(Failed(result), "Copy begin failed. Cause: {}", result) THEN_ABORT(result);
|
|
||||||
|
|
||||||
vk::BufferCopy bufferCopy = {.srcOffset = 0, .dstOffset = 0, .size = staging.GetSize()};
|
|
||||||
copyBuffer.copyBuffer(staging.m_Buffer, vbo.m_Buffer, 1, &bufferCopy);
|
|
||||||
|
|
||||||
result = copyBuffer.end();
|
|
||||||
ERROR_IF(Failed(result), "Copy end failed. Cause: {}", result) THEN_ABORT(result);
|
|
||||||
|
|
||||||
vk::SubmitInfo submitInfo = {
|
|
||||||
.commandBufferCount = 1,
|
|
||||||
.pCommandBuffers = ©Buffer,
|
|
||||||
};
|
|
||||||
|
|
||||||
result = commandQueue.submit(1, &submitInfo, fence);
|
|
||||||
ERROR_IF(Failed(result), "Submit failed. Cause: {}", result) THEN_ABORT(result) ELSE_INFO("Submit copy");
|
|
||||||
|
|
||||||
result = device.m_Device.waitForFences(1, &fence, true, MaxValue<u64>);
|
|
||||||
ERROR_IF(Failed(result), "Fence wait failed. Cause: {}", result) THEN_ABORT(result) ELSE_INFO("Fence wait");
|
|
||||||
|
|
||||||
result = device.m_Device.resetCommandPool(copyPool, {});
|
|
||||||
ERROR_IF(Failed(result), "Couldn't reset command pool. Cause: {}", result) THEN_ABORT(result);
|
|
||||||
|
|
||||||
device.m_Device.destroy(fence, nullptr);
|
|
||||||
staging.Destroy(&device);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Persistent variables
|
// Persistent variables
|
||||||
vk::Viewport viewport = {
|
vk::Viewport viewport = {
|
||||||
.x = 0,
|
.x = 0,
|
||||||
|
|
@ -201,13 +105,12 @@ main(int, char **)
|
||||||
frames.emplace_back(&device, queueAllocation.m_Family, i);
|
frames.emplace_back(&device, queueAllocation.m_Family, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
INFO("Starting loop");
|
|
||||||
u32 frameIndex = 0;
|
u32 frameIndex = 0;
|
||||||
while (window.Poll())
|
while (window.Poll())
|
||||||
{
|
{
|
||||||
Frame *currentFrame = &frames[frameIndex];
|
Frame *currentFrame = &frames[frameIndex];
|
||||||
|
|
||||||
auto result = device.m_Device.waitForFences(1, ¤tFrame->m_FrameAvailableFence, true, MaxValue<u64>);
|
auto result = device.m_Device.waitForFences(1, ¤tFrame->m_FrameAvailableFence, vk::True, MaxValue<u64>);
|
||||||
ERROR_IF(Failed(result), "Waiting for fence {} failed. Cause: {}", frameIndex, result)
|
ERROR_IF(Failed(result), "Waiting for fence {} failed. Cause: {}", frameIndex, result)
|
||||||
THEN_ABORT(result);
|
THEN_ABORT(result);
|
||||||
|
|
||||||
|
|
@ -278,8 +181,6 @@ main(int, char **)
|
||||||
cmd.setViewport(0, 1, &viewport);
|
cmd.setViewport(0, 1, &viewport);
|
||||||
cmd.setScissor(0, 1, &scissor);
|
cmd.setScissor(0, 1, &scissor);
|
||||||
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.m_Pipeline);
|
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.m_Pipeline);
|
||||||
usize offsets = 0;
|
|
||||||
cmd.bindVertexBuffers(0, 1, &vbo.m_Buffer, &offsets);
|
|
||||||
cmd.draw(3, 1, 0, 0);
|
cmd.draw(3, 1, 0, 0);
|
||||||
|
|
||||||
cmd.endRendering();
|
cmd.endRendering();
|
||||||
|
|
@ -338,9 +239,6 @@ main(int, char **)
|
||||||
auto result = device.m_Device.waitIdle();
|
auto result = device.m_Device.waitIdle();
|
||||||
ERROR_IF(Failed(result), "Wait idle failed. Cause: {}", result);
|
ERROR_IF(Failed(result), "Wait idle failed. Cause: {}", result);
|
||||||
|
|
||||||
device.m_Device.destroy(copyPool, nullptr);
|
|
||||||
vbo.Destroy(&device);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -385,7 +283,6 @@ Frame::AllocateCommandBuffer() const
|
||||||
|
|
||||||
return commandBuffer;
|
return commandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline
|
Pipeline
|
||||||
CreatePipeline(const Device *device, const Swapchain *swapchain)
|
CreatePipeline(const Device *device, const Swapchain *swapchain)
|
||||||
{
|
{
|
||||||
|
|
@ -417,18 +314,15 @@ CreatePipeline(const Device *device, const Swapchain *swapchain)
|
||||||
ERROR_IF(Failed(result), "Could not create a pipeline layout. Cause: {}", result) THEN_ABORT(result);
|
ERROR_IF(Failed(result), "Could not create a pipeline layout. Cause: {}", result) THEN_ABORT(result);
|
||||||
device->SetName(pipelineLayout, "Triangle Layout");
|
device->SetName(pipelineLayout, "Triangle Layout");
|
||||||
|
|
||||||
vk::VertexInputBindingDescription inputBindingDescription = Vertex::GetBinding(0);
|
|
||||||
auto inputAttributeDescription = Vertex::GetAttributes(0);
|
|
||||||
|
|
||||||
vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = {
|
vk::PipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = {
|
||||||
.vertexBindingDescriptionCount = 1,
|
.vertexBindingDescriptionCount = 0,
|
||||||
.pVertexBindingDescriptions = &inputBindingDescription,
|
.pVertexBindingDescriptions = nullptr,
|
||||||
.vertexAttributeDescriptionCount = Cast<u32>(inputAttributeDescription.size()),
|
.vertexAttributeDescriptionCount = 0,
|
||||||
.pVertexAttributeDescriptions = inputAttributeDescription.data(),
|
.pVertexAttributeDescriptions = nullptr,
|
||||||
};
|
};
|
||||||
vk::PipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = {
|
vk::PipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = {
|
||||||
.topology = vk::PrimitiveTopology::eTriangleList,
|
.topology = vk::PrimitiveTopology::eTriangleList,
|
||||||
.primitiveRestartEnable = false,
|
.primitiveRestartEnable = vk::False,
|
||||||
};
|
};
|
||||||
|
|
||||||
vk::PipelineViewportStateCreateInfo viewportStateCreateInfo = {
|
vk::PipelineViewportStateCreateInfo viewportStateCreateInfo = {
|
||||||
|
|
@ -437,24 +331,24 @@ CreatePipeline(const Device *device, const Swapchain *swapchain)
|
||||||
};
|
};
|
||||||
|
|
||||||
vk::PipelineRasterizationStateCreateInfo rasterizationStateCreateInfo = {
|
vk::PipelineRasterizationStateCreateInfo rasterizationStateCreateInfo = {
|
||||||
.depthClampEnable = false,
|
.depthClampEnable = vk::False,
|
||||||
.rasterizerDiscardEnable = false,
|
.rasterizerDiscardEnable = vk::False,
|
||||||
.polygonMode = vk::PolygonMode::eFill,
|
.polygonMode = vk::PolygonMode::eFill,
|
||||||
.cullMode = vk::CullModeFlagBits::eNone,
|
.cullMode = vk::CullModeFlagBits::eNone,
|
||||||
.frontFace = vk::FrontFace::eCounterClockwise,
|
.frontFace = vk::FrontFace::eCounterClockwise,
|
||||||
.depthBiasEnable = false,
|
.depthBiasEnable = vk::False,
|
||||||
.lineWidth = 1.0,
|
.lineWidth = 1.0,
|
||||||
};
|
};
|
||||||
vk::PipelineMultisampleStateCreateInfo multisampleStateCreateInfo = {
|
vk::PipelineMultisampleStateCreateInfo multisampleStateCreateInfo = {
|
||||||
.rasterizationSamples = vk::SampleCountFlagBits::e1,
|
.rasterizationSamples = vk::SampleCountFlagBits::e1,
|
||||||
.sampleShadingEnable = false,
|
.sampleShadingEnable = vk::False,
|
||||||
};
|
};
|
||||||
vk::PipelineDepthStencilStateCreateInfo depthStencilStateCreateInfo = {
|
vk::PipelineDepthStencilStateCreateInfo depthStencilStateCreateInfo = {
|
||||||
.depthTestEnable = false,
|
.depthTestEnable = vk::False,
|
||||||
.depthWriteEnable = false,
|
.depthWriteEnable = vk::False,
|
||||||
};
|
};
|
||||||
vk::PipelineColorBlendAttachmentState colorBlendAttachmentState = {
|
vk::PipelineColorBlendAttachmentState colorBlendAttachmentState = {
|
||||||
.blendEnable = false,
|
.blendEnable = vk::False,
|
||||||
.srcColorBlendFactor = vk::BlendFactor::eSrcColor,
|
.srcColorBlendFactor = vk::BlendFactor::eSrcColor,
|
||||||
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcColor,
|
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcColor,
|
||||||
.colorBlendOp = vk::BlendOp::eAdd,
|
.colorBlendOp = vk::BlendOp::eAdd,
|
||||||
|
|
@ -465,7 +359,7 @@ CreatePipeline(const Device *device, const Swapchain *swapchain)
|
||||||
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
|
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
|
||||||
};
|
};
|
||||||
vk::PipelineColorBlendStateCreateInfo colorBlendStateCreateInfo = {
|
vk::PipelineColorBlendStateCreateInfo colorBlendStateCreateInfo = {
|
||||||
.logicOpEnable = false,
|
.logicOpEnable = vk::False,
|
||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
.pAttachments = &colorBlendAttachmentState,
|
.pAttachments = &colorBlendAttachmentState,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue