Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pablode committed Jul 29, 2024
1 parent cc14570 commit ab4a5be
Show file tree
Hide file tree
Showing 44 changed files with 247 additions and 121 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Validation Build

on:
push:
branches:
- 'master'
- 'dev'
# branches:
# - 'master'
# - 'dev'
paths-ignore:
- '**.md'
- '**.glsl'
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

include(CMakeDependentOption)

Expand All @@ -22,7 +22,8 @@ foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_TYPE} ${OUTPUT_DIR})
endforeach()

option(GATLING_BUILD_HDGATLING "Build the gatling hydra render delegate." ON)
option(GTL_BUILD_HDGATLING "Build the gatling hydra render delegate." ON)
option(GTL_VERBOSE "Enable verbose logging." OFF)

if(${GATLING_BUILD_HDGATLING})
find_package(USD REQUIRED HINTS ${USD_ROOT} NAMES pxr)
Expand Down
17 changes: 17 additions & 0 deletions cmake/BuildConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Choose the type of buil

# Append list of configs for multi-output generators like VS
list(APPEND CMAKE_CONFIGURATION_TYPES "Develop")


# TODO: define GTL_COMPILE_OPTIONS that is then manually set for each target
# TODO: define GTL_LINK_OPTIONS -> target_link_options (CMake 3.13). e.g. warnings as errors?
if(MSVC)
set(GTL_COMPILE_OPTIONS "")#"/Wall")
# Disable "not enough arguments for function-like macro invocation" warning caused
# by the transitive inclusion of boost headers and non-conformant MSVC preprocessor
# behaviour. See USD's msvcdefaults.cmake file for a detailed comment.
set(GTL_COMPILE_OPTIONS "${GTL_COMPILE_OPTIONS}" "/wd4003")
else()
set(GTL_COMPILE_OPTIONS "-Wall" "-Wextra" "-Wformat-security")
endif()

# TODO: for headers, either use a #pragma OR in case of USD/pxr, add to the target additionally


1 change: 1 addition & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ set(OPENEXR_INSTALL OFF)
set(OPENEXR_INSTALL_TOOLS OFF)
set(OPENEXR_INSTALL_EXAMPLES OFF)
add_subdirectory(openexr)
target_compile_options(OpenEXR PRIVATE "-Wno-#warnings")

#
# stb
Expand Down
2 changes: 1 addition & 1 deletion extern/efsw
Submodule efsw updated 43 files
+170 −0 .ecode/project_build.json
+5 −0 .gitignore
+20 −26 CMakeLists.txt
+4 −0 README.md
+16 −0 compile_flags.txt
+3 −0 efswConfig.cmake.in
+33 −4 include/efsw/efsw.h
+52 −5 include/efsw/efsw.hpp
+2 −7 premake4.lua
+1 −6 premake5.lua
+1 −1 project/qtcreator-linux/efsw.cflags
+29 −20 project/qtcreator-linux/efsw.creator.user
+1 −1 project/qtcreator-linux/efsw.cxxflags
+0 −18 src/efsw/Atomic.hpp
+2 −2 src/efsw/DirectorySnapshot.cpp
+3 −3 src/efsw/FileInfo.hpp
+24 −6 src/efsw/FileSystem.cpp
+8 −7 src/efsw/FileWatcher.cpp
+19 −1 src/efsw/FileWatcherCWrapper.cpp
+7 −66 src/efsw/FileWatcherFSEvents.cpp
+9 −21 src/efsw/FileWatcherFSEvents.hpp
+5 −3 src/efsw/FileWatcherGeneric.cpp
+10 −9 src/efsw/FileWatcherGeneric.hpp
+11 −0 src/efsw/FileWatcherImpl.cpp
+9 −2 src/efsw/FileWatcherImpl.hpp
+32 −77 src/efsw/FileWatcherInotify.cpp
+11 −7 src/efsw/FileWatcherInotify.hpp
+5 −3 src/efsw/FileWatcherKqueue.cpp
+9 −8 src/efsw/FileWatcherKqueue.hpp
+13 −8 src/efsw/FileWatcherWin32.cpp
+8 −7 src/efsw/FileWatcherWin32.hpp
+17 −2 src/efsw/Log.cpp
+10 −18 src/efsw/WatcherFSEvents.cpp
+0 −4 src/efsw/WatcherFSEvents.hpp
+1 −1 src/efsw/WatcherGeneric.hpp
+0 −4 src/efsw/WatcherInotify.cpp
+0 −3 src/efsw/WatcherInotify.hpp
+4 −8 src/efsw/WatcherKqueue.cpp
+1 −1 src/efsw/WatcherKqueue.hpp
+27 −9 src/efsw/WatcherWin32.cpp
+9 −9 src/efsw/WatcherWin32.hpp
+164 −0 src/test/efsw-test.c
+2 −1 src/test/efsw-test.cpp
6 changes: 6 additions & 0 deletions src/cgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ target_link_libraries(
spirv-reflect-static
)

target_compile_options(
cgpu
PRIVATE
${GTL_COMPILE_OPTIONS}
)

set_target_properties(
cgpu
PROPERTIES
Expand Down
37 changes: 23 additions & 14 deletions src/cgpu/impl/Cgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@

#include <volk.h>

#include <gtl/gb/Fmt.h>
#include <gtl/gb/Log.h>

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
// Silence nullability log spam on AppleClang
#pragma clang diagnostic ignored "-Wnullability-completeness"
#endif

// Uncomment for VMA debug logging
//#define VMA_DEBUG_LOG_FORMAT(format, ...) do { \
// fprintf(stderr, (format), __VA_ARGS__); \
// fprintf(stderr, "\n"); \
// GB_LOG((format), __VA_ARGS__); \
// } while (false)
#ifdef GTL_VERBOSE
#define VMA_DEBUG_LOG_FORMAT(format, ...) do { \
GB_DEBUG_DYN("[VMA] {}", GB_FMT_SPRINTF((format), __VA_ARGS__)); \
} while (false)
#endif

#define VMA_IMPLEMENTATION
#include <vk_mem_alloc.h>
Expand Down Expand Up @@ -373,6 +378,7 @@ namespace gtl

/* API method implementation. */

#ifndef NDEBUG
static bool cgpuFindLayer(const char* name, size_t layerCount, VkLayerProperties* layers)
{
for (size_t i = 0; i < layerCount; i++)
Expand All @@ -384,6 +390,7 @@ namespace gtl
}
return false;
}
#endif

static bool cgpuFindExtension(const char* name, size_t extensionCount, VkExtensionProperties* extensions)
{
Expand All @@ -407,7 +414,7 @@ namespace gtl
.pObjectName = name
};

VkResult result = vkSetDebugUtilsObjectNameEXT(device, &info);
[[maybe_unused]] VkResult result = vkSetDebugUtilsObjectNameEXT(device, &info);

assert(result == VK_SUCCESS);
}
Expand Down Expand Up @@ -689,7 +696,7 @@ namespace gtl
GbSmallVector<VkQueueFamilyProperties, 32> queueFamilies(queueFamilyCount);
vkGetPhysicalDeviceQueueFamilyProperties(idevice->physicalDevice, &queueFamilyCount, queueFamilies.data());

int32_t queueFamilyIndex = -1;
uint32_t queueFamilyIndex = UINT32_MAX;
for (uint32_t i = 0; i < queueFamilyCount; ++i)
{
const VkQueueFamilyProperties* queue_family = &queueFamilies[i];
Expand All @@ -699,7 +706,7 @@ namespace gtl
queueFamilyIndex = i;
}
}
if (queueFamilyIndex == -1)
if (queueFamilyIndex == UINT32_MAX)
{
iinstance->ideviceStore.free(handle);
CGPU_RETURN_ERROR("no suitable queue family");
Expand Down Expand Up @@ -945,7 +952,7 @@ namespace gtl
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = nullptr,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = (uint32_t) queueFamilyIndex,
.queueFamilyIndex = queueFamilyIndex,
};

result = idevice->table.vkCreateCommandPool(
Expand Down Expand Up @@ -1941,7 +1948,7 @@ namespace gtl

for (uint32_t i = 0; i < groups.size(); i++)
{
VkRayTracingShaderGroupCreateInfoKHR createInfo = {
VkRayTracingShaderGroupCreateInfoKHR sgCreateInfo = {
.sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR,
.pNext = nullptr,
.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR,
Expand All @@ -1951,7 +1958,8 @@ namespace gtl
.intersectionShader = VK_SHADER_UNUSED_KHR,
.pShaderGroupCaptureReplayHandle = nullptr,
};
groups[i] = createInfo;

groups[i] = sgCreateInfo;
}

bool anyNullClosestHitShader = false;
Expand Down Expand Up @@ -2257,7 +2265,7 @@ namespace gtl
.pNext = nullptr,
.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR,
.geometry = asGeomData,
.flags = createInfo.isOpaque ? VK_GEOMETRY_OPAQUE_BIT_KHR : VkGeometryFlagsKHR(0),
.flags = VkGeometryFlagsKHR(createInfo.isOpaque ? VK_GEOMETRY_OPAQUE_BIT_KHR : 0)
};

bool creationSuccessul = cgpuCreateTopOrBottomAs(device, VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR,
Expand Down Expand Up @@ -2366,7 +2374,7 @@ namespace gtl
}
},
},
.flags = areAllBlasOpaque ? VK_GEOMETRY_OPAQUE_BIT_KHR : VkGeometryFlagsKHR(0),
.flags = VkGeometryFlagsKHR(areAllBlasOpaque ? VK_GEOMETRY_OPAQUE_BIT_KHR : 0)
};

if (!cgpuCreateTopOrBottomAs(device, VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR, &asGeom, createInfo.instanceCount, &itlas->buffer, &itlas->as))
Expand Down Expand Up @@ -3322,6 +3330,7 @@ namespace gtl
VkSubmitInfo2KHR submitInfo = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2_KHR,
.pNext = nullptr,
.flags = 0,
.waitSemaphoreInfoCount = (uint32_t) waitSubmitInfos.size(),
.pWaitSemaphoreInfos = waitSubmitInfos.data(),
.commandBufferInfoCount = 1,
Expand Down
10 changes: 10 additions & 0 deletions src/gb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,15 @@ target_link_libraries(
quill
)

target_compile_options(
gb
PRIVATE
${GTL_COMPILE_OPTIONS}
)

if(GTL_VERBOSE)
target_compile_definitions(gb PUBLIC GTL_VERBOSE=1)
endif()

# Required since library is linked into hdGatling DSO
set_target_properties(gb PROPERTIES POSITION_INDEPENDENT_CODE ON)
2 changes: 2 additions & 0 deletions src/gb/gtl/gb/Fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
#pragma once

#include <quill/bundled/fmt/format.h>
#include <quill/bundled/fmt/printf.h>

#define GB_FMT(fmt, ...) fmtquill::format(fmt, __VA_ARGS__)
#define GB_FMT_SPRINTF(fmt, ...) fmtquill::sprintf(fmt, __VA_ARGS__)
6 changes: 4 additions & 2 deletions src/gb/gtl/gb/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
#include <quill/std/UnorderedSet.h>
#include <quill/std/Vector.h>

#define GB_LOG(fmt, ...) QUILL_LOG_INFO(gtl::gbGetLogger(), fmt, ##__VA_ARGS__)
#define GB_WARN(fmt, ...) QUILL_LOG_WARNING(gtl::gbGetLogger(), fmt, ##__VA_ARGS__)
#define GB_ERROR(fmt, ...) QUILL_LOG_ERROR(gtl::gbGetLogger(), fmt, ##__VA_ARGS__)
#define GB_WARN(fmt, ...) QUILL_LOG_WARNING(gtl::gbGetLogger(), fmt, ##__VA_ARGS__)
#define GB_LOG(fmt, ...) QUILL_LOG_INFO(gtl::gbGetLogger(), fmt, ##__VA_ARGS__)
#define GB_DEBUG(fmt, ...) QUILL_LOG_DEBUG(gtl::gbGetLogger(), fmt, ##__VA_ARGS__)
#define GB_DEBUG_DYN(fmt, ...) QUILL_LOG_DYNAMIC(gtl::gbGetLogger(), quill::LogLevel::Debug, fmt, ##__VA_ARGS__)

namespace gtl
{
Expand Down
3 changes: 3 additions & 0 deletions src/gb/impl/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace gtl
const char* logPattern = "[%(time)] (%(log_level)) %(message)";
const char* timestampFormat = "%H:%M:%S.%Qms";
s_logger = quill::Frontend::create_or_get_logger("root", std::move(sink), logPattern, timestampFormat);
#ifdef GTL_VERBOSE
s_logger->set_log_level(quill::LogLevel::Debug);
#endif

quill::BackendOptions options;
options.thread_name = "GbLog";
Expand Down
6 changes: 6 additions & 0 deletions src/ggpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ target_link_libraries(
cgpu
)

target_compile_options(
ggpu
PRIVATE
${GTL_COMPILE_OPTIONS}
)

set_target_properties(
ggpu
PROPERTIES
Expand Down
1 change: 0 additions & 1 deletion src/ggpu/gtl/ggpu/LinearDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,5 @@ namespace gtl

GbHandleStore m_handleStore;
GgpuSyncBuffer m_buffer;
uint8_t* m_mappedMem = nullptr;
};
}
1 change: 0 additions & 1 deletion src/ggpu/gtl/ggpu/SyncBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ namespace gtl
private:
CgpuDevice m_device;
GgpuStager& m_stager;
GgpuDelayedResourceDestroyer& m_delayedResourceDestroyer;
uint64_t m_elementSize;
UpdateStrategy m_updateStrategy;

Expand Down
10 changes: 7 additions & 3 deletions src/ggpu/impl/LinearDataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
namespace
{
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
uint32_t _NextPowerOfTwo(uint32_t v)
uint64_t _NextPowerOfTwo(uint64_t v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v |= v >> 32;
v++;
return v;
}
Expand Down Expand Up @@ -107,8 +108,8 @@ namespace gtl
// A resize is very unlikely and can be expensive
if (byteOffset >= m_buffer.byteSize())
{
uint32_t minSize = m_elementSize * m_minCapacity;
uint32_t newSize = std::max(_NextPowerOfTwo(byteOffset), minSize);
uint64_t minSize = m_elementSize * m_minCapacity;
uint64_t newSize = std::max(_NextPowerOfTwo(byteOffset), minSize);

bool result = false;

Expand Down Expand Up @@ -146,6 +147,9 @@ namespace gtl
cgpuDestroyCommandBuffer(m_device, commandBuffer);
if (semaphore.handle)
cgpuDestroySemaphore(m_device, semaphore);

if (!result)
byteOffset = UINT64_MAX;
}

return byteOffset;
Expand Down
12 changes: 6 additions & 6 deletions src/ggpu/impl/Stager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace gtl

bool GgpuStager::stageToImage(const uint8_t* src, uint64_t size, CgpuImage dst, uint32_t width, uint32_t height, uint32_t depth)
{
uint64_t rowCount = height;
uint32_t rowCount = height;
uint64_t rowSize = size / rowCount;

if (rowSize > BUFFER_HALF_SIZE)
Expand All @@ -170,7 +170,7 @@ namespace gtl
while (rowsStaged < rowCount)
{
uint64_t remainingSpace = BUFFER_HALF_SIZE - m_stagedBytes;
uint64_t maxCopyRowCount = remainingSpace / rowSize; // truncate
uint32_t maxCopyRowCount = uint32_t(remainingSpace / rowSize); // truncate

if (maxCopyRowCount == 0)
{
Expand All @@ -179,13 +179,13 @@ namespace gtl
return false;
}

maxCopyRowCount = BUFFER_HALF_SIZE / rowSize; // truncate
maxCopyRowCount = uint32_t(BUFFER_HALF_SIZE / rowSize); // truncate
}

uint64_t remainingRowCount = rowCount - rowsStaged;
uint64_t copyRowCount = std::min(remainingRowCount, maxCopyRowCount);
uint32_t remainingRowCount = rowCount - rowsStaged;
uint32_t copyRowCount = std::min(remainingRowCount, maxCopyRowCount);

auto copyFunc = [this, dst, rowsStaged, width, depth, copyRowCount](uint64_t srcOffset, uint64_t dstOffset, uint64_t size) {
auto copyFunc = [this, dst, rowsStaged, width, depth, copyRowCount](uint64_t srcOffset, [[maybe_unused]] uint64_t dstOffset, [[maybe_unused]] uint64_t size) {
CgpuBufferImageCopyDesc desc;
desc.bufferOffset = srcOffset;
desc.texelOffsetX = 0;
Expand Down
11 changes: 5 additions & 6 deletions src/ggpu/impl/SyncBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ namespace gtl
CgpuBufferUsageFlags bufferUsage)
: m_device(device)
, m_stager(stager)
, m_delayedResourceDestroyer(delayedResourceDestroyer)
, m_elementSize(elementSize)
, m_updateStrategy(updateStrategy)
, m_deviceBuffer(m_device,
delayedResourceDestroyer,
bufferUsage | CGPU_BUFFER_USAGE_FLAG_TRANSFER_DST,
CGPU_MEMORY_PROPERTY_FLAG_DEVICE_LOCAL)
, m_hostBuffer(m_device,
delayedResourceDestroyer,
CGPU_BUFFER_USAGE_FLAG_STORAGE_BUFFER | CGPU_BUFFER_USAGE_FLAG_TRANSFER_SRC,
CGPU_MEMORY_PROPERTY_FLAG_HOST_VISIBLE | CGPU_MEMORY_PROPERTY_FLAG_HOST_COHERENT |
(updateStrategy == UpdateStrategy::PersistentMapping ? CGPU_MEMORY_PROPERTY_FLAG_DEVICE_LOCAL : 0))
, m_deviceBuffer(m_device,
delayedResourceDestroyer,
bufferUsage | CGPU_BUFFER_USAGE_FLAG_TRANSFER_DST,
CGPU_MEMORY_PROPERTY_FLAG_DEVICE_LOCAL)
{

}
Expand All @@ -54,7 +53,7 @@ namespace gtl
assert(m_updateStrategy == UpdateStrategy::PersistentMapping || m_deviceBuffer.size() == 0);
}

uint8_t* GgpuSyncBuffer::read(uint64_t byteOffset, uint64_t byteSize)
uint8_t* GgpuSyncBuffer::read(uint64_t byteOffset, [[maybe_unused]] uint64_t byteSize) // TODO: remove byteSize?
{
assert((byteOffset + byteSize) <= m_size);
return &m_mappedHostMem[byteOffset];
Expand Down
Loading

0 comments on commit ab4a5be

Please sign in to comment.