GL: Add subpass input emulation #112051

Merged
Clément Foucault merged 10 commits from fclem/blender:gl-subpass-emulation into main 2023-10-01 15:27:29 +02:00

This adds basic emulation of the subpass input feature
of vulkan and to a lower extend Raster Order Group on Metal.

This help test paths that might use this feature in the future
(like shadow rendering) on all platform and or simplify higher
level code for supporting older hardware.

This add clear description to the load/store ops and to the
new GPUAttachementState.

The OpenGL backend will correctly mask un-writable
attachments and will bind as texture readable attachments.

Even if possible by the vulkan standard, the GPU API prohibit
the read and write to the same attachment inside the same
subpass.

In the GL backend, this is implemented using glTextureBarrier
and texelFetch as it is described in the ARB_texture_barrier
extension.
https://registry.khronos.org/OpenGL/extensions/ARB/ARB_texture_barrier.txt

This adds basic emulation of the subpass input feature of vulkan and to a lower extend Raster Order Group on Metal. This help test paths that might use this feature in the future (like shadow rendering) on all platform and or simplify higher level code for supporting older hardware. This add clear description to the load/store ops and to the new `GPUAttachementState`. The OpenGL backend will correctly mask un-writable attachments and will bind as texture readable attachments. Even if possible by the vulkan standard, the GPU API prohibit the read and write to the same attachment inside the same subpass. In the GL backend, this is implemented using `glTextureBarrier` and `texelFetch` as it is described in the ARB_texture_barrier extension. https://registry.khronos.org/OpenGL/extensions/ARB/ARB_texture_barrier.txt
Clément Foucault added 1 commit 2023-09-06 20:14:43 +02:00
Clément Foucault requested review from Jeroen Bakker 2023-09-06 20:16:04 +02:00
Jeroen Bakker reviewed 2023-09-14 14:49:16 +02:00
@ -19,2 +19,4 @@
} eGPULoadOp;
typedef enum GPUAttachmentLayout {
GPU_LAYOUT_GENERAL = 0,
Member

Different name, layout tells more about the order of data on the GPU inside the image. Perhaps GPUAttachmentUsage

Different name, layout tells more about the order of data on the GPU inside the image. Perhaps GPUAttachmentUsage
fclem marked this conversation as resolved
Clément Foucault added 2 commits 2023-09-28 23:21:33 +02:00
Clément Foucault added 1 commit 2023-09-28 23:55:58 +02:00
Clément Foucault changed title from WIP: GL: Add subpass input emulation to GL: Add subpass input emulation 2023-09-28 23:58:38 +02:00
Clément Foucault added 1 commit 2023-09-29 00:10:23 +02:00
Jeroen Bakker reviewed 2023-09-29 11:51:04 +02:00
@ -22,0 +39,4 @@
*/
typedef enum eGPUStoreOp {
/**
* Do not care about the content of the attachment when the render pass starts.
Member

when the render pass ends

`when the render pass ends`
fclem marked this conversation as resolved
Jeroen Bakker reviewed 2023-09-29 11:53:44 +02:00
@ -22,0 +64,4 @@
typedef enum GPUAttachmentState {
/** Attachment will not be written during rendering. */
GPU_ATTACHEMENT_IGNORE = 0,
/** Attachment will be written during geometry passes. This also works with blending. */
Member

geometry passes?

geometry passes?
fclem marked this conversation as resolved
Clément Foucault reviewed 2023-09-29 11:59:27 +02:00
@ -116,0 +238,4 @@
case Type::SHORT3:
case Type::SHORT4:
case Type::VEC3_101010I2:
/* TODO(fclem): This could add support for lower bit depth formats. */
Author
Member

This need to be supported for more versatility. However, this will not work with imageLoad because we need to know the format of the image upfront. So I'll change the workaround to use sampler instead of image.

This need to be supported for more versatility. However, this will not work with `imageLoad` because we need to know the format of the image upfront. So I'll change the workaround to use `sampler` instead of `image`.
fclem marked this conversation as resolved
Jeroen Bakker reviewed 2023-09-29 12:10:30 +02:00
@ -56,2 +56,4 @@
void attachment_set_loadstore_op(GPUAttachmentType type, GPULoadStore /*ls*/) override;
void subpass_transition(const GPUAttachmentState depth_attachment_state,
Span<GPUAttachmentState> color_attachment_states) override{};
Member

  void subpass_transition(const GPUAttachmentState /*depth_attachment_state*/,
                          Span<GPUAttachmentState> /*color_attachment_states*/) override {
        NOT_YET_IMPLEMENTED
};
``` void subpass_transition(const GPUAttachmentState /*depth_attachment_state*/, Span<GPUAttachmentState> /*color_attachment_states*/) override { NOT_YET_IMPLEMENTED };
fclem marked this conversation as resolved
Member

When run on Intel ARC/Mesa

Note: Google Test filter = GPUOpenGLTest.framebuffer_subpass_input
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from GPUOpenGLTest
[ RUN      ] GPUOpenGLTest.framebuffer_subpass_input
Failed to start GPU frame capture!
ERROR (gpu.shader):  FragShader: 
      | 
   92 |   in_value = gl_LastFragData[0].x;
      |              ^
      | Error: `gl_LastFragData' undeclared
      | Error: type mismatch

Segmentation fault (core dumped)

Might be that the extension is supported on OpenGL ES, but not on OpenGL...
Perhaps disable the extension for intel GPUs

I validated that it worked using the same Mesa, but with AMD card.

When run on Intel ARC/Mesa ``` Note: Google Test filter = GPUOpenGLTest.framebuffer_subpass_input [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from GPUOpenGLTest [ RUN ] GPUOpenGLTest.framebuffer_subpass_input Failed to start GPU frame capture! ERROR (gpu.shader): FragShader: | 92 | in_value = gl_LastFragData[0].x; | ^ | Error: `gl_LastFragData' undeclared | Error: type mismatch Segmentation fault (core dumped) ``` Might be that the extension is supported on OpenGL ES, but not on OpenGL... Perhaps disable the extension for intel GPUs I validated that it worked using the same Mesa, but with AMD card.
Clément Foucault added 1 commit 2023-09-29 13:08:35 +02:00
Clément Foucault added 1 commit 2023-09-29 14:29:18 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
018fd6d279
Try opengl es 3.0 syntax
Author
Member

@buildbot package windows

@buildbot package windows
Author
Member

@blender-bot package windows

@blender-bot package windows
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR112051) when ready.
Author
Member

Note directly related to this task, but noteworthy mention that it is possible to implement the GPU_STOREACTION_DONT_CARE using ARB_invalidate_subdata in OpenGL.

Note directly related to this task, but noteworthy mention that it is possible to implement the `GPU_STOREACTION_DONT_CARE` using `ARB_invalidate_subdata` in OpenGL.
Author
Member

Reading a bit more and it seems that the current approach without framebuffer fetch is still undefined behavior and that the only option is either to modify the framebuffer or use glTextureBarrier (which is 4.5 core and widely implemented). That's what I'm going to implement.
https://www.khronos.org/opengl/wiki/Memory_Model#Texture_barrier

I think i'll scrap the framebuffer fetch implementation if it still doesnt work on ARC. It isn't supported by the older hardware and will not help much anyway.

Reading a bit more and it seems that the current approach without framebuffer fetch is still undefined behavior and that the only option is either to modify the framebuffer or use `glTextureBarrier` (which is 4.5 core and widely implemented). That's what I'm going to implement. https://www.khronos.org/opengl/wiki/Memory_Model#Texture_barrier I think i'll scrap the framebuffer fetch implementation if it still doesnt work on ARC. It isn't supported by the older hardware and will not help much anyway.
Clément Foucault added 1 commit 2023-09-30 09:08:46 +02:00
Clément Foucault added 1 commit 2023-09-30 09:54:32 +02:00
Clément Foucault added 1 commit 2023-10-01 14:45:29 +02:00
Author
Member

@blender-bot build

@blender-bot build
Clément Foucault merged commit 4a4b1482cd into main 2023-10-01 15:27:29 +02:00
Clément Foucault deleted branch gl-subpass-emulation 2023-10-01 15:27:31 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#112051
No description provided.