Error Display::initialize() { // Re-initialize default platform if it's needed InitDefaultPlatformImpl(); SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS"); TRACE_EVENT0("gpu.angle", "egl::Display::initialize"); ASSERT(mImplementation != nullptr); if (isInitialized()) { return Error(EGL_SUCCESS); } Error error = mImplementation->initialize(this); if (error.isError()) { // Log extended error message here std::stringstream errorStream; errorStream << "ANGLE Display::initialize error " << error.getID() << ": " << error.getMessage(); ANGLEPlatformCurrent()->logError(errorStream.str().c_str()); return error; } mCaps = mImplementation->getCaps(); mConfigSet = mImplementation->generateConfigs(); if (mConfigSet.size() == 0) { mImplementation->terminate(); return Error(EGL_NOT_INITIALIZED); } initDisplayExtensions(); initVendorString(); if (mDisplayExtensions.deviceQuery) { rx::DeviceImpl *impl = nullptr; error = mImplementation->getDevice(&impl); if (error.isError()) { return error; } mDevice = new Device(this, impl); } else { mDevice = nullptr; } mInitialized = true; return Error(EGL_SUCCESS); }
Error Display::initialize() { // Re-initialize default platform if it's needed InitDefaultPlatformImpl(); SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.DisplayInitializeMS"); TRACE_EVENT0("gpu.angle", "egl::Display::initialize"); ASSERT(mImplementation != nullptr); if (isInitialized()) { return egl::Error(EGL_SUCCESS); } Error error = mImplementation->initialize(this); if (error.isError()) { // Log extended error message here std::stringstream errorStream; errorStream << "ANGLE Display::initialize error " << error.getID() << ": " << error.getMessage(); ANGLEPlatformCurrent()->logError(errorStream.str().c_str()); return error; } mCaps = mImplementation->getCaps(); mConfigSet = mImplementation->generateConfigs(); if (mConfigSet.size() == 0) { mImplementation->terminate(); return Error(EGL_NOT_INITIALIZED); } initDisplayExtensions(); initVendorString(); // Populate the Display's EGLDeviceEXT if the Display wasn't created using one if (mPlatform != EGL_PLATFORM_DEVICE_EXT) { if (mDisplayExtensions.deviceQuery) { rx::DeviceImpl *impl = nullptr; ANGLE_TRY(mImplementation->getDevice(&impl)); ANGLE_TRY(Device::CreateDevice(this, impl, &mDevice)); } else { mDevice = nullptr; } } else { // For EGL_PLATFORM_DEVICE_EXT, mDevice should always be populated using // an external device ASSERT(mDevice != nullptr); } mInitialized = true; return egl::Error(EGL_SUCCESS); }
gl::Error HLSLCompiler::compileToBinary(gl::InfoLog &infoLog, const std::string &hlsl, const std::string &profile, const std::vector<CompileConfig> &configs, const D3D_SHADER_MACRO *overrideMacros, ID3DBlob **outCompiledBlob, std::string *outDebugInfo) { ASSERT(mInitialized); #if !defined(ANGLE_ENABLE_WINDOWS_STORE) ASSERT(mD3DCompilerModule); #endif ASSERT(mD3DCompileFunc); #if !defined(ANGLE_ENABLE_WINDOWS_STORE) if (gl::DebugAnnotationsActive()) { std::string sourcePath = getTempPath(); std::string sourceText = FormatString("#line 2 \"%s\"\n\n%s", sourcePath.c_str(), hlsl.c_str()); writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size()); } #endif const D3D_SHADER_MACRO *macros = overrideMacros ? overrideMacros : nullptr; for (size_t i = 0; i < configs.size(); ++i) { ID3DBlob *errorMessage = nullptr; ID3DBlob *binary = nullptr; HRESULT result = S_OK; { TRACE_EVENT0("gpu.angle", "D3DCompile"); SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.D3DCompileMS"); result = mD3DCompileFunc(hlsl.c_str(), hlsl.length(), gl::g_fakepath, macros, nullptr, "main", profile.c_str(), configs[i].flags, 0, &binary, &errorMessage); } if (errorMessage) { std::string message = reinterpret_cast<const char*>(errorMessage->GetBufferPointer()); SafeRelease(errorMessage); infoLog.appendSanitized(message.c_str()); TRACE("\n%s", hlsl.c_str()); TRACE("\n%s", message.c_str()); if ((message.find("error X3531:") != std::string::npos || // "can't unroll loops marked with loop attribute" message.find("error X4014:") != std::string::npos) && // "cannot have gradient operations inside loops with divergent flow control", // even though it is counter-intuitive to disable unrolling for this error, // some very long shaders have trouble deciding which loops to unroll and // turning off forced unrolls allows them to compile properly. macros != nullptr) { macros = nullptr; // Disable [loop] and [flatten] // Retry without changing compiler flags i--; continue; } } if (SUCCEEDED(result)) { *outCompiledBlob = binary; (*outDebugInfo) += "// COMPILER INPUT HLSL BEGIN\n\n" + hlsl + "\n// COMPILER INPUT HLSL END\n"; #if ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED (*outDebugInfo) += "\n\n// ASSEMBLY BEGIN\n\n"; (*outDebugInfo) += "// Compiler configuration: " + configs[i].name + "\n// Flags:\n"; for (size_t fIx = 0; fIx < ArraySize(CompilerFlagInfos); ++fIx) { if (IsCompilerFlagSet(configs[i].flags, CompilerFlagInfos[fIx].mFlag)) { (*outDebugInfo) += std::string("// ") + CompilerFlagInfos[fIx].mName + "\n"; } } (*outDebugInfo) += "// Macros:\n"; if (macros == nullptr) { (*outDebugInfo) += "// - : -\n"; } else { for (const D3D_SHADER_MACRO *mIt = macros; mIt->Name != nullptr; ++mIt) { (*outDebugInfo) += std::string("// ") + mIt->Name + " : " + mIt->Definition + "\n"; } } std::string disassembly; ANGLE_TRY(disassembleBinary(binary, &disassembly)); (*outDebugInfo) += "\n" + disassembly + "\n// ASSEMBLY END\n"; #endif // ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED return gl::NoError(); } if (result == E_OUTOFMEMORY) { *outCompiledBlob = nullptr; return gl::Error(GL_OUT_OF_MEMORY, "HLSL compiler had an unexpected failure, result: 0x%X.", result); } infoLog << "Warning: D3D shader compilation failed with " << configs[i].name << " flags. (" << profile << ")"; if (i + 1 < configs.size()) { infoLog << " Retrying with " << configs[i + 1].name; } } // None of the configurations succeeded in compiling this shader but the compiler is still intact *outCompiledBlob = nullptr; return gl::NoError(); }