GPU: cleanup texture view usage flags

Texture usage flag `GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW`
was originally implemented and used too conservatively for many
cases in which the underlying API flags were not required.

Renaming to `GPU_TEXTURE_USAGE_FORMAT_VIEW` to reflect
the only essential use case for when a texture view is initialized with
a different texture format to the source texture. Texture views can
still be created without this flag when mip range or base level is
adjusted,

This flag is still required by stencil views and internally by the Metal
backend for certain feature support such as SRGB render toggling.

Patch also includes some small changes to the Metal backend to
adapt to this new compatibility and correctly capture all texture view
use-cases.

Related to #115269

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/115300
This commit is contained in:
Jason Fielder 2023-11-24 15:21:00 +01:00 committed by Clément Foucault
parent e14c9552c3
commit 18f7d158fe
21 changed files with 72 additions and 95 deletions

View File

@ -86,8 +86,7 @@ int EEVEE_bloom_init(EEVEE_ViewLayerData * /*sldata*/, EEVEE_Data *vedata)
effects->downsamp_texel_size[i][1] = 1.0f / float(texsize[1]);
eGPUTextureUsage downsample_usage = GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
GPU_TEXTURE_USAGE_ATTACHMENT;
effects->bloom_downsample[i] = DRW_texture_pool_query_2d_ex(
texsize[0], texsize[1], GPU_R11F_G11F_B10F, downsample_usage, &draw_engine_eevee_type);
GPU_framebuffer_ensure_config(
@ -105,8 +104,7 @@ int EEVEE_bloom_init(EEVEE_ViewLayerData * /*sldata*/, EEVEE_Data *vedata)
texsize[1] = std::max(texsize[1], 2);
eGPUTextureUsage upsample_usage = GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
GPU_TEXTURE_USAGE_ATTACHMENT;
effects->bloom_upsample[i] = DRW_texture_pool_query_2d_ex(
texsize[0], texsize[1], GPU_R11F_G11F_B10F, upsample_usage, &draw_engine_eevee_type);

View File

@ -578,8 +578,7 @@ static void dof_reduce_pass_init(EEVEE_FramebufferList *fbl,
DRW_shgroup_call_procedural_triangles(grp, nullptr, 1);
void *owner = (void *)&EEVEE_depth_of_field_init;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
fx->dof_downsample_tx = DRW_texture_pool_query_2d_ex(
UNPACK2(quater_res), COLOR_FORMAT, usage, static_cast<DrawEngineType *>(owner));
@ -643,8 +642,7 @@ static void dof_reduce_pass_init(EEVEE_FramebufferList *fbl,
if (txl->dof_reduced_color == nullptr) {
/* Color needs to be signed format here. See note in shader for explanation. */
/* Do not use texture pool because of needs mipmaps. */
eGPUTextureUsage tex_flags = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage tex_flags = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
txl->dof_reduced_color = GPU_texture_create_2d(
"dof_reduced_color", UNPACK2(res), mip_count, GPU_RGBA16F, tex_flags, nullptr);
txl->dof_reduced_coc = GPU_texture_create_2d(

View File

@ -120,8 +120,7 @@ void EEVEE_effects_init(EEVEE_ViewLayerData *sldata,
});
}
else {
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ;
DRW_texture_ensure_2d_ex(&txl->maxzbuffer,
UNPACK2(effects->hiz_size),
GPU_DEPTH_COMPONENT24,
@ -153,8 +152,7 @@ void EEVEE_effects_init(EEVEE_ViewLayerData *sldata,
* Used for SSReflections & SSRefractions.
*/
if ((effects->enabled_effects & EFFECT_RADIANCE_BUFFER) != 0) {
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ;
DRW_texture_ensure_2d_ex(&txl->filtered_radiance,
UNPACK2(effects->hiz_size),
GPU_R11F_G11F_B10F,

View File

@ -686,8 +686,7 @@ static void eevee_lightbake_count_probes(EEVEE_LightBake *lbake)
static void eevee_lightbake_create_render_target(EEVEE_LightBake *lbake, int rt_res)
{
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
lbake->rt_depth = DRW_texture_create_cube_ex(
rt_res, GPU_DEPTH_COMPONENT24, usage, DRWTextureFlag(0), nullptr);
lbake->rt_color = DRW_texture_create_cube_ex(

View File

@ -103,8 +103,7 @@ static void planar_pool_ensure_alloc(EEVEE_Data *vedata, int num_planar_ref)
/* We need an Array texture so allocate it ourself */
if (!txl->planar_pool) {
eGPUTextureUsage planar_usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage planar_usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ;
eGPUTextureUsage planar_usage_depth = GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_SHADER_READ;
if (num_planar_ref > 0) {
@ -203,8 +202,7 @@ void EEVEE_lightprobes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
/* Placeholder planar pool: used when rendering planar reflections (avoid dependency loop). */
if (!e_data.planar_pool_placeholder) {
eGPUTextureUsage planar_usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage planar_usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ;
e_data.planar_pool_placeholder = DRW_texture_create_2d_array_ex(
1, 1, 1, GPU_RGBA8, planar_usage, DRW_TEX_FILTER, nullptr);
}

View File

@ -168,7 +168,7 @@ void DepthOfField::sync()
* the reduced buffers. Color needs to be signed format here. See note in shader for
* explanation. Do not use texture pool because of needs mipmaps. */
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW | GPU_TEXTURE_USAGE_SHADER_WRITE;
GPU_TEXTURE_USAGE_SHADER_WRITE;
reduced_color_tx_.ensure_2d(GPU_RGBA16F, reduce_size, usage, nullptr, DOF_MIP_COUNT);
reduced_coc_tx_.ensure_2d(GPU_R16F, reduce_size, usage, nullptr, DOF_MIP_COUNT);
reduced_color_tx_.ensure_mip_views();

View File

@ -22,8 +22,7 @@ void HiZBuffer::sync()
int2 hiz_extent = math::ceil_to_multiple(render_extent, int2(1u << (HIZ_MIP_COUNT - 1)));
int2 dispatch_size = math::divide_ceil(hiz_extent, int2(HIZ_GROUP_SIZE));
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_SHADER_WRITE |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_SHADER_WRITE;
hiz_tx_.ensure_2d(GPU_R32F, hiz_extent, usage, nullptr, HIZ_MIP_COUNT);
hiz_tx_.ensure_mip_views();
GPU_texture_mipmap_mode(hiz_tx_, true, false);

View File

@ -269,7 +269,7 @@ void IrradianceCache::set_view(View & /*view*/)
draw::Texture irradiance_d_tx = {"irradiance_d_tx"};
draw::Texture validity_tx = {"validity_tx"};
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ;
int3 grid_size = int3(cache->size);
if (cache->baking.L0) {
irradiance_a_tx.ensure_3d(GPU_RGBA16F, grid_size, usage, (float *)cache->baking.L0);

View File

@ -69,7 +69,7 @@ void RenderBuffers::acquire(int2 extent)
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
/* Depth and combined are always needed. */
depth_tx.ensure_2d(GPU_DEPTH24_STENCIL8, extent, usage | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW);
depth_tx.ensure_2d(GPU_DEPTH24_STENCIL8, extent, usage | GPU_TEXTURE_USAGE_FORMAT_VIEW);
/* TODO(fclem): depth_tx should ideally be a texture from pool but we need stencil_view
* which is currently unsupported by pool textures. */
// depth_tx.acquire(extent, GPU_DEPTH24_STENCIL8);
@ -80,9 +80,7 @@ void RenderBuffers::acquire(int2 extent)
GPU_TEXTURE_USAGE_SHADER_WRITE;
/* TODO(fclem): Make vector pass allocation optional if no TAA or motion blur is needed. */
vector_tx.acquire(extent,
vector_tx_format(),
usage_attachment_read_write | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW);
vector_tx.acquire(extent, vector_tx_format(), usage_attachment_read_write);
int color_len = data.color_len + data.aovs.color_len;
int value_len = data.value_len + data.aovs.value_len;

View File

@ -124,7 +124,7 @@ void DofPass::init(const SceneState &scene_state)
int2 half_res = scene_state.resolution / 2;
half_res = {max_ii(half_res.x, 1), max_ii(half_res.y, 1)};
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ;
source_tx_.ensure_2d(GPU_RGBA16F, half_res, usage, nullptr, 3);
source_tx_.ensure_mip_views();
source_tx_.filter_mode(true);

View File

@ -199,7 +199,7 @@ void OpaquePass::draw(Manager &manager,
resolution,
GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW);
GPU_TEXTURE_USAGE_FORMAT_VIEW);
GPU_texture_copy(shadow_depth_stencil_tx, resources.depth_tx);
clear_fb.ensure(GPU_ATTACHMENT_TEXTURE(shadow_depth_stencil_tx));

View File

@ -312,8 +312,7 @@ static DRWVolumeGrid *volume_grid_cache_get(const Volume *volume,
UNPACK3(dense_grid.resolution),
1,
format,
GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
GPU_TEXTURE_USAGE_SHADER_READ,
dense_grid.voxels);
/* The texture can be null if the resolution along one axis is larger than
* GL_MAX_3D_TEXTURE_SIZE. */

View File

@ -179,12 +179,8 @@ static GPUTexture *create_volume_texture(const int dim[3],
}
while (true) {
tex = GPU_texture_create_3d("volume",
UNPACK3(final_dim),
1,
texture_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
nullptr);
tex = GPU_texture_create_3d(
"volume", UNPACK3(final_dim), 1, texture_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
if (tex != nullptr) {
break;

View File

@ -345,8 +345,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
if (!target->overlay_texture) {
eGPUTextureFormat format = col ? GPU_RGBA8 : GPU_R8;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
target->overlay_texture = GPU_texture_create_2d(
"paint_cursor_overlay", size, size, 1, format, usage, nullptr);
GPU_texture_update(target->overlay_texture, GPU_DATA_UBYTE, buffer);
@ -465,8 +464,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
BLI_task_parallel_range(0, size, &data, load_tex_cursor_task_cb, &settings);
if (!cursor_snap.overlay_texture) {
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
cursor_snap.overlay_texture = GPU_texture_create_2d(
"cursor_snap_overaly", size, size, 1, GPU_R8, usage, nullptr);
GPU_texture_update(cursor_snap.overlay_texture, GPU_DATA_UBYTE, buffer);

View File

@ -539,10 +539,9 @@ typedef enum eGPUTextureUsage {
GPU_TEXTURE_USAGE_SHADER_WRITE = (1 << 1),
/* Whether a texture is used as an attachment in a frame-buffer. */
GPU_TEXTURE_USAGE_ATTACHMENT = (1 << 2),
/* Whether the texture is used as a texture view, uses mip-map layer adjustment,
* OR, uses swizzle access masks. Mip-map base layer adjustment and texture channel swizzling
* requires a texture view under-the-hood. */
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW = (1 << 3),
/* Whether a texture is used to create a texture view utilising a different texture format to the
* source textures format. This includes the use of stencil views. */
GPU_TEXTURE_USAGE_FORMAT_VIEW = (1 << 3),
/* Whether the texture needs to be read from by the CPU. */
GPU_TEXTURE_USAGE_HOST_READ = (1 << 4),
/* When used, the texture will not have any backing storage and can solely exist as a virtual

View File

@ -469,9 +469,13 @@ GPUTexture *GPU_texture_create_view(const char *name,
{
BLI_assert(mip_len > 0);
BLI_assert(layer_len > 0);
BLI_assert_msg(
GPU_texture_usage(src) & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
"Source texture of TextureView must have GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW usage flag.");
BLI_assert_msg(use_stencil == false || (GPU_texture_usage(src) & GPU_TEXTURE_USAGE_FORMAT_VIEW),
"Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
"flag if view texture uses stencil texturing.");
BLI_assert_msg((format == GPU_texture_format(src)) ||
(GPU_texture_usage(src) & GPU_TEXTURE_USAGE_FORMAT_VIEW),
"Source texture of TextureView must have GPU_TEXTURE_USAGE_FORMAT_VIEW usage "
"flag if view texture format is different.");
Texture *view = GPUBackend::get()->texture_alloc(name);
view->init_view(src,
format,

View File

@ -168,7 +168,7 @@ static void gpu_viewport_textures_create(GPUViewport *viewport)
1,
GPU_DEPTH24_STENCIL8,
usage | GPU_TEXTURE_USAGE_HOST_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
GPU_TEXTURE_USAGE_FORMAT_VIEW,
nullptr);
if (GPU_clear_viewport_workaround()) {
static int depth_clear = 0;

View File

@ -620,7 +620,7 @@ inline MTLTextureUsage mtl_usage_from_gpu(eGPUTextureUsage usage)
if (usage & GPU_TEXTURE_USAGE_ATTACHMENT) {
mtl_usage = mtl_usage | MTLTextureUsageRenderTarget;
}
if (usage & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW) {
if (usage & GPU_TEXTURE_USAGE_FORMAT_VIEW) {
mtl_usage = mtl_usage | MTLTextureUsagePixelFormatView;
}
#if defined(MAC_OS_VERSION_14_0)
@ -650,7 +650,7 @@ inline eGPUTextureUsage gpu_usage_from_mtl(MTLTextureUsage mtl_usage)
usage = usage | GPU_TEXTURE_USAGE_ATTACHMENT;
}
if (mtl_usage & MTLTextureUsagePixelFormatView) {
usage = usage | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
usage = usage | GPU_TEXTURE_USAGE_FORMAT_VIEW;
}
return usage;
}

View File

@ -131,29 +131,38 @@ void gpu::MTLTexture::bake_mip_swizzle_view()
}
}
/* Ensure we have texture view usage flagged. */
BLI_assert(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW);
/* if a texture view was previously created we release it. */
if (mip_swizzle_view_ != nil) {
[mip_swizzle_view_ release];
mip_swizzle_view_ = nil;
}
/* Use source texture to determine range limits. If we are using a GPU texture view, the range
* check should only validate the range */
const gpu::Texture *tex_view_src = this;
if (resource_mode_ == MTL_TEXTURE_MODE_TEXTURE_VIEW) {
tex_view_src = unwrap(source_texture_);
}
/* Determine num slices */
int max_slices = 1;
int num_slices = 1;
switch (type_) {
case GPU_TEXTURE_1D_ARRAY:
max_slices = tex_view_src->height_get();
num_slices = h_;
break;
case GPU_TEXTURE_2D_ARRAY:
max_slices = tex_view_src->depth_get();
num_slices = d_;
break;
case GPU_TEXTURE_CUBE:
max_slices = 6;
num_slices = 6;
break;
case GPU_TEXTURE_CUBE_ARRAY:
/* d_ is equal to array levels * 6, including face count. */
max_slices = tex_view_src->depth_get();
num_slices = d_;
break;
default:
@ -163,7 +172,7 @@ void gpu::MTLTexture::bake_mip_swizzle_view()
/* Determine texture view format. If texture view is used as a stencil view, we instead provide
* the equivalent format for performing stencil reads/samples. */
MTLPixelFormat texture_view_pixel_format = texture_.pixelFormat;
MTLPixelFormat texture_view_pixel_format = gpu_texture_format_to_metal(format_);
if (texture_view_stencil_) {
switch (texture_view_pixel_format) {
case MTLPixelFormatDepth24Unorm_Stencil8:
@ -182,11 +191,21 @@ void gpu::MTLTexture::bake_mip_swizzle_view()
* via modifying this textures type flags. */
MTLTextureType texture_view_texture_type = to_metal_type(type_);
/* Ensure we have texture view usage flagged.
* NOTE: This check exists in high level GPU API, however does not cover internal Metal backend
* uses of texture views such as when required to support SRGB enablement toggle during
* rendering. */
BLI_assert_msg(
(texture_view_pixel_format == texture_.pixelFormat) ||
(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_FORMAT_VIEW),
"Usage Flag GPU_TEXTURE_USAGE_FORMAT_VIEW must be specified if a texture view is "
"created with a different format to its source texture.");
int range_len = min_ii((mip_texture_max_level_ - mip_texture_base_level_) + 1,
(int)texture_.mipmapLevelCount - mip_texture_base_level_);
BLI_assert(range_len > 0);
BLI_assert(mip_texture_base_level_ < texture_.mipmapLevelCount);
BLI_assert(mip_texture_base_layer_ < num_slices);
BLI_assert(mip_texture_base_layer_ < max_slices);
mip_swizzle_view_ = [texture_
newTextureViewWithPixelFormat:texture_view_pixel_format
textureType:texture_view_texture_type
@ -672,7 +691,7 @@ void gpu::MTLTexture::update_sub(
* format is unwritable, if our texture has not been initialized with
* texture view support, use a staging texture. */
if ((compatible_write_format != destination_format) &&
!(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW))
!(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_FORMAT_VIEW))
{
use_staging_texture = true;
}
@ -688,7 +707,7 @@ void gpu::MTLTexture::update_sub(
use_staging_texture = true;
}
if (compatible_write_format != destination_format) {
if (!(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW)) {
if (!(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_FORMAT_VIEW)) {
use_staging_texture = true;
}
}
@ -713,7 +732,7 @@ void gpu::MTLTexture::update_sub(
else {
/* Use texture view. */
if (compatible_write_format != destination_format) {
BLI_assert(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW);
BLI_assert(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_FORMAT_VIEW);
texture_handle = [texture_ newTextureViewWithPixelFormat:compatible_write_format];
}
else {
@ -1440,8 +1459,6 @@ void gpu::MTLTexture::swizzle_set(const char swizzle_mask[4])
swizzle_to_mtl(swizzle_mask[2]),
swizzle_to_mtl(swizzle_mask[3]));
BLI_assert_msg(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
"Texture view support is required to change swizzle parameters.");
mtl_swizzle_mask_ = new_swizzle_mask;
texture_view_dirty_flags_ |= TEXTURE_VIEW_SWIZZLE_DIRTY;
}
@ -1645,7 +1662,7 @@ void gpu::MTLTexture::read_internal(int mip,
/* Texture View for SRGB special case. */
id<MTLTexture> read_texture = texture_;
if (format_ == GPU_SRGB8_A8) {
BLI_assert(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW);
BLI_assert(gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_FORMAT_VIEW);
read_texture = [texture_ newTextureViewWithPixelFormat:MTLPixelFormatRGBA8Unorm];
}
@ -2098,9 +2115,6 @@ bool gpu::MTLTexture::init_internal(GPUTexture *src,
/* Assign usage. */
gpu_image_usage_flags_ = GPU_texture_usage(src);
BLI_assert_msg(
gpu_image_usage_flags_ & GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
"Source texture of TextureView must have GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW usage flag.");
/* Assign texture as view. */
gpu::MTLTexture *mtltex = static_cast<gpu::MTLTexture *>(unwrap(src));
@ -2187,7 +2201,7 @@ void gpu::MTLTexture::ensure_baked()
* disabled. Enabling the texture_view or texture_read usage flags disables lossless
* compression, so the situations in which it is used should be limited. */
if (format_ == GPU_SRGB8_A8) {
gpu_image_usage_flags_ = gpu_image_usage_flags_ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW;
gpu_image_usage_flags_ = gpu_image_usage_flags_ | GPU_TEXTURE_USAGE_FORMAT_VIEW;
}
/* Create texture descriptor. */

View File

@ -269,24 +269,12 @@ GPUTexture *IMB_touch_gpu_texture(const char *name,
GPUTexture *tex;
if (layers > 0) {
tex = GPU_texture_create_2d_array(name,
w,
h,
layers,
9999,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
nullptr);
tex = GPU_texture_create_2d_array(
name, w, h, layers, 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
}
else {
tex = GPU_texture_create_2d(name,
w,
h,
9999,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
nullptr);
tex = GPU_texture_create_2d(
name, w, h, 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
}
GPU_texture_swizzle_set(tex, imb_gpu_get_swizzle(ibuf));
@ -379,21 +367,13 @@ GPUTexture *IMB_create_gpu_texture(const char *name,
bool freebuf = false;
/* Create Texture. */
tex = GPU_texture_create_2d(name,
UNPACK2(size),
9999,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
nullptr);
tex = GPU_texture_create_2d(
name, UNPACK2(size), 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
if (tex == nullptr) {
size[0] = max_ii(1, size[0] / 2);
size[1] = max_ii(1, size[1] / 2);
tex = GPU_texture_create_2d(name,
UNPACK2(size),
9999,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
nullptr);
tex = GPU_texture_create_2d(
name, UNPACK2(size), 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
do_rescale = true;
}
BLI_assert(tex != nullptr);

View File

@ -2384,8 +2384,7 @@ static void radial_control_set_tex(RadialControl *rc)
ibuf->y,
1,
GPU_R8,
GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
GPU_TEXTURE_USAGE_SHADER_READ,
ibuf->float_buffer.data);
GPU_texture_filter_mode(rc->texture, true);