Giter Site home page Giter Site logo

gathertown / webgl-gpu-power-estimation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gkjohnson/webgl-gpu-power-estimation

0.0 0.0 0.0 2.53 MB

Utility for estimating the power of the GPU in the browser using WebGL debug parameters.

Home Page: https://gkjohnson.github.io/webgl-gpu-power-estimation/example/

License: MIT License

JavaScript 72.07% HTML 27.93%

webgl-gpu-power-estimation's Introduction

webgl-gpu-power-estimation

Catering a 3d web-based experience to the power of a target platform is difficult with such a small amount of information available about the current graphics hardware. This utility aims to provide performance information about the current hardware by guessing the type of graphics hardware using webgl UNMASKED_RENDERER_WEBGL parameter and looking it up in a provided list of hardware.

See your hardware info here!

Example Data Information

Data used in the example is for demonstration purposes. See the webgl-gpu-power-estimation-data repo for more information.

Matching the Graphics Hardware Name

The values from UNMASKED_RENDERER_WEBGL are irregular and relatively unpredictable. To find the corresponding hardware in the database list we

  • Check if there is a version number in the current GPU hardware name.
  • Filter the database of GPUs to those that include that version number (or to those that have no version number if none was found).
  • From that list pick the hardware the has the most matching tokens between the names.

Installation

The package can be installed using npm via the Github repo by adding this to the package.json dependencies. See [here] for more information.

"webgl-gpu-power-estimation": "gkjohnson/webgl-gpu-power-estimation@<release>"

Use

import { getDetailedInfo, getBasicInfo } from 'gpu-power-estimate';

fetch( './path/to/database.json' )
  .then( res => res.json() )
  .then( database => {

    // get the hardware information
    const canvas = document.createElement( 'canvas' );
    const gl = canvas.getContext( 'webgl' );
    const basicInfo = getBasicInfo( gl );
    const detailedInfo = getDetailedInfo( database, gl );

    // scale the application
    const capability = detailedInfo ? detailedInfo.performance : 0;
    if ( capability > 6000 ) {

      // initialize highest fidelity scene

    } else if ( capability > 3000 ) {

      // initialize moderately complex scene

    } else {

      // initialize simplified scene

    }

  } );

API

getBasicInfo

getBasicInfo( context = null : WebGLContext ) : Object | null

Returns some basic info about the hardware based on the WEBGL_debug_renderer_info extension or null if it's unavailable.

If the context is not provided then a temporary one will be created.

{
  // The full graphics hardware
  name,

  // A guess as to whether or not the hardware is integrated graphics
  integrated,

  // The raw unmasked fields returned from the extension
  unmasked: { vendor, renderer }

}

getDetailedInfo

getDetailedInfo(
  database : Object,
  contextOrCard = null : WebGLContext | string
) : Object | null

Returns more detailed hardware information based on the information in the provided database. The database is expected to be an object where the keys are the names of graphics hardware and the values are objects with detail information.

The database argument is expected to be an object with GPU names as key entries and an object of detailed information as a result. The value of the closest matching key will be returned.

If a WebGL context or card name to search is not provided then a temporary context will be created.

Caveats

For privacy reasons the availability of the UNMASKED_RENDERER_WEBGL parameter may be disabled in which case no estimate can be provided.

References

webgl-gpu-power-estimation's People

Contributors

dependabot[bot] avatar gkjohnson avatar oletus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.