Explorar o código

Fixed 'unexpected EOL' when building shaders. Added error message for missing shader entry point.

bkaradzic %!s(int64=13) %!d(string=hai) anos
pai
achega
cc69b20e14

+ 0 - 10
examples/06-bump/fs_bump.sc

@@ -41,16 +41,6 @@ vec4 powRgba(vec4 _rgba, float _pow)
 	return result;
 }
 
-vec4 toLinear(vec4 _rgba)
-{
-	return powRgba(_rgba, 2.2);
-}
-
-vec4 toGamma(vec4 _rgba)
-{
-	return powRgba(_rgba, 1.0/2.2);
-}
-
 vec3 calcLight(int _idx, mat3 _tbn, vec3 _wpos, vec3 _normal, vec3 _view)
 {
 	vec3 lp = u_lightPosRadius[_idx].xyz - _wpos;

BIN=BIN
examples/runtime/shaders/gles/fs_bump.bin


BIN=BIN
examples/runtime/shaders/glsl/fs_bump.bin


+ 10 - 0
makefile

@@ -78,6 +78,16 @@ osx-release64:
 	make -C .build/projects/gmake-osx config=release64
 osx: osx-debug32 osx-release32 osx-debug64 osx-release64
 
+rebuild-shaders:
+	make -C examples/01-cubes rebuild
+	make -C examples/02-metaballs rebuild
+	make -C examples/03-raymarch rebuild
+	make -C examples/04-mesh rebuild
+	make -C examples/05-instancing rebuild
+	make -C examples/06-bump rebuild
+	make -C examples/07-callback rebuild
+	make -C examples/08-update rebuild
+
 docs:
 	markdown README.md > .build/docs/readme.html
 

+ 12 - 8
src/dds.cpp

@@ -21,7 +21,9 @@ namespace bgfx
 #define DDS_DXT4 BX_MAKEFOURCC('D', 'X', 'T', '4')
 #define DDS_DXT5 BX_MAKEFOURCC('D', 'X', 'T', '5')
 #define DDS_ATI1 BX_MAKEFOURCC('A', 'T', 'I', '1')
+#define DDS_BC4U BX_MAKEFOURCC('B', 'C', '4', 'U')
 #define DDS_ATI2 BX_MAKEFOURCC('A', 'T', 'I', '2')
+#define DDS_BC5U BX_MAKEFOURCC('B', 'C', '5', 'U')
 
 #define D3DFMT_A16B16G16R16  36
 #define D3DFMT_A16B16G16R16F 113
@@ -466,34 +468,36 @@ bool parseDds(Dds& _dds, const Memory* _mem)
 		{
 		case DDS_DXT1:
 			type = TextureFormat::BC1;
-			blockSize = 8;
 			bpp = 4;
+			blockSize = 4*4*bpp/8;
 			break;
 
 		case DDS_DXT2:
 		case DDS_DXT3:
 			type = TextureFormat::BC2;
-			blockSize = 16;
-			bpp = 4;
+			bpp = 8;
+			blockSize = 4*4*bpp/8;
 			break;
 
 		case DDS_DXT4:
 		case DDS_DXT5:
 			type = TextureFormat::BC3;
-			blockSize = 16;
-			bpp = 4;
+			bpp = 8;
+			blockSize = 4*4*bpp/8;
 			break;
 
 		case DDS_ATI1:
+		case DDS_BC4U:
 			type = TextureFormat::BC4;
-			blockSize = 16;
 			bpp = 4;
+			blockSize = 4*4*bpp/8;
 			break;
 
 		case DDS_ATI2:
+		case DDS_BC5U:
 			type = TextureFormat::BC5;
-			blockSize = 16;
-			bpp = 4;
+			bpp = 8;
+			blockSize = 4*4*bpp/8;
 			break;
 
 		case D3DFMT_A16B16G16R16:

BIN=BIN
tools/bin/shaderc.exe


+ 159 - 152
tools/shaderc/shaderc.cpp

@@ -1478,96 +1478,103 @@ int main(int _argc, const char* _argv[])
 			}
 		}
 
-		const size_t padding = 16;
-		uint32_t size = (uint32_t)fsize(file);
- 		char* data = new char[size+padding];
- 		size = (uint32_t)fread(data, 1, size, file);
-		memset(&data[size], 0, padding);
-		fclose(file);
-
-		InOut shaderInputs;
-		InOut shaderOutputs;
-		uint32_t inputHash = 0;
-		uint32_t outputHash = 0;
-
-		const char* input = data;
-		while (input[0] == '$')
-		{
-			const char* str = input+1;
-			const char* eol = bx::streol(str);
-			const char* nl = bx::strnl(eol);
-			input = nl;
-
-			if (0 == strncmp(str, "input", 5) )
-			{
-				str += 5;
-				inputHash = parseInOut(shaderInputs, str, eol);
-			}
-			else if (0 == strncmp(str, "output", 6) )
+		const size_t padding = 16;
+		uint32_t size = (uint32_t)fsize(file);
+		char* data = new char[size+padding+1];
+		size = (uint32_t)fread(data, 1, size, file);
+		// Compiler generates "error X3000: syntax error: unexpected end of file"
+		// if input doesn't have empty line at EOF.
+		data[size] = '\n';
+		memset(&data[size+1], 0, padding);
+		fclose(file);
+
+		char* entry = strstr(data, "void main()");
+		if (NULL == entry)
+		{
+			fprintf(stderr, "Shader entry point 'void main()' is not found.\n");
+		}
+		else
+		{
+			InOut shaderInputs;
+			InOut shaderOutputs;
+			uint32_t inputHash = 0;
+			uint32_t outputHash = 0;
+
+			const char* input = data;
+			while (input[0] == '$')
 			{
-				str += 6;
-				outputHash = parseInOut(shaderOutputs, str, eol);
+				const char* str = input+1;
+				const char* eol = bx::streol(str);
+				const char* nl = bx::strnl(eol);
+				input = nl;
+
+				if (0 == strncmp(str, "input", 5) )
+				{
+					str += 5;
+					inputHash = parseInOut(shaderInputs, str, eol);
+				}
+				else if (0 == strncmp(str, "output", 6) )
+				{
+					str += 6;
+					outputHash = parseInOut(shaderOutputs, str, eol);
+				}
 			}
-		}
 
-		if (glsl)
-		{
-			preprocessor.writef(
-				"#define ivec2 vec2\n"
-				"#define ivec3 vec3\n"
-				"#define ivec4 vec4\n"
-				);
+			if (glsl)
+			{
+				preprocessor.writef(
+					"#define ivec2 vec2\n"
+					"#define ivec3 vec3\n"
+					"#define ivec4 vec4\n"
+					);
 
 
-			for (InOut::const_iterator it = shaderInputs.begin(), itEnd = shaderInputs.end(); it != itEnd; ++it)
-			{
-				VaryingMap::const_iterator varyingIt = varyingMap.find(*it);
-				if (varyingIt != varyingMap.end() )
+				for (InOut::const_iterator it = shaderInputs.begin(), itEnd = shaderInputs.end(); it != itEnd; ++it)
 				{
-					const Varying& var = varyingIt->second;
-					const char* name = var.m_name.c_str();
-					if (0 == strncmp(name, "a_", 2)
-					||  0 == strncmp(name, "i_", 2) )
+					VaryingMap::const_iterator varyingIt = varyingMap.find(*it);
+					if (varyingIt != varyingMap.end() )
 					{
-						preprocessor.writef("attribute %s %s;\n", var.m_type.c_str(), name);
-					}
-					else
-					{
-						preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), name);
+						const Varying& var = varyingIt->second;
+						const char* name = var.m_name.c_str();
+						if (0 == strncmp(name, "a_", 2)
+						||  0 == strncmp(name, "i_", 2) )
+						{
+							preprocessor.writef("attribute %s %s;\n", var.m_type.c_str(), name);
+						}
+						else
+						{
+							preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), name);
+						}
 					}
 				}
-			}
 
-			for (InOut::const_iterator it = shaderOutputs.begin(), itEnd = shaderOutputs.end(); it != itEnd; ++it)
-			{
-				VaryingMap::const_iterator varyingIt = varyingMap.find(*it);
-				if (varyingIt != varyingMap.end() )
+				for (InOut::const_iterator it = shaderOutputs.begin(), itEnd = shaderOutputs.end(); it != itEnd; ++it)
 				{
-					const Varying& var = varyingIt->second;
-					preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), var.m_name.c_str() );
+					VaryingMap::const_iterator varyingIt = varyingMap.find(*it);
+					if (varyingIt != varyingMap.end() )
+					{
+						const Varying& var = varyingIt->second;
+						preprocessor.writef("varying %s %s;\n", var.m_type.c_str(), var.m_name.c_str() );
+					}
 				}
 			}
-		}
-		else
-		{
-			preprocessor.writef(
-				"#define lowp\n"
-				"#define mediump\n"
-				"#define highp\n"
-				"#define ivec2 int2\n"
-				"#define ivec3 int3\n"
-				"#define ivec4 int4\n"
-				"#define vec2 float2\n"
-				"#define vec3 float3\n"
-				"#define vec4 float4\n"
-				"#define mat2 float2x2\n"
-				"#define mat3 float3x3\n"
-				"#define mat4 float4x4\n"
-				);
-
-			char* entry = strstr(data, "void main()");
-			if (NULL != entry)
+			else
 			{
+				preprocessor.writef(
+					"#define lowp\n"
+					"#define mediump\n"
+					"#define highp\n"
+					"#define ivec2 int2\n"
+					"#define ivec3 int3\n"
+					"#define ivec4 int4\n"
+					"#define vec2 float2\n"
+					"#define vec3 float3\n"
+					"#define vec4 float4\n"
+					"#define mat2 float2x2\n"
+					"#define mat3 float3x3\n"
+					"#define mat4 float4x4\n"
+					);
+
 				entry[4] = '_';
 
 				if (fragment)
@@ -1667,109 +1674,109 @@ int main(int _argc, const char* _argv[])
 						);
 				}
 			}
-		}
 
-		if (preprocessor.run(input) )
-		{
-			BX_TRACE("Input file: %s", filePath);
-			BX_TRACE("Output file: %s", outFilePath);
-
-			if (preprocessOnly)
+			if (preprocessor.run(input) )
 			{
-				bx::CrtFileWriter writer;
+				BX_TRACE("Input file: %s", filePath);
+				BX_TRACE("Output file: %s", outFilePath);
 
-				if (0 != writer.open(outFilePath) )
+				if (preprocessOnly)
 				{
-					fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
-					return false;
-				}
+					bx::CrtFileWriter writer;
 
-				if (glsl)
-				{
-					const char* profile = cmdLine.findOption('p', "profile");
-					if (NULL == profile)
+					if (0 != writer.open(outFilePath) )
 					{
-						writef(&writer, "#ifdef GL_ES\n");
-						writef(&writer, "precision highp float;\n");
-						writef(&writer, "#endif // GL_ES\n\n");
+						fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
+						return false;
 					}
-					else
+
+					if (glsl)
 					{
-						writef(&writer, "#version %s\n\n", profile);
+						const char* profile = cmdLine.findOption('p', "profile");
+						if (NULL == profile)
+						{
+							writef(&writer, "#ifdef GL_ES\n");
+							writef(&writer, "precision highp float;\n");
+							writef(&writer, "#endif // GL_ES\n\n");
+						}
+						else
+						{
+							writef(&writer, "#version %s\n\n", profile);
+						}
 					}
-				}
-				writer.write(preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() );
-				writer.close();
-
-				return EXIT_SUCCESS;
-			}
+					writer.write(preprocessor.m_preprocessed.c_str(), (int32_t)preprocessor.m_preprocessed.size() );
+					writer.close();
 
-			bool compiled = false;
+					return EXIT_SUCCESS;
+				}
 
-			{
-				bx::CrtFileWriter* writer = NULL;
+				bool compiled = false;
 
-				if (NULL != bin2c)
-				{
-					writer = new Bin2cWriter(bin2c);
-				}
-				else
 				{
-					writer = new bx::CrtFileWriter;
-				}
+					bx::CrtFileWriter* writer = NULL;
 
-				if (0 != writer->open(outFilePath) )
-				{
-					fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
-					return false;
-				}
+					if (NULL != bin2c)
+					{
+						writer = new Bin2cWriter(bin2c);
+					}
+					else
+					{
+						writer = new bx::CrtFileWriter;
+					}
 
-				if (fragment)
-				{
-					bx::write(writer, BGFX_CHUNK_MAGIC_FSH);
-					bx::write(writer, inputHash);
-				}
-				else
-				{
-					bx::write(writer, BGFX_CHUNK_MAGIC_VSH);
-					bx::write(writer, outputHash);
-				}
+					if (0 != writer->open(outFilePath) )
+					{
+						fprintf(stderr, "Unable to open output file '%s'.", outFilePath);
+						return false;
+					}
 
-				if (glsl)
-				{
-					compiled = compileGLSLShader(cmdLine, preprocessor.m_preprocessed, writer);
-				}
-				else
-				{
-					if (hlsl > 3)
+					if (fragment)
 					{
-						compiled = compileHLSLShaderDx11(cmdLine, preprocessor.m_preprocessed, writer);
+						bx::write(writer, BGFX_CHUNK_MAGIC_FSH);
+						bx::write(writer, inputHash);
 					}
 					else
 					{
-						compiled = compileHLSLShaderDx9(cmdLine, preprocessor.m_preprocessed, writer);
+						bx::write(writer, BGFX_CHUNK_MAGIC_VSH);
+						bx::write(writer, outputHash);
 					}
-				}
 
-				writer->close();
-				delete writer;
-			}
+					if (glsl)
+					{
+						compiled = compileGLSLShader(cmdLine, preprocessor.m_preprocessed, writer);
+					}
+					else
+					{
+						if (hlsl > 3)
+						{
+							compiled = compileHLSLShaderDx11(cmdLine, preprocessor.m_preprocessed, writer);
+						}
+						else
+						{
+							compiled = compileHLSLShaderDx9(cmdLine, preprocessor.m_preprocessed, writer);
+						}
+					}
 
-			if (compiled)
-			{
-				if (depends)
+					writer->close();
+					delete writer;
+				}
+
+				if (compiled)
 				{
-					std::string ofp = outFilePath;
-					ofp += ".d";
-					bx::CrtFileWriter writer;
-					if (0 == writer.open(ofp.c_str() ) )
+					if (depends)
 					{
-						writef(&writer, "%s : %s\n", outFilePath, preprocessor.m_depends.c_str() );
-						writer.close();
+						std::string ofp = outFilePath;
+						ofp += ".d";
+						bx::CrtFileWriter writer;
+						if (0 == writer.open(ofp.c_str() ) )
+						{
+							writef(&writer, "%s : %s\n", outFilePath, preprocessor.m_depends.c_str() );
+							writer.close();
+						}
 					}
-				}
 
-				return EXIT_SUCCESS;
+					return EXIT_SUCCESS;
+				}
 			}
 		}