Skip to content

Commit 2cb75c9

Browse files
committed
Merge branch 'string_literal' into hlsl-compiler-impl
2 parents 7eaa2f5 + 9e6f585 commit 2cb75c9

40 files changed

+518
-607
lines changed

cmake/common.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro(nbl_create_executable_project _EXTRA_SOURCES _EXTRA_OPTIONS _EXTRA_INCLUDE
3232
string(REGEX REPLACE "^[0-9]+\." "" EXECUTABLE_NAME ${EXECUTABLE_NAME})
3333
string(TOLOWER ${EXECUTABLE_NAME} EXECUTABLE_NAME)
3434
string(MAKE_C_IDENTIFIER ${EXECUTABLE_NAME} EXECUTABLE_NAME)
35-
35+
3636
project(${EXECUTABLE_NAME})
3737

3838
if(ANDROID)
@@ -676,7 +676,7 @@ function(NBL_UPDATE_SUBMODULES)
676676
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "All submodules are about to get updated and initialized in repository because NBL_UPDATE_GIT_SUBMODULE is turned ON!")
677677
set(_NBL_UPDATE_SUBMODULES_CMD_NAME_ "nbl-update-submodules")
678678
set(_NBL_UPDATE_SUBMODULES_CMD_FILE_ "${NBL_ROOT_PATH_BINARY}/${_NBL_UPDATE_SUBMODULES_CMD_NAME_}.cmd")
679-
message(STATUS "test")
679+
680680
if(NBL_UPDATE_GIT_SUBMODULE_INCLUDE_PRIVATE)
681681
NBL_WRAPPER_COMMAND("" "" TRUE)
682682
else()

include/nbl/builtin/common.h

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,75 +9,29 @@
99

1010
#include "BuildConfigOptions.h"
1111

12-
#include <cstring>
13-
12+
#include <string>
1413
#include <string_view>
15-
namespace nbl::builtin
16-
{
17-
constexpr std::string_view PathPrefix = "nbl/builtin/";
18-
constexpr bool hasPathPrefix(std::string_view str) { return str.find(PathPrefix) == 0ull; }
19-
}
2014

21-
namespace nbl
22-
{
23-
namespace builtin
24-
{
25-
26-
// if you attempt to use this without `NBL_EMBED_BUILTIN_RESOURCES_` CMake option, you will get loads of undefined references
27-
template<typename StringUniqueLiteralType>
28-
const std::pair<const uint8_t*, size_t> get_resource();
15+
#include "nbl/core/string/StringLiteral.h"
2916

17+
namespace nbl::builtin
18+
{
19+
20+
constexpr std::string_view PathPrefix = "nbl/builtin/";
21+
constexpr bool hasPathPrefix(std::string_view str) { return str.find(PathPrefix) == 0ull; }
22+
3023
// if you attempt to use this without `NBL_EMBED_BUILTIN_RESOURCES_` CMake option, this will always return `{nullptr,0ull}`
3124
std::pair<const uint8_t*,size_t> get_resource_runtime(const std::string&);
3225

33-
}
34-
}
35-
3626
#ifndef _NBL_EMBED_BUILTIN_RESOURCES_
37-
3827
#define _NBL_BUILTIN_PATH_AVAILABLE
39-
namespace nbl
40-
{
41-
namespace builtin
28+
constexpr std::string_view getBuiltinResourcesDirectoryPath()
4229
{
43-
44-
// TODO: move this compile time string stuff somewhere relevant
45-
namespace impl
46-
{
47-
template<std::size_t Pos, std::size_t Len, std::size_t N>
48-
constexpr std::size_t substrlen()
49-
{
50-
constexpr auto PossibleLen = Pos<N ? (N-Pos):0u;
51-
return Len<PossibleLen ? Len:PossibleLen;
52-
}
53-
54-
template <typename C, std::size_t N, std::size_t...Is>
55-
constexpr std::array<C,sizeof...(Is)+1ull> truncate(const C* s, std::index_sequence<Is...>)
56-
{
57-
return {(Is < N ? s[Is] : 0)..., 0};
58-
}
59-
}
60-
61-
template<typename C, std::size_t N>
62-
constexpr std::size_t strlen(const C(&s)[N])
63-
{
64-
return N;
65-
}
66-
67-
template<std::size_t Pos, std::size_t Len, typename C, std::size_t N>
68-
constexpr std::array<C,impl::substrlen<Pos,Len,N>()+1ull> substr(const C(&s)[N])
69-
{
70-
constexpr auto len = impl::substrlen<Pos,Len,N>();
71-
return impl::truncate<C,len>(s+Pos,std::make_index_sequence<len>{});
72-
}
73-
74-
inline std::string getBuiltinResourcesDirectoryPath()
75-
{
76-
return builtin::substr<0ull,builtin::strlen(__FILE__)-builtin::strlen("common.h")>(__FILE__).data();
30+
std::string_view retval = __FILE__;
31+
retval.remove_suffix(std::string_view("common.h").size());
32+
return retval;
7733
}
34+
#endif
7835

79-
}
8036
}
8137
#endif
82-
83-
#endif

include/nbl/core/declarations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#include "nbl/core/parallel/unlock_guard.h"
6161
// string
6262
#include "nbl/core/string/stringutil.h"
63-
#include "nbl/core/string/UniqueStringLiteralType.h"
63+
#include "nbl/core/string/StringLiteral.h"
6464
// other useful things
6565
#include "nbl/core/SingleEventHandler.h"
6666
#include "nbl/core/EventDeferredHandler.h"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2022 - 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+
#ifndef _NBL_CORE_STRING_LITERAL_H_INCLUDED_
5+
#define _NBL_CORE_STRING_LITERAL_H_INCLUDED_
6+
7+
namespace nbl::core
8+
{
9+
10+
template<size_t N>
11+
struct StringLiteral
12+
{
13+
constexpr StringLiteral(const char (&str)[N])
14+
{
15+
std::copy_n(str, N, value);
16+
}
17+
18+
char value[N];
19+
};
20+
21+
}
22+
23+
// for compatibility's sake
24+
#define NBL_CORE_UNIQUE_STRING_LITERAL_TYPE(STRING_LITERAL) nbl::core::StringLiteral(STRING_LITERAL)
25+
26+
#endif // _NBL_CORE_STRING_LITERAL_H_INCLUDED_

include/nbl/core/string/UniqueStringLiteralType.h

Lines changed: 0 additions & 172 deletions
This file was deleted.

include/nbl/scene/ICullingLoDSelectionSystem.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,16 +487,16 @@ class NBL_API ICullingLoDSelectionSystem : public virtual core::IReferenceCounte
487487
return nullptr;
488488

489489
using shader_source_and_path = std::pair<core::smart_refctd_ptr<asset::ICPUShader>,system::path>;
490-
auto getShader = [device](auto uniqueString) -> shader_source_and_path
490+
auto getShader = [device]<core::StringLiteral Path>() -> shader_source_and_path
491491
{
492492
auto system = device->getPhysicalDevice()->getSystem();
493-
auto glslFile = system->loadBuiltinData<decltype(uniqueString)>();
493+
auto glslFile = system->loadBuiltinData<Path>();
494494
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
495495
{
496496
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());
497497
memcpy(glsl->getPointer(), glslFile->getMappedPointer(), glsl->getSize());
498498
}
499-
return {core::make_smart_refctd_ptr<asset::ICPUShader>(std::move(glsl), asset::IShader::ESS_COMPUTE, asset::IShader::E_CONTENT_TYPE::ECT_GLSL, decltype(uniqueString)::value), decltype(uniqueString)::value};
499+
return {core::make_smart_refctd_ptr<asset::ICPUShader>(std::move(glsl), asset::IShader::ESS_COMPUTE, asset::IShader::E_CONTENT_TYPE::ECT_GLSL, Path.value), Path.value};
500500
};
501501
auto overrideShader = [device,&cwdForShaderCompilation,workgroupSize,_scanner](shader_source_and_path&& baseShader, std::string additionalCode)
502502
{
@@ -515,7 +515,7 @@ class NBL_API ICullingLoDSelectionSystem : public virtual core::IReferenceCounte
515515

516516
const std::string workgroupSizeDef = "\n#define _NBL_GLSL_WORKGROUP_SIZE_ _NBL_GLSL_CULLING_LOD_SELECTION_CULL_WORKGROUP_SIZE_\n";
517517

518-
auto firstShader = getShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/culling_lod_selection/instance_cull_and_lod_select.comp")());
518+
auto firstShader = getShader.operator()<core::StringLiteral("nbl/builtin/glsl/culling_lod_selection/instance_cull_and_lod_select.comp")>();
519519
auto instanceCullAndLoDSelect = device->createComputePipeline(
520520
nullptr,core::smart_refctd_ptr(instanceCullAndLoDSelectLayout),
521521
overrideShader(std::move(firstShader),workgroupSizeDef+perViewPerInstanceDefinition+cullAndLoDSelectFuncDefinitions)
@@ -533,7 +533,7 @@ class NBL_API ICullingLoDSelectionSystem : public virtual core::IReferenceCounte
533533

534534
auto instanceDrawCull = device->createComputePipeline(
535535
nullptr,core::smart_refctd_ptr(instanceDrawCullLayout),
536-
overrideShader(getShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/culling_lod_selection/instance_draw_cull.comp")()),workgroupSizeDef+perViewPerInstanceDefinition)
536+
overrideShader(getShader.operator()<core::StringLiteral("nbl/builtin/glsl/culling_lod_selection/instance_draw_cull.comp")>(),workgroupSizeDef+perViewPerInstanceDefinition)
537537
);
538538

539539
auto drawInstanceCountPrefixSum = device->createComputePipeline(
@@ -548,7 +548,7 @@ class NBL_API ICullingLoDSelectionSystem : public virtual core::IReferenceCounte
548548
);
549549
auto instanceRefCountingSortScatter = device->createComputePipeline(
550550
nullptr,core::smart_refctd_ptr(instanceRefCountingSortPipelineLayout),
551-
overrideShader(getShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/culling_lod_selection/instance_ref_counting_sort_scatter.comp")()),workgroupSizeDef)
551+
overrideShader(getShader.operator()<core::StringLiteral("nbl/builtin/glsl/culling_lod_selection/instance_ref_counting_sort_scatter.comp")>(),workgroupSizeDef)
552552
);
553553

554554
//auto drawCompact = ?;

include/nbl/scene/ITransformTreeManager.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ class NBL_API ITransformTreeManager : public virtual core::IReferenceCounted
106106
{
107107
auto device = utils->getLogicalDevice();
108108
auto system = device->getPhysicalDevice()->getSystem();
109-
auto createShader = [&system,&device](auto uniqueString, asset::IShader::E_SHADER_STAGE type=asset::IShader::ESS_COMPUTE) -> core::smart_refctd_ptr<video::IGPUSpecializedShader>
109+
auto createShader = [&system,&device]<core::StringLiteral Path>(asset::IShader::E_SHADER_STAGE type=asset::IShader::ESS_COMPUTE) -> core::smart_refctd_ptr<video::IGPUSpecializedShader>
110110
{
111-
auto glslFile = system->loadBuiltinData<decltype(uniqueString)>();
111+
auto glslFile = system->loadBuiltinData<Path>();
112112
core::smart_refctd_ptr<asset::ICPUBuffer> glsl;
113113
{
114114
glsl = core::make_smart_refctd_ptr<asset::ICPUBuffer>(glslFile->getSize());
@@ -118,11 +118,11 @@ class NBL_API ITransformTreeManager : public virtual core::IReferenceCounted
118118
return device->createSpecializedShader(shader.get(),{nullptr,nullptr,"main"});
119119
};
120120

121-
auto updateRelativeSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/transform_tree/relative_transform_update.comp")());
122-
auto recomputeGlobalSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/transform_tree/global_transform_update.comp")());
123-
auto recomputeGlobalAndNormalSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/transform_tree/global_transform_and_normal_matrix_update.comp")());
124-
auto debugDrawVertexSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/glsl/transform_tree/debug.vert")(),asset::IShader::ESS_VERTEX);
125-
auto debugDrawFragmentSpec = createShader(NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("nbl/builtin/material/debug/vertex_normal/specialized_shader.frag")(),asset::IShader::ESS_FRAGMENT);
121+
auto updateRelativeSpec = createShader.operator()<core::StringLiteral("nbl/builtin/glsl/transform_tree/relative_transform_update.comp")>();
122+
auto recomputeGlobalSpec = createShader.operator()<core::StringLiteral("nbl/builtin/glsl/transform_tree/global_transform_update.comp")>();
123+
auto recomputeGlobalAndNormalSpec = createShader.operator()<core::StringLiteral("nbl/builtin/glsl/transform_tree/global_transform_and_normal_matrix_update.comp")>();
124+
auto debugDrawVertexSpec = createShader.operator()<core::StringLiteral("nbl/builtin/glsl/transform_tree/debug.vert")>(asset::IShader::ESS_VERTEX);
125+
auto debugDrawFragmentSpec = createShader.operator()<core::StringLiteral("nbl/builtin/material/debug/vertex_normal/specialized_shader.frag")>(asset::IShader::ESS_FRAGMENT);
126126
if (!updateRelativeSpec || !recomputeGlobalSpec || !recomputeGlobalAndNormalSpec || !debugDrawVertexSpec || !debugDrawFragmentSpec)
127127
return nullptr;
128128

0 commit comments

Comments
 (0)