Skip to content

Commit

Permalink
Added ShaderResourceStaticArrays device feature
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jul 5, 2024
1 parent 14b4997 commit 1592248
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 45 deletions.
13 changes: 10 additions & 3 deletions Graphics/GraphicsEngine/interface/GraphicsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1742,12 +1742,18 @@ struct DeviceFeatures
/// Indicates if device supports reading 8-bit types from uniform buffers.
DEVICE_FEATURE_STATE UniformBuffer8BitAccess DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);

/// Indicates if device supports static-sized shader arrays.
///
/// \remarks This feature is always enabled in all backends,
/// except for WebGPU.
DEVICE_FEATURE_STATE ShaderResourceStaticArrays DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);

/// Indicates if device supports runtime-sized shader arrays (e.g. arrays without a specific size).
///
/// \remarks This feature is always enabled in DirectX12 backend and
/// can optionally be enabled in Vulkan backend.
/// Run-time sized shader arrays are not available in other backends.
DEVICE_FEATURE_STATE ShaderResourceRuntimeArray DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
DEVICE_FEATURE_STATE ShaderResourceRuntimeArrays DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);

/// Indicates if device supports wave ops (Direct3D12) or subgroups (Vulkan).
DEVICE_FEATURE_STATE WaveOp DEFAULT_INITIALIZER(DEVICE_FEATURE_STATE_DISABLED);
Expand Down Expand Up @@ -1856,7 +1862,8 @@ struct DeviceFeatures
Handler(ShaderInt8) \
Handler(ResourceBuffer8BitAccess) \
Handler(UniformBuffer8BitAccess) \
Handler(ShaderResourceRuntimeArray) \
Handler(ShaderResourceStaticArrays) \
Handler(ShaderResourceRuntimeArrays) \
Handler(WaveOp) \
Handler(InstanceDataStepRate) \
Handler(NativeFence) \
Expand All @@ -1873,7 +1880,7 @@ struct DeviceFeatures

explicit constexpr DeviceFeatures(DEVICE_FEATURE_STATE State) noexcept
{
static_assert(sizeof(*this) == 45, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
static_assert(sizeof(*this) == 46, "Did you add a new feature to DeviceFeatures? Please add it to ENUMERATE_DEVICE_FEATURES.");
#define INIT_FEATURE(Feature) Feature = State;
ENUMERATE_DEVICE_FEATURES(INIT_FEATURE)
#undef INIT_FEATURE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc&
}
}

if ((Res.Flags & PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY) != 0 && Features.ShaderResourceRuntimeArray == DEVICE_FEATURE_STATE_DISABLED)
if ((Res.Flags & PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY) != 0 && Features.ShaderResourceRuntimeArrays == DEVICE_FEATURE_STATE_DISABLED)
{
LOG_PRS_ERROR_AND_THROW("Incorrect Desc.Resources[", i, "].Flags (RUNTIME_ARRAY). The flag can only be used if ShaderResourceRuntimeArray device feature is enabled.");
}
Expand Down
5 changes: 3 additions & 2 deletions Graphics/GraphicsEngine/src/RenderDeviceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ DeviceFeatures EnableDeviceFeatures(const DeviceFeatures& SupportedFeatures,
ENABLE_FEATURE(ShaderInt8, "8-bit int shader operations are");
ENABLE_FEATURE(ResourceBuffer8BitAccess, "8-bit resource buffer access is");
ENABLE_FEATURE(UniformBuffer8BitAccess, "8-bit uniform buffer access is");
ENABLE_FEATURE(ShaderResourceRuntimeArray, "Shader resource runtime array is");
ENABLE_FEATURE(ShaderResourceStaticArrays, "Shader resource static arrays are");
ENABLE_FEATURE(ShaderResourceRuntimeArrays, "Shader resource runtime arrays are");
ENABLE_FEATURE(WaveOp, "Wave operations are");
ENABLE_FEATURE(InstanceDataStepRate, "Instance data step rate is");
ENABLE_FEATURE(NativeFence, "Native fence is");
Expand All @@ -120,7 +121,7 @@ DeviceFeatures EnableDeviceFeatures(const DeviceFeatures& SupportedFeatures,
// clang-format on
#undef ENABLE_FEATURE

ASSERT_SIZEOF(DeviceFeatures, 45, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
ASSERT_SIZEOF(DeviceFeatures, 46, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");

return EnabledFeatures;
}
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ GraphicsAdapterInfo EngineFactoryD3D11Impl::GetGraphicsAdapterInfo(void*
Features.ShaderFloat16 = ShaderFloat16Supported ? DEVICE_FEATURE_STATE_ENABLED : DEVICE_FEATURE_STATE_DISABLED;
}

ASSERT_SIZEOF(Features, 45, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
ASSERT_SIZEOF(Features, 46, "Did you add a new feature to DeviceFeatures? Please handle its status here.");

// Texture properties
{
Expand Down
4 changes: 2 additions & 2 deletions Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ GraphicsAdapterInfo EngineFactoryD3D12Impl::GetGraphicsAdapterInfo(void*
ASSERT_SIZEOF(MeshProps, 16, "Did you add a new member to MeshShaderProperties? Please initialize it here.");
}

Features.ShaderResourceRuntimeArray = DEVICE_FEATURE_STATE_ENABLED;
Features.ShaderResourceRuntimeArrays = DEVICE_FEATURE_STATE_ENABLED;

{
D3D12_FEATURE_DATA_D3D12_OPTIONS d3d12Features = {};
Expand Down Expand Up @@ -1067,7 +1067,7 @@ GraphicsAdapterInfo EngineFactoryD3D12Impl::GetGraphicsAdapterInfo(void*
ASSERT_SIZEOF(DrawCommandProps, 12, "Did you add a new member to DrawCommandProperties? Please initialize it here.");
}

ASSERT_SIZEOF(DeviceFeatures, 45, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
ASSERT_SIZEOF(DeviceFeatures, 46, "Did you add a new feature to DeviceFeatures? Please handle its status here.");

return AdapterInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class EngineFactoryD3DBase : public EngineFactoryBase<BaseInterface>
Features.TextureCompressionBC = DEVICE_FEATURE_STATE_ENABLED;
Features.PixelUAVWritesAndAtomics = DEVICE_FEATURE_STATE_ENABLED;
Features.TextureUAVExtendedFormats = DEVICE_FEATURE_STATE_ENABLED;
Features.ShaderResourceStaticArrays = DEVICE_FEATURE_STATE_ENABLED;
Features.InstanceDataStepRate = DEVICE_FEATURE_STATE_ENABLED;
Features.TileShaders = DEVICE_FEATURE_STATE_DISABLED;
Features.SubpassFramebufferFetch = DEVICE_FEATURE_STATE_DISABLED;
Expand Down
19 changes: 10 additions & 9 deletions Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,15 @@ void RenderDeviceGLImpl::InitAdapterInfo()
glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &MaxLayers);
CHECK_GL_ERROR("Failed to get maximum number of texture array layers");

Features.MeshShaders = DEVICE_FEATURE_STATE_DISABLED;
Features.RayTracing = DEVICE_FEATURE_STATE_DISABLED;
Features.ShaderResourceRuntimeArray = DEVICE_FEATURE_STATE_DISABLED;
Features.InstanceDataStepRate = DEVICE_FEATURE_STATE_ENABLED;
Features.NativeFence = DEVICE_FEATURE_STATE_DISABLED;
Features.TileShaders = DEVICE_FEATURE_STATE_DISABLED;
Features.SubpassFramebufferFetch = DEVICE_FEATURE_STATE_DISABLED;
Features.TextureComponentSwizzle = DEVICE_FEATURE_STATE_DISABLED;
Features.MeshShaders = DEVICE_FEATURE_STATE_DISABLED;
Features.RayTracing = DEVICE_FEATURE_STATE_DISABLED;
Features.ShaderResourceStaticArrays = DEVICE_FEATURE_STATE_ENABLED;
Features.ShaderResourceRuntimeArrays = DEVICE_FEATURE_STATE_DISABLED;
Features.InstanceDataStepRate = DEVICE_FEATURE_STATE_ENABLED;
Features.NativeFence = DEVICE_FEATURE_STATE_DISABLED;
Features.TileShaders = DEVICE_FEATURE_STATE_DISABLED;
Features.SubpassFramebufferFetch = DEVICE_FEATURE_STATE_DISABLED;
Features.TextureComponentSwizzle = DEVICE_FEATURE_STATE_DISABLED;

{
bool WireframeFillSupported = (glPolygonMode != nullptr);
Expand Down Expand Up @@ -1107,7 +1108,7 @@ void RenderDeviceGLImpl::InitAdapterInfo()
m_AdapterInfo.Queues[0].TextureCopyGranularity[2] = 1;
}

ASSERT_SIZEOF(DeviceFeatures, 45, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
ASSERT_SIZEOF(DeviceFeatures, 46, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
}

void RenderDeviceGLImpl::FlagSupportedTexFormats()
Expand Down
6 changes: 3 additions & 3 deletions Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En
}

// clang-format off
if (EnabledFeatures.ShaderResourceRuntimeArray != DEVICE_FEATURE_STATE_DISABLED ||
EnabledFeatures.RayTracing != DEVICE_FEATURE_STATE_DISABLED)
if (EnabledFeatures.ShaderResourceRuntimeArrays != DEVICE_FEATURE_STATE_DISABLED ||
EnabledFeatures.RayTracing != DEVICE_FEATURE_STATE_DISABLED)
// clang-format on
{
VERIFY(PhysicalDevice->IsExtensionSupported(VK_KHR_MAINTENANCE3_EXTENSION_NAME), "VK_KHR_maintenance3 extension must be supported");
Expand Down Expand Up @@ -1170,7 +1170,7 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk(const EngineVkCreateInfo& En
LOG_ERROR_MESSAGE("Can not enable extended device features when VK_KHR_get_physical_device_properties2 extension is not supported by device");
}

ASSERT_SIZEOF(DeviceFeatures, 45, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
ASSERT_SIZEOF(DeviceFeatures, 46, "Did you add a new feature to DeviceFeatures? Please handle its status here.");

for (Uint32 i = 0; i < EngineCI.DeviceExtensionCount; ++i)
{
Expand Down
10 changes: 5 additions & 5 deletions Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,9 +1939,12 @@ DeviceFeatures VkFeaturesToDeviceFeatures(uint32_t
Features.ComputeShaders = DEVICE_FEATURE_STATE_ENABLED;
Features.BindlessResources = DEVICE_FEATURE_STATE_ENABLED;
Features.BinaryOcclusionQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.ShaderResourceStaticArrays = DEVICE_FEATURE_STATE_ENABLED;
Features.SubpassFramebufferFetch = DEVICE_FEATURE_STATE_ENABLED;
Features.TextureComponentSwizzle = DEVICE_FEATURE_STATE_ENABLED;
Features.TextureSubresourceViews = DEVICE_FEATURE_STATE_ENABLED;
Features.AsyncShaderCompilation = DEVICE_FEATURE_STATE_ENABLED;
Features.FormattedBuffers = DEVICE_FEATURE_STATE_ENABLED;

// Timestamps are not a feature and can't be disabled. They are either supported by the device, or not.
Features.TimestampQueries = vkDeviceProps.limits.timestampComputeAndGraphics ? DEVICE_FEATURE_STATE_ENABLED : DEVICE_FEATURE_STATE_DISABLED;
Expand Down Expand Up @@ -1988,7 +1991,7 @@ DeviceFeatures VkFeaturesToDeviceFeatures(uint32_t
// clang-format on

const auto& DescrIndexingFeats = ExtFeatures.DescriptorIndexing;
INIT_FEATURE(ShaderResourceRuntimeArray, DescrIndexingFeats.runtimeDescriptorArray != VK_FALSE);
INIT_FEATURE(ShaderResourceRuntimeArrays, DescrIndexingFeats.runtimeDescriptorArray != VK_FALSE);
const auto& AccelStructFeats = ExtFeatures.AccelStruct;
const auto& RayTracingFeats = ExtFeatures.RayTracingPipeline;
const auto& RayQueryFeats = ExtFeatures.RayQuery;
Expand Down Expand Up @@ -2041,10 +2044,7 @@ DeviceFeatures VkFeaturesToDeviceFeatures(uint32_t
Features.DurationQueries = DEVICE_FEATURE_STATE_DISABLED;
#endif

Features.AsyncShaderCompilation = DEVICE_FEATURE_STATE_ENABLED;
Features.FormattedBuffers = DEVICE_FEATURE_STATE_ENABLED;

ASSERT_SIZEOF(DeviceFeatures, 45, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");
ASSERT_SIZEOF(DeviceFeatures, 46, "Did you add a new feature to DeviceFeatures? Please handle its status here (if necessary).");

return Features;
}
Expand Down
34 changes: 18 additions & 16 deletions Graphics/GraphicsEngineWebGPU/src/EngineFactoryWebGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,23 @@ GraphicsAdapterInfo GetGraphicsAdapterInfo(WGPUAdapter wgpuAdapter)
{
//TODO
auto& Features{AdapterInfo.Features};
Features.SeparablePrograms = DEVICE_FEATURE_STATE_ENABLED;
Features.ShaderResourceQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.WireframeFill = DEVICE_FEATURE_STATE_ENABLED;
Features.ComputeShaders = DEVICE_FEATURE_STATE_ENABLED;
Features.OcclusionQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.BinaryOcclusionQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.DurationQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.DepthBiasClamp = DEVICE_FEATURE_STATE_ENABLED;
Features.IndependentBlend = DEVICE_FEATURE_STATE_ENABLED;
Features.DualSourceBlend = DEVICE_FEATURE_STATE_ENABLED;
Features.MultiViewport = DEVICE_FEATURE_STATE_ENABLED;
Features.PixelUAVWritesAndAtomics = DEVICE_FEATURE_STATE_ENABLED;
Features.TextureUAVExtendedFormats = DEVICE_FEATURE_STATE_ENABLED;
Features.DepthClamp = DEVICE_FEATURE_STATE_ENABLED;
Features.FormattedBuffers = DEVICE_FEATURE_STATE_DISABLED;
Features.SeparablePrograms = DEVICE_FEATURE_STATE_ENABLED;
Features.ShaderResourceQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.WireframeFill = DEVICE_FEATURE_STATE_ENABLED;
Features.ComputeShaders = DEVICE_FEATURE_STATE_ENABLED;
Features.OcclusionQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.BinaryOcclusionQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.DurationQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.DepthBiasClamp = DEVICE_FEATURE_STATE_ENABLED;
Features.IndependentBlend = DEVICE_FEATURE_STATE_ENABLED;
Features.ShaderResourceStaticArrays = DEVICE_FEATURE_STATE_DISABLED;
Features.ShaderResourceRuntimeArrays = DEVICE_FEATURE_STATE_DISABLED;
Features.DualSourceBlend = DEVICE_FEATURE_STATE_ENABLED;
Features.MultiViewport = DEVICE_FEATURE_STATE_ENABLED;
Features.PixelUAVWritesAndAtomics = DEVICE_FEATURE_STATE_ENABLED;
Features.TextureUAVExtendedFormats = DEVICE_FEATURE_STATE_ENABLED;
Features.DepthClamp = DEVICE_FEATURE_STATE_ENABLED;
Features.FormattedBuffers = DEVICE_FEATURE_STATE_DISABLED;

if (wgpuAdapterHasFeature(wgpuAdapter, WGPUFeatureName_DepthClipControl))
Features.DepthBiasClamp = DEVICE_FEATURE_STATE_ENABLED;
Expand All @@ -280,7 +282,7 @@ GraphicsAdapterInfo GetGraphicsAdapterInfo(WGPUAdapter wgpuAdapter)
Features.ShaderFloat16 = DEVICE_FEATURE_STATE_ENABLED;
}

ASSERT_SIZEOF(DeviceFeatures, 45, "Did you add a new feature to DeviceFeatures? Please handle its status here.");
ASSERT_SIZEOF(DeviceFeatures, 46, "Did you add a new feature to DeviceFeatures? Please handle its status here.");

WGPUSupportedLimits wgpuSupportedLimits{};
wgpuAdapterGetLimits(wgpuAdapter, &wgpuSupportedLimits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ TEST(PRSCreationFailureTest, InvalidInputAttachmentFlag)
PRSDesc.Resources = Resources;
PRSDesc.NumResources = _countof(Resources);
const char* ExpectedErrorSubstring;
if (GPUTestingEnvironment::GetInstance()->GetDevice()->GetDeviceInfo().Features.ShaderResourceRuntimeArray)
if (GPUTestingEnvironment::GetInstance()->GetDevice()->GetDeviceInfo().Features.ShaderResourceRuntimeArrays)
ExpectedErrorSubstring = "Incorrect Desc.Resources[1].Flags (RUNTIME_ARRAY). Only the following flags are valid for a input attachment: GENERAL_INPUT_ATTACHMENT";
else
ExpectedErrorSubstring = "Incorrect Desc.Resources[1].Flags (RUNTIME_ARRAY). The flag can only be used if ShaderResourceRuntimeArray device feature is enabled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ TEST_F(PSOCreationFailureTest, InvalidRunTimeArray)
auto* const pDevice = pEnv->GetDevice();
const auto& DeviceInfo = pDevice->GetDeviceInfo();

if (!DeviceInfo.Features.ShaderResourceRuntimeArray)
if (!DeviceInfo.Features.ShaderResourceRuntimeArrays)
{
GTEST_SKIP();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ static void TestRunTimeResourceArray(bool IsGLSL, IShaderSourceInputStreamFactor
auto* pDevice = pEnv->GetDevice();

const auto& deviceCaps = pDevice->GetDeviceInfo();
if (!deviceCaps.Features.ShaderResourceRuntimeArray)
if (!deviceCaps.Features.ShaderResourceRuntimeArrays)
{
GTEST_SKIP() << "Shader Resource Runtime Arrays are not supported by this device";
}
Expand Down

0 comments on commit 1592248

Please sign in to comment.