Python GPU: expose GPU functions in Python #108668
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#108668
Loading…
Reference in New Issue
No description provided.
Delete Branch "gfxcoder/blender:gpu_state_updates"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Several functions in GPU module were not yet exposed to Python.
DepthWrite
on an instance ofGPUShaderCreateInfo
Fixed documentation for
define
method onGPUShaderCreateInfo
.I followed the instructions on https://wiki.blender.org/wiki/Tools/Pull_Requests as best I could. Please let me know if this PR needs to be updated before reviewing.
A note: as of Blender 3.6.0, there is no way to create a shader in Python that updates the depth in fragment shader. This commit exposes that ability.
Could you provide a way to test the changes?
First, I noticed and fixed a bug in the
depth_range_set
function. This change is in commit4e6fcb4349
.Attached is a Python script to demo the
depth_range_set
andwrite_depth
functions. There is some boiler/helper code in the script to simplify iteration and to handle errors gracefully. I can strip it down to individual tests if needed. It can run in Blender 3.6.0 beta (although the features do not work), 4.0.0 alpha (although features don't work), and this branch.The two getter functions can be easily tested from Python console...
@ -520,0 +548,4 @@
Py_RETURN_NONE;
}
// .depth_write(DepthWrite::ANY))
Should be removed?
@ -935,3 +968,3 @@
".. code-block:: glsl\n"
"\n"
" #define name value\n"
" \"#define name value\"\n"
This doesn't seem related, the code-block should not need to be quoted AFAICS.
Ah, I was following the example of doc for fragment_source, which I notice now also has the quotes but should not. I think it just needs indented.
I looked at the markup style guide, but the code samples section was a bit sparse on formatting details.
will get this (and other parts that use incorrect formatting) fixed. should these changes be in a separate PR rather than a general Python / GPU improvement PR?
These documented by https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-code-block - so unless the string is expected to be quoted (when displayed in the web-page), additional quotes should not be added.
These extraneous quotes are removed in this PR.
@ -298,0 +317,4 @@
static PyObject *pygpu_state_depth_range_set(PyObject *UNUSED(self), PyObject *args)
{
float near, far;
if (!PyArg_ParseTuple(args, "ff:depth_range_set", &near, &far)) {
There is no check that
near <= far
. If flipping near/far results in unexpected/buggy behavior, it's probably best to raise an exception in this case.Or, if there is some reason to allow it, that should be noted in the code-comments, possibly the doc-string.
@ -298,0 +330,4 @@
"\n"
" Current mapping of depth values from normalized device coordinates to window coordinates.\n"
"\n"
" :return: The depth range as a tuple\n"
picky
as a tuple
is repeated information, may as well leave it out.I was following example of scissor_get. Should docs for both remove the
as a tuple
?Wasn't aware of that, may as well, yes.
Removed
as a tuple
and made some additional adjustment to docstring.Attached is a better version of testing code. Rather than rendering two triangles with coincident points, here it renders two coplanar triangles. The Z-fighting is very evident and an effect that should be avoided is most cases.
Minor requests, otherwise LGTM.
@ -298,0 +321,4 @@
}
if (near > far) {
PyErr_SetString(PyExc_ValueError, "Near must be less than or equal to far");
Return
NULL
after setting the error.Should this raise an exception for negative values too?
Values over 1 don't make sense either. Should we test against these? Do these tests need to be reported in the docstring?
added checks for negative values and for too positive (>1) values.
This PR is applied to Blender 4.0. Is there any way to get these changes into 3.6? even if 3.6.1?
Thanks for the review+feedback @dr.sybren and @ideasman42!
I've tried building this PR, but I get these errors:
It probably needs some updating to work against current
main
.Checkout
From your project repository, check out a new branch and test the changes.