From 02695b3b95488400dffca3e1924a65f3efdc5a14 Mon Sep 17 00:00:00 2001 From: "adam.b" Date: Fri, 8 Jun 2018 19:03:42 +0100 Subject: [PATCH] [Vulkan] Fixed setting mat3 uniforms - Matrix column stride taken in account - todo: use reflection in order to obtain stride value Change-Id: I7f35006cb13561d8054a7ae66d0868042be3c959 # Conflicts: # dali/internal/update/graphics/graphics-algorithms.cpp # dali/internal/update/rendering/scene-graph-renderer.cpp --- dali/graphics-api/graphics-api-types.h | 4 ++-- dali/internal/update/graphics/graphics-algorithms.cpp | 6 ++++++ dali/internal/update/rendering/scene-graph-renderer.cpp | 12 +++++++++++- dali/internal/update/rendering/scene-graph-renderer.h | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/dali/graphics-api/graphics-api-types.h b/dali/graphics-api/graphics-api-types.h index c59d134..9d7ee85 100644 --- a/dali/graphics-api/graphics-api-types.h +++ b/dali/graphics-api/graphics-api-types.h @@ -378,7 +378,7 @@ struct RasterizationState struct InputAssemblyState { PrimitiveTopology topology {}; - bool primitiveRestartEnable { false }; + bool primitiveRestartEnable { true }; Extension extension { nullptr }; @@ -390,7 +390,7 @@ struct InputAssemblyState InputAssemblyState& SetPrimitiveRestartEnable( bool value ) { - primitiveRestartEnable = value; + primitiveRestartEnable = true; return *this; } }; diff --git a/dali/internal/update/graphics/graphics-algorithms.cpp b/dali/internal/update/graphics/graphics-algorithms.cpp index 9474009..d253c59 100644 --- a/dali/internal/update/graphics/graphics-algorithms.cpp +++ b/dali/internal/update/graphics/graphics-algorithms.cpp @@ -163,6 +163,12 @@ void SubmitRenderItemList( Graphics::API::Controller& graphics, sgRenderer->WriteUniform("uMvpMatrix", mvp2); sgRenderer->WriteUniform("uViewMatrix", *viewMatrix); sgRenderer->WriteUniform("uModelView", item.mModelViewMatrix); + + Matrix3 uNormalMatrix( item.mModelViewMatrix ); + uNormalMatrix.Invert(); + uNormalMatrix.Transpose(); + + sgRenderer->WriteUniform("uNormalMatrix", uNormalMatrix); sgRenderer->WriteUniform("uProjection", vulkanProjectionMatrix); sgRenderer->WriteUniform("uSize", item.mSize); sgRenderer->WriteUniform("uColor", color ); diff --git a/dali/internal/update/rendering/scene-graph-renderer.cpp b/dali/internal/update/rendering/scene-graph-renderer.cpp index 5a0838e..acbf549 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.cpp +++ b/dali/internal/update/rendering/scene-graph-renderer.cpp @@ -292,6 +292,7 @@ void Renderer::PrepareRender( BufferIndex updateBufferIndex ) switch (uniformMap->propertyPtr->GetType()) { + case Property::Type::FLOAT: case Property::Type::INTEGER: case Property::Type::BOOLEAN: @@ -341,7 +342,16 @@ void Renderer::PrepareRender( BufferIndex updateBufferIndex ) DALI_LOG_STREAM( gVulkanFilter, Debug::Verbose, uniformInfo.name << ":[" << uniformInfo.bufferIndex << "]: " << "Writing mat3 offset: " << uniformInfo.offset << ", size: " << sizeof(Matrix3) ); dst += sizeof(Matrix3) * arrayIndex; - memcpy(dst, &uniformMap->propertyPtr->GetMatrix3(updateBufferIndex), sizeof(Matrix3)); + + auto& matrix = uniformMap->propertyPtr->GetMatrix3(updateBufferIndex); + + float* values = reinterpret_cast(dst); + std::fill( values, values+12, 10.0f ); + std::memcpy( &values[0], matrix.AsFloat(), sizeof(float)*3 ); + std::memcpy( &values[4], &matrix.AsFloat()[3], sizeof(float)*3 ); + std::memcpy( &values[8], &matrix.AsFloat()[6], sizeof(float)*3 ); + + memcpy(dst, values, sizeof(float)*12); break; } default: diff --git a/dali/internal/update/rendering/scene-graph-renderer.h b/dali/internal/update/rendering/scene-graph-renderer.h index 4987366..7230030 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.h +++ b/dali/internal/update/rendering/scene-graph-renderer.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace Dali { @@ -373,6 +374,19 @@ public: WriteUniform( name, &data, sizeof(T) ); } + void WriteUniform( const std::string& name, const Matrix3& data ) + { + // Matrix3 has to take stride in account ( 16 ) + float values[12]; + std::fill( values, values+12, 10.0f ); + + std::memcpy( &values[0], data.AsFloat(), sizeof(float)*3 ); + std::memcpy( &values[4], &data.AsFloat()[3], sizeof(float)*3 ); + std::memcpy( &values[8], &data.AsFloat()[6], sizeof(float)*3 ); + + WriteUniform( name, &values, sizeof(float)*12 ); + } + void WriteUniform( const std::string& name, const void* data, uint32_t size ); -- 2.7.4