|
@@ -438,9 +438,6 @@ typedef struct D3D11TextureSubresource
|
|
|
|
|
|
ID3D11UnorderedAccessView *uav; // NULL if not a storage texture
|
|
|
ID3D11DepthStencilView *depthStencilTargetView; // NULL if not a depth stencil target
|
|
|
-
|
|
|
- ID3D11Resource *msaaHandle; // NULL if not using MSAA
|
|
|
- ID3D11RenderTargetView *msaaTargetView; // NULL if not an MSAA color target
|
|
|
} D3D11TextureSubresource;
|
|
|
|
|
|
struct D3D11Texture
|
|
@@ -637,12 +634,8 @@ typedef struct D3D11CommandBuffer
|
|
|
D3D11GraphicsPipeline *graphicsPipeline;
|
|
|
Uint8 stencilRef;
|
|
|
SDL_FColor blendConstants;
|
|
|
-
|
|
|
- // Render Pass MSAA resolve
|
|
|
- D3D11Texture *colorTargetResolveTexture[MAX_COLOR_TARGET_BINDINGS];
|
|
|
- Uint32 colorTargetResolveSubresourceIndex[MAX_COLOR_TARGET_BINDINGS];
|
|
|
- ID3D11Resource *colorTargetMsaaHandle[MAX_COLOR_TARGET_BINDINGS];
|
|
|
- DXGI_FORMAT colorTargetMsaaFormat[MAX_COLOR_TARGET_BINDINGS];
|
|
|
+ D3D11TextureSubresource *colorTargetSubresources[MAX_COLOR_TARGET_BINDINGS];
|
|
|
+ D3D11TextureSubresource *colorResolveSubresources[MAX_COLOR_TARGET_BINDINGS];
|
|
|
|
|
|
// Compute Pass
|
|
|
D3D11ComputePipeline *computePipeline;
|
|
@@ -1090,14 +1083,6 @@ static void D3D11_INTERNAL_DestroyTexture(D3D11Texture *d3d11Texture)
|
|
|
}
|
|
|
|
|
|
for (Uint32 subresourceIndex = 0; subresourceIndex < d3d11Texture->subresourceCount; subresourceIndex += 1) {
|
|
|
- if (d3d11Texture->subresources[subresourceIndex].msaaHandle != NULL) {
|
|
|
- ID3D11Resource_Release(d3d11Texture->subresources[subresourceIndex].msaaHandle);
|
|
|
- }
|
|
|
-
|
|
|
- if (d3d11Texture->subresources[subresourceIndex].msaaTargetView != NULL) {
|
|
|
- ID3D11RenderTargetView_Release(d3d11Texture->subresources[subresourceIndex].msaaTargetView);
|
|
|
- }
|
|
|
-
|
|
|
if (d3d11Texture->subresources[subresourceIndex].colorTargetViews != NULL) {
|
|
|
for (Uint32 depthIndex = 0; depthIndex < d3d11Texture->subresources[subresourceIndex].depth; depthIndex += 1) {
|
|
|
ID3D11RenderTargetView_Release(d3d11Texture->subresources[subresourceIndex].colorTargetViews[depthIndex]);
|
|
@@ -1933,8 +1918,8 @@ static D3D11Texture *D3D11_INTERNAL_CreateTexture(
|
|
|
desc2D.Format = format;
|
|
|
desc2D.MipLevels = createInfo->num_levels;
|
|
|
desc2D.MiscFlags = 0;
|
|
|
- desc2D.SampleDesc.Count = 1;
|
|
|
- desc2D.SampleDesc.Quality = 0;
|
|
|
+ desc2D.SampleDesc.Count = SDLToD3D11_SampleCount[createInfo->sample_count];
|
|
|
+ desc2D.SampleDesc.Quality = isMultisample ? D3D11_STANDARD_MULTISAMPLE_PATTERN : 0;
|
|
|
desc2D.Usage = isStaging ? D3D11_USAGE_STAGING : D3D11_USAGE_DEFAULT;
|
|
|
|
|
|
if (createInfo->type == SDL_GPU_TEXTURETYPE_CUBE || createInfo->type == SDL_GPU_TEXTURETYPE_CUBE_ARRAY) {
|
|
@@ -2067,54 +2052,10 @@ static D3D11Texture *D3D11_INTERNAL_CreateTexture(
|
|
|
d3d11Texture->subresources[subresourceIndex].colorTargetViews = NULL;
|
|
|
d3d11Texture->subresources[subresourceIndex].uav = NULL;
|
|
|
d3d11Texture->subresources[subresourceIndex].depthStencilTargetView = NULL;
|
|
|
- d3d11Texture->subresources[subresourceIndex].msaaHandle = NULL;
|
|
|
- d3d11Texture->subresources[subresourceIndex].msaaTargetView = NULL;
|
|
|
-
|
|
|
- if (isMultisample) {
|
|
|
- D3D11_TEXTURE2D_DESC desc2D;
|
|
|
-
|
|
|
- if (isColorTarget) {
|
|
|
- desc2D.BindFlags = D3D11_BIND_RENDER_TARGET;
|
|
|
- } else if (isDepthStencil) {
|
|
|
- desc2D.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
|
|
- }
|
|
|
-
|
|
|
- desc2D.Width = createInfo->width;
|
|
|
- desc2D.Height = createInfo->height;
|
|
|
- desc2D.ArraySize = 1;
|
|
|
- desc2D.CPUAccessFlags = 0;
|
|
|
- desc2D.Format = format;
|
|
|
- desc2D.MipLevels = 1;
|
|
|
- desc2D.MiscFlags = 0;
|
|
|
- desc2D.SampleDesc.Count = SDLToD3D11_SampleCount[createInfo->sample_count];
|
|
|
- desc2D.SampleDesc.Quality = (UINT)D3D11_STANDARD_MULTISAMPLE_PATTERN;
|
|
|
- desc2D.Usage = D3D11_USAGE_DEFAULT;
|
|
|
-
|
|
|
- res = ID3D11Device_CreateTexture2D(
|
|
|
- renderer->device,
|
|
|
- &desc2D,
|
|
|
- NULL,
|
|
|
- (ID3D11Texture2D **)&d3d11Texture->subresources[subresourceIndex].msaaHandle);
|
|
|
- ERROR_CHECK_RETURN("Could not create MSAA texture!", NULL);
|
|
|
-
|
|
|
- if (!isDepthStencil) {
|
|
|
- D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
|
|
-
|
|
|
- rtvDesc.Format = format;
|
|
|
- rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
|
|
|
-
|
|
|
- res = ID3D11Device_CreateRenderTargetView(
|
|
|
- renderer->device,
|
|
|
- d3d11Texture->subresources[subresourceIndex].msaaHandle,
|
|
|
- &rtvDesc,
|
|
|
- &d3d11Texture->subresources[subresourceIndex].msaaTargetView);
|
|
|
- ERROR_CHECK_RETURN("Could not create MSAA RTV!", NULL);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
if (isDepthStencil) {
|
|
|
- D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
|
|
|
|
|
|
+ D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
|
|
|
dsvDesc.Format = SDLToD3D11_TextureFormat[createInfo->format];
|
|
|
dsvDesc.Flags = 0;
|
|
|
|
|
@@ -2127,31 +2068,42 @@ static D3D11Texture *D3D11_INTERNAL_CreateTexture(
|
|
|
|
|
|
res = ID3D11Device_CreateDepthStencilView(
|
|
|
renderer->device,
|
|
|
- isMultisample ? d3d11Texture->subresources[subresourceIndex].msaaHandle : d3d11Texture->handle,
|
|
|
+ d3d11Texture->handle,
|
|
|
&dsvDesc,
|
|
|
&d3d11Texture->subresources[subresourceIndex].depthStencilTargetView);
|
|
|
ERROR_CHECK_RETURN("Could not create DSV!", NULL);
|
|
|
+
|
|
|
} else if (isColorTarget) {
|
|
|
+
|
|
|
d3d11Texture->subresources[subresourceIndex].colorTargetViews = SDL_calloc(depth, sizeof(ID3D11RenderTargetView *));
|
|
|
|
|
|
for (Uint32 depthIndex = 0; depthIndex < depth; depthIndex += 1) {
|
|
|
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
|
|
-
|
|
|
rtvDesc.Format = SDLToD3D11_TextureFormat[createInfo->format];
|
|
|
|
|
|
- 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_TEXTURE2DARRAY;
|
|
|
- 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;
|
|
|
+ if (isMultisample) {
|
|
|
+ if (createInfo->type == SDL_GPU_TEXTURETYPE_2D) {
|
|
|
+ rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
|
|
|
+ } else if (createInfo->type == SDL_GPU_TEXTURETYPE_2D_ARRAY) {
|
|
|
+ rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
|
|
|
+ rtvDesc.Texture2DMSArray.FirstArraySlice = layerIndex;
|
|
|
+ rtvDesc.Texture2DMSArray.ArraySize = 1;
|
|
|
+ }
|
|
|
} else {
|
|
|
- rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
|
- rtvDesc.Texture2D.MipSlice = levelIndex;
|
|
|
+ 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_TEXTURE2DARRAY;
|
|
|
+ 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(
|
|
@@ -3238,10 +3190,8 @@ static SDL_GPUCommandBuffer *D3D11_AcquireCommandBuffer(
|
|
|
commandBuffer->blendConstants.a = 1.0f;
|
|
|
commandBuffer->computePipeline = NULL;
|
|
|
for (i = 0; i < MAX_COLOR_TARGET_BINDINGS; i += 1) {
|
|
|
- commandBuffer->colorTargetResolveTexture[i] = NULL;
|
|
|
- commandBuffer->colorTargetResolveSubresourceIndex[i] = 0;
|
|
|
- commandBuffer->colorTargetMsaaHandle[i] = NULL;
|
|
|
- commandBuffer->colorTargetMsaaFormat[i] = DXGI_FORMAT_UNKNOWN;
|
|
|
+ commandBuffer->colorTargetSubresources[i] = NULL;
|
|
|
+ commandBuffer->colorResolveSubresources[i] = NULL;
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < MAX_UNIFORM_BUFFERS_PER_STAGE; i += 1) {
|
|
@@ -3507,10 +3457,8 @@ static void D3D11_BeginRenderPass(
|
|
|
|
|
|
// Clear the bound targets for the current command buffer
|
|
|
for (Uint32 i = 0; i < MAX_COLOR_TARGET_BINDINGS; i += 1) {
|
|
|
- d3d11CommandBuffer->colorTargetResolveTexture[i] = NULL;
|
|
|
- d3d11CommandBuffer->colorTargetResolveSubresourceIndex[i] = 0;
|
|
|
- d3d11CommandBuffer->colorTargetMsaaHandle[i] = NULL;
|
|
|
- d3d11CommandBuffer->colorTargetMsaaFormat[i] = DXGI_FORMAT_UNKNOWN;
|
|
|
+ d3d11CommandBuffer->colorTargetSubresources[i] = NULL;
|
|
|
+ d3d11CommandBuffer->colorResolveSubresources[i] = NULL;
|
|
|
}
|
|
|
|
|
|
// Set up the new color target bindings
|
|
@@ -3523,16 +3471,20 @@ static void D3D11_BeginRenderPass(
|
|
|
colorTargetInfos[i].mip_level,
|
|
|
colorTargetInfos[i].cycle);
|
|
|
|
|
|
- if (subresource->msaaHandle != NULL) {
|
|
|
- d3d11CommandBuffer->colorTargetResolveTexture[i] = subresource->parent;
|
|
|
- d3d11CommandBuffer->colorTargetResolveSubresourceIndex[i] = subresource->index;
|
|
|
- d3d11CommandBuffer->colorTargetMsaaHandle[i] = subresource->msaaHandle;
|
|
|
- d3d11CommandBuffer->colorTargetMsaaFormat[i] = SDLToD3D11_TextureFormat[container->header.info.format];
|
|
|
+ Uint32 rtvIndex = container->header.info.type == SDL_GPU_TEXTURETYPE_3D ? colorTargetInfos[i].layer_or_depth_plane : 0;
|
|
|
+ rtvs[i] = subresource->colorTargetViews[rtvIndex];
|
|
|
+ d3d11CommandBuffer->colorTargetSubresources[i] = subresource;
|
|
|
|
|
|
- rtvs[i] = subresource->msaaTargetView;
|
|
|
- } else {
|
|
|
- Uint32 rtvIndex = container->header.info.type == SDL_GPU_TEXTURETYPE_3D ? colorTargetInfos[i].layer_or_depth_plane : 0;
|
|
|
- rtvs[i] = subresource->colorTargetViews[rtvIndex];
|
|
|
+ if (colorTargetInfos[i].store_op == SDL_GPU_STOREOP_RESOLVE || colorTargetInfos[i].store_op == SDL_GPU_STOREOP_RESOLVE_AND_STORE) {
|
|
|
+ D3D11TextureContainer *resolveContainer = (D3D11TextureContainer *)colorTargetInfos[i].resolve_texture;
|
|
|
+ D3D11TextureSubresource *resolveSubresource = D3D11_INTERNAL_PrepareTextureSubresourceForWrite(
|
|
|
+ renderer,
|
|
|
+ resolveContainer,
|
|
|
+ colorTargetInfos[i].resolve_layer,
|
|
|
+ colorTargetInfos[i].resolve_mip_level,
|
|
|
+ colorTargetInfos[i].cycle_resolve_texture);
|
|
|
+
|
|
|
+ d3d11CommandBuffer->colorResolveSubresources[i] = resolveSubresource;
|
|
|
}
|
|
|
|
|
|
if (colorTargetInfos[i].load_op == SDL_GPU_LOADOP_CLEAR) {
|
|
@@ -4220,14 +4172,14 @@ static void D3D11_EndRenderPass(
|
|
|
|
|
|
// Resolve MSAA color render targets
|
|
|
for (i = 0; i < MAX_COLOR_TARGET_BINDINGS; i += 1) {
|
|
|
- if (d3d11CommandBuffer->colorTargetMsaaHandle[i] != NULL) {
|
|
|
+ if (d3d11CommandBuffer->colorResolveSubresources[i] != NULL) {
|
|
|
ID3D11DeviceContext_ResolveSubresource(
|
|
|
d3d11CommandBuffer->context,
|
|
|
- d3d11CommandBuffer->colorTargetResolveTexture[i]->handle,
|
|
|
- d3d11CommandBuffer->colorTargetResolveSubresourceIndex[i],
|
|
|
- d3d11CommandBuffer->colorTargetMsaaHandle[i],
|
|
|
- 0,
|
|
|
- d3d11CommandBuffer->colorTargetMsaaFormat[i]);
|
|
|
+ d3d11CommandBuffer->colorResolveSubresources[i]->parent->handle,
|
|
|
+ d3d11CommandBuffer->colorResolveSubresources[i]->index,
|
|
|
+ d3d11CommandBuffer->colorTargetSubresources[i]->parent->handle,
|
|
|
+ d3d11CommandBuffer->colorTargetSubresources[i]->index,
|
|
|
+ SDLToD3D11_TextureFormat[d3d11CommandBuffer->colorTargetSubresources[i]->parent->container->header.info.format]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -5083,8 +5035,6 @@ static bool D3D11_INTERNAL_InitializeSwapchainTexture(
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // Create container
|
|
|
-
|
|
|
// Fill out the texture struct
|
|
|
pTexture->handle = NULL; // This will be set in AcquireSwapchainTexture.
|
|
|
pTexture->shaderView = NULL; // We don't allow swapchain texture to be sampled
|
|
@@ -5095,8 +5045,6 @@ static bool D3D11_INTERNAL_InitializeSwapchainTexture(
|
|
|
pTexture->subresources[0].colorTargetViews[0] = rtv;
|
|
|
pTexture->subresources[0].uav = NULL;
|
|
|
pTexture->subresources[0].depthStencilTargetView = NULL;
|
|
|
- pTexture->subresources[0].msaaHandle = NULL;
|
|
|
- pTexture->subresources[0].msaaTargetView = NULL;
|
|
|
pTexture->subresources[0].layer = 0;
|
|
|
pTexture->subresources[0].level = 0;
|
|
|
pTexture->subresources[0].depth = 1;
|