gazebosim / gz-rendering

C++ library designed to provide an abstraction for different rendering engines. It offers unified APIs for creating 3D graphics applications.
https://gazebosim.org
Apache License 2.0
56 stars 51 forks source link

Ogre2 Tests Failing in Metal transition #695

Open mjcarroll opened 2 years ago

mjcarroll commented 2 years ago

Environment

Description

When transitioning to metal, three new test failures were introduced. They are captured here so that we remember to address them.

``` [----------] 1 test from UtilTest 185: [ RUN ] UtilTest.ClickToScene 185: [Wrn] [Ogre2RenderTarget.cc:585] Anti-aliasing level of '0' is not supported; valid FSAA levels are: [ 1 2 4 8 ]. Setting to 1 185: [Dbg] [CommonRenderingTest.hh:76] Using OGRE2-METAL backend to test 185: [Msg] Loading plugin [gz-rendering-ogre2] 185: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/common_test/Utils_TEST.cc:123: Failure 185: The difference between 0.0 and result.X() is 0.026159780099987984, which exceeds 2e-6, where 185: 0.0 evaluates to 0, 185: result.X() evaluates to 0.026159780099987984, and 185: 2e-6 evaluates to 1.9999999999999999e-06. 185: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/common_test/Utils_TEST.cc:124: Failure 185: The difference between 0.0 and result.Y() is 0.026159882545471191, which exceeds 2e-6, where 185: 0.0 evaluates to 0, 185: result.Y() evaluates to 0.026159882545471191, and 185: 2e-6 evaluates to 1.9999999999999999e-06. 185: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/common_test/Utils_TEST.cc:132: Failure 185: The difference between 0.0 and result.X() is 0.026159780099987984, which exceeds 2e-6, where 185: 0.0 evaluates to 0, 185: result.X() evaluates to 0.026159780099987984, and 185: 2e-6 evaluates to 1.9999999999999999e-06. 185: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/common_test/Utils_TEST.cc:133: Failure 185: The difference between 0.0 and result.Y() is 0.026159882545471191, which exceeds 2e-6, where 185: 0.0 evaluates to 0, 185: result.Y() evaluates to 0.026159882545471191, and 185: 2e-6 evaluates to 1.9999999999999999e-06. 185: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/common_test/Utils_TEST.cc:145: Failure 185: The difference between 0.0 and result.X() is 0.011728753335773945, which exceeds 2e-6, where 185: 0.0 evaluates to 0, 185: result.X() evaluates to 0.011728753335773945, and 185: 2e-6 evaluates to 1.9999999999999999e-06. 185: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/common_test/Utils_TEST.cc:146: Failure 185: The difference between 0.0 and result.Y() is 0.011728801764547825, which exceeds 2e-6, where 185: 0.0 evaluates to 0, 185: result.Y() evaluates to 0.011728801764547825, and 185: 2e-6 evaluates to 1.9999999999999999e-06. 185: [ FAILED ] UtilTest.ClickToScene (189 ms) ```
``` [ RUN ] CameraTest.VisualAt 9: [Dbg] [CommonRenderingTest.hh:76] Using OGRE2-METAL backend to test 9: [Msg] Loading plugin [gz-rendering-ogre2] 9: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/camera.cc:223: Failure 9: Expected: (nullptr) != (vis), actual: (nullptr) vs (nullptr) 9: X: 200 9: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/camera.cc:223: Failure 9: Expected: (nullptr) != (vis), actual: (nullptr) vs (nullptr) 9: X: 300 9: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/camera.cc:237: Failure 9: Expected: (nullptr) != (vis), actual: (nullptr) vs (nullptr) 9: X: 500 9: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/camera.cc:237: Failure 9: Expected: (nullptr) != (vis), actual: (nullptr) vs (nullptr) 9: X: 600 9: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/camera.cc:237: Failure 9: Expected: (nullptr) != (vis), actual: (nullptr) vs (nullptr) 9: X: 700 9: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/camera.cc:264: Failure 9: Expected: (nullptr) != (vis), actual: (nullptr) vs (nullptr) 9: X: 300 9: [ FAILED ] CameraTest.VisualAt (383 ms) 9: C++ exception with description "OGRE EXCEPTION(3:RenderingAPIException): Vertex Program ```

This appears to be caused by some shader compilation errors:

``` 21:23:39: Metal SL Compiler Error in _gz_simple_color_330_vs.glsl: program_source:1:2: error: invalid preprocessing directive #version ogre_glsl_ver_330 ^ program_source:20:1: error: unknown type name 'vulkan_layout' vulkan_layout( OGRE_POSITION ) in vec4 vertex; ^ program_source:20:31: error: expected ';' after top level declarator vulkan_layout( OGRE_POSITION ) in vec4 vertex; ^ ; program_source:22:1: error: C++ requires a type specifier for all declarations vulkan( layout( ogre_P0 ) uniform Params { ) ^ program_source:22:17: error: use of undeclared identifier 'ogre_P0' vulkan( layout( ogre_P0 ) uniform Params { ) ^ program_source:34:2: error: expected ';' after top level declarator } ^ ; 21:23:39: Error retriving entry point 'main_metal' in shader _gz_simple_color_330_vs.glsl 21:23:39: OGRE EXCEPTION(3:RenderingAPIException): Vertex Program _gz_simple_color_330_vs.glsl failed to compile. See compile log above for details. in MetalProgram::compile at /tmp/ogre2.3-20220725-29639-6uzcl/ogre-next-2.3.1/RenderSystems/Metal/src/OgreMetalProgram.mm (line 273) 21:23:39: High-level program _gz_simple_color_330_vs.glsl encountered an error during loading and is thus not supported. OGRE EXCEPTION(3:RenderingAPIException): Vertex Program _gz_simple_color_330_vs.glsl failed to compile. See compile log above for details. in MetalProgram::compile at /tmp/ogre2.3-20220725-29639-6uzcl/ogre-next-2.3.1/RenderSystems/Metal/src/OgreMetalProgram.mm (line 273) 21:23:39: Metal SL Compiler Error in _gz_simple_color_330_vs.glsl: program_source:1:2: error: invalid preprocessing directive #version ogre_glsl_ver_330 ^ program_source:20:1: error: unknown type name 'vulkan_layout' vulkan_layout( OGRE_POSITION ) in vec4 vertex; ^ program_source:20:31: error: expected ';' after top level declarator vulkan_layout( OGRE_POSITION ) in vec4 vertex; ^ ; program_source:22:1: error: C++ requires a type specifier for all declarations vulkan( layout( ogre_P0 ) uniform Params { ) ^ program_source:22:17: error: use of undeclared identifier 'ogre_P0' vulkan( layout( ogre_P0 ) uniform Params { ) ^ program_source:34:2: error: expected ';' after top level declarator } ^ ; 21:23:39: Error retriving entry point 'main_metal' in shader _gz_simple_color_330_vs.glsl 21:23:39: OGRE EXCEPTION(3:RenderingAPIException): Vertex Program _gz_simple_color_330_vs.glsl failed to compile. See compile log above for details. in MetalProgram::compile at /tmp/ogre2.3-20220725-29639-6uzcl/ogre-next-2.3.1/RenderSystems/Metal/src/OgreMetalProgram.mm (line 273) 21:23:39: Unregistering ResourceManager for type Font 21:23:39: DefaultWorkQueue('Root') shutting down on thread main. 21:23:39: *-*-* OGRE Shutdown ```
``` 25: [ RUN ] RenderPassTest.DepthGaussianNoise 25: [Dbg] [CommonRenderingTest.hh:76] Using OGRE2-METAL backend to test 25: [Msg] Loading plugin [gz-rendering-ogre2] 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:280: Failure 25: The difference between expectedRangeAtMidPoint + noiseMean and mx is 0.40000000000000013, which exceeds noiseTol, where 25: expectedRangeAtMidPoint + noiseMean evaluates to 1.4000000000000001, 25: mx evaluates to 1, and 25: noiseTol evaluates to 0.039999999105930328. 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:286: Failure 25: Expected equality of these values: 25: maxVal 25: Which is: inf 25: lx 25: Which is: 1 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:287: Failure 25: Expected equality of these values: 25: maxVal 25: Which is: inf 25: ly 25: Which is: 1 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:288: Failure 25: Expected equality of these values: 25: maxVal 25: Which is: inf 25: lz 25: Which is: 1 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:293: Failure 25: Expected equality of these values: 25: maxVal 25: Which is: inf 25: rx 25: Which is: 1 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:294: Failure 25: Expected equality of these values: 25: maxVal 25: Which is: inf 25: ry 25: Which is: 1 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:295: Failure 25: Expected equality of these values: 25: maxVal 25: Which is: inf 25: rz 25: Which is: 1 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:315: Failure 25: Expected: (mb) > (0u), actual: 0 vs 0 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:325: Failure 25: The difference between 255u and lr is 255, which exceeds colorNoiseTol, where 25: 255u evaluates to 255, 25: lr evaluates to 0, and 25: colorNoiseTol evaluates to 10. 25: /Users/jenkins/mjcarroll/gz_garden/src/gz-rendering/test/integration/render_pass.cc:336: Failure 25: The difference between 255u and rr is 255, which exceeds colorNoiseTol, where 25: 255u evaluates to 255, 25: rr evaluates to 0, and 25: colorNoiseTol evaluates to 10. 25: [ FAILED ] RenderPassTest.DepthGaussianNoise (259 ms) ```
mjcarroll commented 2 years ago

CC: @darksylinc

darksylinc commented 2 years ago

Metal SL Compiler Error in _gz_simple_color_330_vs.glsl:

I got confused by this error until I realized it says METAL but the shader is GLSL.

The test is simply faulty because it does not provide a Metal version for Gazebo to use. It should be easy to port and I think we have a very similar shader already ported (in gz-rendering/ogre2/src/media/materials/programs/Metal/plain_color_fs.metal).

mjcarroll commented 2 years ago

I got confused by this error until I realized it says METAL but the shader is GLSL.

Yeah, sorry I traced this one down a few minutes ago and came to the same conclusion. It's a shader that is in test/media and not src/media.

darksylinc commented 2 years ago

It's really late and I think this pair of shaders should be the ported version (untested code):

/*
 * Copyright (C) 2022 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <metal_stdlib>
using namespace metal;

struct VS_INPUT
{
  float4 position [[attribute(VES_POSITION)]];
};

struct PS_INPUT
{
  float4 gl_Position [[position]];
};

struct Params
{
  float4x4 worldviewproj_matrix;
};

vertex PS_INPUT main_metal
(
  VS_INPUT input [[stage_in]],
  constant Params &p [[buffer(PARAMETER_SLOT)]]
)
{
  PS_INPUT outVs;

  outVs.gl_Position = ( p.worldviewproj_matrix * input.position ).xyzw;

  return outVs;
}
/*
 * Copyright (C) 2022 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <metal_stdlib>
using namespace metal;

struct PS_INPUT
{
};

fragment float4 main_metal
(
  PS_INPUT inPs [[stage_in]]
)
{
  return float4(1.0, 0.0, 0.0, 1.0);
}