EEVEE-Next: Resolve compilation errors in Metal #106219

Merged
Jeroen Bakker merged 8 commits from Jason-Fielder/blender:MetalEEVEENext_shaderCompilation into main 2023-04-20 08:03:42 +02:00
Member

Shader source requires explicit conversions and shader address
space qualifers in certain places in order to compile for Metal.

We also require constructors for a number of default struct types.

Authored by Apple: Michael Parkin-White

Ref #96261

Shader source requires explicit conversions and shader address space qualifers in certain places in order to compile for Metal. We also require constructors for a number of default struct types. Authored by Apple: Michael Parkin-White Ref #96261
Jason Fielder added 1 commit 2023-03-28 15:09:10 +02:00
d9a52b7bb6 EEVEE-Next: Resolve compilation errors in Metal.
Shader source requires explicit conversions and shader address
space qualifers in certain places in order to compile for Metal.

We also require constructors for a number of default struct types.

Authored by Apple: Michael Parkin-White

Ref #96261
Jason Fielder requested review from Clément Foucault 2023-03-28 15:09:37 +02:00
Jason Fielder requested review from Jeroen Bakker 2023-03-28 15:09:47 +02:00
Hans Goudey changed title from EEVEE-Next: Resolve compilation errors in Metal. to EEVEE-Next: Resolve compilation errors in Metal 2023-03-28 15:33:53 +02:00
Clément Foucault requested changes 2023-03-28 15:43:24 +02:00
Clément Foucault left a comment
Member

I'm fine with most of this. Just want to see 2 points fixed before accepting this.

I'm fine with most of this. Just want to see 2 points fixed before accepting this.
@ -8,2 +8,4 @@
struct AABB {
vec3 min, max;
#ifdef GPU_METAL

Change caller to use the following syntax instead. Same for Sphere()

  AABB aabb;
  aabb.min = vec3(1.0e30);
  aabb.max = vec3(-1.0e30);
Change caller to use the following syntax instead. Same for `Sphere()` ``` AABB aabb; aabb.min = vec3(1.0e30); aabb.max = vec3(-1.0e30);
@ -74,3 +71,1 @@
out vec4 top,
out vec4 near,
out vec4 far)
DEVICE_OUT(vec4, left),

We should avoid that. Change the caller to not pass device memory references (and do some copy instead, hoping the compiler optimizes it). This make the caller code uglier but it is better than having a function that can only take device memory as argument.

We should avoid that. Change the caller to not pass device memory references (and do some copy instead, hoping the compiler optimizes it). This make the caller code uglier but it is better than having a function that can only take device memory as argument.
First-time contributor

Yep, I can make this change for this case, I can't guarantee that it won't incur additional overhead, though most likely the device read needs to happen anyway, it's just a question of whether the read-write is more or less the same.

The slightly more awkward case here is that it is used in combination with the currentDEVICE_OUT_ARRAY in:
void frustum_culling_planes_calc(mat4 winmat, mat4 viewmat, DEVICE_OUT_ARRAY(vec4, planes, 6))

as this routine also then updates the planes stored in device memory.

I'm happy to refactor the code around this function to first pull the data, update locally and then update device memory if this is suitable, even if makes the code a little longer?

Yep, I can make this change for this case, I can't guarantee that it won't incur additional overhead, though most likely the device read needs to happen anyway, it's just a question of whether the read-write is more or less the same. The slightly more awkward case here is that it is used in combination with the current`DEVICE_OUT_ARRAY` in: `void frustum_culling_planes_calc(mat4 winmat, mat4 viewmat, DEVICE_OUT_ARRAY(vec4, planes, 6))` as this routine also then updates the planes stored in device memory. I'm happy to refactor the code around this function to first pull the data, update locally and then update device memory if this is suitable, even if makes the code a little longer?

The proposed way implemented in the latest version of this PR is suitable.

The proposed way implemented in the latest version of this PR is suitable.
Jeroen Bakker requested changes 2023-04-03 08:09:19 +02:00
@ -175,3 +175,4 @@
vec3 v001 = v000 - v_back * radius;
Box bbox = shape_box(v000, v100, v010, v001);
intersect_tile = intersect_tile && intersect(tile, bbox);
} break;
Member

Codestyle: add break inside the code-block.

Codestyle: add break inside the code-block.
Jason Fielder added 1 commit 2023-04-17 14:41:05 +02:00
Michael Parkin-White added 1 commit 2023-04-17 14:55:57 +02:00
Jason Fielder added 1 commit 2023-04-17 16:11:30 +02:00
39ceab2071 Address feedback. Remove Metal constructors and
use struct member population for shapes.

Remove DEVICE_OUT and DEVICE_OUT_ARRAY, refactor
ViewCullingData to allow full struct copy to avoid any additional
overhead from removing device pointer modification, as device
data now copied into local variable for modification, before writing
back to device memory.
Jason Fielder added 1 commit 2023-04-17 17:51:02 +02:00
First-time contributor

Have now addressed feedback, but given there are refactors to avoid passing device pointers directly to utility functions, and compaction of fixed size arrays into structs, the compilation needs verifying on other platforms. (This passes locally for Metal and OpenGL on macOS, though with the caveat that unsupported shaders were not tested for OpenGL, as these cannot compile on macOS anyway).

Thanks!

Have now addressed feedback, but given there are refactors to avoid passing device pointers directly to utility functions, and compaction of fixed size arrays into structs, the compilation needs verifying on other platforms. (This passes locally for Metal and OpenGL on macOS, though with the caveat that unsupported shaders were not tested for OpenGL, as these cannot compile on macOS anyway). Thanks!
Jason Fielder added 1 commit 2023-04-17 22:59:29 +02:00
Michael Parkin-White added 1 commit 2023-04-17 23:00:41 +02:00
Clément Foucault approved these changes 2023-04-19 15:35:07 +02:00
Clément Foucault left a comment
Member

I tested on AMD + Linux (both Mesa & amdgpu-pro drivers) and it works.

I tested on AMD + Linux (both Mesa & amdgpu-pro drivers) and it works.
Clément Foucault added 1 commit 2023-04-19 18:21:41 +02:00
Jeroen Bakker added the
Interest
Metal
label 2023-04-20 07:51:35 +02:00
Jeroen Bakker added this to the 3.6 LTS milestone 2023-04-20 07:51:39 +02:00
Jeroen Bakker added this to the EEVEE & Viewport project 2023-04-20 07:51:43 +02:00
Member

I tested on Linux/NVIDIA and it works.

I tested on Linux/NVIDIA and it works.
Jeroen Bakker approved these changes 2023-04-20 08:02:56 +02:00
Jeroen Bakker merged commit dda4c0721c into main 2023-04-20 08:03:42 +02:00
Sign in to join this conversation.
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 Assignees
4 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#106219
No description provided.