コード例 #1
0
        /// <summary>
        /// Looks through all available devices and estimates which one will have the best performance
        /// </summary>
        public DeviceEntry GetBestDevice()
        {
            DeviceEntry best     = null;
            float       bestRank = 0.0f;

            if (FoundDevices != null)
            {
                foreach (DeviceEntry dev in FoundDevices)
                {
                    if (dev.PerformanceRating > bestRank)
                    {
                        bestRank = dev.PerformanceRating;
                        best     = dev;
                    }
                }
            }

            return(best);
        }
コード例 #2
0
        /// <summary>
        /// Select a device to use based on the current configuration. If no device can be found, this throws NoDevicesFoundException
        /// </summary>
        private DeviceEntry chooseDevice()
        {
            if (mainForm.Renderer.Context == null || FoundDevices == null)            //if there's no graphics context, bail out
            {
                return(null);
            }

            DeviceEntry chosenDev = null;

            //first try to find a device with the same type and ID as the one in the config
            foreach (DeviceEntry dev in FoundDevices)
            {
                if (dev.EngineType == mainForm.Config.EngineType && dev.ID == mainForm.Config.DeviceID)
                {
                    chosenDev = dev;
                }
            }

            //if no match was found, just pick the best device
            if (chosenDev == null)
            {
                chosenDev = GetBestDevice();
            }

            //ok, if still no device is found, then we are in trouble
            if (chosenDev == null)
            {
                Exception cpuEx = null;
                try{
                    CPUDeviceEntry.CheckSupport();
                }
                catch (Exception ex) {
                    cpuEx = ex;
                }
                throw new NoDevicesFoundException("No compatable devices were found.", cpuEx);
            }

            return(chosenDev);
        }
コード例 #3
0
        private void switchState(FractalEngineState rs)
        {
            FractalEngineState cs = this.EngineState;                     //the current engine state

            try{
                if (rs == cs)
                {
                    return;                     //they match, do nothing
                }
                else if (cs == FractalEngineState.Online)
                {
                    if (rs == FractalEngineState.Suspended)                    //go from online to suspended
                    {
                        engine.Deallocate();
                    }
                    else if (rs == FractalEngineState.Offline)                    //go from online to offline
                    {
                        shutdownEngine();
                    }
                }
                else if (cs == FractalEngineState.Suspended)
                {
                    if (rs == FractalEngineState.Online)                    //go from suspended to online
                    {
                        allocateEngine();
                    }
                    else if (rs == FractalEngineState.Offline)                    //go from suspended to offline
                    {
                        shutdownEngine();
                    }
                }
                else if (cs == FractalEngineState.Offline)
                {
                    if (rs == FractalEngineState.Online)                             //go from offline to online
                    {
                        deviceEntry = chooseDevice();
                        engine      = deviceEntry.CreateFractalEngine(mainForm.Renderer.Context);
                        allocateEngine();
                    }
                    else if (rs == FractalEngineState.Suspended)                     //go from offline to suspended
                    {
                        deviceEntry = chooseDevice();
                        engine      = deviceEntry.CreateFractalEngine(mainForm.Renderer.Context);
                    }
                }
                else if (cs == FractalEngineState.Error)
                {
                    if (rs == FractalEngineState.Offline)                                //go from error to offline
                    {
                        shutdownEngine();
                    }
                }
            }
            catch (Exception ex)            //if something goes wrong, switch to the error state
            {
                shutdownEngine();
                if (ex is NoDevicesFoundException)
                {
                    currentException = ex;
                }
                else
                {
                    currentException = new FractalEngineStateException(deviceEntry == null ? EngineType.Auto : deviceEntry.EngineType, cs, rs, ex);
                }
            }
        }