Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D3D11: Enable depth clamping #11402

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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