Skip to content

Commit

Permalink
[Release] Feature/0.5.0 (#206)
Browse files Browse the repository at this point in the history
* made full api stabilization

* renamed .h to .hpp

* linux fix

* Restyled Feature/0.5.0 (#207)

* Restyled by astyle

* Restyled by clang-format

* Restyled by cmake-format

* Restyled by prettier-markdown

* Restyled by whitespace

---------

Co-authored-by: Restyled.io <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2024
1 parent 3231853 commit 8823a44
Show file tree
Hide file tree
Showing 126 changed files with 4,690 additions and 2,536 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ BraceWrapping:
BeforeElse: false
IndentBraces: false

InsertBraces: true

CommentPragmas: '/\*(.+\n.+)+\*/'
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

cmake_minimum_required(VERSION 3.22)

set(WISDOM_VERSION "0.4.0")
set(WISDOM_VERSION "0.5.0")
project("Wisdom" VERSION ${WISDOM_VERSION})

set(CMAKE_DEBUG_POSTFIX d)
Expand Down
16 changes: 16 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@
"CMAKE_CXX_COMPILER": "cl.exe"
}
},
{
"name": "x64-vs",
"displayName": "x64 VS",
"description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)",
"architecture": {
"value": "x64",
"strategy": "external"
},
"generator": "Visual Studio 17 2022",
"cacheVariables": {
"WISDOM_GENERATE_FUNCTIONS": false,
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-debug-only-lib",
"displayName": "x64 Lib Debug",
Expand Down
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Version History

- 0.5.0 API stabilization

- Most of the API is now stable and will not change
- There are 2 versions of return values. One is the ResultValue<> which was there from the beginning, and the other is RVO enabled return value. ResultValue<> is left for compatibility and local use, while RVO enabled return value is for inline construction and chaining. It is recommended to use RVO enabled return value for all new code.
- Added documentation for extended allocation. With Vulkan 1.4 it has become a core feature.
- API structure is consistent. Now all the structures are passed by const reference. This is done to enable language interop.
- Consumed headers are now .hpp instead of .h. Implementation headers are still .h, since they are not intended to be used standalone anyway.

- 0.4.0 Major Update

- Fixed Vulkan Swapchain on resize occasionally result in error messages
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) [year] [fullname]
Copyright (c) 2024 Ilya "Agrael" Doroshenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
390 changes: 278 additions & 112 deletions bindings/wisdom.cpp

Large diffs are not rendered by default.

401 changes: 368 additions & 33 deletions bindings/wisdom.h

Large diffs are not rendered by default.

113 changes: 99 additions & 14 deletions bindings/wisdom_ext.inl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "wisdom.h"

#include "wisdom/wisdom_debug.h"
#include "wisdom/wisdom_descriptor_buffer.h"
#include "wisdom/wisdom_debug.hpp"
#include "wisdom/wisdom_descriptor_buffer.hpp"
#include "wisdom/wisdom_extended_allocation.hpp"

#if defined(WISDOM_DX12)
#include <wisdom/wisdom_dx12.hpp>
Expand Down Expand Up @@ -37,6 +38,10 @@ template<>
struct DX12DeviceExtensionMap<wis::DeviceExtID::DescriptorBufferExtension> {
using Type = wis::DX12DescriptorBufferExtension;
};
template<>
struct DX12DeviceExtensionMap<wis::DeviceExtID::ExtendedAllocation> {
using Type = wis::DX12ExtendedAllocation;
};
//-------------------------------------------------------------------------

template<template<typename T> typename Executor, typename... Args>
Expand All @@ -45,6 +50,8 @@ constexpr static inline decltype(auto) DX12DeviceExtensionBridge(wis::DeviceExtI
switch (id) {
case wis::DeviceExtID::DescriptorBufferExtension:
return Executor<typename DX12DeviceExtensionMap<wis::DeviceExtID::DescriptorBufferExtension>::Type>{}(std::forward<Args>(args)...);
case wis::DeviceExtID::ExtendedAllocation:
return Executor<typename DX12DeviceExtensionMap<wis::DeviceExtID::ExtendedAllocation>::Type>{}(std::forward<Args>(args)...);
default:
return Executor<wis::DX12DeviceExtension>{}(std::forward<Args>(args)...);
}
Expand All @@ -55,12 +62,14 @@ extern "C" WisResult DX12DebugExtensionCreateDebugMessenger(DX12DebugExtension s
auto* xself = reinterpret_cast<wis::DX12DebugExtension*>(self);
auto&& [res, value] = xself->CreateDebugMessenger(reinterpret_cast<wis::DebugCallback>(callback), user_data);

if (res.status != wis::Status::Ok)
if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*messenger = reinterpret_cast<DX12DebugMessenger>(new (std::nothrow) wis::DX12DebugMessenger(std::move(value)));
if (!*messenger)
if (!*messenger) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::DX12DebugMessenger." };
}
return reinterpret_cast<WisResult&>(res);
}
// DX12DescriptorBufferExtension methods --
Expand All @@ -69,25 +78,29 @@ extern "C" WisResult DX12DescriptorBufferExtensionCreateRootSignature(DX12Descri
auto* xself = reinterpret_cast<wis::DX12DescriptorBufferExtension*>(self);
auto&& [res, value] = xself->CreateRootSignature(reinterpret_cast<const wis::PushConstant*&>(root_constants), constants_count, reinterpret_cast<const wis::PushDescriptor*&>(root_descriptors), descriptors_count, reinterpret_cast<const wis::DescriptorTable*&>(tables), tables_count);

if (res.status != wis::Status::Ok)
if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*signature = reinterpret_cast<DX12RootSignature>(new (std::nothrow) wis::DX12RootSignature(std::move(value)));
if (!*signature)
if (!*signature) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::DX12RootSignature." };
}
return reinterpret_cast<WisResult&>(res);
}
extern "C" WisResult DX12DescriptorBufferExtensionCreateDescriptorBuffer(DX12DescriptorBufferExtension self, WisDescriptorHeapType type, WisDescriptorMemory memory, uint64_t memory_bytes, DX12DescriptorBuffer* buffer)
{
auto* xself = reinterpret_cast<wis::DX12DescriptorBufferExtension*>(self);
auto&& [res, value] = xself->CreateDescriptorBuffer(static_cast<wis::DescriptorHeapType>(type), static_cast<wis::DescriptorMemory>(memory), memory_bytes);

if (res.status != wis::Status::Ok)
if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*buffer = reinterpret_cast<DX12DescriptorBuffer>(new (std::nothrow) wis::DX12DescriptorBuffer(std::move(value)));
if (!*buffer)
if (!*buffer) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::DX12DescriptorBuffer." };
}
return reinterpret_cast<WisResult&>(res);
}
extern "C" uint64_t DX12DescriptorBufferExtensionGetDescriptorTableAlignment(DX12DescriptorBufferExtension self, WisDescriptorHeapType type)
Expand All @@ -114,6 +127,36 @@ extern "C" void DX12DescriptorBufferExtensionSetDescriptorTableOffset(DX12Descri
auto* xself = reinterpret_cast<wis::DX12DescriptorBufferExtension*>(self);
xself->SetDescriptorTableOffset(*reinterpret_cast<wis::DX12CommandList*>(list), *reinterpret_cast<wis::DX12RootSignature*>(root_signature), table_index, *reinterpret_cast<wis::DX12DescriptorBuffer*>(buffer), table_aligned_byte_offset);
}
// DX12ExtendedAllocation methods --
extern "C" WisResult DX12ExtendedAllocationCreateGPUUploadTexture(DX12ExtendedAllocation self, const DX12ResourceAllocator* allocator, const WisTextureDesc* desc, WisTextureState initial_state, WisMemoryFlags flags, DX12Texture* texture)
{
auto* xself = reinterpret_cast<wis::DX12ExtendedAllocation*>(self);
auto&& [res, value] = xself->CreateGPUUploadTexture(*reinterpret_cast<const wis::DX12ResourceAllocator*>(allocator), *reinterpret_cast<const wis::TextureDesc*>(desc), static_cast<wis::TextureState>(initial_state), static_cast<wis::MemoryFlags>(flags));

if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*texture = reinterpret_cast<DX12Texture>(new (std::nothrow) wis::DX12Texture(std::move(value)));
if (!*texture) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::DX12Texture." };
}
return reinterpret_cast<WisResult&>(res);
}
extern "C" WisResult DX12ExtendedAllocationWriteMemoryToSubresourceDirect(DX12ExtendedAllocation self, const void* host_data, DX12Texture dst_texture, WisTextureState initial_state, WisTextureRegion region)
{
auto* xself = reinterpret_cast<wis::DX12ExtendedAllocation*>(self);
auto res = xself->WriteMemoryToSubresourceDirect(host_data, *reinterpret_cast<wis::DX12Texture*>(dst_texture), static_cast<wis::TextureState>(initial_state), reinterpret_cast<wis::TextureRegion&>(region));
;
return reinterpret_cast<WisResult&>(res);
}
extern "C" bool DX12ExtendedAllocationSupportedDirectGPUUpload(DX12ExtendedAllocation self, WisDataFormat format)
{
auto* xself = reinterpret_cast<wis::DX12ExtendedAllocation*>(self);
auto res = xself->SupportedDirectGPUUpload(static_cast<wis::DataFormat>(format));
;
return res;
}
#endif

#if defined(WISDOM_VULKAN)
Expand Down Expand Up @@ -150,6 +193,10 @@ template<>
struct VKDeviceExtensionMap<wis::DeviceExtID::DescriptorBufferExtension> {
using Type = wis::VKDescriptorBufferExtension;
};
template<>
struct VKDeviceExtensionMap<wis::DeviceExtID::ExtendedAllocation> {
using Type = wis::VKExtendedAllocation;
};
//-------------------------------------------------------------------------

template<template<typename T> typename Executor, typename... Args>
Expand All @@ -158,6 +205,8 @@ constexpr static inline decltype(auto) VKDeviceExtensionBridge(wis::DeviceExtID
switch (id) {
case wis::DeviceExtID::DescriptorBufferExtension:
return Executor<typename VKDeviceExtensionMap<wis::DeviceExtID::DescriptorBufferExtension>::Type>{}(std::forward<Args>(args)...);
case wis::DeviceExtID::ExtendedAllocation:
return Executor<typename VKDeviceExtensionMap<wis::DeviceExtID::ExtendedAllocation>::Type>{}(std::forward<Args>(args)...);
default:
return Executor<wis::VKDeviceExtension>{}(std::forward<Args>(args)...);
}
Expand All @@ -168,12 +217,14 @@ extern "C" WisResult VKDebugExtensionCreateDebugMessenger(VKDebugExtension self,
auto* xself = reinterpret_cast<wis::VKDebugExtension*>(self);
auto&& [res, value] = xself->CreateDebugMessenger(reinterpret_cast<wis::DebugCallback>(callback), user_data);

if (res.status != wis::Status::Ok)
if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*messenger = reinterpret_cast<VKDebugMessenger>(new (std::nothrow) wis::VKDebugMessenger(std::move(value)));
if (!*messenger)
if (!*messenger) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::VKDebugMessenger." };
}
return reinterpret_cast<WisResult&>(res);
}
// VKDescriptorBufferExtension methods --
Expand All @@ -182,25 +233,29 @@ extern "C" WisResult VKDescriptorBufferExtensionCreateRootSignature(VKDescriptor
auto* xself = reinterpret_cast<wis::VKDescriptorBufferExtension*>(self);
auto&& [res, value] = xself->CreateRootSignature(reinterpret_cast<const wis::PushConstant*&>(root_constants), constants_count, reinterpret_cast<const wis::PushDescriptor*&>(root_descriptors), descriptors_count, reinterpret_cast<const wis::DescriptorTable*&>(tables), tables_count);

if (res.status != wis::Status::Ok)
if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*signature = reinterpret_cast<VKRootSignature>(new (std::nothrow) wis::VKRootSignature(std::move(value)));
if (!*signature)
if (!*signature) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::VKRootSignature." };
}
return reinterpret_cast<WisResult&>(res);
}
extern "C" WisResult VKDescriptorBufferExtensionCreateDescriptorBuffer(VKDescriptorBufferExtension self, WisDescriptorHeapType type, WisDescriptorMemory memory, uint64_t memory_bytes, VKDescriptorBuffer* buffer)
{
auto* xself = reinterpret_cast<wis::VKDescriptorBufferExtension*>(self);
auto&& [res, value] = xself->CreateDescriptorBuffer(static_cast<wis::DescriptorHeapType>(type), static_cast<wis::DescriptorMemory>(memory), memory_bytes);

if (res.status != wis::Status::Ok)
if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*buffer = reinterpret_cast<VKDescriptorBuffer>(new (std::nothrow) wis::VKDescriptorBuffer(std::move(value)));
if (!*buffer)
if (!*buffer) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::VKDescriptorBuffer." };
}
return reinterpret_cast<WisResult&>(res);
}
extern "C" uint64_t VKDescriptorBufferExtensionGetDescriptorTableAlignment(VKDescriptorBufferExtension self, WisDescriptorHeapType type)
Expand All @@ -227,4 +282,34 @@ extern "C" void VKDescriptorBufferExtensionSetDescriptorTableOffset(VKDescriptor
auto* xself = reinterpret_cast<wis::VKDescriptorBufferExtension*>(self);
xself->SetDescriptorTableOffset(*reinterpret_cast<wis::VKCommandList*>(list), *reinterpret_cast<wis::VKRootSignature*>(root_signature), table_index, *reinterpret_cast<wis::VKDescriptorBuffer*>(buffer), table_aligned_byte_offset);
}
// VKExtendedAllocation methods --
extern "C" WisResult VKExtendedAllocationCreateGPUUploadTexture(VKExtendedAllocation self, const VKResourceAllocator* allocator, const WisTextureDesc* desc, WisTextureState initial_state, WisMemoryFlags flags, VKTexture* texture)
{
auto* xself = reinterpret_cast<wis::VKExtendedAllocation*>(self);
auto&& [res, value] = xself->CreateGPUUploadTexture(*reinterpret_cast<const wis::VKResourceAllocator*>(allocator), *reinterpret_cast<const wis::TextureDesc*>(desc), static_cast<wis::TextureState>(initial_state), static_cast<wis::MemoryFlags>(flags));

if (res.status != wis::Status::Ok) {
return reinterpret_cast<WisResult&>(res);
}

*texture = reinterpret_cast<VKTexture>(new (std::nothrow) wis::VKTexture(std::move(value)));
if (!*texture) {
return WisResult{ StatusOutOfMemory, "Failed to allocate memory for wis::VKTexture." };
}
return reinterpret_cast<WisResult&>(res);
}
extern "C" WisResult VKExtendedAllocationWriteMemoryToSubresourceDirect(VKExtendedAllocation self, const void* host_data, VKTexture dst_texture, WisTextureState initial_state, WisTextureRegion region)
{
auto* xself = reinterpret_cast<wis::VKExtendedAllocation*>(self);
auto res = xself->WriteMemoryToSubresourceDirect(host_data, *reinterpret_cast<wis::VKTexture*>(dst_texture), static_cast<wis::TextureState>(initial_state), reinterpret_cast<wis::TextureRegion&>(region));
;
return reinterpret_cast<WisResult&>(res);
}
extern "C" bool VKExtendedAllocationSupportedDirectGPUUpload(VKExtendedAllocation self, WisDataFormat format)
{
auto* xself = reinterpret_cast<wis::VKExtendedAllocation*>(self);
auto res = xself->SupportedDirectGPUUpload(static_cast<wis::DataFormat>(format));
;
return res;
}
#endif
14 changes: 9 additions & 5 deletions examples/basic/descriptor_storage/entry_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class App
App()
: window("Descriptor Storage", 800, 600)
{
wis::Result result = wis::success;

setup.InitDefault(window.GetPlatformExtension());
auto [w, h] = window.PixelSize();
auto swapx = window.CreateSwapchain(setup);
auto swapx = window.CreateSwapchain(result, setup);
std::construct_at(&swap, setup.device, std::move(swapx), w, h);
cmd_list = setup.CreateLists();

Expand All @@ -46,16 +48,17 @@ class App
.cbuffer_count = ex::flight_frames * 2, // one cbuffer per frame
.memory = wis::DescriptorMemory::ShaderVisible, // visible to shaders
};
desc_storage = ex::Unwrap(setup.device.CreateDescriptorStorage(desc));
desc_storage = setup.device.CreateDescriptorStorage(result, desc);
}

public:
void Run()
{
CreateResources();
while (true) {
if (!ProcessEvents())
if (!ProcessEvents()) {
break;
}

Frame();
}
Expand Down Expand Up @@ -97,8 +100,9 @@ class App
offsetx += 0.01f;
if (offsetx > 1.0f) {
offsety += 0.5f;
if (offsety > 1.0f)
if (offsety > 1.0f) {
offsety = -1.0f;
}
offsetx = -1.0f;
}

Expand Down Expand Up @@ -210,7 +214,7 @@ class App
.attachments_count = 1,
},
};
pipeline = ex::Unwrap(setup.device.CreateGraphicsPipeline(&desc));
pipeline = ex::Unwrap(setup.device.CreateGraphicsPipeline(desc));
}

// Create vertex buffer
Expand Down
Loading

0 comments on commit 8823a44

Please sign in to comment.