-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added back the denoise module, with oidn built in.
- Loading branch information
Showing
325 changed files
with
114,508 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Exhaustive licensing information for files in the Godot Engine repository | ||
# ========================================================================= | ||
# | ||
# This file aims at documenting the copyright and license for every source | ||
# file in the Godot Engine repository, and especially outline the files | ||
# whose license differs from the MIT/Expat license used by Godot Engine. | ||
# | ||
# It is written as a machine-readable format following the debian/copyright | ||
# specification. Globbing patterns (e.g. "Files: *") mean that they affect | ||
# all corresponding files (also recursively in subfolders), apart from those | ||
# with a more explicit copyright statement. | ||
# | ||
# Licenses are given with their debian/copyright short name (or SPDX identifier | ||
# if no standard short name exists) and are all included in plain text at the | ||
# end of this file (in alphabetical order). | ||
# | ||
# Disclaimer for thirdparty libraries: | ||
# ------------------------------------ | ||
# | ||
# Licensing details for thirdparty libraries in the 'thirdparty/' directory | ||
# are given in summarized form, i.e. with only the "main" license described | ||
# in the library's license statement. Different licenses of single files or | ||
# code snippets in thirdparty libraries are not documented here. | ||
# For example: | ||
# Files: ./thirdparty/zlib/ | ||
# Copyright: 1995-2017, Jean-loup Gailly and Mark Adler | ||
# License: Zlib | ||
# The exact copyright for each file in that library *may* differ, and some | ||
# files or code snippets might be distributed under other compatible licenses | ||
# (e.g. a public domain dedication), but as far as Godot Engine is concerned | ||
# the library is considered as a whole under the Zlib license. | ||
# | ||
# Nota: When linking dynamically against thirdparty libraries instead of | ||
# building them into the Godot binary, you may remove the corresponding | ||
# license details from this file. | ||
|
||
----------------------------------------------------------------------- | ||
|
||
Files: editor_modules/denoise/oidn | ||
Comment: OpenImageDenoise | ||
Copyright: 2009-2019 Intel Corporation | ||
License: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#!/usr/bin/env python | ||
|
||
import resource_to_cpp | ||
|
||
Import("env") | ||
Import("env_modules") | ||
|
||
env_oidn = env_modules.Clone() | ||
|
||
# Thirdparty source files | ||
|
||
thirdparty_obj = [] | ||
|
||
thirdparty_dir = "oidn/" | ||
thirdparty_sources = [ | ||
"core/api.cpp", | ||
"core/device.cpp", | ||
"core/filter.cpp", | ||
"core/network.cpp", | ||
"core/autoencoder.cpp", | ||
"core/transfer_function.cpp", | ||
"weights/rtlightmap_hdr.gen.cpp", | ||
"mkl-dnn/src/common/batch_normalization.cpp", | ||
"mkl-dnn/src/common/concat.cpp", | ||
"mkl-dnn/src/common/convolution.cpp", | ||
"mkl-dnn/src/common/convolution_pd.cpp", | ||
"mkl-dnn/src/common/deconvolution.cpp", | ||
"mkl-dnn/src/common/eltwise.cpp", | ||
"mkl-dnn/src/common/engine.cpp", | ||
"mkl-dnn/src/common/inner_product.cpp", | ||
"mkl-dnn/src/common/inner_product_pd.cpp", | ||
"mkl-dnn/src/common/lrn.cpp", | ||
"mkl-dnn/src/common/memory.cpp", | ||
"mkl-dnn/src/common/memory_desc_wrapper.cpp", | ||
"mkl-dnn/src/common/mkldnn_debug.cpp", | ||
"mkl-dnn/src/common/mkldnn_debug_autogenerated.cpp", | ||
"mkl-dnn/src/common/pooling.cpp", | ||
"mkl-dnn/src/common/primitive.cpp", | ||
"mkl-dnn/src/common/primitive_attr.cpp", | ||
"mkl-dnn/src/common/primitive_desc.cpp", | ||
"mkl-dnn/src/common/primitive_exec_types.cpp", | ||
"mkl-dnn/src/common/primitive_iterator.cpp", | ||
"mkl-dnn/src/common/query.cpp", | ||
"mkl-dnn/src/common/reorder.cpp", | ||
"mkl-dnn/src/common/rnn.cpp", | ||
"mkl-dnn/src/common/scratchpad.cpp", | ||
"mkl-dnn/src/common/shuffle.cpp", | ||
"mkl-dnn/src/common/softmax.cpp", | ||
"mkl-dnn/src/common/stream.cpp", | ||
"mkl-dnn/src/common/sum.cpp", | ||
"mkl-dnn/src/common/utils.cpp", | ||
"mkl-dnn/src/common/verbose.cpp", | ||
"mkl-dnn/src/cpu/cpu_barrier.cpp", | ||
"mkl-dnn/src/cpu/cpu_concat.cpp", | ||
"mkl-dnn/src/cpu/cpu_engine.cpp", | ||
"mkl-dnn/src/cpu/cpu_memory.cpp", | ||
"mkl-dnn/src/cpu/cpu_reducer.cpp", | ||
"mkl-dnn/src/cpu/cpu_reorder.cpp", | ||
"mkl-dnn/src/cpu/cpu_sum.cpp", | ||
"mkl-dnn/src/cpu/jit_avx2_conv_kernel_f32.cpp", | ||
"mkl-dnn/src/cpu/jit_avx2_convolution.cpp", | ||
"mkl-dnn/src/cpu/jit_avx512_common_conv_kernel.cpp", | ||
"mkl-dnn/src/cpu/jit_avx512_common_conv_winograd_kernel_f32.cpp", | ||
"mkl-dnn/src/cpu/jit_avx512_common_convolution.cpp", | ||
"mkl-dnn/src/cpu/jit_avx512_common_convolution_winograd.cpp", | ||
"mkl-dnn/src/cpu/jit_avx512_core_fp32_wino_conv_2x3.cpp", | ||
"mkl-dnn/src/cpu/jit_avx512_core_fp32_wino_conv_4x3.cpp", | ||
"mkl-dnn/src/cpu/jit_avx512_core_fp32_wino_conv_4x3_kernel.cpp", | ||
"mkl-dnn/src/cpu/jit_sse42_conv_kernel_f32.cpp", | ||
"mkl-dnn/src/cpu/jit_sse42_convolution.cpp", | ||
"mkl-dnn/src/cpu/jit_transpose_src_utils.cpp", | ||
"mkl-dnn/src/cpu/jit_uni_eltwise.cpp", | ||
"mkl-dnn/src/cpu/jit_uni_pool_kernel_f32.cpp", | ||
"mkl-dnn/src/cpu/jit_uni_pooling.cpp", | ||
"mkl-dnn/src/cpu/jit_uni_reorder.cpp", | ||
"mkl-dnn/src/cpu/jit_uni_reorder_utils.cpp", | ||
"mkl-dnn/src/cpu/jit_utils/jit_utils.cpp", | ||
"mkl-dnn/src/cpu/jit_utils/jitprofiling/jitprofiling.c", | ||
"common/platform.cpp", | ||
"common/thread.cpp", | ||
"common/tensor.cpp", | ||
] | ||
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] | ||
|
||
thirdparty_include_dirs = [ | ||
"", | ||
"include", | ||
"mkl-dnn/include", | ||
"mkl-dnn/src", | ||
"mkl-dnn/src/common", | ||
"mkl-dnn/src/cpu/xbyak", | ||
"mkl-dnn/src/cpu", | ||
] | ||
thirdparty_include_dirs = [thirdparty_dir + file for file in thirdparty_include_dirs] | ||
|
||
|
||
env_oidn.Prepend(CPPPATH=thirdparty_include_dirs) | ||
env_oidn.Append( | ||
CPPDEFINES=[ | ||
"MKLDNN_THR=MKLDNN_THR_SEQ", | ||
"OIDN_STATIC_LIB", | ||
"__STDC_CONSTANT_MACROS", | ||
"__STDC_LIMIT_MACROS", | ||
"DISABLE_VERBOSE", | ||
"MKLDNN_ENABLE_CONCURRENT_EXEC", | ||
] | ||
) | ||
env_oidn.AppendUnique(CPPDEFINES=["NDEBUG"]) # No assert() even in debug builds. | ||
|
||
env_thirdparty = env_oidn.Clone() | ||
env_thirdparty.disable_warnings() | ||
|
||
if env["disable_exceptions"]: | ||
# OIDN hard-requires exceptions, so we re-enable them here. | ||
if env.msvc and ("_HAS_EXCEPTIONS", 0) in env_thirdparty["CPPDEFINES"]: | ||
env_thirdparty["CPPDEFINES"].remove(("_HAS_EXCEPTIONS", 0)) | ||
env_thirdparty.AppendUnique(CCFLAGS=["/EHsc"]) | ||
elif not env.msvc and "-fno-exceptions" in env_thirdparty["CCFLAGS"]: | ||
env_thirdparty["CCFLAGS"].remove("-fno-exceptions") | ||
|
||
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) | ||
env.modules_sources += thirdparty_obj | ||
|
||
if env["platform"] == "windows" and not env.msvc: | ||
env_thirdparty.Append(CPPFLAGS=["-mstackrealign"]) | ||
|
||
env_thirdparty.Append(CPPFLAGS=["-frtti"]) | ||
|
||
weights_in_path = thirdparty_dir + "weights/rtlightmap_hdr.tza" | ||
weights_out_path = thirdparty_dir + "weights/rtlightmap_hdr.gen.cpp" | ||
|
||
env_thirdparty.Depends(weights_out_path, weights_in_path) | ||
env_thirdparty.CommandNoCache(weights_out_path, weights_in_path, resource_to_cpp.tza_to_cpp) | ||
|
||
# Godot source files | ||
|
||
module_obj = [] | ||
|
||
env_oidn.add_source_files(module_obj, "denoise_wrapper.cpp") | ||
env_modules.add_source_files(module_obj, ["register_types.cpp", "lightmap_denoiser.cpp"]) | ||
env.modules_sources += module_obj | ||
|
||
# Needed to force rebuilding the module files when the thirdparty library is updated. | ||
env.Depends(module_obj, thirdparty_obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
def can_build(env, platform): | ||
# Thirdparty dependency OpenImage Denoise includes oneDNN library | ||
# and the version we use only supports x86_64. | ||
# It's also only relevant for tools build and desktop platforms, | ||
# as doing lightmap generation and denoising on Android or HTML5 | ||
# would be a bit far-fetched. | ||
# Note: oneDNN doesn't support ARM64, OIDN needs updating to the latest version | ||
supported_platform = platform in ["x11", "osx", "windows", "server"] | ||
supported_arch = env["bits"] == "64" | ||
if env["arch"].startswith("arm"): | ||
supported_arch = False | ||
if env["arch"].startswith("ppc"): | ||
supported_arch = False | ||
if env["arch"].startswith("rv"): | ||
supported_arch = False | ||
|
||
# Hack to disable on Linux arm64. This won't work well for cross-compilation (checks | ||
# host, not target) and would need a more thorough fix by refactoring our arch and | ||
# bits-handling code. | ||
from platform import machine | ||
|
||
if platform == "x11" and machine() != "x86_64": | ||
supported_arch = False | ||
|
||
return env["tools"] and supported_platform and supported_arch | ||
|
||
|
||
def configure(env): | ||
pass | ||
|
||
def get_license_file(): | ||
return "COPYRIGHT.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/**************************************************************************/ | ||
/* denoise_wrapper.cpp */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#include "denoise_wrapper.h" | ||
#include "core/os/memory.h" | ||
#include "oidn/include/OpenImageDenoise/oidn.h" | ||
#include <stdio.h> | ||
|
||
void *oidn_denoiser_init() { | ||
OIDNDeviceImpl *device = oidnNewDevice(OIDN_DEVICE_TYPE_CPU); | ||
oidnCommitDevice(device); | ||
return device; | ||
} | ||
|
||
bool oidn_denoise(void *deviceptr, float *p_floats, int p_width, int p_height) { | ||
OIDNDeviceImpl *device = (OIDNDeviceImpl *)deviceptr; | ||
OIDNFilter filter = oidnNewFilter(device, "RTLightmap"); | ||
oidnSetSharedFilterImage(filter, "color", (void *)p_floats, OIDN_FORMAT_FLOAT3, p_width, p_height, 0, 0, 0); | ||
oidnSetSharedFilterImage(filter, "output", (void *)p_floats, OIDN_FORMAT_FLOAT3, p_width, p_height, 0, 0, 0); | ||
oidnSetFilter1b(filter, "hdr", true); | ||
oidnCommitFilter(filter); | ||
oidnExecuteFilter(filter); | ||
|
||
const char *msg; | ||
bool success = true; | ||
if (oidnGetDeviceError(device, &msg) != OIDN_ERROR_NONE) { | ||
printf("LightmapDenoiser: %s\n", msg); | ||
success = false; | ||
} | ||
|
||
oidnReleaseFilter(filter); | ||
return success; | ||
} | ||
|
||
void oidn_denoiser_finish(void *device) { | ||
oidnReleaseDevice((OIDNDeviceImpl *)device); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/**************************************************************************/ | ||
/* denoise_wrapper.h */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#ifndef DENOISE_WRAPPER_H | ||
#define DENOISE_WRAPPER_H | ||
|
||
void *oidn_denoiser_init(); | ||
bool oidn_denoise(void *device, float *p_floats, int p_width, int p_height); | ||
void oidn_denoiser_finish(void *device); | ||
|
||
#endif // DENOISE_WRAPPER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/**************************************************************************/ | ||
/* lightmap_denoiser.cpp */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#include "lightmap_denoiser.h" | ||
|
||
#include "denoise_wrapper.h" | ||
|
||
LightmapDenoiser *LightmapDenoiserOIDN::create_oidn_denoiser() { | ||
return memnew(LightmapDenoiserOIDN); | ||
} | ||
|
||
void LightmapDenoiserOIDN::make_default_denoiser() { | ||
create_function = create_oidn_denoiser; | ||
} | ||
|
||
Ref<Image> LightmapDenoiserOIDN::denoise_image(const Ref<Image> &p_image) { | ||
Ref<Image> img = p_image->duplicate(); | ||
|
||
img->convert(Image::FORMAT_RGBF); | ||
|
||
PoolByteArray data = img->get_data(); | ||
{ | ||
PoolByteArray::Write w = data.write(); | ||
if (!oidn_denoise(device, (float *)w.ptr(), img->get_width(), img->get_height())) { | ||
return p_image; | ||
} | ||
} | ||
|
||
img->create(img->get_width(), img->get_height(), false, img->get_format(), data); | ||
return img; | ||
} | ||
|
||
LightmapDenoiserOIDN::LightmapDenoiserOIDN() { | ||
device = oidn_denoiser_init(); | ||
} | ||
|
||
LightmapDenoiserOIDN::~LightmapDenoiserOIDN() { | ||
oidn_denoiser_finish(device); | ||
} |
Oops, something went wrong.