{"id":195,"date":"2013-03-14T16:46:54","date_gmt":"2013-03-14T23:46:54","guid":{"rendered":"http:\/\/www.teamfizzgames.com\/Matt\/?p=195"},"modified":"2013-03-20T03:03:27","modified_gmt":"2013-03-20T10:03:27","slug":"premake-fxc-and-you","status":"publish","type":"post","link":"https:\/\/www.teamfizzgames.com\/Matt\/premake-fxc-and-you\/","title":{"rendered":"Premake, FXC, And You"},"content":{"rendered":"<p>When I joined Team Fizz over last summer, I was introduced to the awesomeness that is <a title=\"Premake!\" href=\"http:\/\/industriousone.com\/premake\" target=\"_blank\">Premake<\/a>. \u00a0Shortly after that, <a title=\"Bobby Anguelov's tech blog\" href=\"http:\/\/takinginitiative.net\/2011\/02\/19\/debugging-hlsl\/\" target=\"_blank\">this post on\u00a0Bobby Anguelov&#8217;s blog<\/a> introduced me to FXC and everything awesome that it could bring to the table. \u00a0I instantly wanted to use it. \u00a0The problem then became, how I can get Premake to generate projects and include the necessary custom build steps for my shader files to be able to utilize FXC? \u00a0I figured this would be a pretty common issue for people and it would either be intuitive to setup or there would be a lot of information online on how to make it happen. \u00a0I was completely wrong on both counts and I wasn&#8217;t able to make this work until just last night.<\/p>\n<p>Semi-recently, Premake added support for two features that I felt could potentially solve my issue. \u00a0The buildrule function was supposed to allow me to set a custom build rule to files based on a configuration declaration, and this sounded like it would directly be the solution I was looking for. \u00a0I could just have the shader files in my project, the configuration declaration could look for files based on extension to apply the build rule to, and everything would work. \u00a0I&#8217;m not sure if we just didn&#8217;t set it up properly (the documentation for this feature isn&#8217;t great) or it just doesn&#8217;t work right, but it didn&#8217;t do what I needed it to.<\/p>\n<p>The second option was project reference through the external function. \u00a0While less optimal, the plan was to manually create a project for my shaders, set the custom build tool on each shader file to use FXC, and then have Premake just add this project into the sln when it creates and links in all other projects. \u00a0This is what ended up working for me, so I thought I would document what I did in case anyone else runs into this issue. \u00a0I know I would have appreciated it about 6 months ago.<\/p>\n<p>In your build script, assuming a current enough version of Premake, you can use the external command to reference a pre-existing project into the sln being made. \u00a0Just slide the command in anywhere that you would add &#8220;project&#8221; for a project that you wanted Premake to autogenerate, and make sure that you add the name to the startup project&#8217;s links so that the proper build dependency is made. \u00a0Here is what mine looks like:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/www.teamfizzgames.com\/Matt\/wp-content\/uploads\/2013\/03\/PremakeWithFXC.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-196\" alt=\"\" src=\"http:\/\/www.teamfizzgames.com\/Matt\/wp-content\/uploads\/2013\/03\/PremakeWithFXC-300x77.png\" width=\"300\" height=\"77\" srcset=\"https:\/\/www.teamfizzgames.com\/Matt\/wp-content\/uploads\/2013\/03\/PremakeWithFXC-300x77.png 300w, https:\/\/www.teamfizzgames.com\/Matt\/wp-content\/uploads\/2013\/03\/PremakeWithFXC-250x64.png 250w, https:\/\/www.teamfizzgames.com\/Matt\/wp-content\/uploads\/2013\/03\/PremakeWithFXC.png 430w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Shader is the name of my vcxproj, which is what comes after external. \u00a0It&#8217;s also in a folder named Shader at the root of my sln directory, which is what goes in location. \u00a0Setting the kind to StaticLib (and making sure you actually set the project to match) might not be necessary, but it fit the rest of the architecture of our engine. \u00a0Uuid can be found by opening your vcxproj in notepad and looking for this:<\/p>\n<p>&nbsp;<\/p>\n<div>\u00a0 &lt;PropertyGroup Label=&#8221;Globals&#8221;&gt;<\/div>\n<div>\u00a0 \u00a0 &lt;ProjectGuid&gt;{7CF9442C-12F8-4675-9CE2-D54FEC4C31D0}&lt;\/ProjectGuid&gt;<\/div>\n<div>\u00a0 \u00a0 &lt;RootNamespace&gt;Shader&lt;\/RootNamespace&gt;<\/div>\n<div>\u00a0 &lt;\/PropertyGroup&gt;<\/div>\n<p>&nbsp;<\/p>\n<p>Once you have the project made, setup, and your buildscript ready, you just need to setup your shader files&#8217; properties to use FXC. \u00a0The link to Bobby&#8217;s blog from earlier in this post completely details the process so I won&#8217;t repeat it here.<\/p>\n<p>So, there you have it. \u00a0I won&#8217;t say this is the best way to accomplish what I wanted, or even necessarily a good way, but it&#8217;s a way and it works for me. \u00a0Hopefully if anyone finds themselves in the situation I was in, it will be helpful. \u00a0And if anyone has a better way to solve this, please let me know; I would love to get that kind of feedback and improve things.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I joined Team Fizz over last summer, I was introduced to the awesomeness that is Premake. \u00a0Shortly after that, this post on\u00a0Bobby Anguelov&#8217;s blog introduced me to FXC and everything awesome that it could bring to the table. \u00a0I instantly wanted to use it. \u00a0The problem then became, how \u2026 <a class=\"continue-reading-link\" href=\"https:\/\/www.teamfizzgames.com\/Matt\/premake-fxc-and-you\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[6],"tags":[7,8],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-nongraphicsdevelopment","tag-fxc","tag-premake"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p39ImV-39","_links":{"self":[{"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":10,"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/posts\/195\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.teamfizzgames.com\/Matt\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}