Commit Graph

4691 Commits

Author SHA1 Message Date
Jason Fielder
06f27b564c Fix: DRW: Flickering and sync in Metal
Flickering caused by in-flight SSBO data
overwrites has been resolved by ensuring
data updates go into a new buffer while
existing data is in flight.

GPU_finish has also been removed from
SSBO read due to its frequent mid-frame use
limiting performance.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/113019
2023-09-28 18:42:49 +02:00
Brecht Van Lommel
66056fead0 Fix #112632: crash batch generating previews with Cycles
Don't assume existence of GPU backend in (background) preview rendering.

Also add null pointer checks and rely on assert instead to detect
invalid usage of GPU_render_begin/end, so that potential future mistakes
don't cause crashes.

Pull Request: https://projects.blender.org/blender/blender/pulls/112971
2023-09-28 16:13:09 +02:00
Clément Foucault
3a4fc2c94e EEVEE-Next: Shadow Map Tracing Initial Implementation
Shadow Map Ray Tracing is a technique that ray cast against the shadow
depth buffer. The technique is described in "Soft Shadows by
Ray Tracing Multilayer Transparent Shadow Maps".
Note that we only implement the single layer approach since storing
multiple depth is prohibitively expensive.

Pull Request: https://projects.blender.org/blender/blender/pulls/111809
2023-09-26 23:42:40 +02:00
Jeroen Bakker
7dbe689b63 Vulkan: Use Point Shaders When Drawing Points
In Vulkan (and Metal) it is not possible to use a global as point
size. It needs to be set for each vertex when drawing points. Blender
has specialized shaders for that, but not all code respect those
shaders.

This PR will add an assert inside the vulkan backend when incorrect
usage of shaders are detected.

Pull Request: https://projects.blender.org/blender/blender/pulls/112906
2023-09-26 16:04:08 +02:00
Clément Foucault
788506d7fc GPU: add pragma once to GPU_shader_shared.h
Otherwise there are compilation issues
when the file happens to be included twice.
2023-09-26 15:19:51 +02:00
Campbell Barton
077832e063 Cleanup: spelling in comments 2023-09-26 19:50:48 +10:00
Clément Foucault
a5741e0561 EEVEE: Change do_multiscatter to a bool internally
This avoid confusion outside of the shader node GLSL code.
The issue also is that Metal allow float to cast to bool
implicitly but this create a compilation error on
OpenGL.
2023-09-26 11:48:51 +02:00
Clément Foucault
0a4fa62f51 EEVEE: Add support for metallic F82 tint
This adds a new entry to the split sum LUT to isolate
the effect of the F82 tint.

The application of the tint part is similar to cycles
and uses the same way for precomputing the `b` factor.

Results matches almost perfectly to the extent of the
split sum approximation.

Note that this removes the unused LTC MAG LUT for
EEVEE next to make space for the new table. It can still
be added back if needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/112881
2023-09-26 10:16:39 +02:00
Jason Fielder
ee03bb38cb Metal: Add support for atomic image operations
Texture Atomics have been added in Metal 3.1
and enable the original implementations of
shadow update and irradiance cache baking.

However, a fallback solution will be
required for versions under macOS 14.0 utilising
buffer-backed textures instead.

This patch also includes a stub implementation if
building/running on older macOS versions which
provides locally-synchronized texture access in
place of atomics. This enables some effects to be
partially tested, and ensures non-guarded use
of imageAtomic functions does not result
in compilation failure.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/112866
2023-09-25 21:56:46 +02:00
Brecht Van Lommel
3d38b51435 Shaders: add "Weight" to Transmission/Subsurface/Coat/Sheen socket names
Ref #99447
Ref #112848
2023-09-25 19:51:27 +02:00
Brecht Van Lommel
1d265eed5d Shaders: rename Specular to Specular IOR Level in Principled BSDF
To clarify that this is no longer the primary control, but rather
and adjustment on IOR.

Ref #99447
Ref #112552
2023-09-25 19:51:22 +02:00
Brecht Van Lommel
239edb27ad EEVEE: optimize principled BSDF by skipping unused components
Ref #99447
Ref #112848
2023-09-25 19:51:17 +02:00
Alaska
a03ee1af81 Shaders: clamp various shader inputs for Principled BSDF
Ref #99447

Pull Request: https://projects.blender.org/blender/blender/pulls/112774
2023-09-25 19:51:12 +02:00
Lukas Stockner
6e2f29b421 Shader: change Specular input on Principled BSDF to affect IOR
This keeps the behavior similar to the Disney BRDF, where 0.5
is neutral and lower/higher values respectively decrease/increase
the dielectric specular. But it's more correct in that it's not
an arbitrary scale on Fresnel, but rather adjusting the IOR.

Ref #99447
Ref #112848

Pull Request: https://projects.blender.org/blender/blender/pulls/112552
2023-09-25 19:51:02 +02:00
Brecht Van Lommel
3d986b81c5 Shaders: move subsurface scale input below radius in Principled BSDF
To help clarify that this is a scale on the radius.

Ref #99447
Ref #112848
2023-09-25 19:50:56 +02:00
Brecht Van Lommel
334027063e Shader: use single Principled BSDF input for metallic and specular tint
To match Standard Surface and OpenPBR.

Ref #99447
Ref #112848
2023-09-25 19:50:44 +02:00
Weizhen Huang
def9b76207 Shader: Change specular tint in Principled BSDF from float to color
For more artistic control. Tints the reflection of dielectric materials
at normal incidence.

Ref #99447

Pull Request: https://projects.blender.org/blender/blender/pulls/112192
2023-09-25 19:42:05 +02:00
Lukas Stockner
86156566a7 Cycles: Add Metallic Tint to Principled BSDF using F82-Tint model
With the default value, this is backwards-compatible.

Ref #99447

Pull Request: https://projects.blender.org/blender/blender/pulls/112551
2023-09-25 19:42:05 +02:00
Jeroen Bakker
676a03cf1e Cleanup: Make format 2023-09-25 09:35:00 +02:00
Campbell Barton
e38ff7c06d Cleanup: use C++ comments for disabled code 2023-09-25 17:06:04 +10:00
Jeroen Bakker
805c58d9ec Fix 112641: OpenGL Shader Draw Parameter Workaround Broken
The workaround for shader draw parameters isn't working for OpenGL. The
reason is that it isn't looking for the correct attribute to attach the
buffer to.

This fixes the issue that all objects where drawn using the unit matrix when
starting blender with `--debug-gpu-force-workarounds`.

![image](/attachments/f05b712e-e3f2-4ad5-b098-7e9d01bc4ca4)

Fixes #112641

Pull Request: https://projects.blender.org/blender/blender/pulls/112668
2023-09-21 19:34:07 +02:00
Jeroen Bakker
dd3e23e812 Vulkan: Show Missing Implementations
This PR will print a message when a vulkan method isn't implemented.
So we can keep track of what still needs to be implemented.

Pull Request: https://projects.blender.org/blender/blender/pulls/112671
2023-09-21 15:21:32 +02:00
Jeroen Bakker
6d91d36161 GPU: Remove GPU_shader_storage_buffer_objects_support
Blender 4.0 requires OpenGL 4.3 which always support SSBO's.
Platforms that don't support enough SSBO bind points will be marked
as unsupported.

Users who start Blender on those platforms will be informed via a
dialog. This PR also updates the `--debug-gpu-force-workarounds`
to match our minimum requirements. Note that some bugs are still
there that should be solved in other PRs:

* Workbench only renders the object using a unit matrix this is because
  there is a bug in the workaround for shader_draw_parameters
* Navigating with middle mouse button is not working. Unsure what the
  cause is, but might be a missing feature check in the OpenGL backend.

Related to #112224

Pull Request: https://projects.blender.org/blender/blender/pulls/112572
2023-09-21 12:55:51 +02:00
Jason Fielder
42ddeeadeb Metal: Add support for storage buffer copy_sub
Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/112638
2023-09-20 23:59:08 +02:00
Clément Foucault
e743b353cd GPU: Shader Builder: Guard OpenGL builder with flag 2023-09-20 15:05:41 +02:00
Jeroen Bakker
3a4c238d50 Command Line: Remove Disabling SSBO
Blender has the option to disable SSBO support. This was accessible
as a command line option `--debug-gpu-disable-ssbo`.

Blender 4.0 has a hard requirement for OpenGL 4.3 which includes
SSBO support by default.

This PR removes the command line option as it makes no sense to
have it anymore.

Related to #112224

Pull Request: https://projects.blender.org/blender/blender/pulls/112571
2023-09-19 14:22:32 +02:00
Jeroen Bakker
2d70f46265 Fix: Vulkan Grid Overlay
In Vulkan the grid overlay wasn't rendering correctly. The reason was
a mis alignment in the std430 layout. This PR fixes the std430 layout
so the grid overlay (and perhaps also other sections) would work.

Root cause is that the reserve size if an nVec3 is different when used
as an array versus a single attribute. This was not taken into account
where the overlay flag was read from uninitialized memory.

Pull Request: https://projects.blender.org/blender/blender/pulls/112564
2023-09-19 11:52:59 +02:00
Weizhen Huang
e0dacfdda6 EEVEE: use Schlick's approximation instead of real Fresnel for glass
so that we can tint `F0` separately
Ref: #112192 #99447

Mostly affects `IOR < 1`. The overall appearance matches, with some changes in the reflection.

Pull Request: https://projects.blender.org/blender/blender/pulls/112390
2023-09-18 14:26:19 +02:00
Jeroen Bakker
f7ccec2bcc Vulkan: Fix Generate Mipmaps for Array Textures
Array textures stores the array length inside the size of the image. In
vulkan the size mustn't contain the array length, but it should be set
as a separate parameter. This logic wasn't implemented when updating
the mipmap chain.

Patch also includes some smaller fixes where textures would not yet be
allocated on the device, but was expected to be.

Pull Request: https://projects.blender.org/blender/blender/pulls/112518
2023-09-18 13:45:53 +02:00
Jeroen Bakker
231f1a6076 Vulkan: Implement GPU_storagebuf_copy_sub_from_vertbuf
This PR implements `GPU_storagebuf_copy_sub_from_vertbuf`. It can be
used to copy a part of a vertex buffer to a storage buffer.

Pull Request: https://projects.blender.org/blender/blender/pulls/112516
2023-09-18 13:44:03 +02:00
Jeroen Bakker
a54495b347 Vulkan: Upload Uniform Buffer Attached Data
Uniform buffers can have data provided during construction, or as
attached data. Attached data should be uploaded during bind.

This PR implements `GPU_uniformbuf_create_from_list`.

Pull Request: https://projects.blender.org/blender/blender/pulls/112517
2023-09-18 13:43:16 +02:00
Jeroen Bakker
1daecc24d0 Vulkan: Postpone Resource Destruction
Resources can still be in use inside the vulkan command queue, when
they are destroyed. Especially as Vulkan doesn't allow resetting
bindings to nothing.

This PR will collect the resources that needs to be destroyed inside
the VKDevice and actually destroy the resources when on frame end.

The resources currently include:
* VkBuffer
* VkImage
* VkImageView
* VkFramebuffer
* VkRenderPass

Pull Request: https://projects.blender.org/blender/blender/pulls/112514
2023-09-18 13:42:17 +02:00
Jeroen Bakker
0e47a13e3e Vulkan: Fix Namespace Collision Between Shader Resources
Previous implemetation had some limitations that were not working
for complex shaders. This limitations included:

* All bindings should be bound to a location < 16.
* Collision could happen when image locations where read that
  overlapped with the texture locations.

This PR replaces the fixed binding locations with a dynamic vector.
When allocating locations for images the image offset is determined
that it is always clear if the requested locations is already
offsetted or not. This is done by ensuring the offset to larger than
the max slot of samplers, but also of image slots.

When using Eevee-next materials the slot numbers can be very high
as the location of the first material texture is set to
`GPU_max_textures_frag()` On current NVIDIA drivers this number is
set to 1K. Images are stored after the textures slots upwards.

In the future driver could set this to MAX_INT which will not work
with the new implementation. This isn't the case at this moment
and perhaps also not realistic. We don't check for this situation yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/112511
2023-09-18 13:41:50 +02:00
Jeroen Bakker
80dda1168f Vulkan: Submit after Compute Dispatch
This PR adds command submission after performing any compute dispatch.
This is a work around as the vulkan backend doesn't support memory
barriers yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/112505
2023-09-18 13:41:19 +02:00
Sergey Sharybin
1b3141c06e Cleanup: Strict compiler warning in GPU code
The NDEBUG is a toggle define, and in debug builds it is not defined.

This change solves the warning
  mtl_context.mm:2282:5: warning: 'NDEBUG' is not defined, evaluates to 0 [-Wundef]

Pull Request: https://projects.blender.org/blender/blender/pulls/112504
2023-09-18 12:04:47 +02:00
Alaska
88ad79c2d1 Add panels to Principled BSDF node
Add panels to the Principled BSDF node to organize
and reduce the size of the node.

Layout inspired by previous work from @LukasStockner

Pull Request: https://projects.blender.org/blender/blender/pulls/112314
2023-09-17 15:42:15 +02:00
Weizhen Huang
5baf652374 Cleanup: EEVEE: rename glass BTDF to BSDF at several places
because it contains reflectance and transmittance, so BSDF would be a
morep proper name.
Also rename BSDF to BRDF at places where only reflectance is returned.
2023-09-14 16:06:26 +02:00
Campbell Barton
b7f3e0d84e Cleanup: spelling & punctuation in comments
Also remove some unhelpful/redundant comments.
2023-09-14 13:25:24 +10:00
Lukas Stockner
d7aee5a580 Cycles: Tweak Principled BSDF Subsurface parameters
Previously, the Principled BSDF used the Subsurface input to scale the radius.
When it was zero, it used a diffuse closure, otherwise a subsurface closure.
This sort of scaling input makes sense, but it should be specified in distance
units, rather than a 0..1 factor, so this commit changes the unit and renames
the input to Subsurface Scale.

Additionally, it adds support for mixing diffuse and subsurface components.
This is part of e.g. the OpenPBR spec, and the logic behind it is to support
modeling e.g. dirt or paint on top of skin. Before, materials would be either
fully diffuse (radius=0) or fully subsurface.

For typical materials, this mixing factor will be either zero or one
(just like metallic or transmission), but supporting fractional inputs makes
sense for e.g. smooth transitions at boundaries.

Another change is that there is no separate Subsurface Color anymore - before,
this was mixed with the Base Color using the Subsurface input as the factor,
but this was not really useful since that input was generally very small.

And finally, the handling of how the path enters the material for random walk
subsurface scattering is changed. Before, this always used lambertian (diffuse)
transmission, but this caused some problems, like overly white edges.

Instead, two different methods are now used, depending on the selected mode.
In Fixed Radius mode, the code assumes a simple medium boundary, and performs
refraction into the material using the main Roughness and IOR inputs.

Meanwhile, when not using Fixed Radius, the code assumes a more complex
boundary (as typically found on organic materials, e.g. skin), so the entry
bounce has a 50/50 chance of being either diffuse transmission or refraction
using the separate Subsurface IOR input and a fixed roughness of 1.
Credit for this method goes to Christophe Hery.

Pull Request: https://projects.blender.org/blender/blender/pulls/110989
2023-09-13 02:45:33 +02:00
Lukas Stockner
158dbc1b10 Cycles: Rework Principled BSDF Clearcoat
- Adds tint control, which simulates volumetric absorption inside the coating.
  This results in angle-dependent saturation and affects all underlying layers
  (diffuse, subsurface, metallic, transmission). It provides a physically-based
  alternative to ad-hoc effects such as tinted specular highlights.
- Renames the component from "Clearcoat" to "Coat", since it's no longer
  necessarily clear now. This matches naming in e.g. other renderers or OpenPBR.
- Adds an explicit Coat IOR input, in preparation for future smarter IOR logic
  around the interaction between Coat and main IOR. This used to be hardcoded
  to 1.5.
- Removes hardcoded 0.25 weight multiplier, and adds versioning code to update
  existing files accordingly. OBJ import/export still applies the factor.
- Replaces the GTR1 microfacet component with regular GGX. This removes a corner
  case in the Microfacet code, solves #53038, and makes us more consistent with
  other standard surface shaders. The original Disney BSDF used GTR1, but it
  doesn't appear that it caught on in the industry.

Co-authored-by: Weizhen Huang <weizhen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/110993
2023-09-13 00:03:11 +02:00
Miguel Pozo
d81165f3ec Fix #111960, #112200, #112214: EEVEE: Incorrect BuiltinBits::LAYER use
5cf7089e43 added the `BuiltinBits::LAYER` to shaders with a geometry
stage. This causes compilation errors when
`GLContext::layered_rendering_support` is false (otherwise the flag
does nothing).

This PR moves the `LAYER` flags to the `no_geom` shader versions and
adds a check to `ShaderCreateInfo::finalize()` to ensure the `LAYER` flag
is not used in shaders with a geometry stage.

Pull Request: https://projects.blender.org/blender/blender/pulls/112245
2023-09-12 15:39:33 +02:00
Jeroen Bakker
6920c690f1 Vulkan: Implement Component Swizzling
Component swizzling is part of an image view and localized in the code.
With component swizzling a different channel (or 0 or 1) can be read
when the component is accessed.

Pull Request: https://projects.blender.org/blender/blender/pulls/112273
2023-09-12 11:54:57 +02:00
Jeroen Bakker
ded7d96ba1 Vulkan: Texture View
Adding support for Texture View in Vulkan backend.

When a VKTexture is a texture view many options become
irrelevant, but isn't actually clear via its API. Added
asserts to make sure that the usage is supported.

This patch allows rendering simple workbench-next scenes
without any validation errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/110887
2023-09-12 11:18:38 +02:00
Jeroen Bakker
65a88c3d60 Vulkan: Fix Incorrect UINT formats.
When `COMP_U*` is used together with a `GPU_FETCH_INT` the backend
tried to convert them to floats. What is of course not what should
happen.

Issue was that these cases were never correctly tested. With this
change the `data` attribute of the `overlay_edit_mesh` shaders are
transferred correctly and can draw some pixels as intended.

Pull Request: https://projects.blender.org/blender/blender/pulls/112270
2023-09-12 11:15:51 +02:00
Miguel Pozo
12522e1c86 Cleanup: GPU: Remove duplicated line 2023-09-11 16:08:04 +02:00
Jeroen Bakker
81c6eb9c7f Vulkan: Enable Shader Draw Parameters Support
Shader draw parameter support is needed for Workbench-next. (Almost) All
devices that we support also supports shader draw parameters. This PR
doesn't include a workaround for devices that don't have support.

For end-users this PR will allow workbench-next to render the object on
the correct location. Before this patch they were always drawn on the origin.

The catch is that OpenGL uses gl_InstanceID which always starts counting at 0.
Vulkan has gl_InstanceIndex which holds the correct instance number. By
subtracting the gl_InstanceIndex from gl_BaseInstance will get the correct
gl_InstanceID.

This patch also activates some device extensions to perform in shader printf
statements inside a shader. Documentation for this will be added to the dev
docs how to use them.

Pull Request: https://projects.blender.org/blender/blender/pulls/111461
2023-09-11 15:04:54 +02:00
Campbell Barton
9e41eccc6e Cleanup: spelling in comments 2023-09-08 17:12:29 +10:00
Campbell Barton
4fc5d287ac Cleanup: doxygen parameters, blank comment lines 2023-09-08 16:53:30 +10:00
Campbell Barton
5ab2f61d44 Cleanup: remove use of 'auto' 2023-09-08 16:53:27 +10:00
Miguel Pozo
2aa7961e6f Workbench: Remove old implementation 2023-09-06 15:54:48 +02:00