Skip to content

Commit b2f7055

Browse files
committed
Adds legacy bda accessor, fixes fft accessor usage
1 parent f025adb commit b2f7055

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (C) 2018-2024 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
// TODO: Remove all appearances of this class and refactor to use the real BDA once https://github.com/microsoft/DirectXShaderCompiler/issues/6541 is resolved
6+
// Then, delete this file altogether.
7+
8+
9+
#ifndef _NBL_BUILTIN_HLSL_LEGACY_BDA_ACCESSOR_INCLUDED_
10+
#define _NBL_BUILTIN_HLSL_LEGACY_BDA_ACCESSOR_INCLUDED_
11+
12+
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
13+
#include "nbl/builtin/hlsl/bda/__ptr.hlsl"
14+
15+
namespace nbl
16+
{
17+
namespace hlsl
18+
{
19+
20+
namespace impl {
21+
22+
struct LegacyBdaAccessorBase
23+
{
24+
// Note: Its a funny quirk of the SPIR-V Vulkan Env spec that `MemorySemanticsUniformMemoryMask` means SSBO as well :facepalm: (and probably BDA)
25+
void workgroupExecutionAndMemoryBarrier()
26+
{
27+
// we're only barriering the workgroup and trading memory within a workgroup
28+
spirv::controlBarrier(spv::ScopeWorkgroup, spv::ScopeWorkgroup, spv::MemorySemanticsAcquireReleaseMask | spv::MemorySemanticsUniformMemoryMask);
29+
}
30+
31+
void memoryBarrier()
32+
{
33+
// By default it's device-wide access to the buffer
34+
spirv::memoryBarrier(spv::ScopeDevice, spv::MemorySemanticsAcquireReleaseMask | spv::MemorySemanticsUniformMemoryMask);
35+
}
36+
};
37+
38+
} //namespace impl
39+
40+
template<typename T>
41+
struct LegacyBdaAccessor : impl::LegacyBdaAccessorBase
42+
{
43+
using type_t = T;
44+
static LegacyBdaAccessor<T> create(const uint64_t address)
45+
{
46+
LegacyBdaAccessor<T> accessor;
47+
accessor.address = address;
48+
return accessor;
49+
}
50+
51+
T get(const uint64_t index)
52+
{
53+
return vk::RawBufferLoad<T>(address + index * sizeof(T));
54+
}
55+
56+
void get(const uint64_t index, NBL_REF_ARG(T) value)
57+
{
58+
value = vk::RawBufferLoad<T>(address + index * sizeof(T));
59+
}
60+
61+
void set(const uint64_t index, const T value)
62+
{
63+
vk::RawBufferStore<T>(address + index * sizeof(T), value);
64+
}
65+
66+
uint64_t address;
67+
};
68+
69+
template<typename T>
70+
struct DoubleLegacyBdaAccessor : impl::LegacyBdaAccessorBase
71+
{
72+
using type_t = T;
73+
static DoubleLegacyBdaAccessor<T> create(const uint64_t inputAddress, const uint64_t outputAddress)
74+
{
75+
DoubleLegacyBdaAccessor<T> accessor;
76+
accessor.inputAddress = inputAddress;
77+
accessor.outputAddress = outputAddress;
78+
return accessor;
79+
}
80+
81+
T get(const uint64_t index)
82+
{
83+
return vk::RawBufferLoad<T>(inputAddress + index * sizeof(T));
84+
}
85+
86+
void get(const uint64_t index, NBL_REF_ARG(T) value)
87+
{
88+
value = vk::RawBufferLoad<T>(inputAddress + index * sizeof(T));
89+
}
90+
91+
void set(const uint64_t index, const T value)
92+
{
93+
vk::RawBufferStore<T>(outputAddress + index * sizeof(T), value);
94+
}
95+
96+
uint64_t inputAddress, outputAddress;
97+
};
98+
99+
100+
}
101+
}
102+
103+
#endif

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ struct FFT<K, false, Scalar, device_capabilities>
276276

277277
// do K/2 small workgroup FFTs
278278
accessor_adaptors::Offset<Accessor> offsetAccessor;
279+
offsetAccessor.accessor = accessor;
279280
[unroll]
280281
for (uint32_t k = 0; k < K; k += 2)
281282
{
@@ -297,6 +298,7 @@ struct FFT<K, true, Scalar, device_capabilities>
297298
{
298299
// do K/2 small workgroup FFTs
299300
accessor_adaptors::Offset<Accessor> offsetAccessor;
301+
offsetAccessor.accessor = accessor;
300302
[unroll]
301303
for (uint32_t k = 0; k < K; k += 2)
302304
{

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/barycentric/utils.glsl")
3434
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/bda/__ref.hlsl")
3535
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/bda/__ptr.hlsl")
3636
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/bda/bda_accessor.hlsl")
37+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/bda/legacy_bda_accessor.hlsl")
3738
# bump mapping
3839
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bump_mapping/fragment.glsl") # TODO: rename to `frag.glsl`
3940
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "glsl/bump_mapping/utils.glsl")

0 commit comments

Comments
 (0)