Skip to content

Commit eff1c85

Browse files
committed
Merge branch 'cad-text-rendering'
2 parents a1e5647 + af4375f commit eff1c85

File tree

14 files changed

+2239
-334
lines changed

14 files changed

+2239
-334
lines changed

21_LRUCacheUnitTest/main.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ class LRUCacheTestApp final : public nbl::application_templates::MonoSystemMonoL
1919
public:
2020
using base_t::base_t;
2121

22+
constexpr static uint32_t InvalidTextureIdx = 41234;
23+
struct TextureReference
24+
{
25+
uint32_t alloc_idx;
26+
uint64_t lastUsedSemaphoreValue;
27+
28+
TextureReference(uint32_t alloc_idx, uint64_t semaphoreVal) : alloc_idx(alloc_idx), lastUsedSemaphoreValue(semaphoreVal) {}
29+
TextureReference(uint64_t semaphoreVal) : TextureReference(InvalidTextureIdx, semaphoreVal) {}
30+
TextureReference() : TextureReference(InvalidTextureIdx, ~0ull) {}
31+
32+
// In LRU Cache `insert` function, in case of cache hit, we need to assign semaphore value to TextureReference without changing `alloc_idx`
33+
inline TextureReference& operator=(uint64_t semamphoreVal) { lastUsedSemaphoreValue = semamphoreVal; return *this; }
34+
};
35+
36+
using TextureLRUCache = core::LRUCache<uint32_t, TextureReference>;
37+
2238
// we stuff all our work here because its a "single shot" app
2339
bool onAppInitialized(smart_refctd_ptr<ISystem>&& system) override
2440
{
@@ -108,6 +124,24 @@ class LRUCacheTestApp final : public nbl::application_templates::MonoSystemMonoL
108124
cache2.print(m_logger);
109125
cache2.insert(++i, "key is 112");
110126

127+
m_textureLRUCache = std::unique_ptr<TextureLRUCache>(new TextureLRUCache(1024u));
128+
{
129+
SIntendedSubmitInfo intendedNextSubmit = {};
130+
auto evictionCallback = [&](const TextureReference& evicted)
131+
{
132+
};
133+
const auto nextSemaSignal = intendedNextSubmit.getFutureScratchSemaphore();
134+
TextureReference* inserted = m_textureLRUCache->insert(69420, nextSemaSignal.value, evictionCallback);
135+
}
136+
{
137+
SIntendedSubmitInfo intendedNextSubmit = {};
138+
auto evictionCallback = [&](const TextureReference& evicted)
139+
{
140+
};
141+
const auto nextSemaSignal = intendedNextSubmit.getFutureScratchSemaphore();
142+
TextureReference* inserted = m_textureLRUCache->insert(69420, nextSemaSignal.value, evictionCallback);
143+
}
144+
111145
#ifdef _NBL_DEBUG
112146
cache2.print(m_logger);
113147
#endif
@@ -153,6 +187,7 @@ class LRUCacheTestApp final : public nbl::application_templates::MonoSystemMonoL
153187

154188
return true;
155189
}
190+
std::unique_ptr<TextureLRUCache> m_textureLRUCache;
156191

157192
void workLoopBody() override {}
158193

24_ColorSpaceTest/app_resources/present.frag.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ using namespace nbl::hlsl::ext::FullScreenTriangle;
2121
{
2222
const float32_t2 repeatCoord = vxAttr.uv*float32_t2(pc.grid);
2323
const int32_t layer = int32_t(repeatCoord.y)*pc.grid.x+int32_t(repeatCoord.x);
24-
return texture.Sample(samplerState,float32_t3(repeatCoord,layer));
24+
float4 color = texture.Sample(samplerState,float32_t3(repeatCoord,layer));
25+
return color * color.a;
2526
}

62_CAD/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(EXAMPLE_SOURCES
1111
"${CMAKE_CURRENT_SOURCE_DIR}/Polyline.h"
1212
"${CMAKE_CURRENT_SOURCE_DIR}/DrawResourcesFiller.cpp"
1313
"${CMAKE_CURRENT_SOURCE_DIR}/DrawResourcesFiller.h"
14+
"../../src/nbl/ext/TextRendering/TextRendering.cpp" # TODO: this one will be a part of dedicated Nabla ext called "TextRendering" later on which uses MSDF + Freetype
1415
)
1516
set(EXAMPLE_INCLUDES
1617
"${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/boost/superproject/libs/math/include")
@@ -32,4 +33,27 @@ if(NBL_EMBED_BUILTIN_RESOURCES)
3233
ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")
3334

3435
LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
36+
endif()
37+
38+
# if enabled then try use Nabla "Text Rendering" extension
39+
# with an implemented interface using the 3rdparty deps
40+
41+
set(NBL_CAD_EX_USE_TEXT_RENDERING_EXT OFF) # do not enable, for future usage when the extension is written
42+
43+
if(NBL_BUILD_TEXT_RENDERING AND NBL_CAD_EX_USE_TEXT_RENDERING_EXT)
44+
add_dependencies(${EXECUTABLE_NAME} ${NBL_EXT_TEXT_RENDERING_TARGET})
45+
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_EXT_TEXT_RENDERING_TARGET})
46+
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_EXT_TEXT_RENDERING_TARGET},INCLUDE_DIRECTORIES>)
47+
else()
48+
# Freetype
49+
add_dependencies(${EXECUTABLE_NAME} freetype)
50+
target_link_libraries(${EXECUTABLE_NAME} PRIVATE freetype)
51+
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:freetype,INCLUDE_DIRECTORIES>)
52+
53+
# msdfgen
54+
add_dependencies(${EXECUTABLE_NAME} ${NBL_MSDFGEN_TARGETS})
55+
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_MSDFGEN_TARGETS})
56+
foreach(NBL_TARGET IN LISTS NBL_MSDFGEN_TARGETS)
57+
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_TARGET},INCLUDE_DIRECTORIES>)
58+
endforeach()
3559
endif()

0 commit comments

Comments
 (0)