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

MergedKeywords and CommonParameters Supports in Shader #1316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GZHYBFHHJ
Copy link
Contributor

Fixes #726

@GZHYBFHHJ GZHYBFHHJ changed the title MergedKeywords and CommonParameters Supports for Shader MergedKeywords and CommonParameters Supports in Shader Apr 26, 2024
Copy link
Collaborator

@ds5678 ds5678 left a comment

Choose a reason for hiding this comment

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

Hello again. I appreciate you working on the project.

@@ -0,0 +1,64 @@
using AssetRipper.Export.Modules.Shaders.ShaderBlob.Parameters;
using AssetRipper.SourceGenerated.Extensions.Enums.Shader;
using YAML = AssetRipper.SourceGenerated.Subclasses;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use a different name. Yaml has nothing to do with this.

@@ -97,7 +97,7 @@ private static T[] CreateAndInitializeArray<T>(int length) where T : new()
}


public ShaderSubProgram GetSubProgram(uint blobIndex)
public ShaderSubProgram GetSubProgram(uint blobIndex, Action<ShaderSubProgram>? onRead)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels like an antipattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know this is not a good way
Should CommonParameter be passed as a parameter, or set a out parameter to check if SubProgram is from cache, or just clone the ShaderSubProgram?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It feels like you're trying to process these values after reading them. I think we need 2 object models:

  • A low level layer that adheres very closely to the binary content.
  • A high level layer that includes processing where necessary.

Comment on lines +104 to +109
List<string> keywords = reader.ReadStringArray().ToList(); // GlobalKeywords
if (HasLocalKeywords(unityVersion))
{
LocalKeywords = reader.ReadStringArray();
keywords.AddRange(reader.ReadStringArray());
}
Keywords = keywords.ToArray();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is more efficient.

if (!HasLocalKeywords(unityVersion))
{
	Keywords = reader.ReadStringArray();
}
else
{
	string[] globalKeywords = reader.ReadStringArray();
	string[] localKeywords = reader.ReadStringArray();
	if (localKeywords.Length == 0)
	{
		Keywords = globalKeywords;
	}
	else if (globalKeywords.Length == 0)
	{
		Keywords = localKeywords;
	}
	else
	{
		Keywords = new string[globalKeywords.Length + localKeywords.Length];
		globalKeywords.AsSpan().CopyTo(Keywords);
		localKeywords.AsSpan().CopyTo(Keywords.AsSpan(globalKeywords.Length));
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Shader Decompilation fails on Slime Rancher 2
2 participants