[2.2] GL3+ support for macOS

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


srmainwaring
Gnoblar
Posts: 4
Joined: Tue Jun 22, 2021 10:27 am
x 3

[2.2] GL3+ support for macOS

Post by srmainwaring »

I am attempting to port the Ogre2.1 support for GL3+ to Ogre2.2 and would appreciate any help / guidance.

The background is that I'd like to get OSRF's Ignition graphical front end working on macOS. Gazebo11 works well on macOS (using Ogre1.9) but it is not being further developed. At present OSRF do not intend to support Metal shaders [https://community.gazebosim.org/t/ogre- ... rtress/912], and so having the GL3+ rendering system available provides some options in the interim.

I've made a start here [https://github.com/srmainwaring/ogre-ne ... -egl-macos]. The core code and most of the samples are compiling on macOS 11.4 using the Xcode 12.5 command line tools. Currently a sample will start with GL3+ rendering selected and then seg. fault after parsing the scripts.

I plan to keep chipping away at it, but if there are any experts able to review or contribute that would be most welcome.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: [2.2] GL3+ support for macOS

Post by dark_sylinc »

You seem to be on the right track.

When I'm developing a new RS (or getting a broken one to work on a different platform ) I start with, in this order:
  1. Tutorial00_Basic (very raw Ogre)
  2. Tutorial01_Initialization (still quite raw, but has SDL integration and some components are turned on)
  3. Tutorial02_VariableFramerate (Tuts 03-06 by now should work if 02 works) (black cube is on screen, no lighting)
  4. StereoRendering (cube is on screen + lighting + multiple scene render passes)
  5. ShadowMapDebugging (has cube + lighting + shadow maps)
  6. PbsMaterials (like ShadowMapDebugging but is also textured in many ways: diffuse, normal maps, env maps)
  7. The rest of the samples
Note: Aside from windowing, there is the issue that our texturing code requires ARB_texture_storage (became part of core in GL 4.2, and core in GLES 3.0, aka glTexStorage2D and co.). macOS does not support ARB_texture_storage.

The best approach IMHO would be to override our glTexStorageXD pointers to translate them to equivalent glTexImageXD calls, or a a class that overloads GL3PlusTextureGpu (e.g. GL3PlusLegacyTextureGpu) which overloads routines that use glTexStorageXD and reimplement them (e.g. createInternalResourcesImpl)

Our GL3PlusTextureGpu::copyTo routine relies on GL_ARB_copy_image, which is also unsupported by macOS. We have a fallback path but it is not heavily tested because GL_ARB_copy_image is often supported and the fallback path is only used for MSAA copies which is very rare).

Additionally more advanced samples that make use of TextureFlags::Reinterpretable will need glTextureView which is also not supported by macOS.
srmainwaring
Gnoblar
Posts: 4
Joined: Tue Jun 22, 2021 10:27 am
x 3

Re: [2.2] GL3+ support for macOS

Post by srmainwaring »

Thanks for the very helpful guide.

I've not yet made the additions you suggest to support legacy texture behaviour, but with a first cut of changes the following samples are working:

Tutorial00_Basic
Tutorial01_Initialization
Tutorial02_VariableFramerate
Tutorial03_DeterministicLoop
StereoRendering
(Tutorials04 - 06 have not been ported to Metal on this branch).

Window resizing is not yet properly implemented as the underlying texture is not resized and the StereoRendering is a glitchy, but it's progressing...

Update:

I've implemented fallback calls for glTexStorage1D, etc. These are currently in separate classes for legacy support, but it may be better to just test for GL4.2 support in the existing classes.

It turns out that my card on macOS supports the GL_ARB_texture_storage extensions, so this is not where Sample_PbsMaterial fails:

Code: Select all

***********************************************
***  Starting Mac OS X OpenGL 3+ Subsystem  ***
***********************************************
GL3PlusRenderSystem::_createRenderWindow "PBS Materials Sample", 1024x768 windowed  miscParams: FSAA=0 gamma=Yes parentWindowHandle=140453806275408 reverse_depth=Yes title=PBS Materials Sample vsync= 
Creating a Cocoa Compatible Render System
Mac Cocoa Window: Rendering on an external NSView
Cocoa: Window created 1024 x 768 using content scaling factor 1.0
GL Version = 4.1.0.0
GL_VERSION = 4.1 ATI-4.5.14
GL_VENDOR = ATI Technologies Inc.
GL_RENDERER = AMD Radeon Pro W5700X OpenGL Engine
GL_EXTENSIONS = 
GL_ARB_blend_func_extended
GL_ARB_draw_buffers_blend
GL_ARB_draw_indirect
GL_ARB_ES2_compatibility
GL_ARB_explicit_attrib_location
GL_ARB_gpu_shader_fp64
GL_ARB_gpu_shader5
GL_ARB_instanced_arrays
GL_ARB_internalformat_query
GL_ARB_occlusion_query2
GL_ARB_sample_shading
GL_ARB_sampler_objects
GL_ARB_separate_shader_objects
GL_ARB_shader_bit_encoding
GL_ARB_shader_subroutine
GL_ARB_shading_language_include
GL_ARB_tessellation_shader
GL_ARB_texture_buffer_object_rgb32
GL_ARB_texture_cube_map_array
GL_ARB_texture_gather
GL_ARB_texture_query_lod
GL_ARB_texture_rgb10_a2ui
GL_ARB_texture_storage
GL_ARB_texture_swizzle
GL_ARB_timer_query
GL_ARB_transform_feedback2
GL_ARB_transform_feedback3
GL_ARB_vertex_attrib_64bit
GL_ARB_vertex_type_2_10_10_10_rev
GL_ARB_viewport_array
GL_EXT_debug_label
GL_EXT_debug_marker
GL_EXT_depth_bounds_test
GL_EXT_texture_compression_s3tc
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_mirror_clamp
GL_EXT_texture_sRGB_decode
GL_APPLE_client_storage
GL_APPLE_container_object_shareable
GL_APPLE_flush_render
GL_APPLE_object_purgeable
GL_APPLE_rgb_422
GL_APPLE_row_bytes
GL_APPLE_texture_range
GL_ATI_texture_mirror_once
GL_NV_texture_barrier
Instead the sample is failing in GL3PlusRenderPassDescriptor::switchToFBO, GL3PlusRenderPassDescriptor::updateColourFbo etc. as glFramebufferParameteri requires GL4.3 which is not available in macOS.

I can see that the corresponding frame buffer code has moved out of GL3PlusRenderSystem::_setRenderTarget in 2.1 to GL3PlusRenderPassDescriptor::switchToFBO in 2.2: What would be a suitable fallback option for handling FBOs with no attachments when ARB_framebuffer_no_attachments is not available?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: [2.2] GL3+ support for macOS

Post by dark_sylinc »

srmainwaring wrote: Wed Jun 30, 2021 12:45 pm It turns out that my card on macOS supports the GL_ARB_texture_storage extensions, so this is not where Sample_PbsMaterial fails:
Really?? That's awesome! Apple documents claim otherwise, but I suspected it could be wrong because GLES needs it, and the iOS simulator wouldn't work if macOS drivers didn't have it
srmainwaring wrote: Wed Jun 30, 2021 12:45 pm Instead the sample is failing in GL3PlusRenderPassDescriptor::switchToFBO, GL3PlusRenderPassDescriptor::updateColourFbo etc. as glFramebufferParameteri requires GL4.3 which is not available in macOS.

I can see that the corresponding frame buffer code has moved out of GL3PlusRenderSystem::_setRenderTarget in 2.1 to GL3PlusRenderPassDescriptor::switchToFBO in 2.2: What would be a suitable fallback option for handling FBOs with no attachments when ARB_framebuffer_no_attachments is not available?
Avoid calling them (or provide a stub glFramebufferParameteri that does nothing). That feature is for advanced uses where instead of rendering to a render target, we use UAVs to render to arbitrary locations (e.g. voxelizer) while leveraging raster HW.

macOS simply can't support those advance use cases.

Our code simply sets the values when doing rendertarget-less rasterization, and uses these functions to always reset it (i.e. disable it, we don't check if the previous pass was rt-less render) during normal raster passes.
You will simply ignore it all.
srmainwaring
Gnoblar
Posts: 4
Joined: Tue Jun 22, 2021 10:27 am
x 3

Re: [2.2] GL3+ support for macOS

Post by srmainwaring »

Getting there...

This is the Sample_PbsMaterials.app running on Ogre2.2 with the OpenGL3Plus RS:

Image

As suggested I've stubbed out the glFramebufferParameteri calls in the render pass descriptor. The call to glCopyImageSubData is also stubbed out in GL3PlusTextureGpu::copyTo while I research the best way to implement a fallback for this.

I'll post a PR once that's in place. At the moment the changes are on the v2-2-egl branch since this is the one used to create the OSRF homebrew package. What would be the preferred branch to target for the PR?

Update 11 July 2021

Quick note on current status: a first cut of GL3+ support for macOS in v2.2 has been merged. Thanks to
dark_sylinc for help and feedback.
srmainwaring
Gnoblar
Posts: 4
Joined: Tue Jun 22, 2021 10:27 am
x 3

Re: [2.2] GL3+ support for macOS

Post by srmainwaring »

dark_sylinc - it turns out there is more work to do on GL3+ for macOS to be able to run ignition fortress. The downstream issue I'd like to resolve is here Examples not working on macOS with Ogre2.2 but for starters the focus is on getting Sample_Forward3D and Sample_PostProcessing working properly.

Unfortunately I'm a bit limited for OpenGL frame debug tools on macOS (Bug Sur 11.4), the best option seems to be the Intel GPA Graphics Frame Analyzer. The last version provided by Intel for macOS does not include the dependency analyser but does capture the resource state for each draw call in the frame (so I can inspect that state and render target for each draw but will have to deduce order by other means).

Image

I'm starting to work my way through a comparison between Ogre2.1 and Ogre2.2 frame captures to try and understand where things have gone wrong but would appreciate any guidance the Ogre team can offer on where to focus. If the GPA frame captures for the samples would help I can upload these to dropbox.

Update

There's something odd going with the `render_quad` pass in the compositor under GL3+. The compositor below should render a green window:

Code: Select all

// Ogre2.2 version
compositor_node TestRenderQuadNode
{
    in 0 rt_output

    texture rt_green target_width target_height PFG_RGBA8_UNORM_SRGB

    target rt_green
    {
        pass clear
        {
            colour_value 0 0.5 0 1
        }
    }
    
    target rt_output
    {
        // Clear to yellow
        pass clear
        {
            colour_value 1 1 0 1
        }
        
        // Copy texture from rt_green
        pass render_quad
        {
            load { all dont_care }
            material Ogre/Copy/4xFP32
            input 0 rt_green
        }
    }
}

workspace TestRenderQuadWorkspace
{
    connect_output TestRenderQuadNode 0
}
On metal it works fine, on GL3+ it fails (renders blue). A modified version for Ogre2.1 works on for both metal and GL3+.