Skip to content

Commit

Permalink
Add SpirV-reflection to detect usage of buffer-references
Browse files Browse the repository at this point in the history
- Adds a SpirV-parser to detect dereferencing of buffer-references
- track back to their definition and extract descriptor-set/binding/push-constant-block
- from there using spirv_reflect: extract buffer-offsets and potential array-strides
- issue a warning in case buffer-references are used, currently unsupported
  • Loading branch information
fabian-lunarg committed Jun 11, 2024
1 parent d96ee1e commit dbd9832
Show file tree
Hide file tree
Showing 14 changed files with 10,097 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "external/Vulkan-Headers"]
path = external/Vulkan-Headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
[submodule "external/SPIRV-Headers"]
path = external/SPIRV-Headers
url = https://github.com/KhronosGroup/SPIRV-Headers.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ add_library(vulkan_registry INTERFACE)
target_include_directories(vulkan_registry INTERFACE ${CMAKE_SOURCE_DIR}/external/Vulkan-Headers/include)
target_compile_definitions(vulkan_registry INTERFACE VK_NO_PROTOTYPES VK_ENABLE_BETA_EXTENSIONS)

add_library(spirv_registry INTERFACE)
target_include_directories(spirv_registry INTERFACE ${CMAKE_SOURCE_DIR}/external/SPIRV-Headers/include)

add_library(vulkan_memory_allocator INTERFACE)
target_compile_options(vulkan_memory_allocator INTERFACE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
Expand Down
3 changes: 3 additions & 0 deletions android/framework/cmake-config/PlatformConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ add_library(vulkan_registry INTERFACE)
target_include_directories(vulkan_registry INTERFACE ${GFXRECON_SOURCE_DIR}/external/Vulkan-Headers/include)
target_compile_definitions(vulkan_registry INTERFACE VK_NO_PROTOTYPES VK_ENABLE_BETA_EXTENSIONS)

add_library(spirv_registry INTERFACE)
target_include_directories(spirv_registry INTERFACE ${GFXRECON_SOURCE_DIR}/external/SPIRV-Headers/include)

add_library(vulkan_memory_allocator INTERFACE)
target_include_directories(vulkan_memory_allocator INTERFACE ${GFXRECON_SOURCE_DIR}/external/VulkanMemoryAllocator/include)
6 changes: 6 additions & 0 deletions android/framework/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ target_sources(gfxrecon_util
${GFXRECON_SOURCE_DIR}/framework/util/platform.h
${GFXRECON_SOURCE_DIR}/framework/util/settings_loader.h
${GFXRECON_SOURCE_DIR}/framework/util/settings_loader.cpp
${GFXRECON_SOURCE_DIR}/framework/util/spirv_helper.h
${GFXRECON_SOURCE_DIR}/framework/util/spirv_reflect.h
${GFXRECON_SOURCE_DIR}/framework/util/spirv_reflect.cpp
${GFXRECON_SOURCE_DIR}/framework/util/spirv_parsing_util.h
${GFXRECON_SOURCE_DIR}/framework/util/spirv_parsing_util.cpp
${GFXRECON_SOURCE_DIR}/framework/util/strings.h
${GFXRECON_SOURCE_DIR}/framework/util/strings.cpp
${GFXRECON_SOURCE_DIR}/framework/util/options.h
Expand All @@ -61,6 +66,7 @@ target_include_directories(gfxrecon_util
target_link_libraries(gfxrecon_util
platform_specific
vulkan_registry
spirv_registry
${GFXRECON_SOURCE_DIR}/external/precompiled/android/lib/${ANDROID_ABI}/liblz4_static.a
${GFXRECON_SOURCE_DIR}/external/precompiled/android/lib/${ANDROID_ABI}/libzstd.a
z)
1 change: 1 addition & 0 deletions external/SPIRV-Headers
Submodule SPIRV-Headers added at eb49bb
10 changes: 10 additions & 0 deletions framework/encode/custom_vulkan_encoder_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,16 @@ struct CustomEncoderPostCall<format::ApiCallId::ApiCall_vkCmdDebugMarkerInsertEX
}
};

template <>
struct CustomEncoderPostCall<format::ApiCallId::ApiCall_vkCreateShaderModule>
{
template <typename... Args>
static void Dispatch(VulkanCaptureManager* manager, Args... args)
{
manager->PostProcess_vkCreateShaderModule(args...);
}
};

GFXRECON_END_NAMESPACE(encode)
GFXRECON_END_NAMESPACE(gfxrecon)

Expand Down
30 changes: 30 additions & 0 deletions framework/encode/vulkan_capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "util/logging.h"
#include "util/page_guard_manager.h"
#include "util/platform.h"
#include "util/spirv_parsing_util.h"

#include <cassert>
#include <unordered_set>
Expand Down Expand Up @@ -2822,5 +2823,34 @@ void VulkanCaptureManager::PreProcess_vkBindImageMemory2(VkDevice
}
}

void VulkanCaptureManager::PostProcess_vkCreateShaderModule(VkResult result,
VkDevice device,
const VkShaderModuleCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule)
{
GFXRECON_UNREFERENCED_PARAMETER(device);
GFXRECON_UNREFERENCED_PARAMETER(pAllocator);
GFXRECON_UNREFERENCED_PARAMETER(pShaderModule);

if (result == VK_SUCCESS)
{
// spirv-parsing for buffer-references
gfxrecon::util::SpirVParsingUtil spirv_util;

if (spirv_util.Parse(pCreateInfo->pCode, pCreateInfo->codeSize))
{
auto buffer_reference_infos = spirv_util.GetBufferReferenceInfos();

if (!buffer_reference_infos.empty())
{
GFXRECON_LOG_WARNING_ONCE(
"Shader is using the 'GL_EXT_buffer_reference2' feature. "
"Resource tracking for buffers accessed via references is currently unsupported");
}
}
}
}

GFXRECON_END_NAMESPACE(encode)
GFXRECON_END_NAMESPACE(gfxrecon)
11 changes: 11 additions & 0 deletions framework/encode/vulkan_capture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,17 @@ class VulkanCaptureManager : public ApiCaptureManager
EndFrame();
}

void PreProcess_vkCreateShaderModule(VkDevice device,
const VkShaderModuleCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule);

void PostProcess_vkCreateShaderModule(VkResult result,
VkDevice device,
const VkShaderModuleCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule);

#if defined(__ANDROID__)
void OverrideGetPhysicalDeviceSurfacePresentModesKHR(uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes);
#endif
Expand Down
8 changes: 7 additions & 1 deletion framework/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ target_sources(gfxrecon_util
${CMAKE_CURRENT_LIST_DIR}/settings_loader.cpp
${CMAKE_CURRENT_LIST_DIR}/options.h
${CMAKE_CURRENT_LIST_DIR}/options.cpp
${CMAKE_CURRENT_LIST_DIR}/spirv_helper.h
${CMAKE_CURRENT_LIST_DIR}/spirv_reflect.h
${CMAKE_CURRENT_LIST_DIR}/spirv_reflect.cpp
${CMAKE_CURRENT_LIST_DIR}/spirv_parsing_util.h
${CMAKE_CURRENT_LIST_DIR}/spirv_parsing_util.cpp
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_CURRENT_LIST_DIR}/interception/hooking_detours.h>
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_CURRENT_LIST_DIR}/interception/hooking_detours.cpp>
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_CURRENT_LIST_DIR}/interception/interception_util.h>
Expand Down Expand Up @@ -117,7 +122,8 @@ target_include_directories(gfxrecon_util
PUBLIC
${CMAKE_SOURCE_DIR}/framework
$<$<BOOL:${D3D12_SUPPORT}>:${CMAKE_SOURCE_DIR}/external/AgilitySDK/inc>)
target_link_libraries(gfxrecon_util platform_specific vulkan_registry nlohmann_json::nlohmann_json ${CMAKE_DL_LIBS})
target_link_libraries(gfxrecon_util platform_specific vulkan_registry spirv_registry nlohmann_json::nlohmann_json
${CMAKE_DL_LIBS})
target_link_libraries(gfxrecon_util $<$<BOOL:${WIN32}>:version.lib>)

if (UNIX AND NOT APPLE)
Expand Down
Loading

0 comments on commit dbd9832

Please sign in to comment.