Skip to content

Commit

Permalink
D3D11: Enable depth clamping.
Browse files Browse the repository at this point in the history
Uses the same logic as Vulkan, improving hrydgard#9545 on most D3D11 devices.
  • Loading branch information
unknownbrackets committed Sep 19, 2018
1 parent 1f881d7 commit b7d8492
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions GPU/D3D11/GPU_D3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void GPU_D3D11::CheckGPUFeatures() {
features |= GPU_SUPPORTS_LARGE_VIEWPORTS;
if (draw_->GetDeviceCaps().dualSourceBlend)
features |= GPU_SUPPORTS_DUALSOURCE_BLEND;
if (draw_->GetDeviceCaps().depthClampSupported)
features |= GPU_SUPPORTS_DEPTH_CLAMP;
features |= GPU_SUPPORTS_ANY_COPY_IMAGE;
features |= GPU_SUPPORTS_TEXTURE_FLOAT;
features |= GPU_SUPPORTS_INSTANCE_RENDERING;
Expand Down
16 changes: 13 additions & 3 deletions GPU/D3D11/StateMappingD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,22 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {

if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) {
keys_.raster.value = 0;
if (gstate.isModeClear()) {
if (gstate.isModeClear() || gstate.isModeThrough()) {
keys_.raster.cullMode = D3D11_CULL_NONE;
// TODO: Might happen in clear mode if not through...
keys_.raster.depthClipEnable = 1;
} else {
// Set cull
bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled();
bool wantCull = prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled();
keys_.raster.cullMode = wantCull ? (gstate.getCullMode() ? D3D11_CULL_FRONT : D3D11_CULL_BACK) : D3D11_CULL_NONE;
if (gstate.getDepthRangeMin() == 0 || gstate.getDepthRangeMax() == 65535) {
// TODO: Still has a bug where we clamp to depth range if one is not the full range.
// But the alternate is not clamping in either direction...
keys_.raster.depthClipEnable = !gstate.isDepthClampEnabled() || !gstate_c.Supports(GPU_SUPPORTS_DEPTH_CLAMP);
} else {
// We just want to clip in this case, the clamp would be clipped anyway.
keys_.raster.depthClipEnable = 1;
}
}
ID3D11RasterizerState *rs = rasterCache_.Get(keys_.raster.value);
if (rs == nullptr) {
Expand All @@ -290,7 +300,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) {
desc.FillMode = D3D11_FILL_SOLID;
desc.ScissorEnable = TRUE;
desc.FrontCounterClockwise = TRUE;
desc.DepthClipEnable = TRUE;
desc.DepthClipEnable = keys_.raster.depthClipEnable;
ASSERT_SUCCESS(device_->CreateRasterizerState(&desc, &rs));
rasterCache_.Insert(keys_.raster.value, rs);
}
Expand Down
3 changes: 2 additions & 1 deletion GPU/D3D11/StateMappingD3D11.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct D3D11RasterKey {
union {
uint32_t value;
struct {
unsigned int cullMode : 2; // D3D11_CULL_MODE
unsigned int cullMode : 2; // D3D11_CULL_MODE
unsigned int depthClipEnable : 1;
};
};
};
Expand Down
1 change: 1 addition & 0 deletions ext/native/thin3d/thin3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ struct DeviceCaps {
bool multiViewport;
bool dualSourceBlend;
bool logicOpSupported;
bool depthClampSupported;
bool framebufferCopySupported;
bool framebufferBlitSupported;
bool framebufferDepthCopySupported;
Expand Down
1 change: 1 addition & 0 deletions ext/native/thin3d/thin3d_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *de

// Seems like a fair approximation...
caps_.dualSourceBlend = featureLevel_ >= D3D_FEATURE_LEVEL_10_0;
caps_.depthClampSupported = featureLevel_ >= D3D_FEATURE_LEVEL_10_0;

caps_.depthRangeMinusOneToOne = false;
caps_.framebufferBlitSupported = false;
Expand Down
1 change: 1 addition & 0 deletions ext/native/thin3d/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ VKContext::VKContext(VulkanContext *vulkan, bool splitSubmit)
caps_.tesselationShaderSupported = vulkan->GetFeaturesAvailable().tessellationShader != 0;
caps_.multiViewport = vulkan->GetFeaturesAvailable().multiViewport != 0;
caps_.dualSourceBlend = vulkan->GetFeaturesAvailable().dualSrcBlend != 0;
caps_.depthClampSupported = vulkan->GetFeaturesAvailable().depthClamp != 0;
caps_.framebufferBlitSupported = true;
caps_.framebufferCopySupported = true;
caps_.framebufferDepthBlitSupported = false; // Can be checked for.
Expand Down

0 comments on commit b7d8492

Please sign in to comment.