Skip to content

Commit 58595e4

Browse files
committed
Add feature and format support query functions
1 parent 860f620 commit 58595e4

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

src/vrhi_device.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,28 @@ std::string vhGetDeviceInfo()
499499
return std::string( buffer );
500500
}
501501

502+
bool vhQueryFeatureSupport( nvrhi::Feature feature, void* pInfo, size_t infoSize )
503+
{
504+
if ( !g_vhDevice )
505+
{
506+
VRHI_ERR( "vhQueryFeatureSupport(): Device not initialised.\n" );
507+
return false;
508+
}
509+
std::lock_guard<std::mutex> lock( g_nvRHIStateMutex );
510+
return g_vhDevice->queryFeatureSupport( feature, pInfo, infoSize );
511+
}
512+
513+
nvrhi::FormatSupport vhQueryFormatSupport( nvrhi::Format format )
514+
{
515+
if ( !g_vhDevice )
516+
{
517+
VRHI_ERR( "vhQueryFormatSupport(): Device not initialised.\n" );
518+
return nvrhi::FormatSupport::None;
519+
}
520+
std::lock_guard<std::mutex> lock( g_nvRHIStateMutex );
521+
return g_vhDevice->queryFormatSupport( format );
522+
}
523+
502524
void vhDispatch( vhStateId stateID, glm::uvec3 workGroupCount )
503525
{
504526
VIDL_vhDispatch* cmd = vhCmdAlloc<VIDL_vhDispatch>( stateID, workGroupCount );

test/test_device.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,49 @@ UTEST( Device, HashingReflectionMembers )
287287
emptyName.push_back( m4 );
288288
uint64_t hash7 = vhHashReflectionMembers( emptyName );
289289
EXPECT_NE( hash7, 0u );
290+
}
291+
292+
UTEST( Device, QueryFeatureSupport )
293+
{
294+
if ( !g_testInit )
295+
{
296+
vhInit( g_testInitQuiet );
297+
g_testInit = true;
298+
}
299+
300+
// Test basic feature queries that should return deterministic values
301+
EXPECT_TRUE( vhQueryFeatureSupport( nvrhi::Feature::ComputeQueue ) ); // Vulkan always has this
302+
// Test any bool is valid for this feature
303+
bool deferredSupport = vhQueryFeatureSupport( nvrhi::Feature::DeferredCommandLists );
304+
// Just verify it returns a valid bool - don't assume specific support
305+
306+
// Test feature with info struct
307+
nvrhi::VariableRateShadingFeatureInfo vrsInfo = {};
308+
bool vrsSupported = vhQueryFeatureSupport( nvrhi::Feature::VariableRateShading, &vrsInfo, sizeof(vrsInfo) );
309+
if ( vrsSupported )
310+
{
311+
EXPECT_GT( vrsInfo.shadingRateImageTileSize, 0 ); // Should have valid tile size if supported
312+
}
313+
}
314+
315+
UTEST( Device, QueryFormatSupport )
316+
{
317+
if ( !g_testInit )
318+
{
319+
vhInit( g_testInitQuiet );
320+
g_testInit = true;
321+
}
322+
323+
// Test common format queries
324+
nvrhi::FormatSupport rgba8Support = vhQueryFormatSupport( nvrhi::Format::RGBA8_UNORM );
325+
EXPECT_NE( rgba8Support, nvrhi::FormatSupport::None ); // Common format should be supported
326+
EXPECT_TRUE( ( rgba8Support & nvrhi::FormatSupport::Texture ) != nvrhi::FormatSupport::None );
327+
EXPECT_TRUE( ( rgba8Support & nvrhi::FormatSupport::ShaderSample ) != nvrhi::FormatSupport::None );
328+
329+
// Test format support flags
330+
nvrhi::FormatSupport depthSupport = vhQueryFormatSupport( nvrhi::Format::D24S8 );
331+
EXPECT_TRUE( ( depthSupport & nvrhi::FormatSupport::DepthStencil ) != nvrhi::FormatSupport::None );
332+
333+
nvrhi::FormatSupport floatSupport = vhQueryFormatSupport( nvrhi::Format::R32_FLOAT );
334+
EXPECT_TRUE( ( floatSupport & nvrhi::FormatSupport::ShaderLoad ) != nvrhi::FormatSupport::None );
290335
}

vrhi.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ void vhShutdown( bool quiet = false );
116116
// Returns a string containing information about the selected physical device and queues.
117117
std::string vhGetDeviceInfo();
118118

119+
// Queries whether a specific device feature is supported.
120+
// Returns true if the feature is supported on the current device.
121+
//
122+
// For features that require additional information (e.g. VRS tile size), pass an optional
123+
// output struct via |pInfo| with size |infoSize|. See nvrhi::Feature for available features.
124+
bool vhQueryFeatureSupport( nvrhi::Feature feature, void* pInfo = nullptr, size_t infoSize = 0 );
125+
126+
// Queries the supported operations for a specific texture/buffer format.
127+
// Returns a bitmask of nvrhi::FormatSupport flags indicating what operations
128+
// the format can be used for (e.g. RenderTarget, ShaderSample, UAV, etc).
129+
nvrhi::FormatSupport vhQueryFormatSupport( nvrhi::Format format );
130+
119131
// Flushes the command queue to the backend.
120132
//
121133
// If |wait| is true, blocks until the backend has processed all queued commands.

0 commit comments

Comments
 (0)