HLSL Shader Build Task

This solution is a build task which adds the ability to compile HLSL files referenced in MSBuild projects. Integrates with Visual Studio to make compiling shaders seamless.

C++ (8.3 MB)
 
 
 
 
 
3.7 Star
(3)
5,593 times
Add to favorites
6/25/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C++
// ShaderBuildTask.h

#pragma once

#include "d3dx9.h"

using namespace System;
using namespace Microsoft::Build::Framework;
using namespace Microsoft::Build::Utilities;
using namespace System::IO;
using namespace System::Diagnostics;
using namespace System::Collections::Generic;


namespace ShaderBuildTask {

public ref class ShaderCompile : Task
	{
	public:
		ShaderCompile()
		{
			_dxLibraryToUse = String::Empty;
			_calculatedDxLibraryToUse = false;

			EntryPoint = "main";
			PackMatrixRowMajor = true;
			OptimizationLevel = -1;
			Debug = false;
			ExportConstants = true;			
		}


		[Required]
		property array<ITaskItem^>^ Sources;

		[Required]
		property String^ ShaderProfile;

		property String^ EntryPoint;
		property int OptimizationLevel; // O0-O3
		property bool Debug;
		property bool PackMatrixRowMajor;
		property bool ExportConstants;
		property String^ IntermediateOutputPath;

		[Output]
		property array<ITaskItem^>^ Outputs
		{
			array<ITaskItem^>^ get()
			{
				return _outputs->ToArray();
			}

			void set(array<ITaskItem^>^ value)
			{
				_outputs->AddRange(value);
			}
		};

		virtual bool Execute() override;


	private:
		String^ GetDxLibraryToUse();
		String^ GetOutputFileName(String^ inputFileName);
		void WriteConstants(String^ fileName, LPD3DXCONSTANTTABLE constantTable);

		List<ITaskItem^>^ _outputs;
		String^ _dxLibraryToUse;
		bool _calculatedDxLibraryToUse;
	};
}