Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
13 changes: 13 additions & 0 deletions 12_Mortons/app_resources/common.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//#include "nbl/builtin/hlsl/morton.hlsl"
#include "nbl/builtin/hlsl/cpp_compat.hlsl"

NBL_CONSTEXPR uint32_t bufferSize = 256;

// Proper coverage would require writing tests for ALL possible sign, dimensions and width configurations
//using morton_t2 = nbl::hlsl::morton::code<true, 8, 2>; // Fits in an int16_t
using vector_t2 = nbl::hlsl::vector<int16_t, 3>;

struct PushConstantData
{
uint64_t deviceBufferAddress;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

[[vk::push_constant]] PushConstantData pushConstants;

using namespace nbl::hlsl;

[numthreads(bufferSize, 1, 1)]
void main(uint32_t3 ID : SV_DispatchThreadID)
{
/*
LegacyBdaAccessor<unsigned_scalar_t> accessor = LegacyBdaAccessor<unsigned_scalar_t>::create(pushConstants.deviceBufferAddress);

morton::code<int32_t, 2> foo = morton::code<int32_t, 2>::create(vector<int32_t, 2>(-32768, -1));

accessor.set(0, foo.value);
//accessor.set(0, foo.value);
*/
uint32_t bar = _static_cast<uint32_t>(0xCAFEDEADDEADBEEF);
accessor.set(0, bar);
}
File renamed without changes.
21 changes: 9 additions & 12 deletions XX_Mortons/main.cpp → 12_Mortons/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ class MortonTestApp final : public application_templates::MonoDeviceApplication,
using device_base_t = application_templates::MonoDeviceApplication;
using asset_base_t = application_templates::MonoAssetManagerAndBuiltinResourceApplication;

using morton_t = nbl::hlsl::morton::code<int32_t, 3>;
using vector_t = nbl::hlsl::vector<int32_t, 3>;
using unsigned_morton_t = nbl::hlsl::morton::code<uint32_t, 3>;
using unsigned_vector_t = nbl::hlsl::vector<uint32_t, 3>;
using bool_vector_t = nbl::hlsl::vector<bool, 3>;

inline core::smart_refctd_ptr<video::IGPUShader> createShader(
const char* includeMainName)
{
Expand All @@ -52,6 +46,8 @@ class MortonTestApp final : public application_templates::MonoDeviceApplication,
if (!asset_base_t::onAppInitialized(std::move(system)))
return false;

/*

// ----------------------------------------------- CPP TESTS ----------------------------------------------------------------------

// Coordinate extraction and whole vector decode tests
Expand Down Expand Up @@ -201,7 +197,7 @@ class MortonTestApp final : public application_templates::MonoDeviceApplication,
if(!TestHLSL)
return true;


*/



Expand All @@ -213,7 +209,7 @@ class MortonTestApp final : public application_templates::MonoDeviceApplication,
auto shader = createShader("app_resources/shader.hlsl");

// Create massive upload/download buffers
constexpr uint32_t DownstreamBufferSize = sizeof(unsigned_scalar_t) << 23;
constexpr uint32_t DownstreamBufferSize = sizeof(uint32_t) << 23;

m_utils = make_smart_refctd_ptr<IUtilities>(smart_refctd_ptr(m_device), smart_refctd_ptr(m_logger), DownstreamBufferSize);
if (!m_utils)
Expand All @@ -230,7 +226,7 @@ class MortonTestApp final : public application_templates::MonoDeviceApplication,

deviceLocalBufferParams.queueFamilyIndexCount = 1;
deviceLocalBufferParams.queueFamilyIndices = &queueFamilyIndex;
deviceLocalBufferParams.size = sizeof(unsigned_scalar_t) * bufferSize;
deviceLocalBufferParams.size = sizeof(uint32_t) * bufferSize;
deviceLocalBufferParams.usage = nbl::asset::IBuffer::E_USAGE_FLAGS::EUF_TRANSFER_SRC_BIT | nbl::asset::IBuffer::E_USAGE_FLAGS::EUF_TRANSFER_DST_BIT | nbl::asset::IBuffer::E_USAGE_FLAGS::EUF_SHADER_DEVICE_ADDRESS_BIT;

m_deviceLocalBuffer = m_device->createBuffer(std::move(deviceLocalBufferParams));
Expand Down Expand Up @@ -268,7 +264,7 @@ class MortonTestApp final : public application_templates::MonoDeviceApplication,

IQueue* const queue = getComputeQueue();

const uint32_t inputSize = sizeof(unsigned_scalar_t) * bufferSize;
const uint32_t inputSize = sizeof(uint32_t) * bufferSize;

// Just need a single suballocation in this example
const uint32_t AllocationCount = 1;
Expand Down Expand Up @@ -361,8 +357,9 @@ class MortonTestApp final : public application_templates::MonoDeviceApplication,
assert(dstOffset == 0 && size == outputSize);

std::cout << "Begin array GPU\n";
unsigned_scalar_t* const data = reinterpret_cast<unsigned_scalar_t*>(const_cast<void*>(bufSrc));
std::cout << std::bitset<32>(data[0]) << "\n";
uint32_t* const data = reinterpret_cast<uint32_t*>(const_cast<void*>(bufSrc));
//std::cout << std::bitset<32>(data[0]) << "\n";
std::cout << data[0] << "\n";
/*
for (auto i = 0u; i < bufferSize; i++) {
std::cout << std::bitset<32>(data[i]) << "\n";
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions 22_CppCompat/CIntrinsicsTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class CIntrinsicsTester final : public ITester
testInput.smoothStepEdge0 = realDistributionNeg(mt);
testInput.smoothStepEdge1 = realDistributionPos(mt);
testInput.smoothStepX = realDistribution(mt);
testInput.addCarryA = std::numeric_limits<uint32_t>::max() - uintDistribution(mt);
testInput.addCarryB = uintDistribution(mt);
testInput.subBorrowA = uintDistribution(mt);
testInput.subBorrowB = uintDistribution(mt);

testInput.bitCountVec = int32_t3(intDistribution(mt), intDistribution(mt), intDistribution(mt));
testInput.clampValVec = float32_t3(realDistribution(mt), realDistribution(mt), realDistribution(mt));
Expand Down Expand Up @@ -119,6 +123,10 @@ class CIntrinsicsTester final : public ITester
testInput.refractI = float32_t3(realDistribution(mt), realDistribution(mt), realDistribution(mt));
testInput.refractN = glm::normalize(float32_t3(realDistribution(mt), realDistribution(mt), realDistribution(mt)));
testInput.refractEta = realDistribution(mt);
testInput.addCarryAVec = uint32_t3(std::numeric_limits<uint32_t>::max() - uintDistribution(mt), std::numeric_limits<uint32_t>::max() - uintDistribution(mt), std::numeric_limits<uint32_t>::max() - uintDistribution(mt));
testInput.addCarryBVec = uint32_t3(uintDistribution(mt), uintDistribution(mt), uintDistribution(mt));
testInput.subBorrowAVec = uint32_t3(uintDistribution(mt), uintDistribution(mt), uintDistribution(mt));
testInput.subBorrowBVec = uint32_t3(uintDistribution(mt), uintDistribution(mt), uintDistribution(mt));

// use std library or glm functions to determine expected test values, the output of functions from intrinsics.hlsl will be verified against these values
IntrinsicsTestValues expected;
Expand Down Expand Up @@ -188,6 +196,11 @@ class CIntrinsicsTester final : public ITester
auto inverseGlm = glm::inverse(reinterpret_cast<typename float32_t3x3::Base const&>(testInput.inverse));
expected.inverse = reinterpret_cast<float32_t3x3&>(inverseGlm);

expected.addCarry.result = glm::uaddCarry(testInput.addCarryA, testInput.addCarryB, expected.addCarry.carry);
expected.subBorrow.result = glm::usubBorrow(testInput.subBorrowA, testInput.subBorrowB, expected.subBorrow.borrow);
expected.addCarryVec.result = glm::uaddCarry(testInput.addCarryAVec, testInput.addCarryBVec, expected.addCarryVec.carry);
expected.subBorrowVec.result = glm::usubBorrow(testInput.subBorrowAVec, testInput.subBorrowBVec, expected.subBorrowVec.borrow);

performCpuTests(testInput, expected);
performGpuTests(testInput, expected);
}
Expand Down
Loading