void Shader::compileToHLSL(void *compiler) { // ensure we don't pass a NULL source to the compiler const char *source = "\0"; if (mSource) { source = mSource; } // ensure the compiler is loaded initializeCompiler(); int compileOptions = SH_OBJECT_CODE; std::string sourcePath; if (perfActive()) { sourcePath = ""; writeFile(sourcePath.c_str(), source, strlen(source)); compileOptions |= SH_LINE_DIRECTIVES; } int result; if (sourcePath.empty()) { result = ShCompile(compiler, &source, 1, compileOptions); } else { const char* sourceStrings[2] = { sourcePath.c_str(), source }; result = ShCompile(compiler, sourceStrings, 2, compileOptions | SH_SOURCE_PATH); } if (result) { size_t objCodeLen = 0; ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen); mHlsl = new char[objCodeLen]; ShGetObjectCode(compiler, mHlsl); void *activeUniforms; ShGetInfoPointer(compiler, SH_ACTIVE_UNIFORMS_ARRAY, &activeUniforms); mActiveUniforms = *(sh::ActiveUniforms*)activeUniforms; } else { size_t infoLogLen = 0; ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen); mInfoLog = new char[infoLogLen]; ShGetInfoLog(compiler, mInfoLog); TRACE("\n%s", mInfoLog); } }
ScopedPerfEventHelper::~ScopedPerfEventHelper() { #if defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) if (perfActive()) { D3DPERF_EndEvent(); } #endif }
ScopedPerfEventHelper::~ScopedPerfEventHelper() { #if !defined(ANGLE_DISABLE_PERF) if (perfActive()) { D3DPERF_EndEvent(); } #endif }
ScopedPerfEventHelper::~ScopedPerfEventHelper() { #if defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) if (perfActive()) { g_DebugAnnotationWrapper->endEvent(); } #endif }
void Shader::compileToHLSL(void *compiler) { if (isCompiled() || !mSource) { return; } delete[] mInfoLog; mInfoLog = NULL; int compileOptions = SH_OBJECT_CODE; std::string sourcePath; if (perfActive()) { sourcePath = getTempPath(); writeFile(sourcePath.c_str(), mSource, strlen(mSource)); compileOptions |= SH_LINE_DIRECTIVES; } int result; if (sourcePath.empty()) { result = ShCompile(compiler, &mSource, 1, compileOptions); } else { const char* sourceStrings[2] = { sourcePath.c_str(), mSource }; result = ShCompile(compiler, sourceStrings, 2, compileOptions | SH_SOURCE_PATH); } if (result) { int objCodeLen = 0; ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen); mHlsl = new char[objCodeLen]; ShGetObjectCode(compiler, mHlsl); } else { int infoLogLen = 0; ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen); mInfoLog = new char[infoLogLen]; ShGetInfoLog(compiler, mInfoLog); TRACE("\n%s", mInfoLog); } }
ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...) { #if !defined(ANGLE_DISABLE_PERF) #if defined(ANGLE_DISABLE_TRACE) if (!perfActive()) { return; } #endif va_list vararg; va_start(vararg, format); output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg); va_end(vararg); #endif }
ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...) { #if !defined(ANGLE_ENABLE_DEBUG_TRACE) if (!perfActive()) { return; } #endif // !ANGLE_ENABLE_DEBUG_TRACE va_list vararg; va_start(vararg, format); #if defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg); #else output(true, NULL, format, vararg); #endif // ANGLE_ENABLE_DEBUG_ANNOTATIONS va_end(vararg); }
ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...) { #if !defined(ANGLE_ENABLE_DEBUG_TRACE) if (!perfActive()) { return; } #endif // !ANGLE_ENABLE_DEBUG_TRACE va_list vararg; va_start(vararg, format); #if defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) output(true, DebugTraceOutputTypeBeginEvent, format, vararg); #else output(true, DebugTraceOutputTypeNone, format, vararg); #endif // ANGLE_ENABLE_DEBUG_ANNOTATIONS va_end(vararg); }
static void output(bool traceInDebugOnly, DebugTraceOutputType outputType, const char *format, va_list vararg) { #if defined(ANGLE_ENABLE_DEBUG_ANNOTATIONS) static std::vector<char> buffer(512); if (perfActive()) { size_t len = FormatStringIntoVector(format, vararg, buffer); std::wstring formattedWideMessage(buffer.begin(), buffer.begin() + len); switch (outputType) { case DebugTraceOutputTypeNone: break; case DebugTraceOutputTypeBeginEvent: g_DebugAnnotationWrapper->beginEvent(formattedWideMessage); break; case DebugTraceOutputTypeSetMarker: g_DebugAnnotationWrapper->setMarker(formattedWideMessage); break; } } #endif // ANGLE_ENABLE_DEBUG_ANNOTATIONS #if defined(ANGLE_ENABLE_DEBUG_TRACE) #if defined(NDEBUG) if (traceInDebugOnly) { return; } #endif // NDEBUG std::string formattedMessage = FormatString(format, vararg); static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app); if (file) { file.write(formattedMessage.c_str(), formattedMessage.length()); file.flush(); } #if defined(ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER) OutputDebugStringA(formattedMessage.c_str()); #endif // ANGLE_ENABLE_DEBUG_TRACE_TO_DEBUGGER #endif // ANGLE_ENABLE_DEBUG_TRACE }
void Shader::compileToHLSL(void *compiler) { // ensure the compiler is loaded initializeCompiler(); int compileOptions = SH_OBJECT_CODE; std::string sourcePath; if (perfActive()) { sourcePath = getTempPath(); writeFile(sourcePath.c_str(), mSource.c_str(), mSource.length()); compileOptions |= SH_LINE_DIRECTIVES; } int result; if (sourcePath.empty()) { const char* sourceStrings[] = { mSource.c_str(), }; result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions); } else { const char* sourceStrings[] = { sourcePath.c_str(), mSource.c_str(), }; result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions | SH_SOURCE_PATH); } size_t shaderVersion = 100; ShGetInfo(compiler, SH_SHADER_VERSION, &shaderVersion); mShaderVersion = static_cast<int>(shaderVersion); if (shaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3) { mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts"; TRACE("\n%s", mInfoLog.c_str()); } else if (result) { size_t objCodeLen = 0; ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen); char* outputHLSL = new char[objCodeLen]; ShGetObjectCode(compiler, outputHLSL); #ifdef _DEBUG std::ostringstream hlslStream; hlslStream << "// GLSL\n"; hlslStream << "//\n"; size_t curPos = 0; while (curPos != std::string::npos) { size_t nextLine = mSource.find("\n", curPos); size_t len = (nextLine == std::string::npos) ? std::string::npos : (nextLine - curPos + 1); hlslStream << "// " << mSource.substr(curPos, len); curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1); } hlslStream << "\n\n"; hlslStream << outputHLSL; mHlsl = hlslStream.str(); #else mHlsl = outputHLSL; #endif delete[] outputHLSL; void *activeUniforms; ShGetInfoPointer(compiler, SH_ACTIVE_UNIFORMS_ARRAY, &activeUniforms); mActiveUniforms = *(std::vector<Uniform>*)activeUniforms; void *activeInterfaceBlocks; ShGetInfoPointer(compiler, SH_ACTIVE_INTERFACE_BLOCKS_ARRAY, &activeInterfaceBlocks); mActiveInterfaceBlocks = *(std::vector<InterfaceBlock>*)activeInterfaceBlocks; } else { size_t infoLogLen = 0; ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen); char* infoLog = new char[infoLogLen]; ShGetInfoLog(compiler, infoLog); mInfoLog = infoLog; TRACE("\n%s", mInfoLog.c_str()); } }