GPU: Python: Temporarily add back non-4bytes aligned formats

Add back the deprecated format to avoid asserts.
GPU backends should still have the code to support them.

Also add deprecation warnings as these types will be
removed for 5.0.

Pull Request: https://projects.blender.org/blender/blender/pulls/139213
This commit is contained in:
Clément Foucault
2025-05-22 12:14:52 +02:00
committed by Clément Foucault
parent 980624cc91
commit 57d9c2c098
3 changed files with 94 additions and 0 deletions

View File

@@ -73,6 +73,35 @@ enum class VertAttrType : uint8_t {
/* UFLOAT_9_9_9_EXP_5_(impl) Available on Metal (and maybe VK) but not on GL. */
GPU_VERTEX_FORMAT_EXPAND(DECLARE)
#undef DECLARE
#define DECLARE(a, b, c, blender_enum, d, e, f, g, h) \
blender_enum##_DEPRECATED = int(DataFormat::blender_enum),
/* Deprecated formats. To be removed in 5.0. Needed for python shaders. */
#define GPU_VERTEX_DEPRECATED_FORMAT_EXPAND(impl) \
SNORM_8_(impl) \
SNORM_8_8_(impl) \
SNORM_8_8_8_(impl) \
SNORM_16_(impl) \
SNORM_16_16_16_(impl) \
UNORM_8_(impl) \
UNORM_8_8_(impl) \
UNORM_8_8_8_(impl) \
UNORM_16_(impl) \
UNORM_16_16_16_(impl) \
SINT_8_(impl) \
SINT_8_8_(impl) \
SINT_8_8_8_(impl) \
SINT_16_(impl) \
SINT_16_16_16_(impl) \
UINT_8_(impl) \
UINT_8_8_(impl) \
UINT_8_8_8_(impl) \
UINT_16_(impl) \
UINT_16_16_16_(impl)
GPU_VERTEX_DEPRECATED_FORMAT_EXPAND(DECLARE)
#undef DECLARE
};

View File

@@ -42,12 +42,24 @@ static VertAttrType vertex_format_combine(GPUVertCompType component_type,
switch (fetch_mode) {
case GPU_FETCH_INT_TO_FLOAT_UNIT:
switch (component_len) {
case 1:
return VertAttrType::SNORM_8_DEPRECATED;
case 2:
return VertAttrType::SNORM_8_8_DEPRECATED;
case 3:
return VertAttrType::SNORM_8_8_8_DEPRECATED;
case 4:
return VertAttrType::SNORM_8_8_8_8;
}
break;
case GPU_FETCH_INT:
switch (component_len) {
case 1:
return VertAttrType::SINT_8_DEPRECATED;
case 2:
return VertAttrType::SINT_8_8_DEPRECATED;
case 3:
return VertAttrType::SINT_8_8_8_DEPRECATED;
case 4:
return VertAttrType::SINT_8_8_8_8;
}
@@ -61,12 +73,24 @@ static VertAttrType vertex_format_combine(GPUVertCompType component_type,
switch (fetch_mode) {
case GPU_FETCH_INT_TO_FLOAT_UNIT:
switch (component_len) {
case 1:
return VertAttrType::UNORM_8_DEPRECATED;
case 2:
return VertAttrType::UNORM_8_8_DEPRECATED;
case 3:
return VertAttrType::UNORM_8_8_8_DEPRECATED;
case 4:
return VertAttrType::UNORM_8_8_8_8;
}
break;
case GPU_FETCH_INT:
switch (component_len) {
case 1:
return VertAttrType::UINT_8_DEPRECATED;
case 2:
return VertAttrType::UINT_8_8_DEPRECATED;
case 3:
return VertAttrType::UINT_8_8_8_DEPRECATED;
case 4:
return VertAttrType::UINT_8_8_8_8;
}
@@ -80,16 +104,24 @@ static VertAttrType vertex_format_combine(GPUVertCompType component_type,
switch (fetch_mode) {
case GPU_FETCH_INT_TO_FLOAT_UNIT:
switch (component_len) {
case 1:
return VertAttrType::SNORM_16_DEPRECATED;
case 2:
return VertAttrType::SNORM_16_16;
case 3:
return VertAttrType::SNORM_16_16_16_DEPRECATED;
case 4:
return VertAttrType::SNORM_16_16_16_16;
}
break;
case GPU_FETCH_INT:
switch (component_len) {
case 1:
return VertAttrType::SINT_16_DEPRECATED;
case 2:
return VertAttrType::SINT_16_16;
case 3:
return VertAttrType::SINT_16_16_16_DEPRECATED;
case 4:
return VertAttrType::SINT_16_16_16_16;
}
@@ -103,16 +135,24 @@ static VertAttrType vertex_format_combine(GPUVertCompType component_type,
switch (fetch_mode) {
case GPU_FETCH_INT_TO_FLOAT_UNIT:
switch (component_len) {
case 1:
return VertAttrType::UNORM_16_DEPRECATED;
case 2:
return VertAttrType::UNORM_16_16;
case 3:
return VertAttrType::UNORM_16_16_16_DEPRECATED;
case 4:
return VertAttrType::UNORM_16_16_16_16;
}
break;
case GPU_FETCH_INT:
switch (component_len) {
case 1:
return VertAttrType::UINT_16_DEPRECATED;
case 2:
return VertAttrType::UINT_16_16;
case 3:
return VertAttrType::UINT_16_16_16_DEPRECATED;
case 4:
return VertAttrType::UINT_16_16_16_16;
}

View File

@@ -63,6 +63,16 @@ static PyObject *pygpu_vertformat__tp_new(PyTypeObject * /*type*/, PyObject *arg
return BPyGPUVertFormat_CreatePyObject(nullptr);
}
static uint attr_size(GPUVertCompType type, int len)
{
if (type == GPU_COMP_I10) {
return 4; /* Always packed as 10_10_10_2. */
}
BLI_assert(type <= GPU_COMP_F32); /* Other types have irregular sizes (not bytes). */
const uint sizes[] = {1, 1, 2, 2, 4, 4, 4};
return len * sizes[type];
}
PyDoc_STRVAR(
/* Wrap. */
pygpu_vertformat_attr_add_doc,
@@ -124,6 +134,21 @@ static PyObject *pygpu_vertformat_attr_add(BPyGPUVertFormat *self, PyObject *arg
GPUVertCompType comp_type_enum = GPUVertCompType(comp_type.value_found);
GPUVertFetchMode fetch_mode_enum = GPUVertFetchMode(fetch_mode.value_found);
if (len > 4) {
PyErr_WarnEx(
PyExc_DeprecationWarning,
"Using GPUVertFormat.attr_add(...) with component count greater than 4 is deprecated. "
"Use several attributes for each matrix columns instead.",
1);
}
if (attr_size(comp_type_enum, len) % 4 != 0) {
PyErr_WarnEx(PyExc_DeprecationWarning,
"Using GPUVertFormat.attr_add(...) with a format that is not 4 bytes aligned is "
"deprecated. Add padding components and/or higher precision integers.",
1);
}
bool int_to_float = (int(fetch_mode_enum) == int(GPU_FETCH_INT_TO_FLOAT_DEPRECATED));
/* Fetch int to float is not supported anymore.
* Simply store the data as float in the vertex buffer and convert inside `attr_fill`. */