Skip to content

Commit 70bd114

Browse files
minor fixes and debug
1 parent 4147b99 commit 70bd114

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace hlsl
1414
namespace glsl
1515
{
1616

17+
#ifdef __HLSL_VERSION
1718
template<typename T>
1819
T atomicAdd(NBL_REF_ARG(T) ptr, T value)
1920
{
@@ -59,7 +60,8 @@ T atomicCompSwap(NBL_REF_ARG(T) ptr, T comparator, T value)
5960
* For Compute Shaders
6061
*/
6162

62-
// TODO (Future): Its annoying we have to forward declare those, but accessing gl_NumSubgroups and other gl_* values is not yet possible due to https://github.com/microsoft/DirectXShaderCompiler/issues/4217
63+
// TODO (Future): Its annoying we have to forward declare those, but accessing gl_NumSubgroups and other gl_* values is not yet possible due to https://github.com/microsoft/DirectXShaderCompiler/issues/4217
64+
// also https://github.com/microsoft/DirectXShaderCompiler/issues/5280
6365
uint32_t gl_LocalInvocationIndex();
6466
uint32_t3 gl_GlobalInvocationID();
6567
uint32_t3 gl_WorkGroupID();
@@ -78,6 +80,7 @@ void tess_ctrl_barrier() {
7880
void memoryBarrierShared() {
7981
spirv::memoryBarrier(spv::ScopeDevice, spv::MemorySemanticsAcquireReleaseMask | spv::MemorySemanticsWorkgroupMemoryMask);
8082
}
83+
#endif
8184

8285
}
8386
}

include/nbl/builtin/hlsl/glsl_compat/subgroup_basic.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace hlsl
1414
namespace glsl
1515
{
1616

17+
#ifdef __HLSL_VERSION
1718
uint32_t gl_SubgroupSize() {
1819
return WaveGetLaneCount();
1920
}
@@ -55,6 +56,7 @@ void subgroupMemoryBarrierShared() {
5556
void subgroupMemoryBarrierImage() {
5657
spirv::memoryBarrier(spv::ScopeSubgroup, spv::MemorySemanticsAcquireReleaseMask | spv::MemorySemanticsImageMemoryMask);
5758
}
59+
#endif
5860

5961
}
6062
}

include/nbl/builtin/hlsl/subgroup/arithmetic_portability.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ namespace hlsl
1717
namespace subgroup
1818
{
1919

20-
#ifdef NBL_GL_KHR_shader_subgroup_arithmetic
21-
#define IMPL portability
22-
#else
20+
#ifdef NBL_GLSL_LIMIT_SHADER_SUBGROUP_ARITHMETIC
2321
#define IMPL native
22+
#else
23+
#define IMPL portability
2424
#endif
2525

2626
template<class Binop>

include/nbl/builtin/hlsl/subgroup/arithmetic_portability_impl.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ struct inclusive_scan
8383
const uint subgroupInvocation = glsl::gl_SubgroupInvocationID();
8484
const uint halfSubgroupSize = glsl::gl_SubgroupSize() >> 1u;
8585

86-
uint rhs = glsl::subgroupShuffleUp<type_t>(value, 1u); // all invocations must execute the shuffle, even if we don't apply the op() to all of them
86+
type_t rhs = glsl::subgroupShuffleUp<type_t>(value, 1u); // all invocations must execute the shuffle, even if we don't apply the op() to all of them
8787
value = op(value, subgroupInvocation<1u ? Binop::identity:rhs);
8888

89-
[[unroll(MinSubgroupSizeLog2-1)]]
89+
[[unroll(nbl::hlsl::subgroup::MinSubgroupSizeLog2-1)]]
9090
for (uint step=2u; step<=halfSubgroupSize; step <<= 1u)
9191
{
9292
rhs = glsl::subgroupShuffleUp<type_t>(value, step);

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,18 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
313313
auto resolvedString = proc.Process();
314314
IShaderCompiler::reenableDirectives(resolvedString);
315315

316+
// for debugging cause MSVC doesn't like to show more than 21k LoC in TextVisualizer
317+
if constexpr (true)
318+
{
319+
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
320+
m_system->createFile(future,system::path(preprocessOptions.sourceIdentifier).parent_path()/"preprocessed.hlsl",system::IFileBase::ECF_WRITE);
321+
if (auto file=future.acquire(); file&&bool(*file))
322+
{
323+
system::IFile::success_t succ;
324+
(*file)->write(succ,resolvedString.data(),0,resolvedString.size()+1);
325+
}
326+
}
327+
316328
return resolvedString;
317329
}
318330

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,18 @@ class CVulkanLogicalDevice final : public ILogicalDevice
733733
vk_createInfo.flags = static_cast<VkShaderModuleCreateFlags>(0u); // reserved for future use by Vulkan
734734
vk_createInfo.codeSize = spirv->getSize();
735735
vk_createInfo.pCode = static_cast<const uint32_t*>(spirv->getPointer());
736+
737+
// for debugging
738+
if constexpr (true)
739+
{
740+
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
741+
m_physicalDevice->getSystem()->createFile(future,system::path(cpushader->getFilepathHint()).parent_path()/"compiled.spv", system::IFileBase::ECF_WRITE);
742+
if (auto file = future.acquire(); file && bool(*file))
743+
{
744+
system::IFile::success_t succ;
745+
(*file)->write(succ,vk_createInfo.pCode,0,vk_createInfo.codeSize);
746+
}
747+
}
736748

737749
VkShaderModule vk_shaderModule;
738750
if (m_devf.vk.vkCreateShaderModule(m_vkdev, &vk_createInfo, nullptr, &vk_shaderModule) == VK_SUCCESS)

0 commit comments

Comments
 (0)