-
Notifications
You must be signed in to change notification settings - Fork 533
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
Conversation
@Keenuts PTAL |
@@ -55,23 +63,37 @@ Pass::Status EliminateDeadInputComponentsPass::Process() { | |||
if (ptr_type == nullptr) { | |||
continue; | |||
} | |||
auto sclass = ptr_type->storage_class(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing full stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
// For tesc, or input variables in tese or geom shaders, | ||
// only optimize arrays and skip the first level of arrayness. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
@Keenuts Thank you for the prompt review! It is much appreciated! |
@Keenuts I believe I have addressed all your concerns. PTAL. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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)
// For tesc, or input variables in tese or geom shaders, | ||
// only optimize arrays and skip the first level of arrayness. |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
05944aa
to
a9050dc
Compare
@Keenuts I believe I have addressed your latest concerns. PTAL. |
There was a problem hiding this 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 { | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@Keenuts I believe I have addressed your most recent concerns. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
No description provided.