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

Direct3D 12: Fix shader model support check for devices not aware of the highest ones #89038

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

RandomShaper
Copy link
Member

Following the advice in the note at https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_feature_data_shader_model.

Without this, e.g., a device that is only aware of up to Shader Model 6.4, will fail the check for 6.6, which is the only one we were doing. With this, a lower SM is checked each time that happens until it can make sense of the request and therefore tell what's the maximum it supports.

@RandomShaper RandomShaper requested a review from a team as a code owner March 1, 2024 12:04
@RandomShaper RandomShaper added this to the 4.3 milestone Mar 1, 2024
@RandomShaper RandomShaper requested a review from DarioSamo March 1, 2024 12:04
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks fine to me. I'll let @DarioSamo give the final approval

Copy link
Contributor

@DarioSamo DarioSamo left a comment

Choose a reason for hiding this comment

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

Looks fine to me, but I think we should be explicit about what happens if the loop fails on every iteration. It is possible for D3D12 to support only SM 5.1 under feature level 11.

If we don't intend to support that, perhaps it should explicitly fail if none of the options it checked could be retrieved, as right now it'll continue as if it succeeded (e.g. when every iteration returns invalid arg).

@RandomShaper
Copy link
Member Author

Done.

@akien-mga akien-mga requested a review from DarioSamo March 4, 2024 09:28
Copy link
Contributor

@DarioSamo DarioSamo left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!


auto _d3d_sm_to_str = [](D3D_SHADER_MODEL p_sm) {
return vformat("%d.%d", (p_sm >> 4), (p_sm & 0xf));
};
Copy link
Member

Choose a reason for hiding this comment

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

I'd use a macro instead of a lambda for this

Copy link
Member Author

Choose a reason for hiding this comment

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

If this isn't within the reasonable usage of lambdas, I don't know what is. I've changed it, but I'm curious about what's your rationale here.

Copy link
Member

@AThousandShips AThousandShips Mar 4, 2024

Choose a reason for hiding this comment

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

It doesn't really benefit from being a method I'd say, it doesn't do anything a macro can't do in this case

For this case a macro is perfectly suited as it's just reusing a code snippet, so more a matter of using the right tool for the job rather than not using a lambda specifically, I'd argue the same with not using a static method or a class method

More generally one of my main issues with lambdas is that they hurt navigability of code, by introducing a scope-local method declaration, if you just find in the middle of a method some invocation of a method and you might want to look at what it does under the hood then finding it as a conventional method is relatively easy (assuming you know the codebase enough to recognize more well established methods, but that's unavoidable as a cause of confusion) you just look for a method declaration, that's easy to scan for, but with a lambda it can be almost anywhere in the local scope as long as it's before the current line, to me that ambiguity is a drawback of it

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess in the future we'll be able to come up with a ruleset that lets us take advantage of lambdas in a reasonable manner, without the current uncertainty about what the review outcome will be. I believe lambdas can make the codebase better if wisely used. The ability to tell that something is a lambda by its name seems indeed like an interesting part of that.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I was thinking of a naming standard like prefixing with l_ or f_, that would help with that part

@akien-mga akien-mga merged commit a47e38b into godotengine:master Mar 4, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@RandomShaper RandomShaper deleted the d3d12_sm branch March 5, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants