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