Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional compilation #1367

Merged
merged 3 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@
"strategy": "external"
}
},
{
"name": "release-nogl",
"description": "Release build - no OpenGL",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"YOCTO_APPS": "ON",
"YOCTO_EMBREE": "OFF",
"YOCTO_DENOISE": "OFF",
"YOCTO_OPENGL": "OFF",
"YOCTO_CUDA": "OFF"
},
"architecture": {
"value": "x64",
"strategy": "external"
}
},
{
"name": "debug-nogl",
"description": "Debug build - no OpenGL",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"YOCTO_APPS": "ON",
"YOCTO_EMBREE": "OFF",
"YOCTO_DENOISE": "OFF",
"YOCTO_OPENGL": "OFF",
"YOCTO_CUDA": "OFF"
},
"architecture": {
"value": "x64",
"strategy": "external"
}
},
{
"name": "release-cuda",
"description": "Release build",
Expand Down
3 changes: 3 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ add_yapp(ytonemap)
add_yapp(ycolorgrade)

add_yapp(ytrace)

if(YOCTO_CUDA)
add_yapp(ycutrace)
endif()

add_yapp(yview)

Expand Down
5 changes: 5 additions & 0 deletions apps/ycolorgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ void run(const vector<string>& args) {
// save image
save_image(outname, image);
} else {
#ifdef YOCTO_OPENGL

// color grading parameters
auto params = colorgrade_params{};

Expand Down Expand Up @@ -133,6 +135,9 @@ void run(const vector<string>& args) {

// run ui
show_gui_window({1280 + 320, 720}, "ycolorgrade - " + imagename, callbacks);
#else
throw io_error{"Interactive requires OpenGL"};
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions apps/ycutrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void run(const vector<string>& args) {
save_image(outname, image);
print_info("save image: {}", elapsed_formatted(timer));
} else {
#ifdef YOCTO_OPENGL
// preview state
auto pparams = params;
pparams.resolution /= params.pratio;
Expand Down Expand Up @@ -260,6 +261,9 @@ void run(const vector<string>& args) {

// run ui
show_gui_window({1280 + 320, 720}, "ycutrace - " + scenename, callbacks);
#else
throw io_error{"Interactive requires OpenGL"};
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions apps/ytonemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void run(const vector<string>& args) {
// save
save_image(outname, image);
} else {
#ifdef YOCTO_OPENGL
// display image
auto display = make_image(image.width, image.height, false);
float exposure = 0;
Expand Down Expand Up @@ -110,6 +111,9 @@ void run(const vector<string>& args) {

// run ui
show_gui_window({1280 + 320, 720}, "ytonemap - " + imagename, callbacks);
#else
throw io_error{"Interactive requires OpenGL"};
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions apps/ytrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void run(const vector<string>& args) {
save_image(outname, image);
print_info("save image: {}", elapsed_formatted(timer));
} else {
#ifdef YOCTO_OPENGL
// rendering context
auto context = make_trace_context(params);

Expand Down Expand Up @@ -258,6 +259,9 @@ void run(const vector<string>& args) {

// done
render_cancel();
#else
throw io_error{"Interactive requires OpenGL"};
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions apps/yview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ using namespace std::string_literals;

// main function
void run(const vector<string>& args) {
#ifdef YOCTO_OPENGL
// parameters
auto scenename = "scene.json"s;
auto camname = ""s;
Expand Down Expand Up @@ -66,6 +67,9 @@ void run(const vector<string>& args) {

// run viewer
show_shade_gui("yview", scenename, scene, params);
#else
throw io_error{"Interactive requires OpenGL"};
#endif
}

// Run
Expand Down
6 changes: 6 additions & 0 deletions libs/yocto/yocto_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ struct embree_error : std::runtime_error {

#ifdef YOCTO_EMBREE

// Check if embree is supported
bool embree_supported() { return true; }

// Get Embree device
atomic<ssize_t> embree_memory = 0;
static RTCDevice embree_device() {
Expand Down Expand Up @@ -1096,6 +1099,9 @@ scene_intersection intersect_instance_embree_bvh(const scene_embree_bvh& bvh,

#else

// Check if embree is supported
bool embree_supported() { return false; }

// Not implemented
shape_embree_bvh make_shape_embree_bvh(
const shape_data& shape, bool highquality) {
Expand Down
3 changes: 3 additions & 0 deletions libs/yocto/yocto_bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ struct scene_embree_bvh {
unique_ptr<void, void (*)(void*)> embree_bvh = {nullptr, nullptr}; // embree
};

// Check if embree is supported
bool embree_supported();

// Build the bvh acceleration structure.
shape_embree_bvh make_shape_embree_bvh(
const shape_data& shape, bool highquality = false);
Expand Down
170 changes: 2 additions & 168 deletions libs/yocto/yocto_cutrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@
// SOFTWARE.
//

//
// TODO: upload
// TODO: path tracing
// TODO: environments
// TODO: interactive rendering
//

#include "yocto_cutrace.h"

#include "yocto_sampling.h"

#if YOCTO_CUDA

#include "yocto_sampling.h"

// do not reorder
#include <cuda.h>
// do not reorder
Expand Down Expand Up @@ -1139,163 +1132,4 @@ bool is_display(const cutrace_context& context) {

} // namespace yocto

#else

// -----------------------------------------------------------------------------
// NO CUDA
// -----------------------------------------------------------------------------
namespace yocto {

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4722)
#endif

static void exit_nocuda() { throw std::runtime_error{"Cuda not linked"}; }

cuscene_data::cuscene_data(cuscene_data&& other) { exit_nocuda(); }
cuscene_data& cuscene_data::operator=(cuscene_data&& other) {
exit_nocuda();
return *this;
}
cuscene_data::~cuscene_data() { exit_nocuda(); };

cubvh_data::cubvh_data(cubvh_data&& other) { exit_nocuda(); }
cubvh_data& cubvh_data::operator=(cubvh_data&& other) {
exit_nocuda();
return *this;
}
cubvh_data::~cubvh_data() { exit_nocuda(); }

cutrace_context::cutrace_context(cutrace_context&& other) { exit_nocuda(); }
cutrace_context& cutrace_context::operator=(cutrace_context&& other) {
exit_nocuda();
return *this;
}
cutrace_context::~cutrace_context() { exit_nocuda(); }

cutrace_state::~cutrace_state() { exit_nocuda(); }
cutrace_lights::~cutrace_lights() { exit_nocuda(); }

#ifdef _MSC_VER
#pragma warning(pop)
#endif

image_data cutrace_image(const scene_data& scene, const trace_params& params) {
exit_nocuda();
return {};
}

// Initialize GPU context.
cutrace_context make_cutrace_context(const trace_params& params) {
exit_nocuda();
return {};
}

// Upload the scene to the GPU.
cuscene_data make_cutrace_scene(cutrace_context& context,
const scene_data& scene, const trace_params& params) {
exit_nocuda();
return {};
}

// Update cameras
void update_cutrace_cameras(cutrace_context& context, cuscene_data& cuscene,
const scene_data& scene, const trace_params& params) {
exit_nocuda();
}

// Build the bvh acceleration structure.
cubvh_data make_cutrace_bvh(cutrace_context& context,
const cuscene_data& cuscene, const trace_params& params) {
exit_nocuda();
return {};
}

// Initialize state.
cutrace_state make_cutrace_state(cutrace_context& context,
const scene_data& scene, const trace_params& params) {
exit_nocuda();
return {};
}
void reset_cutrace_state(cutrace_context& context, cutrace_state& state,
const scene_data& scene, const trace_params& params) {
exit_nocuda();
}

// Initialize lights.
cutrace_lights make_cutrace_lights(cutrace_context& context,
const scene_data& scene, const trace_params& params) {
exit_nocuda();
return {};
}

// Start rendering an image.
void trace_start(cutrace_context& context, cutrace_state& state,
const cuscene_data& cuscene, const cubvh_data& bvh,
const cutrace_lights& lights, const scene_data& scene,
const trace_params& params) {
exit_nocuda();
}

// Progressively computes an image.
void trace_samples(cutrace_context& context, cutrace_state& state,
const cuscene_data& cuscene, const cubvh_data& bvh,
const cutrace_lights& lights, const scene_data& scene,
const trace_params& params) {
exit_nocuda();
}

// render preview
void trace_preview(image_data& image, cutrace_context& context,
cutrace_state& state, const cuscene_data& cuscene, const cubvh_data& bvh,
const cutrace_lights& lights, const scene_data& scene,
const trace_params& params) {
exit_nocuda();
return;
}

// Get render
image_data get_image(const cutrace_state& state) {
exit_nocuda();
return {};
}
void get_image(image_data& image, const cutrace_state& state) { exit_nocuda(); }

// Get resulting render
image_data get_rendered_image(const cutrace_state& state) {
exit_nocuda();
return {};
}
void get_rendered_image(image_data& image, const cutrace_state& state) {
exit_nocuda();
}

// Get denoised result
image_data get_denoised_image(const cutrace_state& state) {
exit_nocuda();
return {};
}
void get_denoised_image(image_data& image, const cutrace_state& state) {
exit_nocuda();
}

// Get denoising buffers
image_data get_albedo_image(const cutrace_state& state) {
exit_nocuda();
return {};
}
void get_albedo_image(image_data& image, const cutrace_state& state) {
exit_nocuda();
}
image_data get_normal_image(const cutrace_state& state) {
exit_nocuda();
return {};
}
void get_normal_image(image_data& image, const cutrace_state& state) {
exit_nocuda();
}

} // namespace yocto

#endif
Loading