Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
cdf867d
add operator= for glm:: matrices corresponding to our at home matrice…
AnastaZIuk Oct 25, 2024
6ef4f89
I'm stupid, I have explicit at home matrix constructor taking glm:: m…
AnastaZIuk Oct 25, 2024
22f505c
steal include/nbl/builtin/hlsl/matrix_utils/transformation_matrix_uti…
AnastaZIuk Oct 25, 2024
51f4ced
fix getMatrix3x4As4x4 (return type issues) & buildCameraLookAtMatrixR…
AnastaZIuk Oct 25, 2024
7f2c085
update examples_tests submodule
AnastaZIuk Oct 25, 2024
f1daa25
actually *this* addresses https://github.com/Devsh-Graphics-Programmi…
AnastaZIuk Oct 25, 2024
2192e99
update examples_tests submodule
AnastaZIuk Oct 25, 2024
520b1f5
update examples_tests submodule
AnastaZIuk Oct 28, 2024
a0890f0
forgot to commit projection build methods, update examples_tests subm…
AnastaZIuk Nov 2, 2024
0109b22
add is_smart_refctd_ptr_v, update examples_tests submodule
AnastaZIuk Nov 2, 2024
2a29a2f
update examples_tests submodule
AnastaZIuk Nov 3, 2024
7673769
update examples_tests submodule
AnastaZIuk Nov 3, 2024
fc7bc33
pull master & resolve conflicts
AnastaZIuk Nov 4, 2024
8fc4f89
pull mastrer & resolve conflicts
AnastaZIuk Nov 6, 2024
9a139df
update examples_tests submodule
AnastaZIuk Nov 6, 2024
24a80c9
create ui::E_MOUSE_CODE & constexpr ui::mouseCodeToString - we really…
AnastaZIuk Nov 8, 2024
03fa2ca
pull master & resolve conflicts
AnastaZIuk Nov 11, 2024
21b89b4
@alichraghi small homework - read https://en.cppreference.com/w/cpp/l…
AnastaZIuk Nov 11, 2024
68bc7be
update examples_tests submodule
AnastaZIuk Nov 12, 2024
866e844
update examples_tests submodule
AnastaZIuk Nov 15, 2024
8bd6436
update examples_tests submodule
AnastaZIuk Nov 15, 2024
de69afe
update examples_tests submodule
AnastaZIuk Nov 18, 2024
a55bd39
update imguizmo with its upstream
AnastaZIuk Nov 18, 2024
6f3c5fc
update examples_tests submodule
AnastaZIuk Nov 18, 2024
0d126df
update examples_tests submodule
AnastaZIuk Dec 2, 2024
31e85e7
update examples_tests submodule
AnastaZIuk Dec 2, 2024
08f11f6
update examples_tests submodule
AnastaZIuk Dec 3, 2024
5bcd6ef
add getCastedMatrix & getCastedVector, update examples_tests submodule
AnastaZIuk Dec 12, 2024
5a07fe7
update examples_tests submodule
AnastaZIuk Dec 13, 2024
f55b268
update examples_tests submodule
AnastaZIuk Dec 13, 2024
01f909a
add examples_tests submodule
AnastaZIuk Dec 13, 2024
ab90d33
update examples_tests submodule
AnastaZIuk Dec 13, 2024
c9f0960
update examples_tests submodule
AnastaZIuk Dec 14, 2024
3727ae3
update examples_tests submodule
AnastaZIuk Dec 14, 2024
e9f78a2
update examples_tests submodule
AnastaZIuk Dec 14, 2024
33f8d01
add constexpr stringToKeyCode & stringToMouseCode
AnastaZIuk Dec 16, 2024
b3d7710
update examples_tests submodule
AnastaZIuk Dec 17, 2024
53f72ec
update examples_tests submodule
AnastaZIuk Dec 18, 2024
e3d282b
update examples_tests submodule
AnastaZIuk Dec 19, 2024
5124136
update examples_tests submodule
AnastaZIuk Dec 19, 2024
fb2ce01
update examples_tests submodule
AnastaZIuk Dec 20, 2024
7ce37ba
update examples_tests submodule
AnastaZIuk Dec 20, 2024
406fef8
update examples_tests submodule
AnastaZIuk Dec 21, 2024
661dae9
update examples_tests submodule
AnastaZIuk Dec 21, 2024
183a8fd
update examples_tests submodule
AnastaZIuk Dec 22, 2024
a30c409
update examples_tests submodule
AnastaZIuk Dec 22, 2024
5f033af
update examples_tests submodule
AnastaZIuk Dec 23, 2024
0529f8a
update examples_tests submodule
AnastaZIuk Dec 23, 2024
74b8c11
update examples_tests submodule
AnastaZIuk Dec 23, 2024
2fdf296
update examples_tests submodule
AnastaZIuk Dec 23, 2024
3b68444
update examples_tests submodule
AnastaZIuk Dec 30, 2024
b21de61
pull master & resolve conflicts
AnastaZIuk Jan 24, 2025
2693caf
update examples_tests submodule
AnastaZIuk Jan 24, 2025
ae315a0
a comment for glslFunctions, update examples_tests submodule
AnastaZIuk Jan 24, 2025
07eeef7
small temporary updates to transformation_matrix_utils.hlsl, update e…
AnastaZIuk Jan 31, 2025
15aa72f
introduce reference frame concept to imguizmo - commit submodule update
AnastaZIuk Feb 2, 2025
661f999
update examples_tests submodule
AnastaZIuk Feb 2, 2025
db1102c
update examples_tests submodule
AnastaZIuk Feb 6, 2025
329d98f
pull master & resolve conflicts
AnastaZIuk Feb 17, 2025
52901f2
pull master, resolve conflicts
AnastaZIuk Jan 13, 2026
ba3d7a0
adjust to code, precompile remaining runtime shaders
AnastaZIuk Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3rdparty/imguizmo
Submodule imguizmo updated 2 files
+219 −0 ImGuizmo.cpp
+9 −0 ImGuizmo.h
8 changes: 2 additions & 6 deletions include/nbl/builtin/hlsl/algorithm.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,16 @@ namespace impl
rhs ^= lhs;
lhs ^= rhs;
}
#else
template<typename T>
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
{
std::swap(lhs, rhs);
}
#endif
}

#ifdef __HLSL_VERSION
template<typename T>
NBL_CONSTEXPR_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
{
impl::swap<T>(lhs, rhs);
}
#endif


namespace impl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ namespace nbl
{
namespace hlsl
{
//TODO: stolen from cameraz branch, don't have epsilonEqual here, maybe uncomment when merging from imguizmo-lights branch
//// TODO: -> move somewhere else and nbl:: to implement it
//template<typename T, typename E = double>
//bool isOrthoBase(const T& x, const T& y, const T& z, const E epsilon = 1e-6)
//{
// auto isNormalized = [](const auto& v, const auto& epsilon) -> bool
// {
// return glm::epsilonEqual(glm::length(v), 1.0, epsilon);
// };
//
// auto isOrthogonal = [](const auto& a, const auto& b, const auto& epsilon) -> bool
// {
// return glm::epsilonEqual(glm::dot(a, b), 0.0, epsilon);
// };
//
// return isNormalized(x, epsilon) && isNormalized(y, epsilon) && isNormalized(z, epsilon) &&
// isOrthogonal(x, y, epsilon) && isOrthogonal(x, z, epsilon) && isOrthogonal(y, z, epsilon);
//}
//// <-

// TODO: -> move somewhere else and nbl:: to implement it
template<typename T, typename E = double>
bool isOrthoBase(const T& x, const T& y, const T& z, const E epsilon = 1e-6)
{
auto isNormalized = [](const auto& v, const auto& epsilon) -> bool
{
return glm::epsilonEqual(glm::length(v), 1.0, epsilon);
};

auto isOrthogonal = [](const auto& a, const auto& b, const auto& epsilon) -> bool
{
return glm::epsilonEqual(glm::dot(a, b), 0.0, epsilon);
};

return isNormalized(x, epsilon) && isNormalized(y, epsilon) && isNormalized(z, epsilon) &&
isOrthogonal(x, y, epsilon) && isOrthogonal(x, z, epsilon) && isOrthogonal(y, z, epsilon);
}
// <-

template<typename T>
matrix<T, 4, 4> getMatrix3x4As4x4(const matrix<T, 3, 4>& mat)
Expand Down
9 changes: 9 additions & 0 deletions include/nbl/core/decl/smart_refctd_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ smart_refctd_ptr<U> move_and_dynamic_cast(smart_refctd_ptr<T>& smart_ptr);
template< class U, class T >
smart_refctd_ptr<U> move_and_dynamic_cast(smart_refctd_ptr<T>&& smart_ptr) {return move_and_dynamic_cast<U,T>(smart_ptr);}

template<typename>
struct is_smart_refctd_ptr : std::false_type {};

template<typename T>
struct is_smart_refctd_ptr<smart_refctd_ptr<T>> : std::true_type {};

template<typename T>
inline constexpr bool is_smart_refctd_ptr_v = is_smart_refctd_ptr<T>::value;

} // end namespace nbl::core

/*
Expand Down
2 changes: 2 additions & 0 deletions include/nbl/core/math/glslFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ NBL_FORCE_INLINE vectorSIMDf cross<vectorSIMDf>(const vectorSIMDf& a, const vect
template<typename T>
NBL_FORCE_INLINE T normalize(const T& v)
{
// TODO: THIS CREATES AMGIGUITY WITH GLM:: NAMESPACE!
auto d = dot<T>(v, v);
#ifdef __NBL_FAST_MATH
return v * core::inversesqrt<T>(d);
Expand All @@ -371,6 +372,7 @@ NBL_FORCE_INLINE T normalize(const T& v)
}

// TODO : matrixCompMult, outerProduct, inverse
// Arek: old and to be killed (missing .tcc include?), no definition in Nabla causing linker errors
template<typename T>
NBL_FORCE_INLINE T transpose(const T& m);
template<>
Expand Down
9 changes: 9 additions & 0 deletions include/nbl/ext/ImGui/ImGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ class UI final : public core::IReferenceCounted

//! optional, no cache used if not provided
core::smart_refctd_ptr<video::IGPUPipelineCache> pipelineCache = nullptr;

struct PrecompiledShaders
{
core::smart_refctd_ptr<asset::IShader> vertex = nullptr;
core::smart_refctd_ptr<asset::IShader> fragment = nullptr;
};

//! optional, precompiled spirv shaders
std::optional<PrecompiledShaders> spirv = std::nullopt;
};

//! parameters which may change every frame, used with the .update call to interact with ImGuiIO; we require a very *required* minimum - if you need to cover more IO options simply get the IO with ImGui::GetIO() to customize them (they all have default values you can change before calling the .update)
Expand Down
136 changes: 126 additions & 10 deletions include/nbl/ext/ScreenShot/ScreenShot.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,59 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
const ACCESS_FLAGS accessMask,
const IImage::LAYOUT imageLayout)
{
assert(bool(logicalDevice->getPhysicalDevice()->getQueueFamilyProperties().begin()[queue->getFamilyIndex()].queueFlags.value & IQueue::FAMILY_FLAGS::TRANSFER_BIT));
{
const auto queueFlags = logicalDevice->getPhysicalDevice()->getQueueFamilyProperties().begin()[queue->getFamilyIndex()].queueFlags;
const auto required = core::bitflag<IQueue::FAMILY_FLAGS>(IQueue::FAMILY_FLAGS::TRANSFER_BIT) | IQueue::FAMILY_FLAGS::GRAPHICS_BIT | IQueue::FAMILY_FLAGS::COMPUTE_BIT;
if (!queueFlags.hasAnyFlag(required))
logicalDevice->getLogger()->log("ScreenShot: queue family %u lacks transfer/graphics/compute flags; continuing anyway.", system::ILogger::ELL_WARNING, queue->getFamilyIndex());
}

auto fetchedImageViewParmas = gpuImageView->getCreationParameters();
auto gpuImage = fetchedImageViewParmas.image;
auto fetchedGpuImageParams = gpuImage->getCreationParameters();

if(!fetchedGpuImageParams.usage.hasFlags(IImage::EUF_TRANSFER_SRC_BIT))
{
assert(false);
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: source image missing TRANSFER_SRC usage.", system::ILogger::ELL_ERROR);
return nullptr;
}

if (isBlockCompressionFormat(fetchedGpuImageParams.format))
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: block-compressed formats are not supported.", system::ILogger::ELL_ERROR);
return nullptr;
}

core::smart_refctd_ptr<IGPUBuffer> gpuTexelBuffer;

core::smart_refctd_ptr<IGPUCommandBuffer> gpuCommandBuffer;
{
// commandbuffer should refcount the pool, so it should be 100% legal to drop at the end of the scope
auto gpuCommandPool = logicalDevice->createCommandPool(queue->getFamilyIndex(),IGPUCommandPool::CREATE_FLAGS::TRANSIENT_BIT);
if (!gpuCommandPool)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to create command pool.", system::ILogger::ELL_ERROR);
return nullptr;
}
gpuCommandPool->createCommandBuffers(IGPUCommandPool::BUFFER_LEVEL::PRIMARY, 1u, &gpuCommandBuffer);
assert(gpuCommandBuffer);
if (!gpuCommandBuffer)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to create command buffer.", system::ILogger::ELL_ERROR);
return nullptr;
}
}
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: recording command buffer.", system::ILogger::ELL_INFO);
if (!gpuCommandBuffer->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT))
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to begin command buffer.", system::ILogger::ELL_ERROR);
return nullptr;
}
gpuCommandBuffer->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
{
auto extent = gpuImage->getMipSize();

Expand All @@ -68,9 +96,27 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
bufferCreationParams.size = extent.x*extent.y*extent.z*getTexelOrBlockBytesize(fetchedGpuImageParams.format);
bufferCreationParams.usage = IBuffer::EUF_TRANSFER_DST_BIT;
gpuTexelBuffer = logicalDevice->createBuffer(std::move(bufferCreationParams));
if (!gpuTexelBuffer)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to create GPU texel buffer.", system::ILogger::ELL_ERROR);
return nullptr;
}
auto gpuTexelBufferMemReqs = gpuTexelBuffer->getMemoryReqs();
gpuTexelBufferMemReqs.memoryTypeBits &= logicalDevice->getPhysicalDevice()->getDownStreamingMemoryTypeBits();
if (!gpuTexelBufferMemReqs.memoryTypeBits)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: no down-streaming memory type for texel buffer.", system::ILogger::ELL_ERROR);
return nullptr;
}
auto gpuTexelBufferMem = logicalDevice->allocate(gpuTexelBufferMemReqs, gpuTexelBuffer.get());
if (!gpuTexelBufferMem.isValid())
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to allocate texel buffer memory.", system::ILogger::ELL_ERROR);
return nullptr;
}

IGPUCommandBuffer::SPipelineBarrierDependencyInfo info = {};
decltype(info)::image_barrier_t barrier = {};
Expand Down Expand Up @@ -102,7 +148,12 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
gpuCommandBuffer->pipelineBarrier(EDF_NONE,info);
}
}
gpuCommandBuffer->end();
if (!gpuCommandBuffer->end())
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to end command buffer.", system::ILogger::ELL_ERROR);
return nullptr;
}

auto signalSemaphore = logicalDevice->createSemaphore(0);

Expand All @@ -124,22 +175,63 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
info.waitSemaphores = { &waitSemaphoreInfo, &waitSemaphoreInfo + 1 };
}

queue->submit({ &info, &info + 1});
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: submitting copy command buffer.", system::ILogger::ELL_INFO);
if (queue->submit({ &info, &info + 1}) != IQueue::RESULT::SUCCESS)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to submit copy command buffer.", system::ILogger::ELL_ERROR);
return nullptr;
}

ISemaphore::SWaitInfo waitInfo{ signalSemaphore.get(), 1u};

if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: waiting for copy completion.", system::ILogger::ELL_INFO);
if (logicalDevice->blockForSemaphores({&waitInfo, &waitInfo + 1}) != ISemaphore::WAIT_RESULT::SUCCESS)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to wait for copy completion.", system::ILogger::ELL_ERROR);
return nullptr;
}

core::smart_refctd_ptr<ICPUImageView> cpuImageView;
{
const auto gpuTexelBufferSize = gpuTexelBuffer->getSize(); // If you get validation errors from the `invalidateMappedMemoryRanges` we need to expose VK_WHOLE_BUFFER equivalent constant
ILogicalDevice::MappedMemoryRange mappedMemoryRange(gpuTexelBuffer->getBoundMemory().memory,0u,gpuTexelBufferSize);
auto* allocation = gpuTexelBuffer->getBoundMemory().memory;
if (!allocation)
return nullptr;

if (gpuTexelBuffer->getBoundMemory().memory->haveToMakeVisible())
bool mappedHere = false;
if (!allocation->getMappedPointer())
{
const IDeviceMemoryAllocation::MemoryRange range = { 0u, gpuTexelBufferSize };
if (!allocation->map(range, IDeviceMemoryAllocation::EMCAF_READ))
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to map texel buffer memory.", system::ILogger::ELL_ERROR);
return nullptr;
}
mappedHere = true;
}

ILogicalDevice::MappedMemoryRange mappedMemoryRange(allocation,0u,gpuTexelBufferSize);
if (allocation->haveToMakeVisible())
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: invalidating mapped range.", system::ILogger::ELL_INFO);
logicalDevice->invalidateMappedMemoryRanges(1u,&mappedMemoryRange);
}

auto cpuNewImage = ICPUImage::create(std::move(fetchedGpuImageParams));
if (!cpuNewImage)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to create CPU image.", system::ILogger::ELL_ERROR);
if (mappedHere)
allocation->unmap();
return nullptr;
}

auto regions = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUImage::SBufferCopy>>(1u);
ICPUImage::SBufferCopy& region = regions->front();
Expand All @@ -155,10 +247,22 @@ inline core::smart_refctd_ptr<ICPUImageView> createScreenShot(
region.imageExtent = cpuNewImage->getCreationParameters().extent;

auto cpuNewTexelBuffer = ICPUBuffer::create({ gpuTexelBufferSize });
if (!cpuNewTexelBuffer)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: failed to create CPU buffer.", system::ILogger::ELL_ERROR);
if (mappedHere)
allocation->unmap();
return nullptr;
}
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: copying GPU data to CPU buffer.", system::ILogger::ELL_INFO);
{
memcpy(cpuNewTexelBuffer->getPointer(), gpuTexelBuffer->getBoundMemory().memory->getMappedPointer(), gpuTexelBuffer->getSize());
memcpy(cpuNewTexelBuffer->getPointer(), allocation->getMappedPointer(), gpuTexelBuffer->getSize());
}
cpuNewImage->setBufferAndRegions(core::smart_refctd_ptr(cpuNewTexelBuffer), regions);
if (mappedHere)
allocation->unmap();
{
auto newCreationParams = cpuNewImage->getCreationParameters();

Expand Down Expand Up @@ -190,6 +294,12 @@ inline bool createScreenShot(
{
assert(outFile->getFlags()&system::IFile::ECF_WRITE);
auto cpuImageView = createScreenShot(logicalDevice,queue,semaphore,gpuImageView,accessMask,imageLayout);
if (!cpuImageView)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: GPU readback failed, no image to write.", system::ILogger::ELL_ERROR);
return false;
}
IAssetWriter::SAssetWriteParams writeParams(cpuImageView.get());
return assetManager->writeAsset(outFile,writeParams);
}
Expand All @@ -205,11 +315,17 @@ inline bool createScreenShot(
const ACCESS_FLAGS accessMask = ACCESS_FLAGS::MEMORY_WRITE_BITS)
{
auto cpuImageView = createScreenShot(logicalDevice,queue,semaphore,gpuImageView,accessMask,imageLayout);
if (!cpuImageView)
{
if (auto* logger = logicalDevice->getLogger())
logger->log("ScreenShot: GPU readback failed, no image to write.", system::ILogger::ELL_ERROR);
return false;
}
IAssetWriter::SAssetWriteParams writeParams(cpuImageView.get());
return assetManager->writeAsset(filename.string(),writeParams); // TODO: Use std::filesystem::path
}


} // namespace nbl::ext::ScreenShot

#endif
#endif
Loading
Loading