Page MenuHome

PyGPU: GPUShader: implementation of 'attrs_info_get' method
ClosedPublic

Authored by Germano Cavalcante (mano-wii) on Aug 23 2022, 9:22 PM.

Details

Summary

With the new attrs_info_get method, we can get information about
the attributes used in a GPUShader and thus have more freedom in the
automatic creation of GPUVertFormats


This is a proposal to replace GPUShader.format_calc() (which can even be removed after the commit).

With this solution we can achieve the same objective proposed in D15726, which is to use 2D coordinates in 3D shaders.

With this change we can even remove the 2D builtin shaders.

Usage example

>>> # See the information of: [attribute name, attribute type] used in the GPUShader
>>> import gpu
>>> shader = gpu.shader.from_builtin('3D_FLAT_COLOR')
>>> print(shader.attrs_info_get())
(('color', 'VEC4'), ('pos', 'VEC3'))

Diff Detail

Repository
rB Blender
Branch
arcpatch-D15764 (branched from master)
Build Status
Buildable 23523
Build 23523: arc lint + arc unit

Event Timeline

Germano Cavalcante (mano-wii) requested review of this revision.Aug 23 2022, 9:22 PM
Germano Cavalcante (mano-wii) created this revision.
  • limit except for TypeError
  • Use PyUnicode_InternFromString instead of PyUnicode_FromString for types that are often used in comparisons.
  • Fix compilation error with Makefiles

Only minor change requested.

source/blender/python/gpu/gpu_py_shader.c
702

Follow existing prefix attr_*, attr_from_name is another method in this module.

Germano Cavalcante (mano-wii) marked an inline comment as done.
  • Rename attribute_info_get to attr_info_get
  • Remove array_size information (array vertex inputs are not supported in the gpu module)
  • Use ShaderInterface to get all attribute information
NOTE: the order of the attributes does not follow the same order of their declaration. We could sort in python based on location. But it's not really a problem for now.
Germano Cavalcante (mano-wii) retitled this revision from PyGPU: GPUShader: implementation of 'attribute_info_get' method to PyGPU: GPUShader: implementation of 'attr_info_get' method.Aug 25 2022, 9:44 PM
Germano Cavalcante (mano-wii) edited the summary of this revision. (Show Details)
Clément Foucault (fclem) requested changes to this revision.Aug 28 2022, 7:10 PM
Clément Foucault (fclem) added inline comments.
release/scripts/modules/gpu_extras/batch.py
28

typo present throughout the diff.

36

I am unsure about this. 8bit attribs are not well supported on all platforms. Would recommend I32.

59

either infos or attrs but one should be plural since it returns an list.

This revision now requires changes to proceed.Aug 28 2022, 7:10 PM
Germano Cavalcante (mano-wii) marked 3 inline comments as done.
  • Fix Typos
  • Return I32 for "recommended_comp_type" of BOOL types
  • Rename variables

I also changed the GPU_shader_get_attribute_info function to use attr_location instead of attr_id.

This is because attr_id points to the index of an internal array sorted by the hash of the inputs.

The API doesn't seem to intend to use this index externally.

Also, by using the attribute location, the sequence of attrs in the list in Python is more expected as it follows what is seen in the shader.

Germano Cavalcante (mano-wii) retitled this revision from PyGPU: GPUShader: implementation of 'attr_info_get' method to PyGPU: GPUShader: implementation of 'attrs_info_get' method.Aug 29 2022, 2:08 PM
Germano Cavalcante (mano-wii) edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Sep 1 2022, 11:14 AM