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

xrRender: static geometry buffers code unification (#489) #490

Merged
merged 23 commits into from
Nov 4, 2019
Merged

xrRender: static geometry buffers code unification (#489) #490

merged 23 commits into from
Nov 4, 2019

Conversation

vTurbine
Copy link
Contributor

  • Added staging buffer wrapper for static geometry;
  • Common buffer interface for DX9/DX10/DX11/VK
  • Backend top file simplified and made common

Please check if it works fine on Linux as well: I don't have OpenGL 4.x on my VM

@Xottab-DUTY
Copy link
Member

AppVeyor failed to compile this PR =(

@vTurbine
Copy link
Contributor Author

Right, sorry. BufferUtils.h was lost in pile of untracked files. Re-pushed with it

@vTurbine
Copy link
Contributor Author

vTurbine commented Oct 13, 2019

It turned out that after this modification we able to share some of render targets files(!) across R2/R3/R4/GL since it became fully portable. Also this can give a good boost for #492

@SkyLoaderr
Copy link
Contributor

Has anyone tested this PR on Linux?

R_CHK(HW.pDevice->CreateIndexBuffer(iCount * 2, dwUsage, D3DFMT_INDEX16, D3DPOOL_MANAGED, &_IB[i], 0));
HW.stats_manager.increment_stats_ib(_IB[i]);
R_CHK(_IB[i]->Lock(0, 0, (void**)&pData, 0));
_IB[i].Create(iCount * 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Old code doesn't use D3DUSAGE_SOFTWAREPROCESSING for dwUsage in software mode, but _IB[i].Create has it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This odd for level geometry loading only. I believe this typo came from past times and the flag should be set. See R1 for reference.
Any reasons to treat this particular geometry buffers in different manner? Am I missing smth?

Copy link
Member

Choose a reason for hiding this comment

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

This odd for level geometry loading only. I believe this typo came from past times and the flag should be set. See R1 for reference.
Any reasons to treat this particular geometry buffers in different manner? Am I missing smth?

@SkyLoaderr, so, do you have something to say about it?

Copy link
Member

@Xottab-DUTY Xottab-DUTY Nov 3, 2019

Choose a reason for hiding this comment

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

I bet this is not a typo and was made intentional. But, however, R2 probably won't even launch without hardware features, so this should be safe.

src/Layers/xrRenderDX9/CommonTypes.h Outdated Show resolved Hide resolved
src/Layers/xrRender/BufferUtils.h Outdated Show resolved Hide resolved
src/Layers/xrRender/BufferUtils.h Outdated Show resolved Hide resolved
src/Layers/xrRender/BufferUtils.h Outdated Show resolved Hide resolved
src/Layers/xrRender/BufferUtils.h Outdated Show resolved Hide resolved
src/Layers/xrRender/BufferUtils.h Outdated Show resolved Hide resolved
@007exe
Copy link
Contributor

007exe commented Oct 25, 2019

I checked on ArchLinux in conjunction with the GeForce 9600 GT on proprietary drivers, I did not notice any new bugs

* Dead code restored
* `GetHostPointer` -> `Map`
* Option to keep host buffer for further readings
* `Destroy` is hidden to prevent ref counter miscalculations
@vTurbine
Copy link
Contributor Author

Thank you for review. Let's decide now how to solve the issue with naming.
Two use cases are possible:

  1. Lock(map?) host buffer to fill the buffer obtained with data and then upload it to GPU (unlock + flush)
  2. Lock host buffer again to read data back and then unlock without flushing since no content changed

It will end up with this patterns:
1.

Create(size);
ptr = Lock();
< fill ptr >
Unlock();
Flush();
Create(size, true);
ptr = Lock();
< fill ptr >
Unlock();
Flush();
...
ptr = Lock(true); // for read
Unlock();

So,

  • should I add explicit Unlock after each buffer use?
  • isn't map/unmap names fit better for case 2?
  • Codacy reports wrongly scoped variables came from vanilla code. Do they need to be fixed too?

@Xottab-DUTY
Copy link
Member

Xottab-DUTY commented Oct 26, 2019

isn't map/unmap names fit better for case 2?

Since it doesn't actually Lock/Unlock buffers on DX10+/OpenGL and we want to deprecate DX9 (which is the only implementation which actually does Lock/Unlock) it is better to Map/Unmap, rather than Lock/Unlock.

should I add explicit Unlock after each buffer use?

Summing up the above and the fact that Unmap() does nothing on DX10+/OpenGL, we can just use Map(), Unmap() and FlushAndUnmap(), so no explicit Unlock() calls are required.

Eventually, it can look like that:
1.

Create(size);
ptr = Map();
< fill ptr >
FlushAndUnmap();
Create(size, true);
ptr = Map();
< fill ptr >
FlushAndUnmap();
...
ptr = Map(true); // for read
Unmap();

The main thing with my suggestion is that then Map, Unmap and FlushAndUnmap functions should be documented well.

Layers/xrRender/BufferUtils.h should contain behaviour description for all implementations (DX9/DX10+/OpenGL)

API specific implementations Layers/xrRender*/*BufferUtils.cpp should contain behaviour description specific to that API.

Codacy reports wrongly scoped variables came from vanilla code. Do they need to be fixed too?

Will fix that myself)

@Xottab-DUTY
Copy link
Member

AppVeyor compilation failed

@vTurbine
Copy link
Contributor Author

Summing up the above and the fact that Unmap() does nothing on DX10+/OpenGL, we can just use Map(), Unmap() and FlushAndUnmap(), so no explicit Unlock() calls are required.

Will be Unmap(doFlush=true) easier then?

Create(size);
ptr = Map();
< fill ptr >
Unmap(true); // flush
Create(size, true); // read capable
ptr = Map();
< fill ptr >
Unmap();
...
ptr = Map(true); // for read
< read ptr>
Unmap();
...
DiscardHostBuffer();

@Xottab-DUTY
Copy link
Member

Will be Unmap(doFlush=true) easier then?

Yes, it will.

- `Flush` removed;
- More verbosity in assertions;
- Don't allow to map buffer for writes twice. Such pattern isn't used
in the Engine and this will need buffer handle invalidation.
- Some documentation added
@vTurbine
Copy link
Contributor Author

Sorry for late update: my PC burnt out and it will take a couple of days to bring the next changes

@Xottab-DUTY
Copy link
Member

Hope you will successfully recover your PC! 😃

Copy link
Member

@Xottab-DUTY Xottab-DUTY left a comment

Choose a reason for hiding this comment

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

@vTurbine, anything more to apply or we may merge?

@vTurbine
Copy link
Contributor Author

vTurbine commented Nov 4, 2019

It's fine, no more changes on this step.
BTW, I removed the code which restores pre-computed indices in QuadIB (see CBackend::RestoreQuadIBData()). Not sure if anyone uses it so I'm going to remove it completely right after this PR merging. Is it ok or I need to return this back?

@Xottab-DUTY
Copy link
Member

It's better to just remove it right in this PR. Why removing in two steps? (partial code removing and then full removal in other PR)
We can and it's better to remove it right now.

Some history:
CBackend::RestoreQuadIBData() related to the old bug with rain particles corruption, many programmers tried to fix it in SoC and CS. (the bug appeared even before SoC was released)
It was finally fixed by Armen Abroyan in CoP.

@vTurbine
Copy link
Contributor Author

vTurbine commented Nov 4, 2019

Thank you for explanation.
Done. Will keep an eye on regression

@Xottab-DUTY
Copy link
Member

It was finally fixed by Armen Abroyan in CoP.

The fix is simple. Here's my backport to Clear Sky: OpenXRay/xray-15@b8fd8b9

@Xottab-DUTY Xottab-DUTY merged commit 9086964 into OpenXRay:xd_dev Nov 4, 2019
@vTurbine vTurbine deleted the renderer/staging_buffers branch November 4, 2019 11:41
eagleivg pushed a commit to eagleivg/xray-16 that referenced this pull request Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants