This commit is contained in:
PancakeTAS 2025-06-29 16:25:03 +02:00
parent e5eb4cb740
commit ce6542a039
No known key found for this signature in database
10 changed files with 35 additions and 10 deletions

3
.gitignore vendored
View file

@ -6,3 +6,6 @@
/.clangd
/.cache
/.ccls
# private shaders
/shaders

View file

@ -4,6 +4,7 @@
#include "core/commandpool.hpp"
#include "core/semaphore.hpp"
#include "device.hpp"
#include <vulkan/vulkan_core.h>
#include <optional>

View file

@ -3,10 +3,10 @@
#include "device.hpp"
#include <string>
#include <vector>
#include <vulkan/vulkan_core.h>
#include <string>
#include <vector>
#include <memory>
namespace Vulkan::Core {

View file

@ -1,5 +1,4 @@
#include "core/commandbuffer.hpp"
#include "core/semaphore.hpp"
#include "utils/exceptions.hpp"
using namespace Vulkan::Core;

View file

@ -1,6 +1,5 @@
#include "core/fence.hpp"
#include "utils/exceptions.hpp"
#include <vulkan/vulkan_core.h>
using namespace Vulkan::Core;
@ -29,7 +28,7 @@ Fence::Fence(const Device& device) {
void Fence::reset() const {
if (!this->isValid())
throw std::runtime_error("Invalid fence");
throw std::logic_error("Invalid fence");
VkFence fenceHandle = this->handle();
auto res = vkResetFences(this->device, 1, &fenceHandle);
@ -39,7 +38,7 @@ void Fence::reset() const {
bool Fence::wait(uint64_t timeout) {
if (!this->isValid())
throw std::runtime_error("Invalid fence");
throw std::logic_error("Invalid fence");
VkFence fenceHandle = this->handle();
auto res = vkWaitForFences(this->device, 1, &fenceHandle, VK_TRUE, timeout);

View file

@ -35,7 +35,7 @@ Semaphore::Semaphore(const Device& device, std::optional<uint32_t> initial) {
void Semaphore::signal(uint64_t value) const {
if (!this->isValid() || !this->isTimeline)
throw std::runtime_error("Invalid timeline semaphore");
throw std::logic_error("Invalid timeline semaphore");
const VkSemaphoreSignalInfo signalInfo{
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO,
@ -49,7 +49,7 @@ void Semaphore::signal(uint64_t value) const {
bool Semaphore::wait(uint64_t value, uint64_t timeout) {
if (!this->isValid() || !this->isTimeline)
throw std::runtime_error("Invalid timeline semaphore");
throw std::logic_error("Invalid timeline semaphore");
VkSemaphore semaphore = this->handle();
const VkSemaphoreWaitInfo waitInfo{

View file

@ -29,7 +29,7 @@ ShaderModule::ShaderModule(const Device& device, const std::string& path,
const uint8_t* data_ptr = code.data();
const VkShaderModuleCreateInfo createInfo{
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.codeSize = code.size() * sizeof(uint32_t),
.codeSize = code.size(),
.pCode = reinterpret_cast<const uint32_t*>(data_ptr)
};
VkShaderModule shaderModuleHandle{};

View file

@ -52,6 +52,11 @@ Device::Device(const Instance& instance) {
// create logical device
const float queuePriority{1.0F}; // highest priority
const VkPhysicalDeviceVulkan12Features features{
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
.timelineSemaphore = VK_TRUE,
.vulkanMemoryModel = VK_TRUE,
};
const VkDeviceQueueCreateInfo computeQueueDesc{
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.queueFamilyIndex = *computeFamilyIdx,
@ -60,6 +65,7 @@ Device::Device(const Instance& instance) {
};
const VkDeviceCreateInfo deviceCreateInfo{
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
.pNext = &features,
.queueCreateInfoCount = 1,
.pQueueCreateInfos = &computeQueueDesc
};

View file

@ -21,7 +21,7 @@ Instance::Instance() {
.applicationVersion = VK_MAKE_VERSION(0, 0, 1),
.pEngineName = "lsfg-vk-base",
.engineVersion = VK_MAKE_VERSION(0, 0, 1),
.apiVersion = VK_API_VERSION_1_4
.apiVersion = VK_API_VERSION_1_3
};
const VkInstanceCreateInfo createInfo{
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,

View file

@ -1,12 +1,29 @@
#include "core/shadermodule.hpp"
#include "device.hpp"
#include "instance.hpp"
#include <iostream>
#include <vulkan/vulkan_core.h>
int main() {
const Vulkan::Instance instance;
const Vulkan::Device device(instance);
const Vulkan::Core::ShaderModule computeShader(device, "shaders/downsample.spv",
{
VK_DESCRIPTOR_TYPE_SAMPLER,
VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
}
);
std::cerr << "Application finished" << '\n';
return 0;
}