Stringer Bell이 Disassemble 메서드를 지적했기 때문에 구문 분석 및 효과 확인을 위해 작은 빌드 빌드 유틸리티를 작성했습니다. 이것이 아주 예쁘지 않다는 경고를 받으십시오. XNA 3.1 용으로 설계되었으며의 ServiceContainer
및 GraphicsDeviceService
클래스가 필요합니다. 슬래시가없는 명령 줄에서 내용 디렉토리 경로를 전달하십시오.
class Program
{
const int maxRegisters = 256; // Sutiable for VS 2.0, not much else
static int retval = 0;
static string root;
static ContentManager content;
static void CheckFile(string path)
{
string name = path.Substring(root.Length+1, path.Length - (root.Length+1) - @".xnb".Length);
Effect effect;
try { effect = content.Load<Effect>(name); }
catch { return; } // probably not an Effect
string effectSource = effect.Disassemble(false);
int highest = -1; // highest register allocated
var matches = Regex.Matches(effectSource, @" c([0-9]+)"); // quick and dirty
foreach(Match match in matches)
{
int register = Int32.Parse(match.Groups[1].ToString());
if(register > highest)
highest = register;
}
var parameters = Regex.Matches(effectSource, @"^ *// *[a-zA-Z_0-9]+ +c([0-9]+) +([0-9]+)", RegexOptions.Multiline);
foreach(Match match in parameters)
{
int register = Int32.Parse(match.Groups[1].ToString()) + Int32.Parse(match.Groups[2].ToString()) - 1;
if(register > highest)
highest = register;
}
if(highest+1 > maxRegisters)
{
Console.WriteLine("Error: Shader \"" + name + "\" uses " + (highest+1).ToString() + " constant registers, which is TOO MANY!");
retval = 1;
}
else
{
Console.WriteLine("Shader \"" + name + "\" uses " + (highest+1).ToString() + " constant registers (OK)");
}
}
static void CheckDirectory(string path)
{
try
{
foreach(string file in Directory.GetFiles(path, @"*.xnb"))
CheckFile(file);
foreach(string dir in Directory.GetDirectories(path))
CheckDirectory(dir);
}
catch { return; } // Don't care
}
static int Main(string[] args)
{
root = args[0];
Form form = new Form(); // Dummy form for creating a graphics device
GraphicsDeviceService gds = GraphicsDeviceService.AddRef(form.Handle,
form.ClientSize.Width, form.ClientSize.Height);
ServiceContainer services = new ServiceContainer();
services.AddService<IGraphicsDeviceService>(gds);
content = new ContentManager(services, root);
CheckDirectory(root);
return retval;
}
}
좋은 질문입니다. 나는 DirectX 개발자들이 거기에 매달려 있기 때문에 http://forums.xna.com/forums/27.aspx에 게시 할 것입니다. – Stringer
감사합니다. Stringer Bell. 제안한대로 XNA 포럼에 게시했습니다. http://forums.xna.com/forums/p/53856/326864.aspx –
또한 HLSL이나 컴파일러에서 수행 할 방법이 없다면 컴파일 된 셰이더가 프로그래밍 방식으로 사용하는 상수 레지스터의 수를 계산하는 방법은 무엇입니까? (이상적으로 XNA 사용) –