Skip to content

Commit 7bb1699

Browse files
areidmeyermatthewdcong
authored andcommitted
PNanoVDB. Move StructuredBuffer<uint64_t> to StructuredBuffer<uint2>
Signed-off-by: Matthew Cong <mcong@nvidia.com>
1 parent 7b5b2c2 commit 7bb1699

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

nanovdb/nanovdb/PNanoVDB.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,13 @@ typedef uint32_t pnanovdb_grid_type_t;
200200
#elif defined(PNANOVDB_BUF_HLSL)
201201
#if defined(PNANOVDB_BUF_HLSL_RW)
202202
#if defined(PNANOVDB_BUF_HLSL_64)
203-
#if defined(PNANOVDB_ADDRESS_64)
204-
#define pnanovdb_buf_t RWStructuredBuffer<uint64_t>
205-
#else
206203
#define pnanovdb_buf_t RWStructuredBuffer<uint2>
207-
#endif
208204
#else
209205
#define pnanovdb_buf_t RWStructuredBuffer<uint>
210206
#endif
211207
#else
212208
#if defined(PNANOVDB_BUF_HLSL_64)
213-
#if defined(PNANOVDB_ADDRESS_64)
214-
#define pnanovdb_buf_t StructuredBuffer<uint64_t>
215-
#else
216209
#define pnanovdb_buf_t StructuredBuffer<uint2>
217-
#endif
218210
#else
219211
#define pnanovdb_buf_t StructuredBuffer<uint>
220212
#endif
@@ -268,8 +260,8 @@ void pnanovdb_buf_write_uint64(pnanovdb_buf_t buf, uint byte_offset, uint2 value
268260
uint pnanovdb_buf_read_uint32(pnanovdb_buf_t buf, uint64_t byte_offset)
269261
{
270262
#if defined(PNANOVDB_BUF_HLSL_64)
271-
uint64_t val64 = buf[uint(byte_offset >> 3u)];
272-
return ((uint(byte_offset) & 4u) == 0u) ? uint(val64) : uint(val64 >> 32u);
263+
uint2 val = buf[uint(byte_offset >> 3u)];
264+
return ((uint(byte_offset) & 4u) == 0u) ? val.x : val.y;
273265
#else
274266
return buf[uint(byte_offset >> 2u)];
275267
#endif
@@ -278,10 +270,11 @@ uint64_t pnanovdb_buf_read_uint64(pnanovdb_buf_t buf, uint64_t byte_offset)
278270
{
279271
uint64_t ret;
280272
#if defined(PNANOVDB_BUF_HLSL_64)
281-
ret = buf[uint(byte_offset >> 3u)];
273+
uint2 raw = buf[uint(byte_offset >> 3u)];
274+
ret = uint64_t(raw.x) | (uint64_t(raw.y) << 32u);
282275
#else
283276
ret = pnanovdb_buf_read_uint32(buf, byte_offset + 0u);
284-
ret = ret + (uint64_t(pnanovdb_buf_read_uint32(buf, byte_offset + 4u)) << 32u);
277+
ret = ret | (uint64_t(pnanovdb_buf_read_uint32(buf, byte_offset + 4u)) << 32u);
285278
#endif
286279
return ret;
287280
}
@@ -290,9 +283,8 @@ void pnanovdb_buf_write_uint32(pnanovdb_buf_t buf, uint64_t byte_offset, uint va
290283
// NOP, by default no write in HLSL
291284
#if defined(PNANOVDB_BUF_HLSL_RW)
292285
#if defined(PNANOVDB_BUF_HLSL_64)
293-
uint shift = (uint(byte_offset) & 4u) == 0u ? 0u : 32u;
294-
InterlockedAnd(buf[uint(byte_offset >> 3u)], ~(0xFFFFFFFFllu << shift));
295-
InterlockedOr(buf[uint(byte_offset >> 3u)], uint64_t(value) << shift);
286+
if ((byte_offset & 4u) == 0u) {buf[uint(byte_offset >> 3u)].x = value;}
287+
else {buf[uint(byte_offset >> 3u)].y = value;}
296288
#else
297289
buf[uint(byte_offset >> 2u)] = value;
298290
#endif
@@ -303,7 +295,8 @@ void pnanovdb_buf_write_uint64(pnanovdb_buf_t buf, uint64_t byte_offset, uint64_
303295
// NOP, by default no write in HLSL
304296
#if defined(PNANOVDB_BUF_HLSL_RW)
305297
#if defined(PNANOVDB_BUF_HLSL_64)
306-
buf[uint(byte_offset >> 3u)] = value;
298+
uint2 raw = uint2(uint(value), uint(value >> 32u));
299+
buf[uint(byte_offset >> 3u)] = raw;
307300
#else
308301
pnanovdb_buf_write_uint32(buf, byte_offset + 0u, uint(value));
309302
pnanovdb_buf_write_uint32(buf, byte_offset + 4u, uint(value >> 32u));

0 commit comments

Comments
 (0)