Branimir Karadžić 10 ani în urmă
părinte
comite
2cf7eaaefc
2 a modificat fișierele cu 28 adăugiri și 29 ștergeri
  1. 0 1
      tools/shaderc/shaderc.h
  2. 28 28
      tools/shaderc/shaderc_hlsl.cpp

+ 0 - 1
tools/shaderc/shaderc.h

@@ -61,7 +61,6 @@
 
 
 namespace bgfx
 namespace bgfx
 {
 {
-
 	extern bool g_verbose;
 	extern bool g_verbose;
 
 
 	class LineReader
 	class LineReader

+ 28 - 28
tools/shaderc/shaderc_hlsl.cpp

@@ -26,7 +26,7 @@ namespace bgfx
 	typedef HRESULT(WINAPI* PFN_D3D_COMPILE)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData
 	typedef HRESULT(WINAPI* PFN_D3D_COMPILE)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData
 		, _In_ SIZE_T SrcDataSize
 		, _In_ SIZE_T SrcDataSize
 		, _In_opt_ LPCSTR pSourceName
 		, _In_opt_ LPCSTR pSourceName
-		, _In_reads_opt_(_Inexpressible_(pDefines->Name != NULL)) CONST D3D_SHADER_MACRO* pDefines
+		, _In_reads_opt_(_Inexpressible_(pDefines->Name != NULL) ) CONST D3D_SHADER_MACRO* pDefines
 		, _In_opt_ ID3DInclude* pInclude
 		, _In_opt_ ID3DInclude* pInclude
 		, _In_opt_ LPCSTR pEntrypoint
 		, _In_opt_ LPCSTR pEntrypoint
 		, _In_ LPCSTR pTarget
 		, _In_ LPCSTR pTarget
@@ -127,7 +127,7 @@ namespace bgfx
 		{
 		{
 			const RemapInputSemantic& ris = s_remapInputSemantic[ii];
 			const RemapInputSemantic& ris = s_remapInputSemantic[ii];
 			if (0 == strcmp(ris.m_name, _name)
 			if (0 == strcmp(ris.m_name, _name)
-				&& ris.m_index == _index)
+			&&  ris.m_index == _index)
 			{
 			{
 				return ris;
 				return ris;
 			}
 			}
@@ -164,7 +164,7 @@ namespace bgfx
 			const UniformRemap& remap = s_uniformRemap[ii];
 			const UniformRemap& remap = s_uniformRemap[ii];
 
 
 			if (remap.paramClass == constDesc.Class
 			if (remap.paramClass == constDesc.Class
-				&&  remap.paramType == constDesc.Type)
+			&&  remap.paramType == constDesc.Type)
 			{
 			{
 				if (D3D_SVC_MATRIX_COLUMNS != constDesc.Class)
 				if (D3D_SVC_MATRIX_COLUMNS != constDesc.Class)
 				{
 				{
@@ -172,7 +172,7 @@ namespace bgfx
 				}
 				}
 
 
 				if (remap.columns == constDesc.Columns
 				if (remap.columns == constDesc.Columns
-					&&  remap.rows == constDesc.Rows)
+				&&  remap.rows == constDesc.Rows)
 				{
 				{
 					return remap.id;
 					return remap.id;
 				}
 				}
@@ -222,7 +222,7 @@ namespace bgfx
 		// parse the shader blob for the constant table
 		// parse the shader blob for the constant table
 		const size_t codeSize = _code->GetBufferSize();
 		const size_t codeSize = _code->GetBufferSize();
 		const uint32_t* ptr = (const uint32_t*)_code->GetBufferPointer();
 		const uint32_t* ptr = (const uint32_t*)_code->GetBufferPointer();
-		const uint32_t* end = (const uint32_t*)((const uint8_t*)ptr + codeSize);
+		const uint32_t* end = (const uint32_t*)( (const uint8_t*)ptr + codeSize);
 		const CTHeader* header = NULL;
 		const CTHeader* header = NULL;
 
 
 		ptr++;	// first byte is shader type / version; skip it since we already know
 		ptr++;	// first byte is shader type / version; skip it since we already know
@@ -230,7 +230,7 @@ namespace bgfx
 		while (ptr < end && *ptr != D3DSIO_END)
 		while (ptr < end && *ptr != D3DSIO_END)
 		{
 		{
 			uint32_t cur = *ptr++;
 			uint32_t cur = *ptr++;
-			if ((cur & D3DSI_OPCODE_MASK) != D3DSIO_COMMENT)
+			if ( (cur & D3DSI_OPCODE_MASK) != D3DSIO_COMMENT)
 			{
 			{
 				continue;
 				continue;
 			}
 			}
@@ -243,7 +243,7 @@ namespace bgfx
 				// found the constant table data
 				// found the constant table data
 				header = (const CTHeader*)(ptr + 1);
 				header = (const CTHeader*)(ptr + 1);
 				uint32_t tableSize = (commentSize - 1) * 4;
 				uint32_t tableSize = (commentSize - 1) * 4;
-				if (tableSize < sizeof(CTHeader) || header->Size != sizeof(CTHeader))
+				if (tableSize < sizeof(CTHeader) || header->Size != sizeof(CTHeader) )
 				{
 				{
 					fprintf(stderr, "Error: Invalid constant table data\n");
 					fprintf(stderr, "Error: Invalid constant table data\n");
 					return false;
 					return false;
@@ -322,7 +322,7 @@ namespace bgfx
 			, IID_ID3D11ShaderReflection
 			, IID_ID3D11ShaderReflection
 			, (void**)&reflect
 			, (void**)&reflect
 			);
 			);
-		if (FAILED(hr))
+		if (FAILED(hr) )
 		{
 		{
 			fprintf(stderr, "Error: D3DReflect failed 0x%08x\n", (uint32_t)hr);
 			fprintf(stderr, "Error: D3DReflect failed 0x%08x\n", (uint32_t)hr);
 			return false;
 			return false;
@@ -330,7 +330,7 @@ namespace bgfx
 
 
 		D3D11_SHADER_DESC desc;
 		D3D11_SHADER_DESC desc;
 		hr = reflect->GetDesc(&desc);
 		hr = reflect->GetDesc(&desc);
-		if (FAILED(hr))
+		if (FAILED(hr) )
 		{
 		{
 			fprintf(stderr, "Error: ID3D11ShaderReflection::GetDesc failed 0x%08x\n", (uint32_t)hr);
 			fprintf(stderr, "Error: ID3D11ShaderReflection::GetDesc failed 0x%08x\n", (uint32_t)hr);
 			return false;
 			return false;
@@ -382,7 +382,7 @@ namespace bgfx
 
 
 			_size = (uint16_t)bufferDesc.Size;
 			_size = (uint16_t)bufferDesc.Size;
 
 
-			if (SUCCEEDED(hr))
+			if (SUCCEEDED(hr) )
 			{
 			{
 				BX_TRACE("%s, %d, vars %d, size %d"
 				BX_TRACE("%s, %d, vars %d, size %d"
 					, bufferDesc.Name
 					, bufferDesc.Name
@@ -397,16 +397,16 @@ namespace bgfx
 					ID3D11ShaderReflectionType* type = var->GetType();
 					ID3D11ShaderReflectionType* type = var->GetType();
 					D3D11_SHADER_VARIABLE_DESC varDesc;
 					D3D11_SHADER_VARIABLE_DESC varDesc;
 					hr = var->GetDesc(&varDesc);
 					hr = var->GetDesc(&varDesc);
-					if (SUCCEEDED(hr))
+					if (SUCCEEDED(hr) )
 					{
 					{
 						D3D11_SHADER_TYPE_DESC constDesc;
 						D3D11_SHADER_TYPE_DESC constDesc;
 						hr = type->GetDesc(&constDesc);
 						hr = type->GetDesc(&constDesc);
-						if (SUCCEEDED(hr))
+						if (SUCCEEDED(hr) )
 						{
 						{
 							UniformType::Enum uniformType = findUniformType(constDesc);
 							UniformType::Enum uniformType = findUniformType(constDesc);
 
 
 							if (UniformType::Count != uniformType
 							if (UniformType::Count != uniformType
-								&& 0 != (varDesc.uFlags & D3D_SVF_USED))
+							&&  0 != (varDesc.uFlags & D3D_SVF_USED) )
 							{
 							{
 								Uniform un;
 								Uniform un;
 								un.name = varDesc.Name;
 								un.name = varDesc.Name;
@@ -426,7 +426,7 @@ namespace bgfx
 							}
 							}
 							else
 							else
 							{
 							{
-								if (0 == (varDesc.uFlags & D3D_SVF_USED))
+								if (0 == (varDesc.uFlags & D3D_SVF_USED) )
 								{
 								{
 									unusedUniforms.push_back(varDesc.Name);
 									unusedUniforms.push_back(varDesc.Name);
 								}
 								}
@@ -445,7 +445,7 @@ namespace bgfx
 			D3D11_SHADER_INPUT_BIND_DESC bindDesc;
 			D3D11_SHADER_INPUT_BIND_DESC bindDesc;
 
 
 			hr = reflect->GetResourceBindingDesc(ii, &bindDesc);
 			hr = reflect->GetResourceBindingDesc(ii, &bindDesc);
-			if (SUCCEEDED(hr))
+			if (SUCCEEDED(hr) )
 			{
 			{
 				if (D3D_SIT_SAMPLER == bindDesc.Type)
 				if (D3D_SIT_SAMPLER == bindDesc.Type)
 				{
 				{
@@ -460,7 +460,7 @@ namespace bgfx
 					if (NULL != end)
 					if (NULL != end)
 					{
 					{
 						Uniform un;
 						Uniform un;
-						un.name.assign(bindDesc.Name, (end - bindDesc.Name));
+						un.name.assign(bindDesc.Name, (end - bindDesc.Name) );
 						un.type = UniformType::Enum(BGFX_UNIFORM_SAMPLERBIT | UniformType::Int1);
 						un.type = UniformType::Enum(BGFX_UNIFORM_SAMPLERBIT | UniformType::Int1);
 						un.num = 1;
 						un.num = 1;
 						un.regIndex = bindDesc.BindPoint;
 						un.regIndex = bindDesc.BindPoint;
@@ -528,7 +528,7 @@ namespace bgfx
 		}
 		}
 
 
 		uint32_t optimization = 3;
 		uint32_t optimization = 3;
-		if (_cmdLine.hasArg(optimization, 'O'))
+		if (_cmdLine.hasArg(optimization, 'O') )
 		{
 		{
 			optimization = bx::uint32_min(optimization, BX_COUNTOF(s_optimizationLevelD3D11) - 1);
 			optimization = bx::uint32_min(optimization, BX_COUNTOF(s_optimizationLevelD3D11) - 1);
 			flags |= s_optimizationLevelD3D11[optimization];
 			flags |= s_optimizationLevelD3D11[optimization];
@@ -553,7 +553,7 @@ namespace bgfx
 		{
 		{
 			hlslfp = _cmdLine.findOption('o');
 			hlslfp = _cmdLine.findOption('o');
 			hlslfp += ".hlsl";
 			hlslfp += ".hlsl";
-			writeFile(hlslfp.c_str(), _code.c_str(), (int32_t)_code.size());
+			writeFile(hlslfp.c_str(), _code.c_str(), (int32_t)_code.size() );
 		}
 		}
 
 
 		HRESULT hr = D3DCompile(_code.c_str()
 		HRESULT hr = D3DCompile(_code.c_str()
@@ -569,7 +569,7 @@ namespace bgfx
 			, &errorMsg
 			, &errorMsg
 			);
 			);
 		if (FAILED(hr)
 		if (FAILED(hr)
-		|| (werror && NULL != errorMsg))
+		|| (werror && NULL != errorMsg) )
 		{
 		{
 			const char* log = (char*)errorMsg->GetBufferPointer();
 			const char* log = (char*)errorMsg->GetBufferPointer();
 
 
@@ -579,7 +579,7 @@ namespace bgfx
 			int32_t end = INT32_MAX;
 			int32_t end = INT32_MAX;
 
 
 			if (2 == sscanf(log, "(%u,%u):", &line, &column)
 			if (2 == sscanf(log, "(%u,%u):", &line, &column)
-				&& 0 != line)
+			&&  0 != line)
 			{
 			{
 				start = bx::uint32_imax(1, line - 10);
 				start = bx::uint32_imax(1, line - 10);
 				end = start + 20;
 				end = start + 20;
@@ -598,7 +598,7 @@ namespace bgfx
 
 
 		if (_d3d == 9)
 		if (_d3d == 9)
 		{
 		{
-			if (!getReflectionDataD3D9(code, uniforms))
+			if (!getReflectionDataD3D9(code, uniforms) )
 			{
 			{
 				fprintf(stderr, "Error: Unable to get D3D9 reflection data.\n");
 				fprintf(stderr, "Error: Unable to get D3D9 reflection data.\n");
 				goto error;
 				goto error;
@@ -620,8 +620,8 @@ namespace bgfx
 
 
 				// first time through, we just find unused uniforms and get rid of them
 				// first time through, we just find unused uniforms and get rid of them
 				std::string output;
 				std::string output;
-				LineReader reader(_code.c_str());
-				while (!reader.isEof())
+				LineReader reader(_code.c_str() );
+				while (!reader.isEof() )
 				{
 				{
 					std::string line = reader.getLine();
 					std::string line = reader.getLine();
 					for (UniformNameList::iterator it = unusedUniforms.begin(), itEnd = unusedUniforms.end(); it != itEnd; ++it)
 					for (UniformNameList::iterator it = unusedUniforms.begin(), itEnd = unusedUniforms.end(); it != itEnd; ++it)
@@ -637,7 +637,7 @@ namespace bgfx
 						// included in the uniform blob that the application must upload
 						// included in the uniform blob that the application must upload
 						// we can't just remove them, because unused functions might still reference
 						// we can't just remove them, because unused functions might still reference
 						// them and cause a compile error when they're gone
 						// them and cause a compile error when they're gone
-						if (!!bx::findIdentifierMatch(line.c_str(), it->c_str()))
+						if (!!bx::findIdentifierMatch(line.c_str(), it->c_str() ) )
 						{
 						{
 							line = line.replace(index, strLength, "static");
 							line = line.replace(index, strLength, "static");
 							unusedUniforms.erase(it);
 							unusedUniforms.erase(it);
@@ -689,7 +689,7 @@ namespace bgfx
 				, &stripped
 				, &stripped
 				);
 				);
 
 
-			if (SUCCEEDED(hr))
+			if (SUCCEEDED(hr) )
 			{
 			{
 				code->Release();
 				code->Release();
 				code = stripped;
 				code = stripped;
@@ -707,12 +707,12 @@ namespace bgfx
 		if (_d3d > 9)
 		if (_d3d > 9)
 		{
 		{
 			bx::write(_writer, numAttrs);
 			bx::write(_writer, numAttrs);
-			bx::write(_writer, attrs, numAttrs*sizeof(uint16_t));
+			bx::write(_writer, attrs, numAttrs*sizeof(uint16_t) );
 
 
 			bx::write(_writer, size);
 			bx::write(_writer, size);
 		}
 		}
 
 
-		if (_cmdLine.hasArg('\0', "disasm"))
+		if (_cmdLine.hasArg('\0', "disasm") )
 		{
 		{
 			ID3DBlob* disasm;
 			ID3DBlob* disasm;
 			D3DDisassemble(code->GetBufferPointer()
 			D3DDisassemble(code->GetBufferPointer()
@@ -727,7 +727,7 @@ namespace bgfx
 				std::string disasmfp = _cmdLine.findOption('o');
 				std::string disasmfp = _cmdLine.findOption('o');
 				disasmfp += ".disasm";
 				disasmfp += ".disasm";
 
 
-				writeFile(disasmfp.c_str(), disasm->GetBufferPointer(), (uint32_t)disasm->GetBufferSize());
+				writeFile(disasmfp.c_str(), disasm->GetBufferPointer(), (uint32_t)disasm->GetBufferSize() );
 				disasm->Release();
 				disasm->Release();
 			}
 			}
 		}
 		}