# SDL: Fix mip generation for 2x1 textures on D3D12

**URL:** <https://discourse.libsdl.org/t/sdl-fix-mip-generation-for-2x1-textures-on-d3d12/56598>\
**Category:** SDL Commits\
**Created:** [January 13, 2025, 8:34pm UTC](https://discourse.libsdl.org/t/sdl-fix-mip-generation-for-2x1-textures-on-d3d12/56598 "2025-01-13T20:34:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [January 13, 2025, 8:34pm UTC](https://discourse.libsdl.org/t/sdl-fix-mip-generation-for-2x1-textures-on-d3d12/56598/1 "2025-01-13T20:34:21Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/67ea67f191450cedf99b5b0ae70c1a5c72335e20>

```diff
From 67ea67f191450cedf99b5b0ae70c1a5c72335e20 Mon Sep 17 00:00:00 2001
From: Katelyn Gadd <[EMAIL REDACTED]>
Date: Wed, 1 Jan 2025 23:21:37 -0800
Subject: [PATCH] Fix mip generation for 2x1 textures on D3D12

---
 src/gpu/d3d12/SDL_gpu_d3d12.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c
index c064d33d5d1c3..d073b88f196fd 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -6222,16 +6222,16 @@ static void D3D12_GenerateMipmaps(
             blitInfo.source.layer_or_depth_plane = layerOrDepthIndex;
             blitInfo.source.x = 0;
             blitInfo.source.y = 0;
- blitInfo.source.w = container->header.info.width >> (levelIndex - 1);
- blitInfo.source.h = container->header.info.height >> (levelIndex - 1);
+ blitInfo.source.w = SDL_max(container->header.info.width >> (levelIndex - 1), 1);
+ blitInfo.source.h = SDL_max(container->header.info.height >> (levelIndex - 1), 1);
 
             blitInfo.destination.texture = texture;
             blitInfo.destination.mip_level = levelIndex;
             blitInfo.destination.layer_or_depth_plane = layerOrDepthIndex;
             blitInfo.destination.x = 0;
             blitInfo.destination.y = 0;
- blitInfo.destination.w = container->header.info.width >> levelIndex;
- blitInfo.destination.h = container->header.info.height >> levelIndex;
+ blitInfo.destination.w = SDL_max(container->header.info.width >> levelIndex, 1);
+ blitInfo.destination.h = SDL_max(container->header.info.height >> levelIndex, 1);
 
             blitInfo.load_op = SDL_GPU_LOADOP_DONT_CARE;
             blitInfo.filter = SDL_GPU_FILTER_LINEAR;

```
