This tutorial demonstrates the VK_KHR_ray_tracing_position_fetch extension, which allows retrieving vertex positions directly from the acceleration structure during ray traversal. This eliminates the need for separate vertex buffers during rendering, reducing memory usage and simplifying data management. The main learning objective is to understand how to use position fetch for memory-efficient ray tracing with proper feature detection and graceful hardware compatibility handling.
Modified: 10_position_fetch.cpp
- Added
VK_KHR_ray_tracing_position_fetchextension support with proper feature detection - Implemented runtime hardware capability checking to gracefully handle unsupported devices
- Added UI status indicators showing "SUPPORTED" or "ERROR" based on hardware capabilities
// Feature detection for position fetch support
VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR m_rtPosFetch{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR
};
// Runtime validation
if(m_rtPosFetch.rayTracingPositionFetch == VK_FALSE)
{
// Handle unsupported hardware gracefully
return;
}Modified: createBottomLevelAS() function
- Added
VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_DATA_ACCESS_KHRflag to enable position data access - This flag allows the acceleration structure to retain vertex data for position fetch operations
// Enable data access for position fetch
m_asBuilder.blasSubmitBuildAndWait(geoInfos,
VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR |
VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_DATA_ACCESS_KHR);Modified: 10_position_fetch.slang
- Replaced vertex buffer access with
HitTriangleVertexPosition()built-in function - Implemented geometric normal calculation from fetched vertex positions
- Added position fetch visualization with subtle purple tint
// Core position fetch functionality
const float3 pos0 = HitTriangleVertexPosition(0); // First vertex
const float3 pos1 = HitTriangleVertexPosition(1); // Second vertex
const float3 pos2 = HitTriangleVertexPosition(2); // Third vertex
// Calculate geometric normal from fetched positions
const float3 edge1 = pos1 - pos0;
const float3 edge2 = pos2 - pos0;
const float3 geoNormal = normalize(cross(edge1, edge2));Modified: User interface system
- Added real-time material parameter controls (metallic/roughness sliders)
- Implemented feature status display with color-coded support indicators
- Added reset functionality to restore default material values
Position fetch works by enabling direct access to vertex data stored within the acceleration structure itself. Instead of maintaining separate vertex buffers for shading calculations, the HitTriangleVertexPosition() function retrieves vertex positions directly from the BLAS during ray traversal.
The key insight is that the acceleration structure already contains the vertex data needed for intersection testing. By building the BLAS with the ALLOW_DATA_ACCESS flag, this data becomes accessible to shaders, eliminating the need for duplicate vertex storage.
- Memory Efficiency: Eliminates redundant vertex buffer storage, reducing memory footprint
- Simplified Data Management: Single source of truth for geometry data in the acceleration structure
- Cache Efficiency: Only fetches vertex data when actually needed during ray traversal
- Bandwidth Reduction: Reduces memory bandwidth requirements for vertex data access
- Vulkan 1.2+ with ray tracing support
- GPU supporting
VK_KHR_ray_tracing_position_fetchextension - Recent NVIDIA RTX GPUs (RTX 20 series and newer)
- Advantages: Reduced memory usage, simplified management, improved cache efficiency
- Trade-offs: Requires hardware extension support, limited to position data only, slight BLAS build time increase
- Best Practice: Always include runtime feature detection for graceful degradation
- Only vertex positions are directly accessible (normals, UVs require separate storage or calculation)
- Requires modern hardware with extension support
- BLAS build time may increase slightly due to data retention
- Hardware Check: The tutorial automatically detects position fetch support and displays status
- Material Controls: Use the metallic and roughness sliders to adjust material properties in real-time
- Visual Feedback: Look for the subtle purple tint on rendered objects indicating position fetch is active
- Error Handling: If hardware doesn't support the extension, clear error messages are displayed
Position fetch enables several advanced rendering techniques:
- Memory-constrained ray tracing scenarios
- Displacement mapping without vertex buffer expansion
- Adaptive level-of-detail based on ray distance
- Procedural geometry with minimal memory overhead
- Combined with compressed attribute storage for maximum efficiency
For more information, see:
