Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-04-27 13:34:57 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-04-27 13:36:56 +0300
commitcdd4354c81f6f9ae3bc72b7abd5dbcfd74fa548e (patch)
tree065b357e7c98673201a8f4d3e9fc2fcc75db31e1 /source/blender/gpu/intern/gpu_texture_private.hh
parent68ca12a7fc0eea117103d894609eb46c169ec88b (diff)
Metal: MTLTexture core implementation for Metal backend, with minimal surrounding functionality.
This covers implementation of the GPUTexture abstraction for the Metal backend, with additional utility functionality as required. Some components have been temporarily disabled pending dependencies on upcoming Metal backend components, and these will be addressed as the backend is fleshed out. One core challenge addressed in the Metal backend is the requirement for read/update routines for textures. MTLBlitCommandEncoders offer a limited range of the full functionality provided by OpenGLs texture update and read functions such that a series of compute kernels have been implemented to provide advanced functionality such as data format conversion and partial/swizzled component updates. This diff is provided in full, but if further division is required for purposes of code review, this can be done. Authored by Apple: Michael Parkin-White Ref T96261 Reviewed By: fclem Maniphest Tasks: T96261 Differential Revision: https://developer.blender.org/D14543
Diffstat (limited to 'source/blender/gpu/intern/gpu_texture_private.hh')
-rw-r--r--source/blender/gpu/intern/gpu_texture_private.hh67
1 files changed, 66 insertions, 1 deletions
diff --git a/source/blender/gpu/intern/gpu_texture_private.hh b/source/blender/gpu/intern/gpu_texture_private.hh
index 109e60e19a6..00bcc9fac00 100644
--- a/source/blender/gpu/intern/gpu_texture_private.hh
+++ b/source/blender/gpu/intern/gpu_texture_private.hh
@@ -131,7 +131,6 @@ class Texture {
/* TODO(fclem): Legacy. Should be removed at some point. */
virtual uint gl_bindcode_get() const = 0;
-
int width_get() const
{
return w_;
@@ -458,6 +457,72 @@ inline bool validate_data_format(eGPUTextureFormat tex_format, eGPUDataFormat da
}
}
+/* Ensure valid upload formats. With format conversion support, certain types can be extended to
+ * allow upload from differing source formats. If these cases are added, amend accordingly. */
+inline bool validate_data_format_mtl(eGPUTextureFormat tex_format, eGPUDataFormat data_format)
+{
+ switch (tex_format) {
+ case GPU_DEPTH_COMPONENT24:
+ case GPU_DEPTH_COMPONENT16:
+ case GPU_DEPTH_COMPONENT32F:
+ return ELEM(data_format, GPU_DATA_FLOAT, GPU_DATA_UINT);
+ case GPU_DEPTH24_STENCIL8:
+ case GPU_DEPTH32F_STENCIL8:
+ /* Data can be provided as a 4-byte UINT. */
+ return ELEM(data_format, GPU_DATA_UINT_24_8, GPU_DATA_UINT);
+ case GPU_R8UI:
+ case GPU_R16UI:
+ case GPU_RG16UI:
+ case GPU_R32UI:
+ case GPU_RGBA32UI:
+ case GPU_RGBA16UI:
+ case GPU_RG8UI:
+ case GPU_RG32UI:
+ return data_format == GPU_DATA_UINT;
+ case GPU_R32I:
+ case GPU_RG16I:
+ case GPU_R16I:
+ case GPU_RGBA8I:
+ case GPU_RGBA32I:
+ case GPU_RGBA16I:
+ case GPU_RG8I:
+ case GPU_RG32I:
+ case GPU_R8I:
+ return data_format == GPU_DATA_INT;
+ case GPU_R8:
+ case GPU_RG8:
+ case GPU_RGBA8:
+ case GPU_RGBA8_DXT1:
+ case GPU_RGBA8_DXT3:
+ case GPU_RGBA8_DXT5:
+ case GPU_RGBA8UI:
+ case GPU_SRGB8_A8:
+ case GPU_SRGB8_A8_DXT1:
+ case GPU_SRGB8_A8_DXT3:
+ case GPU_SRGB8_A8_DXT5:
+ return ELEM(data_format, GPU_DATA_UBYTE, GPU_DATA_FLOAT);
+ case GPU_RGB10_A2:
+ return ELEM(data_format, GPU_DATA_2_10_10_10_REV, GPU_DATA_FLOAT);
+ case GPU_R11F_G11F_B10F:
+ return ELEM(data_format, GPU_DATA_10_11_11_REV, GPU_DATA_FLOAT);
+ case GPU_RGBA16F:
+ return ELEM(data_format, GPU_DATA_HALF_FLOAT, GPU_DATA_FLOAT);
+ case GPU_RGBA32F:
+ case GPU_RGBA16:
+ case GPU_RG32F:
+ case GPU_RG16F:
+ case GPU_RG16:
+ case GPU_R32F:
+ case GPU_R16F:
+ case GPU_R16:
+ case GPU_RGB16F:
+ return data_format == GPU_DATA_FLOAT;
+ default:
+ BLI_assert_msg(0, "Unrecognized data format");
+ return data_format == GPU_DATA_FLOAT;
+ }
+}
+
inline eGPUDataFormat to_data_format(eGPUTextureFormat tex_format)
{
switch (tex_format) {