Refactor: GPU: Texture: Replace eGPUTextureFormat by TextureFormat
This offers better semantic and safety of the API. Part of #130632 Pull Request: https://projects.blender.org/blender/blender/pulls/142818
This commit is contained in:
committed by
Clément Foucault
parent
144696f7ee
commit
32d64d35bb
@@ -563,7 +563,8 @@ static PyObject *pygpu_framebuffer_read_color(BPyGPUFrameBuffer *self,
|
||||
PYGPU_FRAMEBUFFER_CHECK_OBJ(self);
|
||||
int x, y, w, h, channels;
|
||||
uint slot;
|
||||
PyC_StringEnum pygpu_dataformat = {bpygpu_dataformat_items, GPU_RGBA8};
|
||||
PyC_StringEnum pygpu_dataformat = {bpygpu_dataformat_items,
|
||||
int(blender::gpu::TextureFormat::UNORM_8_8_8_8)};
|
||||
BPyGPUBuffer *py_buffer = nullptr;
|
||||
|
||||
static const char *_keywords[] = {
|
||||
|
||||
@@ -48,10 +48,10 @@
|
||||
* \{ */
|
||||
|
||||
static const PyC_StringEnumItems pygpu_framebuffer_color_texture_formats[] = {
|
||||
{GPU_RGBA8, "RGBA8"},
|
||||
{GPU_RGBA16, "RGBA16"},
|
||||
{GPU_RGBA16F, "RGBA16F"},
|
||||
{GPU_RGBA32F, "RGBA32F"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_8_8_8_8), "RGBA8"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_16_16_16_16), "RGBA16"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_16_16_16_16), "RGBA16F"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_32_32_32_32), "RGBA32F"},
|
||||
{0, nullptr},
|
||||
};
|
||||
|
||||
@@ -284,7 +284,8 @@ static PyObject *pygpu_offscreen__tp_new(PyTypeObject * /*self*/, PyObject *args
|
||||
|
||||
GPUOffScreen *ofs = nullptr;
|
||||
int width, height;
|
||||
PyC_StringEnum pygpu_textureformat = {pygpu_framebuffer_color_texture_formats, GPU_RGBA8};
|
||||
PyC_StringEnum pygpu_textureformat = {pygpu_framebuffer_color_texture_formats,
|
||||
int(blender::gpu::TextureFormat::UNORM_8_8_8_8)};
|
||||
char err_out[256];
|
||||
|
||||
static const char *_keywords[] = {"width", "height", "format", nullptr};
|
||||
@@ -308,7 +309,7 @@ static PyObject *pygpu_offscreen__tp_new(PyTypeObject * /*self*/, PyObject *args
|
||||
ofs = GPU_offscreen_create(width,
|
||||
height,
|
||||
true,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_HOST_READ,
|
||||
false,
|
||||
err_out);
|
||||
|
||||
@@ -792,12 +792,12 @@ static PyObject *pygpu_shader_info_image(BPyGPUShaderCreateInfo *self,
|
||||
}
|
||||
|
||||
if (pygpu_texformat.value_found == GPU_DEPTH24_STENCIL8_DEPRECATED) {
|
||||
pygpu_texformat.value_found = GPU_DEPTH32F_STENCIL8;
|
||||
pygpu_texformat.value_found = int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8);
|
||||
PyErr_WarnEx(
|
||||
PyExc_DeprecationWarning, "'DEPTH24_STENCIL8' is deprecated. Use 'DEPTH32F_STENCIL8'.", 1);
|
||||
}
|
||||
if (pygpu_texformat.value_found == GPU_DEPTH_COMPONENT24_DEPRECATED) {
|
||||
pygpu_texformat.value_found = GPU_DEPTH_COMPONENT32F;
|
||||
pygpu_texformat.value_found = int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH);
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"'DEPTH_COMPONENT24' is deprecated. Use 'DEPTH_COMPONENT32F'.",
|
||||
1);
|
||||
@@ -809,7 +809,7 @@ static PyObject *pygpu_shader_info_image(BPyGPUShaderCreateInfo *self,
|
||||
|
||||
ShaderCreateInfo *info = reinterpret_cast<ShaderCreateInfo *>(self->info);
|
||||
info->image(slot,
|
||||
(eGPUTextureFormat)pygpu_texformat.value_found,
|
||||
(blender::gpu::TextureFormat)pygpu_texformat.value_found,
|
||||
qualifier,
|
||||
blender::gpu::shader::ImageReadWriteType(pygpu_imagetype.value_found),
|
||||
name);
|
||||
|
||||
@@ -36,50 +36,50 @@
|
||||
* \{ */
|
||||
|
||||
const PyC_StringEnumItems pygpu_textureformat_items[] = {
|
||||
{GPU_RGBA8UI, "RGBA8UI"},
|
||||
{GPU_RGBA8I, "RGBA8I"},
|
||||
{GPU_RGBA8, "RGBA8"},
|
||||
{GPU_RGBA32UI, "RGBA32UI"},
|
||||
{GPU_RGBA32I, "RGBA32I"},
|
||||
{GPU_RGBA32F, "RGBA32F"},
|
||||
{GPU_RGBA16UI, "RGBA16UI"},
|
||||
{GPU_RGBA16I, "RGBA16I"},
|
||||
{GPU_RGBA16F, "RGBA16F"},
|
||||
{GPU_RGBA16, "RGBA16"},
|
||||
{GPU_RG8UI, "RG8UI"},
|
||||
{GPU_RG8I, "RG8I"},
|
||||
{GPU_RG8, "RG8"},
|
||||
{GPU_RG32UI, "RG32UI"},
|
||||
{GPU_RG32I, "RG32I"},
|
||||
{GPU_RG32F, "RG32F"},
|
||||
{GPU_RG16UI, "RG16UI"},
|
||||
{GPU_RG16I, "RG16I"},
|
||||
{GPU_RG16F, "RG16F"},
|
||||
{GPU_RG16, "RG16"},
|
||||
{GPU_R8UI, "R8UI"},
|
||||
{GPU_R8I, "R8I"},
|
||||
{GPU_R8, "R8"},
|
||||
{GPU_R32UI, "R32UI"},
|
||||
{GPU_R32I, "R32I"},
|
||||
{GPU_R32F, "R32F"},
|
||||
{GPU_R16UI, "R16UI"},
|
||||
{GPU_R16I, "R16I"},
|
||||
{GPU_R16F, "R16F"},
|
||||
{GPU_R16, "R16"},
|
||||
{GPU_R11F_G11F_B10F, "R11F_G11F_B10F"},
|
||||
{GPU_DEPTH32F_STENCIL8, "DEPTH32F_STENCIL8"},
|
||||
{int(blender::gpu::TextureFormat::UINT_8_8_8_8), "RGBA8UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_8_8_8_8), "RGBA8I"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_8_8_8_8), "RGBA8"},
|
||||
{int(blender::gpu::TextureFormat::UINT_32_32_32_32), "RGBA32UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_32_32_32_32), "RGBA32I"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_32_32_32_32), "RGBA32F"},
|
||||
{int(blender::gpu::TextureFormat::UINT_16_16_16_16), "RGBA16UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_16_16_16_16), "RGBA16I"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_16_16_16_16), "RGBA16F"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_16_16_16_16), "RGBA16"},
|
||||
{int(blender::gpu::TextureFormat::UINT_8_8), "RG8UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_8_8), "RG8I"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_8_8), "RG8"},
|
||||
{int(blender::gpu::TextureFormat::UINT_32_32), "RG32UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_32_32), "RG32I"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_32_32), "RG32F"},
|
||||
{int(blender::gpu::TextureFormat::UINT_16_16), "RG16UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_16_16), "RG16I"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_16_16), "RG16F"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_16_16), "RG16"},
|
||||
{int(blender::gpu::TextureFormat::UINT_8), "R8UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_8), "R8I"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_8), "R8"},
|
||||
{int(blender::gpu::TextureFormat::UINT_32), "R32UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_32), "R32I"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_32), "R32F"},
|
||||
{int(blender::gpu::TextureFormat::UINT_16), "R16UI"},
|
||||
{int(blender::gpu::TextureFormat::SINT_16), "R16I"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_16), "R16F"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_16), "R16"},
|
||||
{int(blender::gpu::TextureFormat::UFLOAT_11_11_10), "R11F_G11F_B10F"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8), "DEPTH32F_STENCIL8"},
|
||||
{GPU_DEPTH24_STENCIL8_DEPRECATED, "DEPTH24_STENCIL8"},
|
||||
{GPU_SRGB8_A8, "SRGB8_A8"},
|
||||
{GPU_RGB16F, "RGB16F"},
|
||||
{GPU_SRGB8_A8_DXT1, "SRGB8_A8_DXT1"},
|
||||
{GPU_SRGB8_A8_DXT3, "SRGB8_A8_DXT3"},
|
||||
{GPU_SRGB8_A8_DXT5, "SRGB8_A8_DXT5"},
|
||||
{GPU_RGBA8_DXT1, "RGBA8_DXT1"},
|
||||
{GPU_RGBA8_DXT3, "RGBA8_DXT3"},
|
||||
{GPU_RGBA8_DXT5, "RGBA8_DXT5"},
|
||||
{GPU_DEPTH_COMPONENT32F, "DEPTH_COMPONENT32F"},
|
||||
{int(blender::gpu::TextureFormat::SRGBA_8_8_8_8), "SRGB8_A8"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_16_16_16), "RGB16F"},
|
||||
{int(blender::gpu::TextureFormat::SRGB_DXT1), "SRGB8_A8_DXT1"},
|
||||
{int(blender::gpu::TextureFormat::SRGB_DXT3), "SRGB8_A8_DXT3"},
|
||||
{int(blender::gpu::TextureFormat::SRGB_DXT5), "SRGB8_A8_DXT5"},
|
||||
{int(blender::gpu::TextureFormat::SNORM_DXT1), "RGBA8_DXT1"},
|
||||
{int(blender::gpu::TextureFormat::SNORM_DXT3), "RGBA8_DXT3"},
|
||||
{int(blender::gpu::TextureFormat::SNORM_DXT5), "RGBA8_DXT5"},
|
||||
{int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH), "DEPTH_COMPONENT32F"},
|
||||
{GPU_DEPTH_COMPONENT24_DEPRECATED, "DEPTH_COMPONENT24"},
|
||||
{GPU_DEPTH_COMPONENT16, "DEPTH_COMPONENT16"},
|
||||
{int(blender::gpu::TextureFormat::UNORM_16_DEPTH), "DEPTH_COMPONENT16"},
|
||||
{0, nullptr},
|
||||
};
|
||||
|
||||
@@ -121,7 +121,8 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
|
||||
int size[3] = {1, 1, 1};
|
||||
int layers = 0;
|
||||
int is_cubemap = false;
|
||||
PyC_StringEnum pygpu_textureformat = {pygpu_textureformat_items, GPU_RGBA8};
|
||||
PyC_StringEnum pygpu_textureformat = {pygpu_textureformat_items,
|
||||
int(blender::gpu::TextureFormat::UNORM_8_8_8_8)};
|
||||
BPyGPUBuffer *pybuffer_obj = nullptr;
|
||||
char err_out[256] = "unknown error. See console";
|
||||
|
||||
@@ -153,12 +154,12 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
|
||||
}
|
||||
|
||||
if (pygpu_textureformat.value_found == GPU_DEPTH24_STENCIL8_DEPRECATED) {
|
||||
pygpu_textureformat.value_found = GPU_DEPTH32F_STENCIL8;
|
||||
pygpu_textureformat.value_found = int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8);
|
||||
PyErr_WarnEx(
|
||||
PyExc_DeprecationWarning, "'DEPTH24_STENCIL8' is deprecated. Use 'DEPTH32F_STENCIL8'.", 1);
|
||||
}
|
||||
if (pygpu_textureformat.value_found == GPU_DEPTH_COMPONENT24_DEPRECATED) {
|
||||
pygpu_textureformat.value_found = GPU_DEPTH_COMPONENT32F;
|
||||
pygpu_textureformat.value_found = int(blender::gpu::TextureFormat::SFLOAT_32_DEPTH);
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"'DEPTH_COMPONENT24' is deprecated. Use 'DEPTH_COMPONENT32F'.",
|
||||
1);
|
||||
@@ -200,7 +201,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
|
||||
}
|
||||
|
||||
int component_len = GPU_texture_component_len(
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found));
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found));
|
||||
int component_size_expected = sizeof(float);
|
||||
size_t data_space_expected = size_t(size[0]) * size[1] * size[2] * max_ii(1, layers) *
|
||||
component_len * component_size_expected;
|
||||
@@ -235,42 +236,45 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
|
||||
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL;
|
||||
if (is_cubemap) {
|
||||
if (layers) {
|
||||
tex = GPU_texture_create_cube_array(name,
|
||||
size[0],
|
||||
layers,
|
||||
1,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
tex = GPU_texture_create_cube_array(
|
||||
name,
|
||||
size[0],
|
||||
layers,
|
||||
1,
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
}
|
||||
else {
|
||||
tex = GPU_texture_create_cube(name,
|
||||
size[0],
|
||||
1,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
}
|
||||
}
|
||||
else if (layers) {
|
||||
if (len == 2) {
|
||||
tex = GPU_texture_create_2d_array(name,
|
||||
size[0],
|
||||
size[1],
|
||||
layers,
|
||||
1,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
tex = GPU_texture_create_2d_array(
|
||||
name,
|
||||
size[0],
|
||||
size[1],
|
||||
layers,
|
||||
1,
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
}
|
||||
else {
|
||||
tex = GPU_texture_create_1d_array(name,
|
||||
size[0],
|
||||
layers,
|
||||
1,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
tex = GPU_texture_create_1d_array(
|
||||
name,
|
||||
size[0],
|
||||
layers,
|
||||
1,
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
}
|
||||
}
|
||||
else if (len == 3) {
|
||||
@@ -279,7 +283,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
|
||||
size[1],
|
||||
size[2],
|
||||
1,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
data);
|
||||
}
|
||||
@@ -288,7 +292,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
|
||||
size[0],
|
||||
size[1],
|
||||
1,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
}
|
||||
@@ -296,7 +300,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args,
|
||||
tex = GPU_texture_create_1d(name,
|
||||
size[0],
|
||||
1,
|
||||
eGPUTextureFormat(pygpu_textureformat.value_found),
|
||||
blender::gpu::TextureFormat(pygpu_textureformat.value_found),
|
||||
usage,
|
||||
static_cast<const float *>(data));
|
||||
}
|
||||
@@ -343,8 +347,9 @@ PyDoc_STRVAR(
|
||||
static PyObject *pygpu_texture_format_get(BPyGPUTexture *self, void * /*type*/)
|
||||
{
|
||||
BPYGPU_TEXTURE_CHECK_OBJ(self);
|
||||
eGPUTextureFormat format = GPU_texture_format(self->tex);
|
||||
return PyUnicode_FromString(PyC_StringEnum_FindIDFromValue(pygpu_textureformat_items, format));
|
||||
blender::gpu::TextureFormat format = GPU_texture_format(self->tex);
|
||||
return PyUnicode_FromString(
|
||||
PyC_StringEnum_FindIDFromValue(pygpu_textureformat_items, int(format)));
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(
|
||||
@@ -443,35 +448,35 @@ PyDoc_STRVAR(
|
||||
static PyObject *pygpu_texture_read(BPyGPUTexture *self)
|
||||
{
|
||||
BPYGPU_TEXTURE_CHECK_OBJ(self);
|
||||
eGPUTextureFormat tex_format = GPU_texture_format(self->tex);
|
||||
blender::gpu::TextureFormat tex_format = GPU_texture_format(self->tex);
|
||||
|
||||
/* #GPU_texture_read is restricted in combining 'data_format' with 'tex_format'.
|
||||
* So choose data_format here. */
|
||||
eGPUDataFormat best_data_format;
|
||||
switch (tex_format) {
|
||||
case GPU_DEPTH_COMPONENT16:
|
||||
case GPU_DEPTH_COMPONENT32F:
|
||||
case GPU_DEPTH32F_STENCIL8:
|
||||
case blender::gpu::TextureFormat::UNORM_16_DEPTH:
|
||||
case blender::gpu::TextureFormat::SFLOAT_32_DEPTH:
|
||||
case blender::gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8:
|
||||
best_data_format = GPU_DATA_FLOAT;
|
||||
break;
|
||||
case GPU_R8UI:
|
||||
case GPU_R16UI:
|
||||
case GPU_RG16UI:
|
||||
case GPU_R32UI:
|
||||
case blender::gpu::TextureFormat::UINT_8:
|
||||
case blender::gpu::TextureFormat::UINT_16:
|
||||
case blender::gpu::TextureFormat::UINT_16_16:
|
||||
case blender::gpu::TextureFormat::UINT_32:
|
||||
best_data_format = GPU_DATA_UINT;
|
||||
break;
|
||||
case GPU_RG16I:
|
||||
case GPU_R16I:
|
||||
case blender::gpu::TextureFormat::SINT_16_16:
|
||||
case blender::gpu::TextureFormat::SINT_16:
|
||||
best_data_format = GPU_DATA_INT;
|
||||
break;
|
||||
case GPU_R8:
|
||||
case GPU_RG8:
|
||||
case GPU_RGBA8:
|
||||
case GPU_RGBA8UI:
|
||||
case GPU_SRGB8_A8:
|
||||
case blender::gpu::TextureFormat::UNORM_8:
|
||||
case blender::gpu::TextureFormat::UNORM_8_8:
|
||||
case blender::gpu::TextureFormat::UNORM_8_8_8_8:
|
||||
case blender::gpu::TextureFormat::UINT_8_8_8_8:
|
||||
case blender::gpu::TextureFormat::SRGBA_8_8_8_8:
|
||||
best_data_format = GPU_DATA_UBYTE;
|
||||
break;
|
||||
case GPU_R11F_G11F_B10F:
|
||||
case blender::gpu::TextureFormat::UFLOAT_11_11_10:
|
||||
best_data_format = GPU_DATA_10_11_11_REV;
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user