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

Cycles : Improve device selection and handling #5678

Merged
merged 4 commits into from
Feb 21, 2024

Conversation

johnhaddon
Copy link
Member

This improves the UI for device selection in CyclesOptions, like so :

image

It also refactors the device handling logic in the renderer backend, fixing a bug and significantly reducing the amount of code involved. Now I'm a bit more familiar with this part of the codebase, I think I'm in a better place to start considering the device reset stuff from #5101.

This was just the same as Cycles' own `available_devices()` method, but with the additional of a strange "MULTI" device that included every single other device, including both the CUDA and Optix variants of the same NVIDIA card. I don't know what that device was intended for, but it doesn't seem to make sense.
While "MULTI" does seem to be used as a value for `CyclesRenderer::m_deviceName`, in that case it seems to mean something else - to use the list of devices gathered into `m_multiDevices`.

The one potential downside here is that we now call `available_devices()` more, but internally it keeps track of what has been initialised already to avoid repeat work anyway. And most of those calls are going to disappear in upcoming refactoring anyway.
It isn't a thing any more.

Also don't completely hide the threads plug - just disable it, so that the layout doesn't jump around distractingly.
Copy link
Contributor

@murraystevenson murraystevenson left a comment

Choose a reason for hiding this comment

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

Nice one! Think I've picked up on one little thing that's preventing CPU usage in the GPU + CPU modes, but otherwise this looks good to me.

src/GafferCycles/IECoreCyclesPreview/Renderer.cpp Outdated Show resolved Hide resolved
@@ -114,9 +104,4 @@ const std::string &versionString()
return cyclesVersion;
}

const std::vector<ccl::DeviceInfo> &devices()
{
return cyclesDevices;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Long ago from what I remember the available_devices() call wasn't reentrant and gave different results after the first call, giving me many headaches until I realised that the Blender code only calls it once and stores the results, but maybe they've fixed that now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the info on the history here Alex. In my own testing available_devices() seems to always return exactly the same results each time, and a glance at the Cycles source suggests that is expected (it uses a lock and flags to avoid multiple initialisations). Unless we see problems in practice, my preference is for the more minimal approach.

Copy link
Contributor

@murraystevenson murraystevenson left a comment

Choose a reason for hiding this comment

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

Thanks! Fix looks good to me.

- Remove all four member variables previously used for device tracking, and just use `m_sessionParams.device`.
- Fix bug where we never actually visited the code path for warning about the CPU fallback when trying to mix GPU and OSL.
- Move all device matching logic into a single place in `option()` (previously was spread between `option()`, `init()` and `getCyclesDevices()`).
- Don't hardcode the device types - use a map for tracking indices per type.
- Use `StringAlgo::matchMultiple()` instead of custom splitting and matching logic.
- Consult `DeviceInfo:has_osl` rather than assuming only the CPU supports OSL. Not important now, but will be necessary when we eventually compile with Optix/OSL support.

This removes around 75% of the device handling code, while keeping the functionality and matching logic the same.
- Add presets widget instead of string field.
- Don't hardcode the list of device types.
- Don't show types that aren't available.
- Organise presets into menus by type.
- Only show the "All" options when two or more devices of the same type exist.

The "Custom" mode is a get out of jail free card if you need to do something else, but for the vast majority of users the most important thing is clear and obvious selection of their one GPU.
@johnhaddon johnhaddon merged commit e3f0c39 into GafferHQ:main Feb 21, 2024
4 of 5 checks passed
@johnhaddon johnhaddon deleted the cyclesDevices branch March 15, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants