nx_gpu_choice_emit.nx
buildroot/runtime/nx_gpu_choice_emit.nx
about
Reusable browser graphics control emitted by Nishi; OS preferences remain an explicit user action.
dependencies 0 imports · 9 importers
imports: none
imported by: nx_game_page_emit.nxnx_game_page_imported_body_t45.nxnx_game_page_knight_bind_t25.nxnx_game_page_knight_feedback_t28.nxnx_game_page_knight_feedback_t29.nxnx_game_page_knight_support_t31.nxnx_game_page_knight_support_t31_before_t44.nxnx_game_page_recovery_feedback_t28.nxnx_game_page_recovery_t23.nx
structs
| none |
consts
| none |
functions
| 2 | func ngc_source() -> *u8 { return "const NX_GPU_CHOICES=[['default','Browser default'],['high-performance','High performance'],['low-power','Power saving']];\nfunction nxGpuPreference(){const v=new URL(location.href).searchParams.get('gpuPreference');return NX_GPU_CHOICES.some(x=>x[0]===v)?v:'default';}\nfunction nxGpuAdapterOptions(){const v=nxGpuPreference();return v==='default'?{}:{powerPreference:v};}\nfunction nxGpuAdapterReport(ad){\n const i=ad.info;\n const fields=['vendor','architecture','device','description'];\n const report={state:'unavailable',selection:nxGpuPreference(),scope:'active-webgpu-device',observed_at:new Date().toISOString(),isFallbackAdapter:i&&typeof i.isFallbackAdapter==='boolean'?i.isFallbackAdapter:null};\n for(const k of fields)report[k]=i&&typeof i[k]==='string'&&i[k].trim()?i[k]:null;\n if(fields.some(k=>report[k]))report.state='reported';\n window.__nx_gpu_adapter=report;\n nxGpuChoiceRefresh();\n}\nfunction nxGpuChoiceRefresh(){\n const node=document.getElementById('nx-graphics-status');if(!node)return;\n const r=window.__nx_gpu_adapter;\n if(!r){node.textContent=navigator.gpu?'WebGPU adapter has not been established.':'WebGPU is unavailable in this browser.';return;}\n const name=[r.vendor,r.architecture,r.description,r.device].filter(Boolean).join(' / ');\n node.textContent=name?'Active WebGPU adapter: '+name:'WebGPU is active; this browser does not disclose the adapter identity.';\n if(r.isFallbackAdapter===true)node.textContent+=' Software or fallback adapter reported.';\n}\nfunction nxGpuChoiceMount(){\n if(document.getElementById('nx-graphics-choice'))return;\n const box=document.createElement('details');box.id='nx-graphics-choice';\n box.style.cssText='position:fixed;right:12px;bottom:12px;z-index:10000;max-width:min(360px,calc(100vw - 24px));max-height:70vh;overflow:auto;background:#161c25;color:#f1f5f9;border:1px solid #64748b;border-radius:10px;padding:10px 14px;font:14px/1.5 system-ui;box-sizing:border-box';\n const title=document.createElement('summary');title.textContent='Graphics / Performance';title.style.cursor='pointer';box.append(title);\n const status=document.createElement('p');status.id='nx-graphics-status';status.setAttribute('aria-live','polite');box.append(status);\n const label=document.createElement('label');label.htmlFor='nx-graphics-preference';label.textContent='GPU preference ';box.append(label);\n const select=document.createElement('select');select.id='nx-graphics-preference';\n for(const [value,text] of NX_GPU_CHOICES){const o=document.createElement('option');o.value=value;o.textContent=text;select.append(o);}\n select.value=nxGpuPreference();select.disabled=!navigator.gpu;box.append(select);\n const note=document.createElement('p');note.textContent='This requests a GPU preference. Your browser and operating system choose the adapter; a switch is not guaranteed.';box.append(note);\n const apply=document.createElement('button');apply.type='button';apply.textContent='Apply and reload';apply.disabled=!navigator.gpu;\n apply.addEventListener('click',()=>{const u=new URL(location.href);if(select.value==='default')u.searchParams.delete('gpuPreference');else u.searchParams.set('gpuPreference',select.value);location.assign(u.href);});box.append(apply);\n const warning=document.createElement('p');warning.textContent='Reloading restarts this scene. The choice is carried in this page URL.';box.append(warning);\n const help=document.createElement('details');const heading=document.createElement('summary');heading.textContent='Still using the wrong GPU?';help.append(heading);\n const instructions=document.createElement('p');instructions.textContent='On Windows: Settings > System > Display > Graphics. Select your browser application, choose High performance with the GPU you want, save, then fully restart the browser. Check the active adapter again. This webpage cannot change that Windows setting.';help.append(instructions);box.append(help);\n for(const type of ['keydown','keyup','pointerdown','pointerup','click','wheel'])box.addEventListener(type,e=>e.stopPropagation());\n box.addEventListener('toggle',nxGpuChoiceRefresh);\n document.body.append(box);nxGpuChoiceRefresh();\n}\nif(document.readyState==='loading')document.addEventListener('DOMContentLoaded',nxGpuChoiceMount,{once:true});else nxGpuChoiceMount();\n" as *u8 } |