/// <summary> /// Function to assign a single shader resource view to the draw call. /// </summary> /// <param name="shaderType">The shader stage to use.</param> /// <param name="resourceView">The shader resource view to assign.</param> /// <param name="slot">[Optional] The slot used to asign the view.</param> /// <returns>The fluent builder interface.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="slot"/> is less than 0, or greater than/equal to <see cref="GorgonShaderResourceViews.MaximumShaderResourceViewCount"/>.</exception> /// <exception cref="NotSupportedException">Thrown if the <paramref name="shaderType"/> is not valid.</exception> /// <remarks> /// <para> /// <see cref="ShaderType.Compute"/> shaders are not supported in this method will throw an exception. /// </para> /// </remarks> public TB ShaderResource(ShaderType shaderType, GorgonShaderResourceView resourceView, int slot = 0) { if ((slot < 0) || (slot >= GorgonShaderResourceViews.MaximumShaderResourceViewCount)) { throw new ArgumentOutOfRangeException(nameof(slot), string.Format(Resources.GORGFX_ERR_SRV_SLOT_INVALID, GorgonShaderResourceViews.MaximumShaderResourceViewCount)); } switch (shaderType) { case ShaderType.Pixel: DrawCall.D3DState.PsSrvs[slot] = resourceView; break; case ShaderType.Vertex: DrawCall.D3DState.VsSrvs[slot] = resourceView; break; case ShaderType.Geometry: DrawCall.D3DState.GsSrvs[slot] = resourceView; break; case ShaderType.Domain: DrawCall.D3DState.DsSrvs[slot] = resourceView; break; case ShaderType.Hull: DrawCall.D3DState.HsSrvs[slot] = resourceView; break; default: throw new NotSupportedException(string.Format(Resources.GORGFX_ERR_SHADER_UNKNOWN_TYPE, shaderType)); } return((TB)this); }
/// <summary> /// Function to assign a single shader resource view to the dispatch call. /// </summary> /// <param name="resourceView">The shader resource view to assign.</param> /// <param name="slot">[Optional] The slot used to asign the view.</param> /// <returns>The fluent builder interface.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="slot"/> is less than 0, or greater than/equal to <see cref="GorgonShaderResourceViews.MaximumShaderResourceViewCount"/>.</exception> public GorgonDispatchCallBuilder ShaderResource(GorgonShaderResourceView resourceView, int slot = 0) { if ((slot < 0) || (slot >= GorgonShaderResourceViews.MaximumShaderResourceViewCount)) { throw new ArgumentOutOfRangeException(nameof(slot), string.Format(Resources.GORGFX_ERR_SRV_SLOT_INVALID, GorgonShaderResourceViews.MaximumShaderResourceViewCount)); } _worker.D3DState.CsSrvs[slot] = resourceView; return(this); }
/// <summary> /// Function to expire any previously allocated targets after a certain amount of time. /// </summary> /// <param name="force"><b>true</b> to clear all unrented targets immediately, <b>false</b> to only remove targets that have expired past the <see cref="ExpiryTime"/>.</param> /// <remarks> /// <para> /// Applications should call this method to free up memory associated with the cached render targets. This only affects targets that are not currently rented out. /// </para> /// </remarks> /// <seealso cref="ExpiryTime"/> public void ExpireTargets(bool force = false) { double currentMinutes = _expiryTimer.Minutes; _cleanupList.Clear(); foreach (KeyValuePair <GorgonRenderTarget2DView, double> time in _expiryTime) { // If we're already rented, then do nothing. if ((_rented.Contains(time.Key)) || (!_renderTargets.Contains(time.Key))) { continue; } // If a target has been alive for more than time limit, then dump it. if ((!force) && ((currentMinutes - time.Value) < 0)) { continue; } _cleanupList.Add(time.Key); } foreach (GorgonRenderTarget2DView target in _cleanupList) { GorgonShaderResourceView srv = target.GetShaderResourceView(); if (_srvs.Contains(srv)) { srv.Dispose(); _srvs.Remove(srv); } target.OwnerFactory = null; _renderTargets.Remove(target); _expiryTime.Remove(target); target.Dispose(); } _cleanupList.Clear(); }