Refactor: GPU: Use Depth32F

Blender uses depth24 for legacy reasons. All backends that we support
have support for depth32f.

This PR updates all usages of depth24 with depth32f.

- depth24 are not supported on AMD/Intel/Vulkan and Metal. There depth32f
  was already used to work around this limitation.
- This allows us to implement reverse depth in workbench, overlay and
grease pencil in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/140531
This commit is contained in:
Jeroen Bakker
2025-06-19 13:30:50 +02:00
parent 0e737b23c5
commit a5e30aaa9e
12 changed files with 19 additions and 19 deletions

View File

@@ -65,7 +65,7 @@ void Instance::init()
if (!dummy_depth.is_valid()) {
const float pixels[1] = {1.0f};
dummy_depth.ensure_2d(
GPU_DEPTH_COMPONENT24, int2(1), GPU_TEXTURE_USAGE_SHADER_READ, &pixels[0]);
GPU_DEPTH_COMPONENT32F, int2(1), GPU_TEXTURE_USAGE_SHADER_READ, &pixels[0]);
}
/* Resize and reset memory-blocks. */
@@ -230,7 +230,7 @@ void Instance::begin_sync()
const float2 size = draw_ctx->viewport_size_get();
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT;
this->snapshot_depth_tx.ensure_2d(GPU_DEPTH24_STENCIL8, int2(size), usage);
this->snapshot_depth_tx.ensure_2d(GPU_DEPTH32F_STENCIL8, int2(size), usage);
this->snapshot_color_tx.ensure_2d(GPU_R11F_G11F_B10F, int2(size), usage);
this->snapshot_reveal_tx.ensure_2d(GPU_R11F_G11F_B10F, int2(size), usage);
@@ -624,7 +624,7 @@ void Instance::acquire_resources()
eGPUTextureFormat format = this->use_signed_fb ? GPU_RGBA16F : GPU_R11F_G11F_B10F;
this->depth_tx.acquire(size, GPU_DEPTH24_STENCIL8);
this->depth_tx.acquire(size, GPU_DEPTH32F_STENCIL8);
this->color_tx.acquire(size, format);
this->reveal_tx.acquire(size, format);
@@ -654,7 +654,7 @@ void Instance::acquire_resources()
/* Use high quality format for render. */
eGPUTextureFormat mask_format = this->is_render ? GPU_R16 : GPU_R8;
/* We need an extra depth to not disturb the normal drawing. */
this->mask_depth_tx.acquire(size, GPU_DEPTH24_STENCIL8);
this->mask_depth_tx.acquire(size, GPU_DEPTH32F_STENCIL8);
/* The mask_color_tx is needed for frame-buffer completeness. */
this->mask_color_tx.acquire(size, GPU_R8);
this->mask_tx.acquire(size, mask_format);

View File

@@ -110,7 +110,7 @@ static void render_init_buffers(const DRWContext *draw_ctx,
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT |
GPU_TEXTURE_USAGE_HOST_READ;
inst.render_depth_tx.ensure_2d(
GPU_DEPTH_COMPONENT24, int2(size), usage, do_region ? nullptr : pix_z);
GPU_DEPTH_COMPONENT32F, int2(size), usage, do_region ? nullptr : pix_z);
}
if (inst.render_color_tx.is_valid() && !do_clear_col) {
GPU_texture_update(inst.render_color_tx, GPU_DATA_FLOAT, pix_col);

View File

@@ -682,7 +682,7 @@ void Instance::end_sync()
size.x,
size.y,
1,
GPU_DEPTH24_STENCIL8,
GPU_DEPTH32F_STENCIL8,
GPU_TEXTURE_USAGE_GENERAL,
nullptr);
}

View File

@@ -239,7 +239,7 @@ class Outline : Overlay {
int2 render_size = int2(res.depth_tx.size());
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
tmp_depth_tx_.acquire(render_size, GPU_DEPTH24_STENCIL8, usage);
tmp_depth_tx_.acquire(render_size, GPU_DEPTH32F_STENCIL8, usage);
object_id_tx_.acquire(render_size, GPU_R16UI, usage);
prepass_fb_.ensure(GPU_ATTACHMENT_TEXTURE(tmp_depth_tx_),

View File

@@ -775,16 +775,16 @@ struct Resources : public select::SelectMap {
if (state.xray_enabled) {
/* For X-ray we render the scene to a separate depth buffer. */
this->xray_depth_tx.acquire(render_size, GPU_DEPTH24_STENCIL8);
this->xray_depth_tx.acquire(render_size, GPU_DEPTH32F_STENCIL8);
this->depth_target_tx.wrap(this->xray_depth_tx);
/* TODO(fclem): Remove mandatory allocation. */
this->xray_depth_in_front_tx.acquire(render_size, GPU_DEPTH24_STENCIL8);
this->xray_depth_in_front_tx.acquire(render_size, GPU_DEPTH32F_STENCIL8);
this->depth_target_in_front_tx.wrap(this->xray_depth_in_front_tx);
}
else {
/* TODO(fclem): Remove mandatory allocation. */
if (!this->depth_in_front_tx.is_valid()) {
this->depth_in_front_alloc_tx.acquire(render_size, GPU_DEPTH24_STENCIL8);
this->depth_in_front_alloc_tx.acquire(render_size, GPU_DEPTH32F_STENCIL8);
this->depth_in_front_tx.wrap(this->depth_in_front_alloc_tx);
}
this->depth_target_tx.wrap(this->depth_tx);

View File

@@ -260,7 +260,7 @@ class Wireframe : Overlay {
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
int2 render_size = int2(depth_tx.size());
tmp_depth_tx_.acquire(render_size, GPU_DEPTH24_STENCIL8, usage);
tmp_depth_tx_.acquire(render_size, GPU_DEPTH32F_STENCIL8, usage);
/* WORKAROUND: Nasty framebuffer copy.
* We should find a way to have nice wireframe without this. */

View File

@@ -149,7 +149,7 @@ void AntiAliasingPass::sync(const SceneState &scene_state, SceneResources &resou
taa_accumulation_tx_.ensure_2d(GPU_RGBA16F,
scene_state.resolution,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT);
sample0_depth_tx_.ensure_2d(GPU_DEPTH24_STENCIL8,
sample0_depth_tx_.ensure_2d(GPU_DEPTH32F_STENCIL8,
scene_state.resolution,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT);
@@ -260,7 +260,7 @@ void AntiAliasingPass::draw(const DRWContext *draw_ctx,
GPU_texture_copy(sample0_depth_tx_, resources.depth_tx);
if (resources.depth_in_front_tx.is_valid()) {
sample0_depth_in_front_tx_.ensure_2d(
GPU_DEPTH24_STENCIL8, scene_state.resolution, GPU_TEXTURE_USAGE_ATTACHMENT);
GPU_DEPTH32F_STENCIL8, scene_state.resolution, GPU_TEXTURE_USAGE_ATTACHMENT);
GPU_texture_copy(sample0_depth_in_front_tx_, resources.depth_in_front_tx);
}
else {

View File

@@ -589,9 +589,9 @@ static bool workbench_render_framebuffers_init(const DRWContext *draw_ctx)
dtxl->color = GPU_texture_create_2d(
"txl.color", size.x, size.y, 1, GPU_RGBA16F, usage, nullptr);
dtxl->depth = GPU_texture_create_2d(
"txl.depth", size.x, size.y, 1, GPU_DEPTH24_STENCIL8, usage, nullptr);
"txl.depth", size.x, size.y, 1, GPU_DEPTH32F_STENCIL8, usage, nullptr);
dtxl->depth_in_front = GPU_texture_create_2d(
"txl.depth_in_front", size.x, size.y, 1, GPU_DEPTH24_STENCIL8, usage, nullptr);
"txl.depth_in_front", size.x, size.y, 1, GPU_DEPTH32F_STENCIL8, usage, nullptr);
}
if (!(dtxl->depth && dtxl->color && dtxl->depth_in_front)) {

View File

@@ -186,7 +186,7 @@ void OpaquePass::draw(Manager &manager,
}
if (shadow_pass) {
shadow_depth_stencil_tx.ensure_2d(GPU_DEPTH24_STENCIL8,
shadow_depth_stencil_tx.ensure_2d(GPU_DEPTH32F_STENCIL8,
resolution,
GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_ATTACHMENT |

View File

@@ -1624,7 +1624,7 @@ static void draw_select_framebuffer_depth_only_setup(const int size[2])
if (g_select_buffer.texture_depth == nullptr) {
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_ATTACHMENT;
g_select_buffer.texture_depth = GPU_texture_create_2d(
"select_depth", size[0], size[1], 1, GPU_DEPTH_COMPONENT24, usage, nullptr);
"select_depth", size[0], size[1], 1, GPU_DEPTH_COMPONENT32F, usage, nullptr);
GPU_framebuffer_texture_attach(
g_select_buffer.framebuffer_depth_only, g_select_buffer.texture_depth, 0, 0);

View File

@@ -749,7 +749,7 @@ GPUOffScreen *GPU_offscreen_create(int width,
/* Format view flag is needed by Workbench Volumes to read the stencil view. */
eGPUTextureUsage depth_usage = usage | GPU_TEXTURE_USAGE_FORMAT_VIEW;
ofs->depth = GPU_texture_create_2d(
"ofs_depth", width, height, 1, GPU_DEPTH24_STENCIL8, depth_usage, nullptr);
"ofs_depth", width, height, 1, GPU_DEPTH32F_STENCIL8, depth_usage, nullptr);
}
if ((with_depth_buffer && !ofs->depth) || !ofs->color) {

View File

@@ -167,7 +167,7 @@ static void gpu_viewport_textures_create(GPUViewport *viewport)
viewport->depth_tx = GPU_texture_create_2d("dtxl_depth",
UNPACK2(size),
1,
GPU_DEPTH24_STENCIL8,
GPU_DEPTH32F_STENCIL8,
usage | GPU_TEXTURE_USAGE_HOST_READ |
GPU_TEXTURE_USAGE_FORMAT_VIEW,
nullptr);