|
| 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 |
0 commit comments