mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-12 14:28:14 +00:00
GPU: MSAA fixes (#10917)
This commit is contained in:
@@ -959,6 +959,10 @@ SDL_GPUTexture *SDL_CreateGPUTexture(
|
|||||||
SDL_assert_release(!"For array textures: usage must not contain DEPTH_STENCIL_TARGET");
|
SDL_assert_release(!"For array textures: usage must not contain DEPTH_STENCIL_TARGET");
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
if (createinfo->sample_count > SDL_GPU_SAMPLECOUNT_1) {
|
||||||
|
SDL_assert_release(!"For array textures: sample_count must be SDL_GPU_SAMPLECOUNT_1");
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (createinfo->sample_count > SDL_GPU_SAMPLECOUNT_1 && createinfo->num_levels > 1) {
|
if (createinfo->sample_count > SDL_GPU_SAMPLECOUNT_1 && createinfo->num_levels > 1) {
|
||||||
SDL_assert_release(!"For 2D multisample textures: num_levels must be 1");
|
SDL_assert_release(!"For 2D multisample textures: num_levels must be 1");
|
||||||
@@ -1378,6 +1382,9 @@ SDL_GPURenderPass *SDL_BeginGPURenderPass(
|
|||||||
if (resolveTextureHeader->info.type == SDL_GPU_TEXTURETYPE_3D) {
|
if (resolveTextureHeader->info.type == SDL_GPU_TEXTURETYPE_3D) {
|
||||||
SDL_assert_release(!"Resolve texture must not be of TEXTURETYPE_3D!");
|
SDL_assert_release(!"Resolve texture must not be of TEXTURETYPE_3D!");
|
||||||
}
|
}
|
||||||
|
if (!(resolveTextureHeader->info.usage & SDL_GPU_TEXTUREUSAGE_COLOR_TARGET)) {
|
||||||
|
SDL_assert_release(!"Resolve texture usage must include COLOR_TARGET!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2081,29 +2081,21 @@ static D3D11Texture *D3D11_INTERNAL_CreateTexture(
|
|||||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
||||||
rtvDesc.Format = SDLToD3D11_TextureFormat[createInfo->format];
|
rtvDesc.Format = SDLToD3D11_TextureFormat[createInfo->format];
|
||||||
|
|
||||||
if (isMultisample) {
|
if (createInfo->type == SDL_GPU_TEXTURETYPE_2D_ARRAY || createInfo->type == SDL_GPU_TEXTURETYPE_CUBE || createInfo->type == SDL_GPU_TEXTURETYPE_CUBE_ARRAY) {
|
||||||
if (createInfo->type == SDL_GPU_TEXTURETYPE_2D) {
|
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
|
||||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
|
rtvDesc.Texture2DArray.MipSlice = levelIndex;
|
||||||
} else if (createInfo->type == SDL_GPU_TEXTURETYPE_2D_ARRAY) {
|
rtvDesc.Texture2DArray.FirstArraySlice = layerIndex;
|
||||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
|
rtvDesc.Texture2DArray.ArraySize = 1;
|
||||||
rtvDesc.Texture2DMSArray.FirstArraySlice = layerIndex;
|
} else if (createInfo->type == SDL_GPU_TEXTURETYPE_3D) {
|
||||||
rtvDesc.Texture2DMSArray.ArraySize = 1;
|
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
|
||||||
}
|
rtvDesc.Texture3D.MipSlice = levelIndex;
|
||||||
|
rtvDesc.Texture3D.FirstWSlice = depthIndex;
|
||||||
|
rtvDesc.Texture3D.WSize = 1;
|
||||||
|
} else if (isMultisample) {
|
||||||
|
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
|
||||||
} else {
|
} else {
|
||||||
if (createInfo->type == SDL_GPU_TEXTURETYPE_2D_ARRAY || createInfo->type == SDL_GPU_TEXTURETYPE_CUBE || createInfo->type == SDL_GPU_TEXTURETYPE_CUBE_ARRAY) {
|
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
|
rtvDesc.Texture2D.MipSlice = levelIndex;
|
||||||
rtvDesc.Texture2DArray.MipSlice = levelIndex;
|
|
||||||
rtvDesc.Texture2DArray.FirstArraySlice = layerIndex;
|
|
||||||
rtvDesc.Texture2DArray.ArraySize = 1;
|
|
||||||
} else if (createInfo->type == SDL_GPU_TEXTURETYPE_3D) {
|
|
||||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
|
|
||||||
rtvDesc.Texture3D.MipSlice = levelIndex;
|
|
||||||
rtvDesc.Texture3D.FirstWSlice = depthIndex;
|
|
||||||
rtvDesc.Texture3D.WSize = 1;
|
|
||||||
} else {
|
|
||||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
||||||
rtvDesc.Texture2D.MipSlice = levelIndex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = ID3D11Device_CreateRenderTargetView(
|
res = ID3D11Device_CreateRenderTargetView(
|
||||||
|
@@ -2957,31 +2957,23 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
|
|||||||
|
|
||||||
rtvDesc.Format = SDLToD3D12_TextureFormat[createinfo->format];
|
rtvDesc.Format = SDLToD3D12_TextureFormat[createinfo->format];
|
||||||
|
|
||||||
if (isMultisample) {
|
if (createinfo->type == SDL_GPU_TEXTURETYPE_2D_ARRAY || createinfo->type == SDL_GPU_TEXTURETYPE_CUBE || createinfo->type == SDL_GPU_TEXTURETYPE_CUBE_ARRAY) {
|
||||||
if (createinfo->type == SDL_GPU_TEXTURETYPE_2D) {
|
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY;
|
||||||
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMS;
|
rtvDesc.Texture2DArray.MipSlice = levelIndex;
|
||||||
} else if (createinfo->type == SDL_GPU_TEXTURETYPE_2D_ARRAY) {
|
rtvDesc.Texture2DArray.FirstArraySlice = layerIndex;
|
||||||
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY;
|
rtvDesc.Texture2DArray.ArraySize = 1;
|
||||||
rtvDesc.Texture2DMSArray.FirstArraySlice = layerIndex;
|
rtvDesc.Texture2DArray.PlaneSlice = 0;
|
||||||
rtvDesc.Texture2DMSArray.ArraySize = 1;
|
} else if (createinfo->type == SDL_GPU_TEXTURETYPE_3D) {
|
||||||
}
|
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D;
|
||||||
|
rtvDesc.Texture3D.MipSlice = levelIndex;
|
||||||
|
rtvDesc.Texture3D.FirstWSlice = depthIndex;
|
||||||
|
rtvDesc.Texture3D.WSize = 1;
|
||||||
|
} else if (isMultisample) {
|
||||||
|
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMS;
|
||||||
} else {
|
} else {
|
||||||
if (createinfo->type == SDL_GPU_TEXTURETYPE_2D_ARRAY || createinfo->type == SDL_GPU_TEXTURETYPE_CUBE || createinfo->type == SDL_GPU_TEXTURETYPE_CUBE_ARRAY) {
|
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
|
||||||
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY;
|
rtvDesc.Texture2D.MipSlice = levelIndex;
|
||||||
rtvDesc.Texture2DArray.MipSlice = levelIndex;
|
rtvDesc.Texture2D.PlaneSlice = 0;
|
||||||
rtvDesc.Texture2DArray.FirstArraySlice = layerIndex;
|
|
||||||
rtvDesc.Texture2DArray.ArraySize = 1;
|
|
||||||
rtvDesc.Texture2DArray.PlaneSlice = 0;
|
|
||||||
} else if (createinfo->type == SDL_GPU_TEXTURETYPE_3D) {
|
|
||||||
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D;
|
|
||||||
rtvDesc.Texture3D.MipSlice = levelIndex;
|
|
||||||
rtvDesc.Texture3D.FirstWSlice = depthIndex;
|
|
||||||
rtvDesc.Texture3D.WSize = 1;
|
|
||||||
} else {
|
|
||||||
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
|
|
||||||
rtvDesc.Texture2D.MipSlice = levelIndex;
|
|
||||||
rtvDesc.Texture2D.PlaneSlice = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D12Device_CreateRenderTargetView(
|
ID3D12Device_CreateRenderTargetView(
|
||||||
|
@@ -313,14 +313,6 @@ static NSUInteger SDLToMetal_SampleCount[] = {
|
|||||||
8 // SDL_GPU_SAMPLECOUNT_8
|
8 // SDL_GPU_SAMPLECOUNT_8
|
||||||
};
|
};
|
||||||
|
|
||||||
static MTLTextureType SDLToMetal_TextureType[] = {
|
|
||||||
MTLTextureType2D, // SDL_GPU_TEXTURETYPE_2D
|
|
||||||
MTLTextureType2DArray, // SDL_GPU_TEXTURETYPE_2D_ARRAY
|
|
||||||
MTLTextureType3D, // SDL_GPU_TEXTURETYPE_3D
|
|
||||||
MTLTextureTypeCube, // SDL_GPU_TEXTURETYPE_CUBE
|
|
||||||
MTLTextureTypeCubeArray // SDL_GPU_TEXTURETYPE_CUBE_ARRAY
|
|
||||||
};
|
|
||||||
|
|
||||||
static SDL_GPUTextureFormat SwapchainCompositionToFormat[] = {
|
static SDL_GPUTextureFormat SwapchainCompositionToFormat[] = {
|
||||||
SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM, // SDR
|
SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM, // SDR
|
||||||
SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB, // SDR_LINEAR
|
SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB, // SDR_LINEAR
|
||||||
@@ -330,6 +322,24 @@ static SDL_GPUTextureFormat SwapchainCompositionToFormat[] = {
|
|||||||
|
|
||||||
static CFStringRef SwapchainCompositionToColorSpace[4]; // initialized on device creation
|
static CFStringRef SwapchainCompositionToColorSpace[4]; // initialized on device creation
|
||||||
|
|
||||||
|
static MTLTextureType SDLToMetal_TextureType(SDL_GPUTextureType textureType, bool isMSAA)
|
||||||
|
{
|
||||||
|
switch (textureType) {
|
||||||
|
case SDL_GPU_TEXTURETYPE_2D:
|
||||||
|
return isMSAA ? MTLTextureType2DMultisample : MTLTextureType2D;
|
||||||
|
case SDL_GPU_TEXTURETYPE_2D_ARRAY:
|
||||||
|
return MTLTextureType2DArray;
|
||||||
|
case SDL_GPU_TEXTURETYPE_3D:
|
||||||
|
return MTLTextureType3D;
|
||||||
|
case SDL_GPU_TEXTURETYPE_CUBE:
|
||||||
|
return MTLTextureTypeCube;
|
||||||
|
case SDL_GPU_TEXTURETYPE_CUBE_ARRAY:
|
||||||
|
return MTLTextureTypeCubeArray;
|
||||||
|
default:
|
||||||
|
return MTLTextureType2D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static MTLColorWriteMask SDLToMetal_ColorWriteMask(
|
static MTLColorWriteMask SDLToMetal_ColorWriteMask(
|
||||||
SDL_GPUColorComponentFlags mask)
|
SDL_GPUColorComponentFlags mask)
|
||||||
{
|
{
|
||||||
@@ -1323,7 +1333,7 @@ static MetalTexture *METAL_INTERNAL_CreateTexture(
|
|||||||
id<MTLTexture> texture;
|
id<MTLTexture> texture;
|
||||||
MetalTexture *metalTexture;
|
MetalTexture *metalTexture;
|
||||||
|
|
||||||
textureDescriptor.textureType = SDLToMetal_TextureType[createinfo->type];
|
textureDescriptor.textureType = SDLToMetal_TextureType(createinfo->type, createinfo->sample_count > SDL_GPU_SAMPLECOUNT_1);
|
||||||
textureDescriptor.pixelFormat = SDLToMetal_SurfaceFormat[createinfo->format];
|
textureDescriptor.pixelFormat = SDLToMetal_SurfaceFormat[createinfo->format];
|
||||||
// This format isn't natively supported so let's swizzle!
|
// This format isn't natively supported so let's swizzle!
|
||||||
if (createinfo->format == SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM) {
|
if (createinfo->format == SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM) {
|
||||||
@@ -2965,7 +2975,7 @@ static void METAL_BeginComputePass(
|
|||||||
METAL_INTERNAL_TrackTexture(metalCommandBuffer, texture);
|
METAL_INTERNAL_TrackTexture(metalCommandBuffer, texture);
|
||||||
|
|
||||||
textureView = [texture->handle newTextureViewWithPixelFormat:SDLToMetal_SurfaceFormat[textureContainer->header.info.format]
|
textureView = [texture->handle newTextureViewWithPixelFormat:SDLToMetal_SurfaceFormat[textureContainer->header.info.format]
|
||||||
textureType:SDLToMetal_TextureType[textureContainer->header.info.type]
|
textureType:SDLToMetal_TextureType(textureContainer->header.info.type, false)
|
||||||
levels:NSMakeRange(storageTextureBindings[i].mip_level, 1)
|
levels:NSMakeRange(storageTextureBindings[i].mip_level, 1)
|
||||||
slices:NSMakeRange(storageTextureBindings[i].layer, 1)];
|
slices:NSMakeRange(storageTextureBindings[i].layer, 1)];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user