Skip to content

Commit 25a85e4

Browse files
committed
Merge branch 'abstract_image_decoder' into wip
2 parents 0bbaabf + 7511766 commit 25a85e4

File tree

33 files changed

+1649
-874
lines changed

33 files changed

+1649
-874
lines changed

CMakeLists.txt.island_prolog.in

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ set(CMAKE_DEBUG_POSTFIX "" CACHE STRING "Suffix for debug builds" FORCE)
2828

2929
set ( PLUGIN_LIBS_DEPENDENCIES "" CACHE INTERNAL "plugins_libs_dependencies" )
3030
set ( PLUGIN_LINK_DIRS "")
31+
32+
set ( CMAKE_DEBUG_POSTFIX "" CACHE STRING "Suffix for debug builds" FORCE )
3133

3234
# specify output directory
33-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
34-
set(CMAKE_MODULE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
35-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
36-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
35+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "" FORCE )
36+
set(CMAKE_MODULE_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modules" CACHE PATH "" FORCE)
37+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modules" CACHE PATH "archive output directory" FORCE)
38+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modules" CACHE PATH "" FORCE )
3739

3840
# get git commit version for island framework
3941
execute_process(COMMAND
@@ -63,10 +65,12 @@ function (link_resources param_target param_link_name)
6365

6466
else()
6567
if (EXISTS "${param_link_name}")
66-
message(STATUS "local resources exists ${param_link_name}")
68+
message(STATUS "Link already exists: '${param_link_name}'")
6769
else()
68-
execute_process(COMMAND ln -sfn ${param_target} ${param_link_name} )
69-
message(STATUS "created symbolic link ${param_target} ${param_link_name}")
70+
get_filename_component( tmp_link_dir "${param_link_name}" DIRECTORY )
71+
execute_process(COMMAND mkdir -p "${tmp_link_dir}" )
72+
execute_process(COMMAND ln -sfn "${param_target}" "${param_link_name}" )
73+
message(STATUS "Created symbolic link '${param_link_name}' → '${param_target}'" )
7074
endif()
7175
endif()
7276

@@ -116,7 +120,7 @@ if (REQUIRES_ISLAND_CORE)
116120
include_using_absolute_path("${ISLAND_BASE_DIR}/3rdparty/src/glm/")
117121

118122
# create a link to shared resources
119-
link_resources(${ISLAND_BASE_DIR}/resources ${CMAKE_BINARY_DIR}/resources )
123+
link_resources(${ISLAND_BASE_DIR}/resources ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources )
120124

121125
# Check if a local copy of the Vulkan SDK exists, and the environment VULKAN_SDK points to it.
122126
# If yes, use this directory for header includes, and linking.

apps/examples/asterisks/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ add_subdirectory (asterisks_app)
4040
include ("${ISLAND_BASE_DIR}/CMakeLists.txt.island_epilog.in")
4141

4242
# (optional) create a link to local resources
43-
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/local_resources)
43+
link_resources("${PROJECT_SOURCE_DIR}/resources" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/local_resources")
4444

4545
source_group(${PROJECT_NAME} FILES ${SOURCES})

apps/examples/bitonic_merge_sort_example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_subdirectory (bitonic_merge_sort_example_app)
3939
include ("${ISLAND_BASE_DIR}/CMakeLists.txt.island_epilog.in")
4040

4141
# create a link to local resources
42-
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/local_resources)
42+
link_resources("${PROJECT_SOURCE_DIR}/resources" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/local_resources")
4343

4444
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
4545

apps/examples/bitonic_merge_sort_example/bitonic_merge_sort_example_app/bitonic_merge_sort_example_app.cpp

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "le_pipeline_builder.h"
77
#include "le_ui_event.h"
88
#include "le_pixels.h"
9+
#include "shared/interfaces/le_image_decoder_interface.h"
10+
911
#include "le_log.h"
1012

1113
#define GLM_FORCE_DEPTH_ZERO_TO_ONE // vulkan clip space is from 0 to 1
@@ -19,6 +21,12 @@
1921
#include <vector>
2022
#include <stdlib.h> // for random
2123

24+
// Wrapper for format enum so that we can pass this around in a c-style api without
25+
// completely losing type safety.
26+
struct le_image_decoder_format_o {
27+
le::Format format;
28+
};
29+
2230
struct pixels_data_t {
2331
le_buf_resource_handle handle;
2432
uint32_t w; // let's make sure that w is a power of 2
@@ -103,10 +111,10 @@ static bitonic_merge_sort_example_app_o* bitonic_merge_sort_example_app_create()
103111
// ----------------------------------------------------------------------
104112

105113
static void bitonic_merge_sort_example_app_destroy( bitonic_merge_sort_example_app_o* self ) {
106-
if (self) {
107-
delete self->pixels_data;
108-
}
109-
delete ( self );
114+
if ( self ) {
115+
delete self->pixels_data;
116+
}
117+
delete ( self );
110118
}
111119

112120
// ----------------------------------------------------------------------
@@ -225,7 +233,7 @@ static bool pass_sort_setup( le_renderpass_o* rp_, void* user_data ) {
225233

226234
static void pass_noise_execute( le_command_buffer_encoder_o* encoder_, void* user_data ) {
227235
le::TransferEncoder encoder{ encoder_ };
228-
auto app = static_cast<app_o*>( user_data );
236+
auto app = static_cast<app_o*>( user_data );
229237

230238
std::vector<uint32_t> buffer_initial_data;
231239
buffer_initial_data.reserve( app->pixels_data->w * app->pixels_data->h * app->pixels_data->num_channels );
@@ -256,20 +264,28 @@ static void pass_upload_image_execute( le_command_buffer_encoder_o* encoder_, vo
256264

257265
// we must load image from disk
258266

259-
le::Pixels pixels( app->dropped_image_path.c_str(), 4 );
267+
le_image_decoder_interface_t* image_decoder_api = le_pixels::api->le_pixels_image_decoder_i;
268+
le_image_decoder_o* image_decoder = image_decoder_api->create_image_decoder( app->dropped_image_path.c_str() );
260269

261-
if ( !pixels.isValid() ) {
270+
if ( nullptr == image_decoder ) {
262271
log.warn( "Could not load image '%s'", app->dropped_image_path.c_str() );
263272
app->dropped_image_path.clear();
264273
return;
265274
}
266275

267276
// invariant: pixels must be valid
268277

269-
le_pixels_info info = pixels.getInfo();
278+
uint32_t width;
279+
uint32_t height;
280+
281+
// request that the image decoder provide us with a float image
282+
le_image_decoder_format_o format = { le::Format::eR8G8B8A8Unorm };
283+
284+
image_decoder_api->set_requested_format( image_decoder, &format );
285+
image_decoder_api->get_image_data_description( image_decoder, &format, &width, &height );
270286

271-
if ( info.width * info.height < app->pixels_data->w * app->pixels_data->h ) {
272-
log.warn( "Could not load image '%s': Too small: w: %d, h: %d", app->dropped_image_path.c_str(), info.width, info.height );
287+
if ( width * height < app->pixels_data->w * app->pixels_data->h || format.format != le::Format::eR8G8B8A8Unorm ) {
288+
log.warn( "Could not load image '%s': Too small: w: %d, h: %d", app->dropped_image_path.c_str(), width, height );
273289
app->dropped_image_path.clear();
274290

275291
app->pixels_data->unsorted = false;
@@ -287,8 +303,21 @@ static void pass_upload_image_execute( le_command_buffer_encoder_o* encoder_, vo
287303

288304
uint32_t num_bytes = app->pixels_data->w * app->pixels_data->h * app->pixels_data->bytes_per_channel * app->pixels_data->num_channels;
289305

290-
// upload pixels
291-
encoder.writeToBuffer( app->pixels_data->handle, 0, pixels.getData(), num_bytes );
306+
// Allocate data so that the image decoder can read pixels into
307+
uint8_t* data = ( uint8_t* )malloc( num_bytes );
308+
309+
if ( data ) {
310+
311+
// Use the image decoder to read pixels into `data`
312+
image_decoder_api->read_pixels( image_decoder, data, num_bytes );
313+
314+
// Upload pixels to buffer GPU memory
315+
encoder.writeToBuffer( app->pixels_data->handle, 0, data, num_bytes );
316+
317+
free( data );
318+
} else {
319+
LeLog( "app" ).error( "Could not allocate data to hold image. %d bytes requested", num_bytes );
320+
}
292321

293322
app->dropped_image_path.clear();
294323
}
@@ -302,7 +331,7 @@ static void pass_sort_execute( le_command_buffer_encoder_o* encoder_, void* user
302331
log.info( "running compute pass..." );
303332

304333
le::ComputeEncoder encoder{ encoder_ };
305-
auto app = static_cast<app_o*>( user_data );
334+
auto app = static_cast<app_o*>( user_data );
306335

307336
size_t n = app->pixels_data->w * app->pixels_data->h;
308337

@@ -452,7 +481,7 @@ static void pass_sort_execute( le_command_buffer_encoder_o* encoder_, void* user
452481
// ----------------------------------------------------------------------
453482
// Draw contents of buffer to screen
454483
static void pass_draw_exec( le_command_buffer_encoder_o* encoder_, void* user_data ) {
455-
auto app = static_cast<bitonic_merge_sort_example_app_o*>( user_data );
484+
auto app = static_cast<bitonic_merge_sort_example_app_o*>( user_data );
456485
le::GraphicsEncoder encoder{ encoder_ };
457486

458487
// Draw main scene

apps/examples/compute_example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ add_subdirectory (compute_example_app)
4040
include ("${ISLAND_BASE_DIR}/CMakeLists.txt.island_epilog.in")
4141

4242
# create a link to local resources
43-
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/local_resources)
43+
link_resources("${PROJECT_SOURCE_DIR}/resources" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/local_resources")
4444
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
4545

4646
source_group(${PROJECT_NAME} FILES ${SOURCES})

apps/examples/hello_world/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ add_subdirectory (hello_world_app)
4040
include ("${ISLAND_BASE_DIR}/CMakeLists.txt.island_epilog.in")
4141

4242
# create a link to local resources
43-
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/local_resources)
43+
link_resources("${PROJECT_SOURCE_DIR}/resources" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/local_resources")
4444

4545
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
4646

apps/examples/hello_world/hello_world_app/hello_world_app.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static bool pass_resource_setup( le_renderpass_o* pRp, void* user_data ) {
276276
// ----------------------------------------------------------------------
277277

278278
static void pass_resource_exec( le_command_buffer_encoder_o* encoder_, void* user_data ) {
279-
auto app = static_cast<hello_world_app_o*>( user_data );
279+
auto app = static_cast<hello_world_app_o*>( user_data );
280280
le::TransferEncoder encoder{ encoder_ };
281281

282282
if ( false == app->worldGeometry.wasLoaded ) {
@@ -395,7 +395,7 @@ static bool pass_main_setup( le_renderpass_o* pRp, void* user_data ) {
395395
// ----------------------------------------------------------------------
396396

397397
static void pass_main_exec( le_command_buffer_encoder_o* encoder_, void* user_data ) {
398-
auto app = static_cast<hello_world_app_o*>( user_data );
398+
auto app = static_cast<hello_world_app_o*>( user_data );
399399
le::GraphicsEncoder encoder{ encoder_ };
400400

401401
le::Extent2D passExtent = encoder.getRenderpassExtent();
@@ -551,8 +551,8 @@ static void pass_main_exec( le_command_buffer_encoder_o* encoder_, void* user_da
551551

552552
bool hit = hello_world_app_ray_cam_to_sun_hits_earth( app, howClose );
553553

554-
// std::cout << "Hit? " << ( hit ? "true " : " false " ) << ", distance: " << howClose << std::endl
555-
// << std::flush;
554+
// std::cout << "Hit? " << ( hit ? "true " : " false " ) << ", distance: " << howClose << std::endl
555+
// << std::flush;
556556

557557
if ( !hit && fabsf( howClose ) > 1000.f ) {
558558

@@ -698,7 +698,7 @@ static void hello_world_app_process_ui_events( hello_world_app_o* self ) {
698698
using namespace le_window;
699699
uint32_t numEvents;
700700
LeUiEvent const* pEvents;
701-
window_i.get_ui_event_queue( self->window, &pEvents,&numEvents );
701+
window_i.get_ui_event_queue( self->window, &pEvents, &numEvents );
702702

703703
std::vector<LeUiEvent> events{ pEvents, pEvents + numEvents };
704704

apps/examples/imgui_example/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ add_subdirectory (imgui_example_app)
4040
include ("${ISLAND_BASE_DIR}/CMakeLists.txt.island_epilog.in")
4141

4242
# (optional) create a link to local resources
43-
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/local_resources)
43+
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/local_resources)
4444
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
45-
source_group(${PROJECT_NAME} FILES ${SOURCES})
45+
source_group(${PROJECT_NAME} FILES ${SOURCES})

apps/examples/imgui_example/resources/.gitignore

Whitespace-only changes.

apps/examples/lut_grading_example/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(REQUIRES_ISLAND_CORE ON )
2727
include ("${ISLAND_BASE_DIR}/CMakeLists.txt.island_prolog.in")
2828

2929
# Add custom module search paths
30-
# add_island_module_location(${PROJECT_SOURCE_DIR}/../../modules)
30+
add_island_module_location(${ISLAND_BASE_DIR}/../extra_modules)
3131

3232
# Main application c++ file. Not much to see there,
3333
set (SOURCES main.cpp)
@@ -40,7 +40,7 @@ add_subdirectory (lut_grading_example_app)
4040
include ("${ISLAND_BASE_DIR}/CMakeLists.txt.island_epilog.in")
4141

4242
# create a link to local resources
43-
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_BINARY_DIR}/local_resources)
43+
link_resources(${PROJECT_SOURCE_DIR}/resources ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/local_resources)
4444

4545
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
4646

0 commit comments

Comments
 (0)