1*8975f5c5SAndroid Build Coastguard Worker# Vertex Texture Fetch 2*8975f5c5SAndroid Build Coastguard Worker 3*8975f5c5SAndroid Build Coastguard WorkerThis page details the steps necessary to implement vertex texture fetch in ANGLE 4*8975f5c5SAndroid Build Coastguard Workerand documents some of the pitfalls that may be encountered along the way. 5*8975f5c5SAndroid Build Coastguard Worker 6*8975f5c5SAndroid Build Coastguard Worker# Details 7*8975f5c5SAndroid Build Coastguard Worker 8*8975f5c5SAndroid Build Coastguard WorkerTasks to implement vertex texture support. 9*8975f5c5SAndroid Build Coastguard Worker 10*8975f5c5SAndroid Build Coastguard Worker1. add/enable vertex shader texture look up functions in compiler & HLSL 11*8975f5c5SAndroid Build Coastguard Worker translator. 12*8975f5c5SAndroid Build Coastguard Worker * add texture2DLod, texture2DProjLod (2 variants), textureCubeLod (these 13*8975f5c5SAndroid Build Coastguard Worker are **only** valid in vertex shaders) 14*8975f5c5SAndroid Build Coastguard Worker * ensure other (non-bias/non-LOD) texture functions work in vertex shaders 15*8975f5c5SAndroid Build Coastguard Worker * non-mipmapped textures use the only level available 16*8975f5c5SAndroid Build Coastguard Worker * mipmapped textures use only the base level (ie level 0). 17*8975f5c5SAndroid Build Coastguard Worker2. update implementation-dependent constants in Context.h 18*8975f5c5SAndroid Build Coastguard Worker * MAX\_VERTEX\_TEXTURE\_IMAGE\_UNITS = 4 19*8975f5c5SAndroid Build Coastguard Worker * MAX\_COMBINED\_TEXTURE\_IMAGE\_UNITS = 20*8975f5c5SAndroid Build Coastguard Worker MAX\_VERTEX\_TEXTURE\_IMAGE\_UNITS + MAX\_TEXTURE\_IMAGE\_UNITS (ie 20). 21*8975f5c5SAndroid Build Coastguard Worker * these limits have to change based on the d3d device characteristics. For 22*8975f5c5SAndroid Build Coastguard Worker example we likely don't want to advertise vertex image units on SM2.0 23*8975f5c5SAndroid Build Coastguard Worker cards (unless we end up using software vertex processing). 24*8975f5c5SAndroid Build Coastguard Worker * detection of hardware support for various formats, types, etc. 25*8975f5c5SAndroid Build Coastguard Worker * As a first pass, use the "hasVertexTextures" check that Aras suggested 26*8975f5c5SAndroid Build Coastguard Worker to only enable VTF on DX10 NVIDIA and AMD parts, and SM3 Intel parts. 27*8975f5c5SAndroid Build Coastguard Worker * If this proves insufficient, there are other things we can do, but it 28*8975f5c5SAndroid Build Coastguard Worker involves using software vertex processing for unsupported formats and 29*8975f5c5SAndroid Build Coastguard Worker system memory copies of textures -- all stuff which is rather annoying 30*8975f5c5SAndroid Build Coastguard Worker and likely to hurt performance (see point 4. below). 31*8975f5c5SAndroid Build Coastguard Worker3. add support and handling for vertex textures/samplers in the API. 32*8975f5c5SAndroid Build Coastguard Worker * any textures used in a vertex shader need to get assigned to the special 33*8975f5c5SAndroid Build Coastguard Worker samplers in d3d9 34*8975f5c5SAndroid Build Coastguard Worker * there are only 4 of them (D3DVERTEXTEXTURESAMPLER0.. 35*8975f5c5SAndroid Build Coastguard Worker D3DVERTEXTEXTURESAMPLER3) 36*8975f5c5SAndroid Build Coastguard Worker * if a texture is used in both vertex & fragment it counts twice against 37*8975f5c5SAndroid Build Coastguard Worker the "MAX\_COMBINED" limit (validated in Program::validateSamplers) 38*8975f5c5SAndroid Build Coastguard Worker * there are a number of places in our code where we have arrays of size, 39*8975f5c5SAndroid Build Coastguard Worker or iterate over, MAX\_TEXTURE\_IMAGE\_UNITS. These will need to be 40*8975f5c5SAndroid Build Coastguard Worker changed to operate on MAX\_COMBINED\_TEXTURE\_IMAGE\_UNITS instead. A 41*8975f5c5SAndroid Build Coastguard Worker (possibly incomplete & outdated) list of areas that need to be updated 42*8975f5c5SAndroid Build Coastguard Worker is as follows: 43*8975f5c5SAndroid Build Coastguard Worker * Program.h - increase size of mSamplers 44*8975f5c5SAndroid Build Coastguard Worker * Context.h - increase size of samplerTexture 45*8975f5c5SAndroid Build Coastguard Worker * glActiveTexture needs accept values in the range 46*8975f5c5SAndroid Build Coastguard Worker 0..MAX\_COMBINED\_TEXTURE\_IMAGE\_UNITS-1 47*8975f5c5SAndroid Build Coastguard Worker * Context::~Context 48*8975f5c5SAndroid Build Coastguard Worker * GetIntegerv (2D\_BINDING, CUBE\_BINDING) 49*8975f5c5SAndroid Build Coastguard Worker * Context::applyTextures 50*8975f5c5SAndroid Build Coastguard Worker * Context::detachTexture 51*8975f5c5SAndroid Build Coastguard Worker * Program::getSamplerMapping 52*8975f5c5SAndroid Build Coastguard Worker * Program::dirtyAllSamplers 53*8975f5c5SAndroid Build Coastguard Worker * Program::applyUniform1iv 54*8975f5c5SAndroid Build Coastguard Worker * Program::unlink 55*8975f5c5SAndroid Build Coastguard Worker * Program::validateSamplers 56*8975f5c5SAndroid Build Coastguard Worker4. handling the nasty corner cases: texture formats, filtering and cube 57*8975f5c5SAndroid Build Coastguard Worker textures. 58*8975f5c5SAndroid Build Coastguard Worker * OpenGL doesn't provide any restrictions on what formats and/or types of 59*8975f5c5SAndroid Build Coastguard Worker textures can used for vertex textures, or if filtering can be enabled, 60*8975f5c5SAndroid Build Coastguard Worker whereas D3D9 does. 61*8975f5c5SAndroid Build Coastguard Worker * Reference Rasterizer / Software Vertex Processing: all formats & types 62*8975f5c5SAndroid Build Coastguard Worker supported (including filtering) 63*8975f5c5SAndroid Build Coastguard Worker * ATI R500 (on Google Code) cards do not support VTF (even though they are 64*8975f5c5SAndroid Build Coastguard Worker SM 3.0) 65*8975f5c5SAndroid Build Coastguard Worker * ATI R600 (on Google Code) (and later) and in theory the Intel 965+, 66*8975f5c5SAndroid Build Coastguard Worker claim to support all texture formats/types we care about and some with 67*8975f5c5SAndroid Build Coastguard Worker filtering 68*8975f5c5SAndroid Build Coastguard Worker * NVIDIA cards fall into two camps: 69*8975f5c5SAndroid Build Coastguard Worker * dx9 SM3 (6&7 series): only R32F & A32B32G32R32F supported for 2D and no 70*8975f5c5SAndroid Build Coastguard Worker filtering, CUBE or VOL texture support 71*8975f5c5SAndroid Build Coastguard Worker * dx10 (8+ series): only float texture formats for 2D, CUBE & VOLUME. no 72*8975f5c5SAndroid Build Coastguard Worker filtering (according to caps) 73*8975f5c5SAndroid Build Coastguard Worker * further info from Aras P. suggests that all formats are supported on 74*8975f5c5SAndroid Build Coastguard Worker DX10 hardware, but are just not advertised. 75*8975f5c5SAndroid Build Coastguard Worker * unsure what they do on these cards under OpenGL. Need to do more 76*8975f5c5SAndroid Build Coastguard Worker testing, but suspect software fallback. 77