Skip to content

Commit 9a1cc64

Browse files
committed
Add SpecializationConstants to DeviceFeatures.
1 parent f88e3f3 commit 9a1cc64

8 files changed

Lines changed: 32 additions & 17 deletions

File tree

Graphics/GraphicsEngine/interface/GraphicsTypes.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -1856,6 +1856,17 @@ struct DeviceFeatures
18561856
/// Indicates if device supports formatted buffers.
18571857
DEVICE_FEATURE_STATE FormattedBuffers DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
18581858

1859+
/// Indicates if device supports pipeline specialization constants.
1860+
1861+
/// When this feature is enabled, applications can provide specialization
1862+
/// constants when creating a pipeline state to set constant values at
1863+
/// pipeline creation time. The driver may use these values to optimize
1864+
/// the compiled shader code.
1865+
///
1866+
/// Vulkan and WebGPU backends support this feature.
1867+
/// D3D11, D3D12, OpenGL, and Metal backends do not.
1868+
DEVICE_FEATURE_STATE SpecializationConstants DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
1869+
18591870
#if DILIGENT_CPP_INTERFACE
18601871
constexpr DeviceFeatures() noexcept {}
18611872

@@ -1906,11 +1917,12 @@ struct DeviceFeatures
19061917
Handler(TextureSubresourceViews) \
19071918
Handler(NativeMultiDraw) \
19081919
Handler(AsyncShaderCompilation) \
1909-
Handler(FormattedBuffers)
1920+
Handler(FormattedBuffers) \
1921+
Handler(SpecializationConstants)
19101922

19111923
explicit constexpr DeviceFeatures(DEVICE_FEATURE_STATE State) noexcept
19121924
{
1913-
static_assert(sizeof(*this) == 47, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
1925+
static_assert(sizeof(*this) == 48, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
19141926
#define INIT_FEATURE(Feature) Feature = State;
19151927
ENUMERATE_DEVICE_FEATURES(INIT_FEATURE)
19161928
#undef INIT_FEATURE

Graphics/GraphicsEngine/src/RenderDeviceBase.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -120,9 +120,10 @@ DeviceFeatures EnableDeviceFeatures(const DeviceFeatures& SupportedFeatures,
120120
ENABLE_FEATURE(NativeMultiDraw, "Native multi-draw commands are");
121121
ENABLE_FEATURE(AsyncShaderCompilation, "Async shader compilation is");
122122
ENABLE_FEATURE(FormattedBuffers, "Formatted buffers are");
123+
ENABLE_FEATURE(SpecializationConstants, "Specialization constants are");
123124
// clang-format on
124125

125-
ASSERT_SIZEOF(DeviceFeatures, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
126+
ASSERT_SIZEOF(DeviceFeatures, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
126127

127128
return EnabledFeatures;
128129
}

Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -490,7 +490,7 @@ GraphicsAdapterInfo EngineFactoryD3D11Impl::GetGraphicsAdapterInfo(void*
490490
Features.ShaderFloat16 = ShaderFloat16Supported ? DEVICE_FEATURE_STATE_ENABLED : DEVICE_FEATURE_STATE_DISABLED;
491491
}
492492

493-
ASSERT_SIZEOF(Features, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
493+
ASSERT_SIZEOF(Features, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
494494

495495
// Texture properties
496496
{

Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -1106,7 +1106,7 @@ GraphicsAdapterInfo EngineFactoryD3D12Impl::GetGraphicsAdapterInfo(void*
11061106
ASSERT_SIZEOF(DrawCommandProps, 12, "Did you add a new member to DrawCommandProperties? Please initialize it here.");
11071107
}
11081108

1109-
ASSERT_SIZEOF(DeviceFeatures, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
1109+
ASSERT_SIZEOF(DeviceFeatures, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
11101110

11111111
return AdapterInfo;
11121112
}

Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -1129,7 +1129,7 @@ void RenderDeviceGLImpl::InitAdapterInfo()
11291129
m_AdapterInfo.Queues[0].TextureCopyGranularity[2] = 1;
11301130
}
11311131

1132-
ASSERT_SIZEOF(DeviceFeatures, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
1132+
ASSERT_SIZEOF(DeviceFeatures, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
11331133
}
11341134

11351135
void RenderDeviceGLImpl::FlagSupportedTexFormats()

Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -1279,7 +1279,7 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En
12791279
LOG_ERROR_MESSAGE("Can not enable extended device features when VK_KHR_get_physical_device_properties2 extension is not supported by device");
12801280
}
12811281

1282-
ASSERT_SIZEOF(DeviceFeatures, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
1282+
ASSERT_SIZEOF(DeviceFeatures, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
12831283

12841284
for (Uint32 i = 0; i < EngineCI.DeviceExtensionCount; ++i)
12851285
{

Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -1968,6 +1968,7 @@ DeviceFeatures VkFeaturesToDeviceFeatures(uint32_t
19681968
Features.TextureSubresourceViews = DEVICE_FEATURE_STATE_ENABLED;
19691969
Features.AsyncShaderCompilation = DEVICE_FEATURE_STATE_ENABLED;
19701970
Features.FormattedBuffers = DEVICE_FEATURE_STATE_ENABLED;
1971+
Features.SpecializationConstants = DEVICE_FEATURE_STATE_ENABLED;
19711972

19721973
// Timestamps are not a feature and can't be disabled. They are either supported by the device, or not.
19731974
Features.TimestampQueries = vkDeviceProps.limits.timestampComputeAndGraphics ? DEVICE_FEATURE_STATE_ENABLED : DEVICE_FEATURE_STATE_DISABLED;
@@ -2061,7 +2062,7 @@ DeviceFeatures VkFeaturesToDeviceFeatures(uint32_t
20612062

20622063
#undef INIT_FEATURE
20632064

2064-
ASSERT_SIZEOF(DeviceFeatures, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
2065+
ASSERT_SIZEOF(DeviceFeatures, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
20652066

20662067
return Features;
20672068
}

Graphics/GraphicsEngineWebGPU/src/EngineFactoryWebGPU.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2025 Diligent Graphics LLC
2+
* Copyright 2023-2026 Diligent Graphics LLC
33
*
44
* You may not use this file except in compliance with the License (see License.txt).
55
*
@@ -403,13 +403,14 @@ DeviceFeatures GetSupportedFeatures(WGPUAdapter wgpuAdapter, WGPUDevice wgpuDevi
403403
Features.NativeMultiDraw = DEVICE_FEATURE_STATE_DISABLED;
404404
Features.AsyncShaderCompilation = DEVICE_FEATURE_STATE_ENABLED;
405405
Features.FormattedBuffers = DEVICE_FEATURE_STATE_DISABLED;
406+
Features.SpecializationConstants = DEVICE_FEATURE_STATE_ENABLED;
406407

407408
Features.TimestampQueries = CheckFeature(WGPUFeatureName_TimestampQuery);
408409
Features.DurationQueries = Features.TimestampQueries ?
409410
CheckFeature(WGPUFeatureName_ChromiumExperimentalTimestampQueryInsidePasses) :
410411
DEVICE_FEATURE_STATE_DISABLED;
411412

412-
ASSERT_SIZEOF(DeviceFeatures, 47, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
413+
ASSERT_SIZEOF(DeviceFeatures, 48, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
413414

414415
return Features;
415416
}

0 commit comments

Comments
 (0)