Skip to content

Commit f53d23f

Browse files
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla
2 parents 690f9f6 + 5bee07e commit f53d23f

File tree

11 files changed

+147
-128
lines changed

11 files changed

+147
-128
lines changed

3rdparty/dxc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ if(NBL_EMBED_BUILTIN_RESOURCES)
139139
# SPIRV Header in builtin resources, nbl paths as aliases
140140
LIST_BUILTIN_RESOURCE(SPIRV_RESOURCES_TO_EMBED "unified1/spirv.h")
141141
LIST_BUILTIN_RESOURCE(SPIRV_RESOURCES_TO_EMBED "unified1/spirv.hpp")
142+
LIST_BUILTIN_RESOURCE(SPIRV_RESOURCES_TO_EMBED "unified1/GLSL.std.450.h")
142143

143144
ADD_CUSTOM_BUILTIN_RESOURCES(spirvBuiltinResourceData SPIRV_RESOURCES_TO_EMBED "${_SPIRV_BR_BUNDLE_SEARCH_DIRECTORY_}" "spirv" "spirv::builtin" "${_SPIRV_BR_OUTPUT_DIRECTORY_HEADER_}" "${_SPIRV_BR_OUTPUT_DIRECTORY_SOURCE_}" "STATIC" "INTERNAL")
144145
endif()

include/nbl/asset/IGraphicsPipeline.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,29 @@ class IGraphicsPipeline : public IPipeline<PipelineLayoutType>
100100
// TODO: check rasterization samples, etc.
101101
//rp->getCreationParameters().subpasses[i]
102102

103-
std::bitset<GRAPHICS_SHADER_STAGE_COUNT> stagePresence = {};
103+
core::bitflag<ICPUShader::E_SHADER_STAGE> stagePresence = {};
104104
for (const auto info : shaders)
105105
if (info.shader)
106106
{
107107
if (!extra(info))
108108
return false;
109109
const auto stage = info.shader->getStage();
110-
if (stage>=GRAPHICS_SHADER_STAGE_COUNT)
110+
if (stage>ICPUShader::ESS_FRAGMENT)
111111
return false;
112-
const auto stageIx = hlsl::findLSB(stage);
113-
if (stagePresence.test(stageIx))
112+
if (stagePresence.hasFlags(stage))
114113
return false;
115-
stagePresence.set(stageIx);
114+
stagePresence |= stage;
116115
}
117116
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-stage-02096
118-
if (!stagePresence.test(ICPUShader::ESS_VERTEX))
117+
if (!stagePresence.hasFlags(ICPUShader::ESS_VERTEX))
119118
return false;
120119
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-00729
121120
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-00730
122-
if (stagePresence.test(ICPUShader::ESS_TESSELLATION_CONTROL)!=stagePresence.test(ICPUShader::ESS_TESSELLATION_EVALUATION))
121+
if (stagePresence.hasFlags(ICPUShader::ESS_TESSELLATION_CONTROL)!=stagePresence.hasFlags(ICPUShader::ESS_TESSELLATION_EVALUATION))
123122
return false;
124123
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-pStages-08888
125124
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkGraphicsPipelineCreateInfo.html#VUID-VkGraphicsPipelineCreateInfo-topology-08889
126-
if (stagePresence.test(ICPUShader::ESS_TESSELLATION_EVALUATION)!=(cached.primitiveAssembly.primitiveType==EPT_PATCH_LIST))
125+
if (stagePresence.hasFlags(ICPUShader::ESS_TESSELLATION_EVALUATION)!=(cached.primitiveAssembly.primitiveType==EPT_PATCH_LIST))
127126
return false;
128127

129128
return true;

include/nbl/asset/utils/CHLSLCompiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
6161
L"-fvk-use-scalar-layout",
6262
L"-Wno-c++11-extensions",
6363
L"-Wno-c++1z-extensions",
64+
L"-Wno-c++14-extensions",
6465
L"-Wno-gnu-static-float-init",
6566
L"-fspv-target-env=vulkan1.3"
6667
};

include/nbl/builtin/hlsl/ext/FullScreenTriangle/SVertexAttributes.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace ext
1313
namespace FullScreenTriangle
1414
{
1515

16-
struct VertexAttributes
16+
struct SVertexAttributes
1717
{
1818
[[vk::location(0)]] float32_t2 uv : TEXCOORD0;
1919
};

include/nbl/builtin/hlsl/ext/FullScreenTriangle/default.vert.hlsl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For conditions of distribution and use, see copyright notice in nabla.h
44
#include <nbl/builtin/hlsl/glsl_compat/core.hlsl>
55
#include <nbl/builtin/hlsl/ext/FullScreenTriangle/SVertexAttributes.hlsl>
6-
//#include <nbl/builtin/glsl/utils/surface_transform.glsl>
6+
#include <nbl/builtin/hlsl/surface_transform.h>
77

88
using namespace ::nbl::hlsl;
99
using namespace ::nbl::hlsl::ext::FullScreenTriangle;
@@ -19,20 +19,18 @@ const static float32_t2 tc[3] = {
1919
float32_t2(2.0,0.0)
2020
};
2121

22-
/*
23-
layout (push_constant) uniform pushConstants
24-
{
25-
layout (offset = 0) uint swapchainTransform;
26-
} u_pushConstants;
27-
*/
22+
[[vk::constant_id(0)]] const uint32_t SwapchainTransform = 0;
23+
2824

29-
VertexAttributes main()
25+
SVertexAttributes main()
3026
{
3127
using namespace ::nbl::hlsl::glsl;
3228

33-
VertexAttributes retval;
34-
// vec2 pos = nbl_glsl_surface_transform_applyToNDC(u_pushConstants.swapchainTransform, pos[gl_VertexIndex]);
35-
spirv::Position = float32_t4(pos[gl_VertexIndex()], 0.f, 1.f);
29+
spirv::Position.xy = SurfaceTransform::applyToNDC((SurfaceTransform::FLAG_BITS)SwapchainTransform,pos[gl_VertexIndex()]);
30+
spirv::Position.z = 0.f;
31+
spirv::Position.w = 1.f;
32+
33+
SVertexAttributes retval;
3634
retval.uv = tc[gl_VertexIndex()];
3735
return retval;
3836
}

include/nbl/builtin/hlsl/glsl_compat/core.hlsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace glsl
1616
{
1717

1818
#ifdef __HLSL_VERSION
19+
/**
20+
* Generic SPIR-V
21+
*/
1922
template<typename T>
2023
T atomicAdd(NBL_REF_ARG(T) ptr, T value)
2124
{
@@ -57,6 +60,16 @@ T atomicCompSwap(NBL_REF_ARG(T) ptr, T comparator, T value)
5760
return spirv::atomicCompSwap<T>(ptr, spv::ScopeDevice, spv::DecorationRelaxedPrecision, spv::DecorationRelaxedPrecision, value, comparator);
5861
}
5962

63+
/**
64+
* GLSL extended math
65+
*/
66+
template<typename SquareMatrix> // NBL_REQUIRES() extents are square
67+
SquareMatrix inverse(NBL_CONST_REF_ARG(SquareMatrix) mat)
68+
{
69+
return spirv::matrixInverse(mat);
70+
}
71+
72+
6073
/**
6174
* For Vertex Shaders
6275
*/

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#ifdef __HLSL_VERSION // TODO: AnastZIuk fix public search paths so we don't choke
99
#include "spirv/unified1/spirv.hpp"
10-
//#include "spirv/unified1/spirv.hpp" TODO: also GLSL.450.std for the extended instruction set
10+
#include "spirv/unified1/GLSL.std.450.h"
1111
#endif
1212

1313

@@ -47,6 +47,7 @@ static const uint32_t3 GlobalInvocationId;
4747
[[vk::ext_builtin_input(spv::BuiltInLocalInvocationIndex)]]
4848
static const uint32_t LocalInvocationIndex;
4949

50+
//! General Operations
5051
template<typename T>
5152
T atomicAdd([[vk::ext_reference]] T ptr, uint32_t memoryScope, uint32_t memorySemantics, T value);
5253
template<>
@@ -124,6 +125,10 @@ template<>
124125
uint32_t atomicCompSwap([[vk::ext_reference]] uint32_t ptr, uint32_t memoryScope, uint32_t memSemanticsEqual, uint32_t memSemanticsUnequal, uint32_t value, uint32_t comparator);
125126

126127

128+
//! Std 450 Extended set operations
129+
template<typename SquareMatrix>
130+
[[vk::ext_instruction(GLSLstd450MatrixInverse)]]
131+
SquareMatrix matrixInverse(NBL_CONST_REF_ARG(SquareMatrix) mat);
127132

128133
// Memory Semantics link here: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Memory_Semantics_-id-
129134

include/nbl/builtin/hlsl/surface_transform.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef _NBL_BUILTIN_HLSL_SURFACE_TRANSFORM_INCLUDED_
55
#define _NBL_BUILTIN_HLSL_SURFACE_TRANSFORM_INCLUDED_
66
#include <nbl/builtin/hlsl/limits.hlsl>
7+
#include <nbl/builtin/hlsl/glsl_compat/core.hlsl>
78

89
namespace nbl
910
{
@@ -82,7 +83,7 @@ inline uint16_t2 transformedExtents(const FLAG_BITS transform, const uint16_t2 s
8283
default:
8384
break;
8485
}
85-
return uint16_t2(0);
86+
return uint16_t2(0,0);
8687
}
8788

8889
inline float transformedAspectRatio(const FLAG_BITS transform, const uint16_t2 screenSize)
@@ -123,7 +124,7 @@ inline uint16_t2 applyInverseToScreenSpaceCoordinate(const FLAG_BITS transform,
123124
default:
124125
break;
125126
}
126-
return uint16_t2(0);
127+
return uint16_t2(0,0);
127128
}
128129

129130
//! Use this function to apply the swapchain tranformation to the screenspace coordinate `coord`
@@ -155,7 +156,7 @@ inline uint16_t2 applyToScreenSpaceCoordinate(const FLAG_BITS transform, const u
155156
default:
156157
break;
157158
}
158-
return uint16_t2(0);
159+
return uint16_t2(0,0);
159160
}
160161

161162
//! Same as `applyToScreenSpaceCoordinate` but const NDC space
@@ -173,6 +174,7 @@ inline float32_t2 applyToNDC(const FLAG_BITS transform, const float32_t2 ndc)
173174
template<typename TwoColumns>
174175
TwoColumns applyToDerivatives(const FLAG_BITS transform, TwoColumns dDx_dDy)
175176
{
177+
using namespace glsl; // IN HLSL mode, C++ doens't need this to access `inverse`
176178
return mul(inverse(transformMatrix(transform)),dDx_dDy);
177179
}
178180

0 commit comments

Comments
 (0)