Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def check_if_under_mesa():
vendor = gpu.platform.vendor_get()
renderer = gpu.platform.renderer_get()
version = gpu.platform.version_get()
print("GPU Vendor:", vendor)
print("GPU Renderer:", renderer)
print("GPU Version:", version)
combined = (vendor + renderer + version).lower()
return "mesa" in combined or "llvmpipe" in combined

Expand Down Expand Up @@ -109,21 +112,25 @@ def __init__(self, *args, **kwargs):
else:
print("GLSL extension directives mid-shader are disabled!")

if self.allow_glsl_extension_directive_midshader:
ext_list = gpu.capabilities.extensions_get()
else:
ext_list = []
self.shader_interlock_support = "GL_ARB_fragment_shader_interlock" in ext_list
if not self.shader_interlock_support:
print("Warning: GL_ARB_fragment_shader_interlock not supported!")
self.shader_derivative_control_support = "GL_ARB_derivative_control" in ext_list
if not self.shader_derivative_control_support:
print("Warning: GL_ARB_derivative_control not supported!")
ext_list = gpu.capabilities.extensions_get()
self.available_extensions = []
useful_exts = ["GL_ARB_fragment_shader_interlock", "GL_ARB_derivative_control"]
mesa_caused_issues = False
for ext in useful_exts:
if ext in ext_list:
if self.allow_glsl_extension_directive_midshader:
self.available_extensions.append(ext)
else:
print(f"Warning: {ext} supported, but cannot be enabled due to driver.")
mesa_caused_issues = True
else:
print(f"Warning: {ext} not supported!")

if bpy.app.version < (4, 1, 0):
print("Warning: Blender version too old! Expect limited blending emulation!")
self.draw_range_impl = bpy.app.version >= (3, 6, 0)

if not self.allow_glsl_extension_directive_midshader and self.is_mesa_driver:
if not self.allow_glsl_extension_directive_midshader and self.is_mesa_driver and mesa_caused_issues:
bpy.app.timers.register(show_mesa_warning)

def __del__(self):
Expand Down Expand Up @@ -175,12 +182,11 @@ def init_shader(self, scene: bpy.types.Scene):
vert_out.smooth("VEC2", "inputUV")
vert_out.no_perspective("VEC2", "posScreen")

for ext in self.available_extensions:
shader_info.define(f"USE_{ext}", "1")

if self.use_atomic_rendering:
shader_info.define("depth_unchanged", "depth_any")
if self.shader_interlock_support:
shader_info.define("USE_SHADER_INTERLOCK", "1")
if self.shader_derivative_control_support:
shader_info.define("USE_DERIVATIVE_CONTROL", "1")
shader_info.define("BLEND_EMULATION", "1")
# Using the already calculated view space normals instead of transforming the light direction makes
# for cleaner and faster code
Expand Down
20 changes: 11 additions & 9 deletions shader/main3d.frag.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// allows for a per-pixel atomic access to the depth texture (needed for decals & blending)
#ifdef USE_SHADER_INTERLOCK
#extension GL_ARB_fragment_shader_interlock : enable
layout(pixel_interlock_unordered) in;
#ifdef BLEND_EMULATION
#ifdef USE_GL_ARB_fragment_shader_interlock
// allows for a per-pixel atomic access to the depth texture (needed for decals & blending)
#extension GL_ARB_fragment_shader_interlock : enable
layout(pixel_interlock_unordered) in;
#endif
#endif

#ifdef USE_DERIVATIVE_CONTROL
#ifdef USE_GL_ARB_derivative_control
#extension GL_ARB_derivative_control : enable
#endif

Expand Down Expand Up @@ -148,7 +150,7 @@ void main()

vec4 ccShade = geoModeSelect(G_SHADE_SMOOTH, cc_shade_flat, cc_shade);

#ifdef USE_DERIVATIVE_CONTROL
#ifdef USE_GL_ARB_derivative_control
const vec2 dx = abs(vec2(dFdxCoarse(inputUV.x), dFdyCoarse(inputUV.x)));
const vec2 dy = abs(vec2(dFdxCoarse(inputUV.y), dFdyCoarse(inputUV.y)));
#else
Expand Down Expand Up @@ -216,7 +218,7 @@ void main()

if(alphaTestFailed)writeDepth = -0xFFFFFF;

#ifdef USE_SHADER_INTERLOCK
#ifdef USE_GL_ARB_fragment_shader_interlock
beginInvocationInterlockARB();
#else
if(alphaTestFailed)discard; // discarding in interlock seems to cause issues, only do it here
Expand All @@ -227,7 +229,7 @@ void main()
uint writeColor = 0;
color_depth_blending(alphaTestFailed, writeDepth, currDepth, ccValue, oldColorInt, writeColor);

#ifdef USE_SHADER_INTERLOCK
#ifdef USE_GL_ARB_fragment_shader_interlock
imageAtomicCompSwap(color_texture, screenPosPixel, oldColorInt, writeColor.r);
#else
int count = 4;
Expand All @@ -242,7 +244,7 @@ void main()
#endif
}

#ifdef USE_SHADER_INTERLOCK
#ifdef USE_GL_ARB_fragment_shader_interlock
endInvocationInterlockARB();
#endif

Expand Down