Skip to content

Commit 947475f

Browse files
authored
Merge pull request #848 from Devsh-Graphics-Programming/dxc_spirv_references
Dxc spirv references
2 parents 9f935ef + 4136f7d commit 947475f

File tree

10 files changed

+31
-23
lines changed

10 files changed

+31
-23
lines changed

3rdparty/dxc/dxc

Submodule dxc updated 104 files

include/nbl/builtin/hlsl/algorithm.hlsl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct bound_t
113113
}
114114

115115

116-
uint operator()(inout Accessor accessor)
116+
uint operator()(NBL_REF_ARG(Accessor) accessor)
117117
{
118118
if (isNPoT(len))
119119
{
@@ -132,19 +132,19 @@ struct bound_t
132132
return it;
133133
}
134134

135-
void iteration(inout Accessor accessor)
135+
void iteration(NBL_REF_ARG(Accessor) accessor)
136136
{
137137
len >>= 1;
138138
const uint mid = it+len;
139139
comp_step(accessor,mid);
140140
}
141141

142-
void comp_step(inout Accessor accessor, const uint testPoint, const uint rightBegin)
142+
void comp_step(NBL_REF_ARG(Accessor) accessor, const uint testPoint, const uint rightBegin)
143143
{
144144
if (comp(accessor[testPoint],value))
145145
it = rightBegin;
146146
}
147-
void comp_step(inout Accessor accessor, const uint testPoint)
147+
void comp_step(NBL_REF_ARG(Accessor) accessor, const uint testPoint)
148148
{
149149
comp_step(accessor,testPoint,testPoint);
150150
}
@@ -170,14 +170,14 @@ struct lower_to_upper_comparator_transform_t
170170

171171

172172
template<class Accessor, class Comparator>
173-
uint lower_bound(inout Accessor accessor, const uint begin, const uint end, const typename Accessor::value_type value, const Comparator comp)
173+
uint lower_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value, const Comparator comp)
174174
{
175175
impl::bound_t<Accessor,Comparator> implementation = impl::bound_t<Accessor,Comparator>::setup(begin,end,value,comp);
176176
return implementation(accessor);
177177
}
178178

179179
template<class Accessor, class Comparator>
180-
uint upper_bound(inout Accessor accessor, const uint begin, const uint end, const typename Accessor::value_type value, const Comparator comp)
180+
uint upper_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value, const Comparator comp)
181181
{
182182
//using TransformedComparator = impl::lower_to_upper_comparator_transform_t<Accessor,Comparator>;
183183
//TransformedComparator transformedComparator;
@@ -193,7 +193,7 @@ namespace impl
193193

194194
// extra indirection due to https://github.com/microsoft/DirectXShaderCompiler/issues/4771
195195
template<class Accessor, typename T>
196-
uint lower_bound(inout Accessor accessor, const uint begin, const uint end, const T value)
196+
uint lower_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const T value)
197197
{
198198
//using Comparator = nbl::hlsl::less<T>;
199199
//Comparator comp;
@@ -202,7 +202,7 @@ uint lower_bound(inout Accessor accessor, const uint begin, const uint end, cons
202202
return nbl::hlsl::lower_bound<Accessor, nbl::hlsl::less<T> >(accessor,begin,end,value,comp);
203203
}
204204
template<class Accessor, typename T>
205-
uint upper_bound(inout Accessor accessor, const uint begin, const uint end, const T value)
205+
uint upper_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const T value)
206206
{
207207
//using Comparator = nbl::hlsl::less<T>;
208208
//Comparator comp;
@@ -214,12 +214,12 @@ uint upper_bound(inout Accessor accessor, const uint begin, const uint end, cons
214214
}
215215

216216
template<class Accessor>
217-
uint lower_bound(inout Accessor accessor, const uint begin, const uint end, const typename Accessor::value_type value)
217+
uint lower_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value)
218218
{
219219
return impl::lower_bound<Accessor,typename Accessor::value_type>(accessor,begin,end,value);
220220
}
221221
template<class Accessor>
222-
uint upper_bound(inout Accessor accessor, const uint begin, const uint end, const typename Accessor::value_type value)
222+
uint upper_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value)
223223
{
224224
return impl::upper_bound<Accessor,typename Accessor::value_type>(accessor,begin,end,value);
225225
}

include/nbl/builtin/hlsl/bit.hlsl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ enable_if_t<sizeof(T)==sizeof(U)&&(is_scalar_v<T>||is_vector_v<T>)==(is_scalar_v
3737
{
3838
return spirv::bitcast<T,U>(val);
3939
}
40-
// unfortunately its impossible to deduce Storage Class right now,
41-
// also this function will only work as long as `inout` behaves as `__restrict &` in DXC
40+
// unfortunately its impossible to deduce Storage Class right now
4241
template<class T, class U, uint32_t StorageClass>
43-
enable_if_t<sizeof(T)==sizeof(U),T> bit_cast(inout U val)
42+
enable_if_t<sizeof(T)==sizeof(U),T> bit_cast(NBL_REF_ARG(U) val)
4443
{
4544
using ptr_u_t = spirv::pointer_t<U,StorageClass>;
4645
// get the address of U

include/nbl/builtin/hlsl/concepts/accessors/fft.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace workgroup
1313
namespace fft
1414
{
1515
// The SharedMemoryAccessor MUST provide the following methods:
16-
// * void get(uint32_t index, inout uint32_t value);
16+
// * void get(uint32_t index, NBL_REF_ARG(uint32_t) value);
1717
// * void set(uint32_t index, in uint32_t value);
1818
// * void workgroupExecutionAndMemoryBarrier();
1919

@@ -39,7 +39,7 @@ NBL_CONCEPT_END(
3939

4040

4141
// The Accessor (for a small FFT) MUST provide the following methods:
42-
// * void get(uint32_t index, inout complex_t<Scalar> value);
42+
// * void get(uint32_t index, NBL_REF_ARG(complex_t<Scalar>) value);
4343
// * void set(uint32_t index, in complex_t<Scalar> value);
4444

4545
#define NBL_CONCEPT_NAME FFTAccessor

include/nbl/builtin/hlsl/cpp_compat/basic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct add_pointer
9595
}
9696
}
9797

98-
#define NBL_REF_ARG(...) inout __VA_ARGS__
98+
#define NBL_REF_ARG(...) [[vk::ext_reference]] inout __VA_ARGS__
9999
#define NBL_CONST_REF_ARG(...) const in __VA_ARGS__
100100

101101
#endif

include/nbl/builtin/hlsl/scanning_append.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct result_t
2828
// Elements with value 0 do not get appended
2929
// Note: If NBL_GLSL_EXT_shader_atomic_int64 is not present, then the call to these functions needs to be subgroup uniform
3030
template<class AtomicCounterAccessor>
31-
result_t non_negative(inout AtomicCounterAccessor accessor, in uint value)
31+
result_t non_negative(NBL_REF_ARG(AtomicCounterAccessor) accessor, in uint value)
3232
{
3333
const bool willAppend = bool(value);
3434

@@ -70,7 +70,7 @@ result_t non_negative(inout AtomicCounterAccessor accessor, in uint value)
7070

7171
// optimized version which tries to omit the atomicAdd and locks if it can, in return it may return garbage/invalid value when invocation's `value==0`
7272
template<class AtomicCounterAccessor>
73-
result_t positive(inout AtomicCounterAccessor accessor, in uint value)
73+
result_t positive(NBL_REF_ARG(AtomicCounterAccessor) accessor, in uint value)
7474
{
7575
const bool willAppend = bool(value);
7676
#ifdef NBL_GLSL_EXT_shader_atomic_int64

include/nbl/builtin/hlsl/workgroup/fft.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ struct FFT;
294294
// If `ConstevalParameters::ElementsPerInvocationLog2 == 1`, the arrays it accesses with `get` and `set` can optionally be different,
295295
// if you don't want the FFT to be done in-place. Otherwise, you MUST make it in-place.
296296
// The Accessor MUST provide the following methods:
297-
// * void get(uint32_t index, inout complex_t<Scalar> value);
297+
// * void get(uint32_t index, NBL_REF_ARG(complex_t<Scalar>) value);
298298
// * void set(uint32_t index, in complex_t<Scalar> value);
299299
// * void memoryBarrier();
300300
// For it to work correctly, this memory barrier must use `AcquireRelease` semantics, with the proper flags set for the memory type.
@@ -303,7 +303,7 @@ struct FFT;
303303

304304
// - SharedMemoryAccessor accesses a workgroup-shared memory array of size `WorkgroupSize` elements of type complex_t<Scalar>.
305305
// The SharedMemoryAccessor MUST provide the following methods:
306-
// * void get(uint32_t index, inout uint32_t value);
306+
// * void get(uint32_t index, NBL_REF_ARG(uint32_t) value);
307307
// * void set(uint32_t index, in uint32_t value);
308308
// * void workgroupExecutionAndMemoryBarrier();
309309

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using namespace nbl;
2424
using namespace nbl::asset;
2525
using Microsoft::WRL::ComPtr;
2626

27-
static constexpr const wchar_t* SHADER_MODEL_PROFILE = L"XX_6_7";
27+
static constexpr const wchar_t* SHADER_MODEL_PROFILE = L"XX_6_8";
2828
static const wchar_t* ShaderStageToString(asset::IShader::E_SHADER_STAGE stage) {
2929
switch (stage)
3030
{
@@ -128,14 +128,15 @@ static void try_upgrade_hlsl_version(std::vector<std::wstring>& arguments, syste
128128

129129
static void try_upgrade_shader_stage(std::vector<std::wstring>& arguments, asset::IShader::E_SHADER_STAGE shaderStageOverrideFromPragma, system::logger_opt_ptr& logger) {
130130

131-
constexpr int MajorReqVersion = 6, MinorReqVersion = 7;
131+
constexpr int MajorReqVersion = 6, MinorReqVersion = 8;
132132
auto overrideStageStr = ShaderStageToString(shaderStageOverrideFromPragma);
133133
if (shaderStageOverrideFromPragma != IShader::E_SHADER_STAGE::ESS_UNKNOWN && !overrideStageStr)
134134
{
135135
logger.log("Invalid shader stage with int value '%i'.\nThis value does not have a known string representation.",
136136
system::ILogger::ELL_ERROR, shaderStageOverrideFromPragma);
137137
return;
138138
}
139+
// still unknown, then we take value from commandline arguments (precedence: pragma > DXC specific command line > compile option)
139140
bool setDefaultValue = true;
140141
auto foundShaderStageArgument = std::find(arguments.begin(), arguments.end(), L"-T");
141142
if (foundShaderStageArgument != arguments.end() && foundShaderStageArgument +1 != arguments.end()) {
@@ -202,6 +203,9 @@ static void try_upgrade_shader_stage(std::vector<std::wstring>& arguments, asset
202203
}
203204
if (setDefaultValue)
204205
{
206+
// if stage is still not known, lets go with library
207+
if (shaderStageOverrideFromPragma==IShader::E_SHADER_STAGE::ESS_UNKNOWN)
208+
overrideStageStr = ShaderStageToString(hlsl::ShaderStage::ESS_ALL_OR_LIBRARY);
205209
// in case of no -T
206210
// push back default values for -T argument
207211
// can be safely pushed to the back of argument list as output files should be evicted from args before passing to this func
@@ -379,6 +383,7 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
379383
if (context.get_hooks().m_dxc_compile_flags_override.size() != 0)
380384
dxc_compile_flags_override = context.get_hooks().m_dxc_compile_flags_override;
381385

386+
// pragma overrides what we passed in
382387
if(context.get_hooks().m_pragmaStage != IShader::E_SHADER_STAGE::ESS_UNKNOWN)
383388
stage = context.get_hooks().m_pragmaStage;
384389

src/nbl/asset/utils/IShaderCompiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ core::smart_refctd_ptr<ICPUShader> nbl::asset::IShaderCompiler::compileToSPIRV(c
4545

4646
auto retVal = compileToSPIRV_impl(code, options, options.writeCache ? &entry.dependencies : nullptr);
4747
// compute the SPIR-V shader content hash
48+
if (retVal)
4849
{
4950
auto backingBuffer = retVal->getContent();
5051
const_cast<ICPUBuffer*>(backingBuffer)->setContentHash(backingBuffer->computeContentHash());

src/nbl/builtin/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,5 +359,8 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/concepts/accessors/fft.hlsl")
359359
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/tgmath.hlsl")
360360
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/tgmath/impl.hlsl")
361361
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/tgmath/output_structs.hlsl")
362+
#blur
363+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/prefix_sum_blur/blur.hlsl")
364+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/prefix_sum_blur/box_sampler.hlsl")
362365

363366
ADD_CUSTOM_BUILTIN_RESOURCES(nblBuiltinResourceData NBL_RESOURCES_TO_EMBED "${NBL_ROOT_PATH}/include" "nbl/builtin" "nbl::builtin" "${NBL_ROOT_PATH_BINARY}/include" "${NBL_ROOT_PATH_BINARY}/src" "STATIC" "INTERNAL")

0 commit comments

Comments
 (0)