/// <summary> /// Constructs a new instance of the texture bindings manager. /// </summary> /// <param name="context">The GPU context that the texture bindings manager belongs to</param> /// <param name="channel">The GPU channel that the texture bindings manager belongs to</param> /// <param name="poolCache">Texture pools cache used to get texture pools from</param> /// <param name="scales">Array where the scales for the currently bound textures are stored</param> /// <param name="isCompute">True if the bindings manager is used for the compute engine</param> public TextureBindingsManager(GpuContext context, GpuChannel channel, TexturePoolCache poolCache, float[] scales, bool isCompute) { _context = context; _channel = channel; _texturePoolCache = poolCache; _scales = scales; _isCompute = isCompute; int stages = isCompute ? 1 : Constants.ShaderStages; _textureBindings = new TextureBindingInfo[stages][]; _imageBindings = new TextureBindingInfo[stages][]; _textureState = new TextureStatePerStage[stages][]; _imageState = new TextureStatePerStage[stages][]; _textureBindingsCount = new int[stages]; _imageBindingsCount = new int[stages]; for (int stage = 0; stage < stages; stage++) { _textureBindings[stage] = new TextureBindingInfo[InitialTextureStateSize]; _imageBindings[stage] = new TextureBindingInfo[InitialImageStateSize]; _textureState[stage] = new TextureStatePerStage[InitialTextureStateSize]; _imageState[stage] = new TextureStatePerStage[InitialImageStateSize]; } }
/// <summary> /// Rents the texture bindings array for a given stage, so that they can be modified. /// </summary> /// <param name="stage">Shader stage number, or 0 for compute shaders</param> /// <param name="count">The number of bindings needed</param> /// <returns>The texture bindings array</returns> public TextureBindingInfo[] RentTextureBindings(int stage, int count) { if (count > _textureBindings[stage].Length) { Array.Resize(ref _textureBindings[stage], count); Array.Resize(ref _textureState[stage], count); } int toClear = Math.Max(_textureBindingsCount[stage], count); TextureStatePerStage[] state = _textureState[stage]; for (int i = 0; i < toClear; i++) { state[i] = new TextureStatePerStage(); } _textureBindingsCount[stage] = count; return(_textureBindings[stage]); }
/// <summary> /// Binds images for a given shader stage. /// </summary> /// <param name="stage">Shader stage number, or 0 for compute shaders</param> /// <param name="bindings">Image bindings</param> public void SetImages(int stage, TextureBindingInfo[] bindings) { _imageBindings[stage] = bindings; _imageState[stage] = new TextureStatePerStage[bindings.Length]; }