1 Copyright © Oracle Corporation, 2001. All rights reserved. Programación en ensamblador.
Ensamblador ARB Vertex Program v1.0
description
Transcript of Ensamblador ARB Vertex Program v1.0
Ensamblador ARB Vertex Program v1.0Jordi Roca Monfort
30 de Junio del 2004
Parte 1: El ensamblador implementado
Arquitectura Ensamblador!!ARBvp1.0PARAM arr[5] = { program.env[0..4] };#ADDRESS addr;ATTRIB v1 = vertex.attrib[1];PARAM par1 = program.local[0];OUTPUT oPos = result.position;OUTPUT oCol = result.color.front.primary;OUTPUT oTex = result.texcoord[2];ARL addr.x, v1.x;MOV res, arr[addr.x - 1];END
Análisis léxico – Sintáctico
(Flex + Bison)
Análisis Semántico
(casi completo)
!!ARBvp1.0
AST
Tabla símbolos
InsertarST(“arr”,5, ENV_PARAMETER)
GeneraciónCódigo
EspecíficoGPU
Genérico
Line:By0By1By2By3By4By5By6By7By8By9ByAByBByByDByEByF 011: 16 00 03 28 00 01 00 08 26 1b 6a 00 0f 1b 04 78 012: 09 00 03 00 00 00 02 08 24 1b 1b 00 08 1b 14 18 013: 09 00 04 00 00 00 02 08 24 1b 1b 00 04 1b 14 b8 014: 09 00 05 00 00 00 02 08 24 1b 1b 00 02 1b 04 58 015: 09 00 06 00 00 00 02 08 24 1b 1b 00 01 1b 04 f8 016: 16 00 01 00 00 00 02 30 24 1b 1b 00 08 1b 14 98 017: 16 00 02 00 00 01 02 30 24 1b 1b 00 08 1b 04 38 018: 16 00 00 00 00 00 03 30 24 00 1b 00 02 1b 04 d8 019: 16 00 01 00 00 00 03 30 24 00 1b 00 01 1b 14 78 020: 01 00 08 00 00 08 18 08 24 04 ae 00 0c 1b 04 18 021: 17 00 00 00 00 00 13 30 24 00 00 00 08 1b 04 b8 022: 17 00 01 00 00 00 13 30 24 00 00 00 04 1b 14 58 023: 01 00 08 00 00 09 18 08 24 04 04 00 0c 1b 14 f8 024: 01 00 08 00 00 0a 18 08 26 04 ae 00 0c 1b 04 98 025: 01 00 08 00 00 0b 18 08 26 04 04 00 0c 1b 14 38
Arquitectura Ensamblador (2) Generación de código
2 fases: Front-End: Traducción a instrucciones y bancos de registros
genéricos. Back-End: Traducción a instrucciones y bancos de registros
de la GPU. Justificación:
Separar código dependiente sólo de la especificación y código dependiente de la GPU:
Abstraer limitaciones de la GPU (un solo operando direccionado de forma relativa, una sola lectura por instrucción al banco de parametros).
Cambiar la tecnología de la shader unit implica cambiar sólo el código dependiente
ARB Vertex Program v1.0 model
Vertex Attributes
ARB Vertex Program
1.0
Vertex Result Registers
Nx4 registers (N 16)
M instructions (M 128)
Program Local Parameters
Lx4 registers (L 96)
Temporary Variables
Tx4 variables (T 12)
Program Environment Parameters
Ex4 registers (E 96)
Rx4 registers (R 8)
Address Variables
Ax4 variables (A 1)
Program Constant Parameters
Lx4 registers (L 96)
Todos los bancos:3 puertos de lectura!!
Direccionamiento relativo en los 3 operandos!!
NV Vertex Shader 2.0 modelConstant
Memory
256 entries
128 bits4 floats
16 entries
21 entries
16 entries
Vertex Input
Vertex Output
Temporaries Registers NV Vertex
Shader 2.0
A0
64k instructions with branchs
addr
data
128 bits4 floats
128 bits4 floats
128 bits4 floats
A1
CC register
Temporaries Bank: 3p Constant Memory: 1p Vertex Input: 1p
Necesidad de código independienteRef (ARB1_0_vertex_program.txt) Issues section, Issue 14,
line 441 "What semantic restrictions, if any, should be imposed on
using multiple vertex attributes or program parameters in the same instruction?
RESOLVED: None. If the underlying hardware implementation does not support reads of multiple attributes or program parameters, the driver may need to transparently insert additional instructions and/or consume temporaries to perform the operation."
Necesidad de código independiente (2)NV VP2 Instructions Limitations:Ref (NV_vertex_program2.txt) Section 2.14.1.8, Vertex Program Specificationsubsection Semantic Restrictions
"A vertex program fails to load if any instruction sources more than one unique program parameter register. An instruction can match the<progParamRegister> rule more than once only if all such matches are identical.
A vertex program fails to load if any instruction sources more than oneunique vertex attribute register. An instruction can match the<vtxAttribRegister> rule more than once only if all such matches refer tothe same register."
Prefetch de operandos (caso1)
ARBVP1.0 NV30 VS2.0
MAD r3, c0 , c1, c2 MOV r0, c0
MOV r3, c1
MAD r3, r0 , r3, c2
3 lecturas al banco de constantes en lamisma instrucción
Prefetch de operandos (caso2)
ARBVP1.0 NV30 VS2.0
ADD r3, c0[a0.x] , c1[a0.x + 4] MOV r3, c0[a0.x]
ADD r3, r3 , c1[a0.x + 4]
2 accesos relativos albanco de constantesen la misma instrucción
Instrucciones no soportadas (SUB)
ARBVP1.0 NV30 VS2.0
SUB r3, r1, r2 ADD r3, r1, -r2
Instrucciones no soportadas (ABS)
ARBVP1.0 NV30 VS2.0
ABS r2, r1 MAX r2, r1, -r1
Instrucciones no soportadas (POW)
ARBVP1.0 NV30 VS2.0
POW r3.xy, r1.x, r2.y
LOG r3.x, r1.x;MUL r3.x, r3.x, r2.y;
EXP r3.xy, r3.x;
ab = 2 (b x log 2(a))
Si a es potencia de 2resultado exacto:
43 = 2 (3 x log 2(4));43 = 2 (3 x 2);43 = 2 6;
Si no, hay perdidade precisión:
33 = 2 (3 x log 2(3));33 = 2 (3 x 1.5849);33 = 2 4.7547;
Instrucciones no soportadas (XPD)
ARBVP1.0 NV30 VS2.0
XPD r3, r1, r2 MUL r3.xyz, r1.zxy, r2.yzx;MAD r3.xyz, r1.yzx, r2.zxy, - r3.xyz;
Ojo: los operandos pueden tener swizzles masks !!
Hay que componer las swizzles !!Composición de permutaciones
a x b = (aybz – azby,
azbx – axbz,
axby – aybx)
Instrucciones no soportadas (SWZ)
ARBVP1.0 NV30 VS2.0
SWZ r3, r0, -1,0,x,-w
r0 r3
1.0
2.3
4.7
1.2
-1.0
0.0
1.0
-1.2
Constant Memory
MAD r3, r0.xxxw, c1.xxyz, c1.zxxx
0.0 1.0 -1.0 0.0c1
1.0
1.0
1.0
1.2
=
-1.0
0.0
1.0
-1.2
=
0.0
0.0
1.0
-1.2
0.0
0.0
1.0
-1.0
X +
-1.0
0.0
0.0
0.0
Parte 2: Integración con la librería
Soporte OpenGL para Vertex Program Los atributos de un vertice se transforman antes
de primitive assembly y rasterización. La transformación se puede hacer con 2 modos:
OpenGL conventional T&L mode Vertex Program mode
Para establecer este modo:
void Enable(VERTEX_PROGRAM_ARB);
Concepto de program target
Target = tipo de programa ARB La extensión ARB vertex program proporciona
llamadas en las que se especifica el tipo de programa: La misma extensión especifica nuevos tipos de
programas. Esta extensión incluye solo un tipo: VERTEX_PROGRAM_ARB
Para nuevos tipos de programas de futuras extensiones
FRAGMENT_PROGRAM_ARB
Concepto de program target Ejemplo: carga de un vertex program:
Paso 1: generamos un identificador único para cualquier tipo de programa.
glGenProgramsARB( 1, &progid ); Paso 2: creamos un objeto (program object) con el
identificador y este se asocia al tipo de programa. El nuevo objeto pasa a ser el current program del tipo de programa:
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, progid );
podemos tener varios programas del mismo tipo pero solamente el current (el especificado con el último glBindProgramARB()) es el que se aplica.
Concepto de program target
Ejemplo: carga de un vertex program: Paso 3: especificamos el programa del objeto current para
un tipo de programa:glProgramStringARB( GL_VERTEX_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen(myProgString), myProgString ); En este momento se compila el programa. Paso 4: Con
glGetIntergv(GL_PROGRAM_ERROR_POSITION_ARB,&errPos );
glGetString( GL_PROGRAM_ERROR_STRING_ARB,&errString );
comprovamos errores de compilación.
Estado de un programa Se mantiene en el program object:
progid
param.local[0..96]
Used Stats
Line:By0By1By2By3By4By5By6By7By8By9ByAByBBy 011: 16 00 03 28 00 01 00 08 26 1b 6a 00 012: 09 00 03 00 00 00 02 08 24 1b 1b 00 013: 09 00 04 00 00 00 02 08 24 1b 1b 00 04 014: 09 00 05 00 00 00 02 08 24 1b 1b 00 015: 09 00 06 00 00 00 02 08 24 1b 1b 00 01016: 16 00 01 00 00 00 02 30 24 1b 1b 00 08017: 16 00 02 00 00 01 02 30 24 1b 1b 00 08018: 16 00 00 00 00 00 03 30 24 00 1b 00 02019: 16 00 01 00 00 00 03 30 24 00 1b 00 01
Program object
currentBound
param.env[0..96]
Target object
program mode enabled
global state
current object id´s
Assemblers pointers
ARB VP 1.0assembler
más llamadas Valores de atributos “genéricos” de un
vértice se especifican con nuevos comandos: glVertexAttrib4fARB( index, x, y, z, w ) glVertexAttribs4fvARB( index, values )
También se pueden utilizar los “convencionales”:glVertex3f(), glNormal(), glColor() ....
más llamadas Especificar parámetros locales del current
program: glProgramLocalParameter4fARB( GL_VERTEX_PROGRAM_ARB,
index, x, y, z, w ) glProgramLocalParameter4fvARB(
GL_VERTEX_PROGRAM_ARB, index, params )
Especificar parámetros globales del target: glProgramEnvParameter4fARB( GL_VERTEX_PROGRAM_ARB,
index, x, y, z, w ) glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB,
index, params )
Consulta de limites de la implementación
• Número máximo de instruccionesglGetProgramivARB( GL_VERTEX_PROGRAM_ARB,
GL_MAX_PROGRAM_INSTRUCTIONS, &maxInsts );
• Número máximo de temporalesglGetProgramivARB( GL_VERTEX_PROGRAM_ARB,
GL_MAX_PROGRAM_INSTRUCTIONS, &maxTemps );
• Número máximo de parametros declaradosglGetProgramivARB( GL_VERTEX_PROGRAM_ARB,
GL_MAX_PROGRAM_PARAMETERS, &maxParams );
• ...y otras