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

Add support for tesc, tese and geom to EliminateDead*Components #4990

Merged
merged 1 commit into from
Nov 18, 2022

Conversation

greg-lunarg
Copy link
Contributor

No description provided.

@greg-lunarg
Copy link
Contributor Author

@Keenuts PTAL

@@ -55,23 +63,37 @@ Pass::Status EliminateDeadInputComponentsPass::Process() {
if (ptr_type == nullptr) {
continue;
}
auto sclass = ptr_type->storage_class();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@@ -42,6 +43,13 @@ Pass::Status EliminateDeadInputComponentsPass::Process() {
// Current functionality assumes shader capability.
if (!context()->get_feature_mgr()->HasCapability(spv::Capability::Shader))
return Status::SuccessWithoutChange;
// Current functionality assumes vert, frag, tesc, tese or geom shader
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing full stop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Comment on lines 76 to 77
// For tesc, or input variables in tese or geom shaders,
// only optimize arrays and skip the first level of arrayness.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why? IMO a comment should not describe what the code does, but why the code is doing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general, these particular variables MUST be arrays. The outer array is called the "per-vertex-array". It is completely orthogonal to this analysis/optimization and can and really must be ignored. This is a somewhat tricky and confusing aspect of input/output variables in these shaders. Please refer to the GLSL spec and search for per-vertex-array.

I will improve the comment per this explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, if the vertex shader looks like this:

#version 450

layout (location = 0) out Vertex
{
    vec4 Cd;
    vec2 uv;
} oVert;

layout (location = 0) in vec4 P;

void main()
{
    oVert.Cd = P;
}

the following tesc shader will match:

#version 450

layout (vertices = 4) out;

layout (location = 0) in Vertex
{
    vec4 Cd;
    vec2 uv;
} iVert[];

layout (location = 0) out vec4 position[4];

void main()
{
    vec4 pos = iVert[gl_InvocationID].Cd;
    position[gl_InvocationID] = pos;
}

Note oVert is scalar in the vert shader, but the matching iVert is an array in the tesc shader. See also 15.1.3 in the Vulkan spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, thanks for the explanation. Thought it could be applied to other arrays, like uniforms and such, but they don't have the Input storage class.
And because this only is applied on the unsafe pass, which means input/output will undergo the same behavior, we shouldn't have any stride issue.
Thanks for taking the time to explain all that!

const analysis::Struct* struct_ty = ptr_type->pointee_type()->AsStruct();
auto core_type = ptr_type->pointee_type();
// Check for array of struct from tesc, tese and geom
auto arr_type = core_type->AsArray();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

unsigned idx_id = use->GetSingleWordInOperand(kAccessChainIndex0InIdx);
unsigned in_idx = skip_first_index ? kAccessChainIndex1InIdx
: kAccessChainIndex0InIdx;
unsigned idx_id = use->GetSingleWordInOperand(in_idx);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: const (base_id, in_idx, idx_id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@@ -116,12 +138,14 @@ Pass::Status EliminateDeadInputComponentsPass::Process() {
}

unsigned EliminateDeadInputComponentsPass::FindMaxIndex(Instruction& var,
unsigned original_max) {
unsigned original_max,
Copy link
Contributor

Choose a reason for hiding this comment

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

you can mark all those parameters as const (especially the reference)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@greg-lunarg
Copy link
Contributor Author

@Keenuts Thank you for the prompt review! It is much appreciated!

@greg-lunarg
Copy link
Contributor Author

@Keenuts I believe I have addressed all your concerns. PTAL.

Copy link
Contributor

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

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

Thanks! some additional items and we should be good to go!

@@ -27,6 +27,7 @@ namespace {

const uint32_t kAccessChainBaseInIdx = 0;
const uint32_t kAccessChainIndex0InIdx = 1;
const uint32_t kAccessChainIndex1InIdx = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

there is PR that should land today (that will change const into constexpr for all opt/ folder), we'll see which one is submitted first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Merged with that.

if (stage != spv::ExecutionModel::Vertex && vertex_shader_only_)
return Status::SuccessWithoutChange;
// Current functionality assumes shader capability.
if (!context()->get_feature_mgr()->HasCapability(spv::Capability::Shader))
return Status::SuccessWithoutChange;
// Current functionality assumes vert, frag, tesc, tese or geom shader.
// TODO(greg-lunarg): Add GLCompute.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe TODO(issue #4988) ?
(so people can have context without having to contact you)

Comment on lines 76 to 77
// For tesc, or input variables in tese or geom shaders,
// only optimize arrays and skip the first level of arrayness.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, thanks for the explanation. Thought it could be applied to other arrays, like uniforms and such, but they don't have the Input storage class.
And because this only is applied on the unsafe pass, which means input/output will undergo the same behavior, we shouldn't have any stride issue.
Thanks for taking the time to explain all that!

// Check for array of struct from tesc, tese and geom
const auto arr_type = core_type->AsArray();
if (arr_type) core_type = arr_type->element_type();
const analysis::Struct* struct_ty = core_type->AsStruct();
Copy link
Contributor

Choose a reason for hiding this comment

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

missed this in the first review, sorry.

  • this is called ChangeStructType, and was a straightforward function: take a struct, change its length.
  • now it's doing some magic with arrays, allowing one level of array top be skipped. I understand the goal in this context, but don't think this should be done here.

What about:

  • this function takes a struct type, and returns a new type with the proper size.
  • outside, you do struct_var->setResultType(resized_type);

This way, the function remains true to its name, and doesn't have some less known behaviors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. But rather than change the function to be true to the name, I decided to change the name :)

I changed the name to ChangeIOVarStructLength, which is to say, change the (outermost) struct length in the IO var. I also renamed the argument from struct_var to io_var to reflect that the var may not be be a struct (eg a per-vertex-array of struct). I also improved the header comment of this function to explain this all.

@greg-lunarg
Copy link
Contributor Author

@Keenuts I believe I have addressed your latest concerns. PTAL.

Keenuts
Keenuts previously approved these changes Nov 18, 2022
Copy link
Contributor

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

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

Thanks. One small nit and we are good. (Will drop later tonight to re-approve after your push so you can submit before the weekend)

namespace {

Copy link
Contributor

Choose a reason for hiding this comment

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

consistency with other files, no spacing around those namespaces and before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@greg-lunarg
Copy link
Contributor Author

@Keenuts I believe I have addressed your most recent concerns. PTAL.

Copy link
Contributor

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

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

Thanks!

@greg-lunarg greg-lunarg merged commit 46ca66e into KhronosGroup:master Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants