Skip to content

Commit 4fabab9

Browse files
authored
Merge pull request #643 from Devsh-Graphics-Programming/nahim_shader_defines
Nahim shader defines
2 parents dd2c5d3 + 0ccb0c1 commit 4fabab9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+15125
-3344
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ tools/nsc/.profiles/*
3535
tools/nsc/bin/*
3636
*/__pycache__/*
3737
__pycache__/*
38+
*.pyc

include/nbl/application_templates/MonoDeviceApplication.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MonoDeviceApplication : public virtual MonoSystemMonoLoggerApplication
118118
{
119119
video::SPhysicalDeviceLimits retval = {};
120120

121-
retval.subgroupOpsShaderStages = asset::IShader::ESS_COMPUTE;
121+
retval.subgroupOpsShaderStages = asset::IShader::E_SHADER_STAGE::ESS_COMPUTE;
122122

123123
return retval;
124124
}

include/nbl/asset/ICPUComputePipeline.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
3838
inline E_TYPE getAssetType() const override { return AssetType; }
3939

4040
// provide default arg
41-
inline IShader::SSpecInfo<ICPUShader> getSpecInfo() {return base_t::getSpecInfo(ICPUShader::ESS_COMPUTE);}
42-
inline IShader::SSpecInfo<const ICPUShader> getSpecInfo() const {return base_t::getSpecInfo(ICPUShader::ESS_COMPUTE);}
41+
inline IShader::SSpecInfo<ICPUShader> getSpecInfo() {return base_t::getSpecInfo(ICPUShader::E_SHADER_STAGE::ESS_COMPUTE);}
42+
inline IShader::SSpecInfo<const ICPUShader> getSpecInfo() const {return base_t::getSpecInfo(ICPUShader::E_SHADER_STAGE::ESS_COMPUTE);}
4343

4444
protected:
4545
using base_t::base_t;
@@ -51,7 +51,7 @@ class ICPUComputePipeline : public ICPUPipeline<IPipeline<ICPUPipelineLayout>,1>
5151
}
5252
inline int8_t stageToIndex(const ICPUShader::E_SHADER_STAGE stage) const override
5353
{
54-
return stage!=ICPUShader::ESS_COMPUTE ? (-1):0;
54+
return stage!=ICPUShader::E_SHADER_STAGE::ESS_COMPUTE ? (-1):0;
5555
}
5656
};
5757

include/nbl/asset/IGraphicsPipeline.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,22 @@ class IGraphicsPipeline : public IPipeline<PipelineLayoutType>
107107
if (!extra(info))
108108
return false;
109109
const auto stage = info.shader->getStage();
110-
if (stage>ICPUShader::ESS_FRAGMENT)
110+
if (stage>ICPUShader::E_SHADER_STAGE::ESS_FRAGMENT)
111111
return false;
112112
if (stagePresence.hasFlags(stage))
113113
return false;
114114
stagePresence |= stage;
115115
}
116116
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-stage-02096
117-
if (!stagePresence.hasFlags(ICPUShader::ESS_VERTEX))
117+
if (!stagePresence.hasFlags(ICPUShader::E_SHADER_STAGE::ESS_VERTEX))
118118
return false;
119119
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-00729
120120
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-00730
121-
if (stagePresence.hasFlags(ICPUShader::ESS_TESSELLATION_CONTROL)!=stagePresence.hasFlags(ICPUShader::ESS_TESSELLATION_EVALUATION))
121+
if (stagePresence.hasFlags(ICPUShader::E_SHADER_STAGE::ESS_TESSELLATION_CONTROL)!=stagePresence.hasFlags(ICPUShader::E_SHADER_STAGE::ESS_TESSELLATION_EVALUATION))
122122
return false;
123123
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-08888
124124
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-topology-08889
125-
if (stagePresence.hasFlags(ICPUShader::ESS_TESSELLATION_EVALUATION)!=(cached.primitiveAssembly.primitiveType==EPT_PATCH_LIST))
125+
if (stagePresence.hasFlags(ICPUShader::E_SHADER_STAGE::ESS_TESSELLATION_EVALUATION)!=(cached.primitiveAssembly.primitiveType==EPT_PATCH_LIST))
126126
return false;
127127

128128
return true;

include/nbl/asset/IImage.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "nbl/asset/ECommonEnums.h"
1616
#include "nbl/system/ILogger.h"
1717

18+
#include "nbl/builtin/hlsl/enums.hlsl"
19+
1820
#include <bitset>
1921
#include <compare>
2022

@@ -110,15 +112,14 @@ class IImage : public IDescriptor
110112
ET_3D,
111113
ET_COUNT
112114
};
113-
enum E_SAMPLE_COUNT_FLAGS : uint8_t
114-
{
115-
ESCF_1_BIT = 0x01,
116-
ESCF_2_BIT = 0x02,
117-
ESCF_4_BIT = 0x04,
118-
ESCF_8_BIT = 0x08,
119-
ESCF_16_BIT = 0x10,
120-
ESCF_32_BIT = 0x20,
121-
ESCF_64_BIT = 0x40
115+
enum E_SAMPLE_COUNT_FLAGS : uint8_t {
116+
ESCF_1_BIT = nbl::hlsl::SampleCountFlags::ESCF_1_BIT,
117+
ESCF_2_BIT = nbl::hlsl::SampleCountFlags::ESCF_2_BIT,
118+
ESCF_4_BIT = nbl::hlsl::SampleCountFlags::ESCF_4_BIT,
119+
ESCF_8_BIT = nbl::hlsl::SampleCountFlags::ESCF_8_BIT,
120+
ESCF_16_BIT = nbl::hlsl::SampleCountFlags::ESCF_16_BIT,
121+
ESCF_32_BIT = nbl::hlsl::SampleCountFlags::ESCF_32_BIT,
122+
ESCF_64_BIT = nbl::hlsl::SampleCountFlags::ESCF_64_BIT
122123
};
123124
enum E_USAGE_FLAGS : uint16_t
124125
{
@@ -354,7 +355,7 @@ class IImage : public IDescriptor
354355
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImageCreateInfo.html#VUID-VkImageCreateInfo-flags-08866
355356
if (_params.arrayLayers < 6u)
356357
return false;
357-
if (_params.samples != ESCF_1_BIT)
358+
if (_params.samples != E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
358359
return false;
359360
}
360361

@@ -433,7 +434,7 @@ class IImage : public IDescriptor
433434
return false;
434435
}
435436

436-
if (_params.samples != ESCF_1_BIT)
437+
if (_params.samples != E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
437438
{
438439
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImageCreateInfo.html#VUID-VkImageCreateInfo-samples-02257
439440
if (_params.type != ET_2D || _params.flags.hasFlags(ECF_CUBE_COMPATIBLE_BIT) || _params.mipLevels == 1u)
@@ -476,7 +477,7 @@ class IImage : public IDescriptor
476477

477478
if (asset::isPlanarFormat(_params.format))
478479
{
479-
if (_params.mipLevels > 1u || _params.samples != ESCF_1_BIT || _params.type != ET_2D)
480+
if (_params.mipLevels > 1u || _params.samples != E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT || _params.type != ET_2D)
480481
return false;
481482
}
482483
else if (!_params.flags.hasFlags(ECF_ALIAS_BIT) && _params.flags.hasFlags(ECF_DISJOINT_BIT))
@@ -489,7 +490,7 @@ class IImage : public IDescriptor
489490
if (_params.usage.hasFlags(EUF_SHADING_RATE_ATTACHMENT_BIT))
490491
{
491492
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImageCreateInfo.html#VUID-VkImageCreateInfo-imageType-02082
492-
if (_params.type!=ET_2D || _params.samples!=ESCF_1_BIT)
493+
if (_params.type!=ET_2D || _params.samples != E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
493494
return false;
494495
}
495496

@@ -681,7 +682,7 @@ class IImage : public IDescriptor
681682
}
682683
else
683684
{
684-
if (m_creationParams.samples!=ESCF_1_BIT)
685+
if (m_creationParams.samples!=E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
685686
die = true;
686687
}
687688

@@ -850,8 +851,6 @@ class IImage : public IDescriptor
850851
static_assert(sizeof(IImage)-sizeof(IDescriptor)!=3u*sizeof(uint32_t)+sizeof(VkExtent3D)+sizeof(uint32_t)*3u,"BaW File Format won't work");
851852

852853
NBL_ENUM_ADD_BITWISE_OPERATORS(IImage::E_USAGE_FLAGS)
853-
NBL_ENUM_ADD_BITWISE_OPERATORS(IImage::E_SAMPLE_COUNT_FLAGS)
854-
855854
} // end namespace nbl::asset
856855

857856
#endif

include/nbl/asset/IImageView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class IImageView : public IImageViewBase
188188
break;
189189
default:
190190
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImageViewCreateInfo.html#VUID-VkImageViewCreateInfo-image-04972
191-
if (imgParams.samples!=IImage::ESCF_1_BIT)
191+
if (imgParams.samples!=IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
192192
return false;
193193
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkImageViewCreateInfo.html#VUID-VkImageViewCreateInfo-image-02086
194194
if (imgParams.usage.hasFlags(IImage::EUF_SHADING_RATE_ATTACHMENT_BIT))

include/nbl/asset/IRenderpass.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class IRenderpass
5858
struct SAttachmentDescriptionBase
5959
{
6060
E_FORMAT format = EF_UNKNOWN;
61-
IImage::E_SAMPLE_COUNT_FLAGS samples : 6 = IImage::ESCF_1_BIT;
61+
IImage::E_SAMPLE_COUNT_FLAGS samples : 6 = IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT;
6262
uint8_t mayAlias : 1 = false;
6363

6464
auto operator<=>(const SAttachmentDescriptionBase&) const = default;
@@ -163,13 +163,13 @@ class IRenderpass
163163
};
164164
struct SDepthStencilAttachmentsRef final : SRenderAttachmentsRef<SDepthStencilAttachmentRef>
165165
{
166-
enum class RESOLVE_MODE : uint8_t
166+
enum RESOLVE_MODE : uint8_t
167167
{
168-
NONE = 0,
169-
SAMPLE_ZERO_BIT = 0x00000001,
170-
AVERAGE_BIT = 0x00000002,
171-
MIN_BIT = 0x00000004,
172-
MAX_BIT = 0x00000008
168+
NONE = nbl::hlsl::ResolveModeFlags::NONE,
169+
SAMPLE_ZERO_BIT = nbl::hlsl::ResolveModeFlags::SAMPLE_ZERO_BIT,
170+
AVERAGE_BIT = nbl::hlsl::ResolveModeFlags::AVERAGE_BIT,
171+
MIN_BIT = nbl::hlsl::ResolveModeFlags::MIN_BIT,
172+
MAX_BIT = nbl::hlsl::ResolveModeFlags::MAX_BIT
173173
};
174174
struct ResolveMode
175175
{
@@ -720,12 +720,12 @@ inline bool IRenderpass::SCreationParams::SSubpassDescription::SRenderAttachment
720720
const auto& renderAttachment = descs[render.attachmentIndex];
721721
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSubpassDescription2.html#VUID-VkSubpassDescription2-pResolveAttachments-03066
722722
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSubpassDescriptionDepthStencilResolve.html#VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03179
723-
if (renderAttachment.samples!=IImage::ESCF_1_BIT)
723+
if (renderAttachment.samples!=IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
724724
return true;
725725
const auto& resolveAttachment = descs[resolve.attachmentIndex];
726726
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSubpassDescription2.html#VUID-VkSubpassDescription2-pResolveAttachments-03067
727727
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSubpassDescriptionDepthStencilResolve.html#VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03180
728-
if (resolveAttachment.samples==IImage::ESCF_1_BIT)
728+
if (resolveAttachment.samples==IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
729729
return true;
730730
if constexpr (attachment_ref_t::IsDepthStencil)
731731
{

include/nbl/asset/IShader.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
#include "nbl/core/declarations.h"
9+
#include "nbl/builtin/hlsl/enums.hlsl"
910

1011
#include <algorithm>
1112
#include <string>
@@ -31,27 +32,7 @@ namespace nbl::asset
3132
class IShader : public virtual core::IReferenceCounted // TODO: do we need this inheritance?
3233
{
3334
public:
34-
// TODO: make this enum class
35-
enum E_SHADER_STAGE : uint32_t
36-
{
37-
ESS_UNKNOWN = 0,
38-
ESS_VERTEX = 1 << 0,
39-
ESS_TESSELLATION_CONTROL = 1 << 1,
40-
ESS_TESSELLATION_EVALUATION = 1 << 2,
41-
ESS_GEOMETRY = 1 << 3,
42-
ESS_FRAGMENT = 1 << 4,
43-
ESS_COMPUTE = 1 << 5,
44-
ESS_TASK = 1 << 6,
45-
ESS_MESH = 1 << 7,
46-
ESS_RAYGEN = 1 << 8,
47-
ESS_ANY_HIT = 1 << 9,
48-
ESS_CLOSEST_HIT = 1 << 10,
49-
ESS_MISS = 1 << 11,
50-
ESS_INTERSECTION = 1 << 12,
51-
ESS_CALLABLE = 1 << 13,
52-
ESS_ALL_GRAPHICS = 0x0000001F,
53-
ESS_ALL = 0x7fffffff
54-
};
35+
using E_SHADER_STAGE = nbl::hlsl::ShaderStage;
5536

5637
IShader(const E_SHADER_STAGE shaderStage, std::string&& filepathHint)
5738
: m_shaderStage(shaderStage), m_filepathHint(std::move(filepathHint)) {}
@@ -254,9 +235,6 @@ class IShader : public virtual core::IReferenceCounted // TODO: do we need this
254235
E_SHADER_STAGE m_shaderStage;
255236
std::string m_filepathHint;
256237
};
257-
258-
NBL_ENUM_ADD_BITWISE_OPERATORS(IShader::E_SHADER_STAGE)
259-
260238
}
261239

262240
#endif

include/nbl/asset/filters/CFlattenRegionsImageFilter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CFlattenRegionsImageFilter : public CImageFilter<CFlattenRegionsImageFilte
4242

4343
const auto& inParams = state->inImage->getCreationParameters();
4444
// TODO: remove this later when we can actually handle multi samples
45-
if (inParams.samples!=IImage::ESCF_1_BIT)
45+
if (inParams.samples!=IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT)
4646
return false;
4747

4848
// Reject formats that can have more than one valid aspect masks, which are only depth-stencil formats.

include/nbl/asset/utils/CSPIRVIntrospector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ class NBL_API2 CSPIRVIntrospector : public core::Uncopyable
401401
inline const auto& getInputs() const { return m_input; }
402402
inline const std::span<const SFragmentOutputInterface> getFragmentShaderOutputs() const
403403
{
404-
if (m_shaderStage != IShader::ESS_FRAGMENT)
404+
if (m_shaderStage != IShader::E_SHADER_STAGE::ESS_FRAGMENT)
405405
return {};
406406

407407
const auto& outputInterface = std::get<core::vector<SFragmentOutputInterface>>(m_output);
408408
return { outputInterface.data(), outputInterface.size() };
409409
}
410410
inline const std::span<const SOutputInterface> getShaderOutputs() const
411411
{
412-
if (m_shaderStage == IShader::ESS_UNKNOWN || m_shaderStage == IShader::ESS_FRAGMENT)
412+
if (m_shaderStage == IShader::E_SHADER_STAGE::ESS_UNKNOWN || m_shaderStage == IShader::E_SHADER_STAGE::ESS_FRAGMENT)
413413
return {};
414414

415415
const auto& outputInterface = std::get<core::vector<SOutputInterface>>(m_output);
@@ -571,12 +571,12 @@ class NBL_API2 CSPIRVIntrospector : public core::Uncopyable
571571
uint32_t count : 31 = 0;
572572
uint32_t isRuntimeSizedFlag : 1;
573573
// Which shader stages touch it
574-
core::bitflag<ICPUShader::E_SHADER_STAGE> stageMask = ICPUShader::ESS_UNKNOWN;
574+
core::bitflag<ICPUShader::E_SHADER_STAGE> stageMask = ICPUShader::E_SHADER_STAGE::ESS_UNKNOWN;
575575
};
576576
//
577577
inline CPipelineIntrospectionData()
578578
{
579-
std::fill(m_pushConstantBytes.begin(),m_pushConstantBytes.end(),ICPUShader::ESS_UNKNOWN);
579+
std::fill(m_pushConstantBytes.begin(),m_pushConstantBytes.end(),ICPUShader::E_SHADER_STAGE::ESS_UNKNOWN);
580580
std::fill(m_highestBindingNumbers.begin(), m_highestBindingNumbers.end(), HighestBindingData());
581581
}
582582

0 commit comments

Comments
 (0)