From 05645f09fb0d209a653e392f94663ab6e16f67bf Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Fri, 8 Jun 2018 14:12:30 -0700 Subject: [PATCH] Integrating latest fixes. --- WORKSPACE | 9 ++++++ dev/custom_rules.bzl | 16 ++++++++++ lullaby/contrib/device_tooltips/BUILD | 1 + .../contrib/device_tooltips/device_tooltips.h | 3 +- .../hello_world/data/hello_world.json | 14 +++++--- lullaby/systems/render/BUILD | 23 ++++++++++++- .../systems/render/fpl/render_system_fpl.cc | 13 +++++--- lullaby/systems/render/next/material.cc | 4 +-- lullaby/systems/render/next/material.h | 3 +- lullaby/systems/render/next/next_renderer.cc | 3 +- lullaby/systems/render/next/shader_data.cc | 2 +- lullaby/tools/anim_pipeline/BUILD | 2 +- lullaby/tools/anim_pipeline/import_fbx.cc | 1 + lullaby/tools/common/BUILD | 2 +- lullaby/tools/model_pipeline/BUILD | 2 +- lullaby/tools/shader_pipeline/build_shader.cc | 17 ++++++++++ schemas/lull/shader_def.fbs | 32 +++++++++++++++++-- third_party/libfbx/BUILD | 20 +++++++++--- third_party/libfbx/build_defs.bzl | 25 +++++++++++++++ 19 files changed, 164 insertions(+), 28 deletions(-) create mode 100644 dev/custom_rules.bzl create mode 100644 third_party/libfbx/build_defs.bzl diff --git a/WORKSPACE b/WORKSPACE index 5311907..27adb43 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,3 +1,6 @@ +load("//dev:custom_rules.bzl", "local_repository_env") +load("//third_party/libfbx:build_defs.bzl", "FBX_BUILD_FILE_CONTENTS") + new_http_archive( name = "absl", urls = ["https://github.com/abseil/abseil-cpp/archive/7aacab8ae05d.tar.gz"], @@ -100,6 +103,12 @@ new_http_archive( strip_prefix = "KTX-Software-0e6b5c7c21818044da33da5f39534ea268fed181", ) +local_repository_env( + name = "libfbx", + env = "FBX_SDK_ROOT", + build_file = FBX_BUILD_FILE_CONTENTS, +) + new_http_archive( name = "libjpeg_turbo", urls = ["https://github.com/libjpeg-turbo/libjpeg-turbo/archive/3041cf67ffdc.tar.gz"], diff --git a/dev/custom_rules.bzl b/dev/custom_rules.bzl new file mode 100644 index 0000000..9283254 --- /dev/null +++ b/dev/custom_rules.bzl @@ -0,0 +1,16 @@ +# Custom rules for OSS bazel project. + +def _local_repository(ctx): + ctx.symlink(ctx.os.environ[ctx.attr.env], ctx.attr.env) + ctx.file("BUILD", ctx.attr.build_file) + return None + +local_repository_env = repository_rule( + implementation = _local_repository, + local = True, + attrs = { + "env": attr.string(mandatory=True), + "build_file": attr.string(mandatory=True), + } +) + diff --git a/lullaby/contrib/device_tooltips/BUILD b/lullaby/contrib/device_tooltips/BUILD index f67b189..6416ce0 100644 --- a/lullaby/contrib/device_tooltips/BUILD +++ b/lullaby/contrib/device_tooltips/BUILD @@ -21,6 +21,7 @@ cc_library( "//lullaby/systems/text", "//lullaby/systems/transform", "//lullaby/util:entity", + "//lullaby/util:enum_hash", "//lullaby/util:registry", ], ) diff --git a/lullaby/contrib/device_tooltips/device_tooltips.h b/lullaby/contrib/device_tooltips/device_tooltips.h index bd15123..1d8b129 100644 --- a/lullaby/contrib/device_tooltips/device_tooltips.h +++ b/lullaby/contrib/device_tooltips/device_tooltips.h @@ -22,6 +22,7 @@ limitations under the License. #include "lullaby/modules/dispatcher/dispatcher.h" #include "lullaby/modules/input/input_manager.h" #include "lullaby/util/entity.h" +#include "lullaby/util/enum_hash.h" #include "lullaby/util/registry.h" namespace lull { @@ -83,7 +84,7 @@ class DeviceTooltips { std::unordered_map tooltips_; - std::unordered_map devices_; + std::unordered_map devices_; Dispatcher::ScopedConnection device_connnected_connection_; Dispatcher::ScopedConnection show_tooltip_connection_; diff --git a/lullaby/examples/hello_world/data/hello_world.json b/lullaby/examples/hello_world/data/hello_world.json index 817f424..641478c 100644 --- a/lullaby/examples/hello_world/data/hello_world.json +++ b/lullaby/examples/hello_world/data/hello_world.json @@ -23,9 +23,9 @@ "def": { "shader": "shaders/text.fplshader", "color": { - "r": 1.0, - "g": 1.0, - "b": 1.0, + "r": 0.0, + "g": 0.5, + "b": 0.0, "a": 1.0 } } @@ -35,8 +35,12 @@ "fonts": [ "Roboto-Regular.ttf" ], - "text": "Hello World!", - "font_size": 0.2, + "text": "Hello World!\nThis is a Lullaby example.", + "font_size": 0.5, + "bounds": { + "x": 10.0, + "y": 0.0, + }, "vertical_alignment": "Center" } }] diff --git a/lullaby/systems/render/BUILD b/lullaby/systems/render/BUILD index bc1a4e1..02ef66a 100644 --- a/lullaby/systems/render/BUILD +++ b/lullaby/systems/render/BUILD @@ -211,6 +211,7 @@ cc_library( "//lullaby/util:flatbuffer_reader", "//lullaby/util:async_processor", "//lullaby/util:buffered_data", + "//lullaby/util:enum_hash", "//lullaby/util:filename", "//lullaby/util:fixed_string", "//lullaby/util:resource_manager", @@ -227,7 +228,6 @@ cc_library( name = "render_system_mock", testonly = 1, srcs = [ - "detail/port/default/gpu_profiler.cc", "testing/mock_render_system_impl.cc", ], hdrs = [ @@ -325,6 +325,27 @@ cc_library( }), ) +# Test-only target that doesn't include any GL. +cc_library( + name = "profiler_no_gl", + testonly = 1, + srcs = [ + "detail/port/default/gpu_profiler.cc", + "detail/profiler.cc", + ], + hdrs = [ + "detail/gpu_profiler.h", + "detail/profiler.h", + ], + deps = [ + ":render", + "//lullaby/util:clock", + "//lullaby/util:logging", + "//lullaby/util:time", + "//lullaby/util:typeid", + ], +) + cc_library( name = "render_helpers", srcs = ["render_helpers.cc"], diff --git a/lullaby/systems/render/fpl/render_system_fpl.cc b/lullaby/systems/render/fpl/render_system_fpl.cc index 444a4cc..86422ad 100644 --- a/lullaby/systems/render/fpl/render_system_fpl.cc +++ b/lullaby/systems/render/fpl/render_system_fpl.cc @@ -1178,6 +1178,14 @@ void RenderSystemFpl::SetClearColor(float r, float g, float b, float a) { clear_color_ = mathfu::vec4(r, g, b, a); } +void RenderSystemFpl::SetClearParams(HashValue pass, + const ClearParams& clear_params) { + if (CheckBit(clear_params.clear_options, RenderClearParams::kColor)) { + SetClearColor(clear_params.color_value.x, clear_params.color_value.y, + clear_params.color_value.z, clear_params.color_value.w); + } +} + void RenderSystemFpl::BeginFrame() { LULLABY_CPU_TRACE_CALL(); GL_CALL(glClearColor(clear_color_.x, clear_color_.y, clear_color_.z, @@ -1826,11 +1834,6 @@ void RenderSystemFpl::SetSortOrderOffset(Entity /*e*/, HashValue pass, LOG(DFATAL) << "This feature is only implemented in RenderSystemNext."; } -void RenderSystemFpl::SetClearParams(HashValue pass, - const ClearParams& clear_params) { - LOG(DFATAL) << "This feature is only implemented in RenderSystemNext."; -} - void RenderSystemFpl::SetRenderState(HashValue pass, const fplbase::RenderState& render_state) { LOG(DFATAL) << "This feature is only implemented in RenderSystemNext."; diff --git a/lullaby/systems/render/next/material.cc b/lullaby/systems/render/next/material.cc index fbba077..93aae97 100644 --- a/lullaby/systems/render/next/material.cc +++ b/lullaby/systems/render/next/material.cc @@ -237,8 +237,8 @@ void Material::Bind(int max_texture_units) { } void Material::CopyUniforms(const Material& rhs) { - for (auto& iter : uniform_index_map_) { - Uniform& uniform = uniforms_[iter.second]; + for (const auto& iter : rhs.uniform_index_map_) { + const Uniform& uniform = rhs.uniforms_[iter.second]; const uint8_t* bytes = uniform.data.GetData(); const size_t size = uniform.data.Size(); SetUniform(iter.first, uniform.data.Type(), {bytes, size}); diff --git a/lullaby/systems/render/next/material.h b/lullaby/systems/render/next/material.h index 5257bd6..34d357d 100644 --- a/lullaby/systems/render/next/material.h +++ b/lullaby/systems/render/next/material.h @@ -25,6 +25,7 @@ limitations under the License. #include "lullaby/systems/render/next/uniform.h" #include "lullaby/systems/render/shader.h" #include "lullaby/systems/render/texture.h" +#include "lullaby/util/enum_hash.h" #include "lullaby/util/hash.h" #include "lullaby/util/optional.h" #include "lullaby/util/variant.h" @@ -117,7 +118,7 @@ class Material { std::vector uniforms_; std::vector textures_; std::unordered_map uniform_index_map_; - std::unordered_map sampler_index_map_; + std::unordered_map sampler_index_map_; // Render State. Optional blend_state_; diff --git a/lullaby/systems/render/next/next_renderer.cc b/lullaby/systems/render/next/next_renderer.cc index 9338c6b..c288d55 100644 --- a/lullaby/systems/render/next/next_renderer.cc +++ b/lullaby/systems/render/next/next_renderer.cc @@ -175,7 +175,8 @@ NextRenderer::NextRenderer() { } // Check for ASTC. -#if defined(GL_COMPRESSED_RGBA_ASTC_4x4_KHR) +#if defined(GL_COMPRESSED_RGBA_ASTC_4x4_KHR) and \ + defined(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR) // If we have the ASTC type enums defined, check using them. gContextCapabilities.supports_astc_textures = true; diff --git a/lullaby/systems/render/next/shader_data.cc b/lullaby/systems/render/next/shader_data.cc index 7d75f4b..5ca0f94 100644 --- a/lullaby/systems/render/next/shader_data.cc +++ b/lullaby/systems/render/next/shader_data.cc @@ -348,7 +348,7 @@ void PrintSnippetsNames(string_view prefix_string, } // namespace ShaderData::ShaderData(const ShaderDefT& def) { - const ShaderCreateParams params; + const ShaderCreateParams params{}; BuildFromShaderDefT(def, params); } diff --git a/lullaby/tools/anim_pipeline/BUILD b/lullaby/tools/anim_pipeline/BUILD index 30830b7..e813222 100644 --- a/lullaby/tools/anim_pipeline/BUILD +++ b/lullaby/tools/anim_pipeline/BUILD @@ -24,7 +24,7 @@ cc_library( ], deps = [ ":animation_lib", - "@libfbx//:2016_1_2", + "@libfbx//:libfbx", "//lullaby/util:logging", "//lullaby/tools/common:fbx_utils", ], diff --git a/lullaby/tools/anim_pipeline/import_fbx.cc b/lullaby/tools/anim_pipeline/import_fbx.cc index 20c0481..0c7cb1b 100644 --- a/lullaby/tools/anim_pipeline/import_fbx.cc +++ b/lullaby/tools/anim_pipeline/import_fbx.cc @@ -15,6 +15,7 @@ limitations under the License. */ #include +#include #include "lullaby/util/logging.h" #include "lullaby/tools/anim_pipeline/animation.h" #include "lullaby/tools/common/fbx_utils.h" diff --git a/lullaby/tools/common/BUILD b/lullaby/tools/common/BUILD index 656746b..6b83565 100644 --- a/lullaby/tools/common/BUILD +++ b/lullaby/tools/common/BUILD @@ -15,7 +15,7 @@ cc_library( "fbx_utils.h", ], deps = [ - "//third_party/libfbx:libfbx", + "@libfbx//:libfbx", "//:fbs", ], ) diff --git a/lullaby/tools/model_pipeline/BUILD b/lullaby/tools/model_pipeline/BUILD index 78f4ddb..511dcea 100644 --- a/lullaby/tools/model_pipeline/BUILD +++ b/lullaby/tools/model_pipeline/BUILD @@ -53,7 +53,7 @@ cc_library( copts = ["-Wno-null-dereference"], deps = [ ":model_lib", - "//third_party/libfbx:libfbx", + "@libfbx//:libfbx", "//:fbs", "//lullaby/util:common_types", "//lullaby/tools/common:fbx_utils", diff --git a/lullaby/tools/shader_pipeline/build_shader.cc b/lullaby/tools/shader_pipeline/build_shader.cc index 8ce136b..b182b44 100644 --- a/lullaby/tools/shader_pipeline/build_shader.cc +++ b/lullaby/tools/shader_pipeline/build_shader.cc @@ -30,6 +30,7 @@ namespace lull { namespace tool { namespace { +static constexpr int kUnspecifiedVersion = 0; static constexpr HashValue kAttributeHashPosition = ConstHash("ATTR_POSITION"); static constexpr HashValue kAttributeHashUV = ConstHash("ATTR_UV"); static constexpr HashValue kAttributeHashColor = ConstHash("ATTR_COLOR"); @@ -59,6 +60,21 @@ void AddUnique(ValueType value, rapidjson::Value* array, array->PushBack(value, document->GetAllocator()); } +// Helper function that ensures there is a version in the snippet. +void CheckForVersion(rapidjson::Value* snippet, rapidjson::Document* document) { + if (!snippet || !document) { + return; + } + + if (!snippet->HasMember("versions")) { + rapidjson::Value versions(rapidjson::kArrayType); + rapidjson::Value version(rapidjson::kObjectType); + version.AddMember("lang", "GL_Compat", document->GetAllocator()); + versions.PushBack(version, document->GetAllocator()); + snippet->AddMember("versions", versions, document->GetAllocator()); + } +} + // Helper function to create the environment flags of a snippet. void CreateSnippetEnvironmentFlags(rapidjson::Value* snippet, rapidjson::Document* document) { @@ -360,6 +376,7 @@ bool AddSnippetsFromJson(const std::string& json_string, for (rapidjson::Value::ValueIterator iter = snippets.Begin(); iter != snippets.End(); ++iter) { rapidjson::Value* snippet = &*iter; + CheckForVersion(snippet, &json); CreateSnippetEnvironmentFlags(snippet, &json); ValidateAndProcessUniforms(snippet, &json); ProcessSnippetCodeSection("code", snippet, &json); diff --git a/schemas/lull/shader_def.fbs b/schemas/lull/shader_def.fbs index 7ea64b8..538abc0 100644 --- a/schemas/lull/shader_def.fbs +++ b/schemas/lull/shader_def.fbs @@ -65,12 +65,39 @@ enum ShaderStageType : ushort { Fragment, } +/// Types of programmable shader stages. +enum ShaderLanguage : ushort { + /// GL Shading Language Compatible across GLSL and GLSL_ES. Version mapping + /// attempts to keep OpenGL ES and OpenGL Core compatible and uses OpenGL ES + /// as the base for versioning. + /// Sample mapping: 100 = [100 GLES, 110 GL], 300 = [300 GLES, 330 GL]. + GL_Compat, + /// OpenGL Shading Language. Versions map directly to the GLSL versions. + GLSL, + /// OpenGL ES Shading Language. Versions map directly to GLSL ES versions. + GLSL_ES, +} + +table ShaderSnippetVersionDef { + /// Shader language defined for the snippet. + lang: ShaderLanguage; + /// Minimum shading language version supported. + /// [0 = no minimum version]. + min_version: int; + /// Maximum shading language version supported. + /// [0 = no maximum version]. + max_version: int; +} + /// Snippet containing shader source code or reference to a file containing the /// source code. table ShaderSnippetDef { // Name identifier for this snippet. This is mostly for debug purposes. name: string; + // Shading language versions supported by this shader snippet. + versions: [ShaderSnippetVersionDef]; + /// Features implemented by this snippet. features: [uint] (hashvalue); /// Environment flags required for this snippet to work. @@ -78,6 +105,8 @@ table ShaderSnippetDef { /// Uniforms used by this snippet's shader code. uniforms: [ShaderUniformDef]; + /// Samplers used by this snippet's shader code. + samplers: [ShaderSamplerDef]; /// Input data received by the snippet in the form of attributes or varying. inputs: [ShaderAttributeDef]; /// Output data sent by the snippet in the form of attributes or varying. @@ -87,9 +116,6 @@ table ShaderSnippetDef { code: string; /// Shader main() function implementation code for this snippet. main_code: string; - - /// Samplers used by this snippet's shader code. - samplers: [ShaderSamplerDef]; } /// A shader stage and associated snippets. diff --git a/third_party/libfbx/BUILD b/third_party/libfbx/BUILD index 36c2288..9b9a4b5 100644 --- a/third_party/libfbx/BUILD +++ b/third_party/libfbx/BUILD @@ -2,12 +2,22 @@ package( default_visibility = ["//visibility:public"], ) -licenses(["notice"]) # Apache 2.0 - cc_library( name = "libfbx", - linkopts = [ - "-L/usr/lib/gcc4/x64/release -lfbxsdk" + srcs = [ + "FBX_SDK_ROOT/lib/gcc4/x64/release/libfbxsdk.a" ], - includes = ["include"], + hdrs = [ + "FBX_SDK_ROOT/include/fbxsdk.h" + ] + glob([ + "FBX_SDK_ROOT/include/fbxsdk/**/*.h" + ]), + includes = [ + "FBX_SDK_ROOT/include", + "." + ], + linkopts = [ + "-ldl", + "-pthread", + ] ) diff --git a/third_party/libfbx/build_defs.bzl b/third_party/libfbx/build_defs.bzl new file mode 100644 index 0000000..03ad68f --- /dev/null +++ b/third_party/libfbx/build_defs.bzl @@ -0,0 +1,25 @@ +FBX_BUILD_FILE_CONTENTS = """ +package( + default_visibility = ["//visibility:public"], +) + +cc_library( + name = "libfbx", + srcs = [ + "FBX_SDK_ROOT/lib/gcc4/x64/release/libfbxsdk.a" + ], + hdrs = [ + "FBX_SDK_ROOT/include/fbxsdk.h" + ] + glob([ + "FBX_SDK_ROOT/include/fbxsdk/**/*.h" + ]), + includes = [ + "FBX_SDK_ROOT/include", + "." + ], + linkopts = [ + "-ldl", + "-pthread", + ] +) +"""