Skip to content

Commit

Permalink
fix to endcaps. fixing incorrect unmap of instance buffer when made a…
Browse files Browse the repository at this point in the history
…s host buffer
  • Loading branch information
natevm committed Feb 16, 2025
1 parent 63b7975 commit 1aec048
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gprt/cmake/embed_devicecode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function(embed_devicecode)
-zero-initialize # zero-initialize all variables
-Wno-39001 # for VK_EXT_mutable_descriptor_type, allows overlapping bindings
-g
-O0
-O3
-I ${GPRT_INCLUDE_DIR}
-o ${CMAKE_CURRENT_BINARY_DIR}/${EMBED_DEVICECODE_OUTPUT_TARGET}.spv
DEPENDS ${EMBED_DEVICECODE_SOURCES} ${EMBED_DEVICECODE_HEADERS} ${GPRT_INCLUDE_DIR}/gprt.slang ${GPRT_INCLUDE_DIR}/gprt.h
Expand Down
16 changes: 10 additions & 6 deletions gprt/gprt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4577,10 +4577,12 @@ Context::buildSBT(GPRTBuildSBTFlags flags) {
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
// means we can use this buffer as a storage buffer resource
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
const VkMemoryPropertyFlags memoryUsageFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | // mappable to host with
// vkMapMemory
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; // means "flush" and
// "invalidate" not needed
const VkMemoryPropertyFlags memoryUsageFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; // means most efficient for
// device access
// const VkMemoryPropertyFlags memoryUsageFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | // mappable to host with
// // vkMapMemory
// VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; // means "flush" and
// // "invalidate" not needed

// std::cout<<"Todo, get some smarter memory allocation working..."
// <<std::endl;
Expand Down Expand Up @@ -4724,7 +4726,9 @@ Context::buildSBT(GPRTBuildSBTFlags flags) {
// SBT data... So, if we have a bunch of instances set by reference on
// device, we need to eventually do something smarter here...
// Todo, move this setup to the device...
instanceAccel->instancesBuffer->map();

bool previouslyMapped = (instanceAccel->instancesBuffer->mapped != nullptr);
if (!previouslyMapped) instanceAccel->instancesBuffer->map();
gprt::Instance *instances = (gprt::Instance *) instanceAccel->instancesBuffer->mapped;

for (uint32_t blasID = 0; blasID < instanceAccel->numInstances; ++blasID) {
Expand Down Expand Up @@ -4797,7 +4801,7 @@ Context::buildSBT(GPRTBuildSBTFlags flags) {
}
}

instanceAccel->instancesBuffer->unmap();
if (!previouslyMapped) instanceAccel->instancesBuffer->unmap();
}
}
hitgroupTable->unmap();
Expand Down
4 changes: 2 additions & 2 deletions gprt/gprt_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ typedef enum {
// } GPRTCellType;

typedef enum {
GPRT_LSS_CHAINED_END_CAPS = 0,
GPRT_LSS_NO_END_CAPS = 1
GPRT_LSS_CHAINED_END_CAPS = 1,
GPRT_LSS_NO_END_CAPS = 2
} GPRTLSSFlags;

typedef enum {
Expand Down

0 comments on commit 1aec048

Please sign in to comment.