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

VideoCommon: Abstract bounding box #9803

Merged
merged 1 commit into from Oct 8, 2021

Conversation

Techjar
Copy link
Contributor

@Techjar Techjar commented Jun 9, 2021

This moves much of the duplicated bounding box code into VideoCommon, leaving only the specific buffer implementations in each backend.

I also accidentally fixed the bug where bounding box doesn't work on software renderer unless you select some other backend first.

@Techjar Techjar force-pushed the bbox-videocommon branch 2 times, most recently from 8b88af6 to d95fada Compare June 9, 2021 12:23
@@ -531,7 +531,7 @@
<ClInclude Include="VideoBackends\D3DCommon\D3DCommon.h" />
<ClInclude Include="VideoBackends\D3DCommon\Shader.h" />
<ClInclude Include="VideoBackends\D3DCommon\SwapChain.h" />
<ClInclude Include="VideoBackends\Null\NullPerfQuery.h" />

This comment has been hidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's a non-existent file. Must've been leftover accidentally from some past refactor.

@Techjar Techjar force-pushed the bbox-videocommon branch 4 times, most recently from 8e7f0ef to 5f231bf Compare June 9, 2021 12:37
Source/Core/VideoBackends/Software/SWBoundingBox.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BoundingBox.h Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BoundingBox.h Outdated Show resolved Hide resolved
Source/Core/VideoCommon/RenderBase.h Outdated Show resolved Hide resolved
Source/Core/VideoCommon/RenderBase.h Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BoundingBox.h Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BoundingBox.h Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BoundingBox.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BoundingBox.cpp Outdated Show resolved Hide resolved
Source/Core/VideoCommon/BoundingBox.cpp Outdated Show resolved Hide resolved
@Techjar Techjar force-pushed the bbox-videocommon branch 3 times, most recently from 214192d to 16fc8d1 Compare June 9, 2021 13:18
@iwubcode
Copy link
Contributor

iwubcode commented Jun 9, 2021

This looks really good @Techjar , thanks for doing this!!

One silly comment, thoughts on renaming VideoCommon/BoundingBox to VideoCommon/AbstractBoundingBox to match the other classes?

}

void BBox::Init()
bool D3DBoundingBox::Initialize()
{
if (!g_ActiveConfig.backend_info.bSupportsBBox)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check happens in every backend (save for D3D12, Software, and Null). Should it be moved to the abstract interface? Vulkan supports a log message which might be nice in general.

Additionally, why is this returning true? If it's not supported, seems like we would want to error out or possibly return a NullBoundingBox to avoid errors when it is being used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read/Write also check this same config option (but not in all backends).

Copy link
Contributor Author

@Techjar Techjar Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning false would cause us to abort backend initialization, which we don't want because games can still run without bounding box support. There's checks in place to avoid errors when things aren't initialized.

Copy link
Contributor

@iwubcode iwubcode Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I see what you mean now. Well, let me amend my suggestion then to modifying Read in AbstractBoundingBox to:

std::vector<BBoxType> Read(int index, int length)
{
  if (!g_ActiveConfig.backend_info.bSupportsBBox)
    return {};

  return ReadImpl(index, length);
}

with a

private:
virtual std::vector<BBoxType> ReadImpl(int index, int length) = 0;

and same with Write() so that all backends get this behavior in a single place.

And I'd add that check to D3D12's Initialize() for consistency with D3D11, OpenGL, and Vulkan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already addressed it in a slightly different way, but thanks. Didn't want to create forwarding functions, as the implementation here is pretty tight anyways.

D3D12 implicitly supports bounding box, so the check would be kinda pointless there. In any case I moved the initialization check to RenderBase.

@Techjar Techjar force-pushed the bbox-videocommon branch 2 times, most recently from 076d761 to d55ade5 Compare June 9, 2021 21:44
@Techjar Techjar force-pushed the bbox-videocommon branch 2 times, most recently from 74d84bb to a79b505 Compare June 9, 2021 21:55
@Techjar
Copy link
Contributor Author

Techjar commented Jun 10, 2021

One silly comment, thoughts on renaming VideoCommon/BoundingBox to VideoCommon/AbstractBoundingBox to match the other classes?

I dunno. The naming of other things isn't entirely consistent either, something being AbstractX and others being XBase.

@Rumi-Larry
Copy link

One silly comment, thoughts on renaming VideoCommon/BoundingBox to VideoCommon/AbstractBoundingBox to match the other classes?

I dunno. The naming of other things isn't entirely consistent either, something being AbstractX and others being XBase.

My personal preference would be XBase being consistently used. Any piece of code is already an abstraction :P

@iwubcode
Copy link
Contributor

iwubcode commented Jun 10, 2021

Any piece of code is already an abstraction

That's...not what this is referring to at all, see https://www.tutorialspoint.com/cplusplus/cpp_interfaces.htm

I dunno. The naming of other things isn't entirely consistent either, something being AbstractX and others being XBase.

Well "Base" does not technically imply "Abstract" but I do understand what you're saying. Honestly, not a big deal to leave it either, the backend specific abbreviations are prepended onto the derived classes, so the distinction is there.

I'll take another pass later today but this code seemed mergeable to me.

@Techjar Techjar force-pushed the bbox-videocommon branch 3 times, most recently from 33e2b96 to 06ad4bf Compare June 11, 2021 06:15
@Techjar Techjar force-pushed the bbox-videocommon branch 2 times, most recently from dcb51a2 to 7a28c14 Compare September 20, 2021 18:51
@JMC47
Copy link
Contributor

JMC47 commented Sep 27, 2021

Is there anything left for this?

Copy link
Contributor

@iwubcode iwubcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Untested

Copy link
Member

@leoetlino leoetlino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 41 of 41 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @Techjar)


Source/Core/VideoBackends/Null/NullBoundingBox.h, line 2 at r1 (raw file):

// Copyright 2021 Dolphin Emulator Project
// Licensed under GPLv2+

should be // SPDX-License-Identifier: GPL-2.0-or-later


Source/Core/VideoBackends/Software/SWBoundingBox.h, line 2 at r1 (raw file):

// Copyright 2021 Dolphin Emulator Project
// Licensed under GPLv2+

license header


Source/Core/VideoBackends/Software/SWBoundingBox.cpp, line 2 at r1 (raw file):

// Copyright 2021 Dolphin Emulator Project
// Licensed under GPLv2+

license header


Source/Core/VideoCommon/BoundingBox.h, line 47 at r1 (raw file):

  bool m_is_active = false;

  std::array<BBoxType, NUM_BBOX_VALUES> m_values = {};

Shouldn't this default to {0x80, 0xA0, ...}?


Source/Core/VideoCommon/BoundingBox.cpp, line 43 at r1 (raw file):

      continue;
    }

I feel like it would be clearer to separate the m_dirty updates and the end index search:

u32 end = start + 1;
while (end < NUM_BBOX_VALUES && m_dirty[end])
  ++end;

for (u32 i = start; i < end; ++i)
  m_dirty[i] = false;

Having two for loops, one missing the iteration expression and the other missing an initialiser expression, is kind of difficult to read.

@Techjar
Copy link
Contributor Author

Techjar commented Sep 29, 2021

Shouldn't this default to {0x80, 0xA0, ...}?

Is this the default value of the registers on hardware? Honestly I don't even know what these values are, I only see them in the software bbox implementation.

This moves much of the duplicated bounding box code into VideoCommon,
leaving only the specific buffer implementations in each backend.
Copy link
Member

@leoetlino leoetlino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Techjar)

@leoetlino leoetlino merged commit ff1cb5a into dolphin-emu:master Oct 8, 2021
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
8 participants