/// <summary> /// Initializes a new instance of the <see cref="GorgonRenderTargetTextureView"/> class. /// </summary> /// <param name="target">The render target to bind.</param> /// <param name="format">The format of the render target view.</param> /// <param name="mipSlice">The mip slice to use in the view.</param> /// <param name="arrayIndex">The first array index to use in the view.</param> /// <param name="arrayCount">The number of array indices to use in the view.</param> internal GorgonRenderTargetTextureView(GorgonResource target, BufferFormat format, int mipSlice, int arrayIndex, int arrayCount) : base(target, format) { MipSlice = mipSlice; FirstArrayOrDepthIndex = arrayIndex; ArrayOrDepthCount = arrayCount; }
/// <summary> /// Function to unbind a shader resource from all shaders. /// </summary> /// <param name="resource">Shader resource to unbind.</param> internal void UnbindResource(GorgonResource resource) { PixelShader.Resources.UnbindResource(resource); VertexShader.Resources.UnbindResource(resource); if (GeometryShader != null) { GeometryShader.Resources.UnbindResource(resource); } if (ComputeShader != null) { ComputeShader.Resources.UnbindResource(resource); ComputeShader.UnorderedAccessViews.UnbindResource(resource); } if (HullShader != null) { HullShader.Resources.UnbindResource(resource); } if (DomainShader != null) { DomainShader.Resources.UnbindResource(resource); } // If we have multiple contexts, then we need to unbind from those as well. if ((_graphics.IsDeferred) || (_graphics.VideoDevice.SupportedFeatureLevel < DeviceFeatureLevel.SM5)) { return; } foreach (var context in _graphics.GetTrackedObjectsOfType <GorgonGraphics>()) { context.Shaders.UnbindResource(resource); } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonRenderTargetView"/> class. /// </summary> /// <param name="resource">The resource to bind to the view.</param> /// <param name="format">The format of the view.</param> protected GorgonRenderTargetView(GorgonResource resource, BufferFormat format) : base(resource, format) { switch (resource.ResourceType) { case ResourceType.Buffer: _bufferTarget = (GorgonRenderTargetBuffer)resource; break; case ResourceType.Texture1D: _1DTarget = (GorgonRenderTarget1D)resource; break; case ResourceType.Texture2D: _2DTarget = (GorgonRenderTarget2D)resource; if (_2DTarget.IsSwapChain) { _swapChain = (GorgonSwapChain)_2DTarget; } break; case ResourceType.Texture3D: _3DTarget = (GorgonRenderTarget3D)resource; break; } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonStructuredBufferUnorderedAccessView"/> class. /// </summary> /// <param name="resource">The buffer to bind to the view.</param> /// <param name="firstElement">The first element in the buffer.</param> /// <param name="elementCount">The number of elements to view.</param> /// <param name="viewType">The type of unordered access view.</param> internal GorgonStructuredBufferUnorderedAccessView(GorgonResource resource, int firstElement, int elementCount, UnorderedAccessViewType viewType) : base(resource, BufferFormat.Unknown, firstElement, elementCount, false) { ViewType = viewType; InitialCount = -1; _structuredBuffer = (GorgonStructuredBuffer)resource; }
/// <summary> /// Initializes a new instance of the <see cref="GorgonViewCache"/> class. /// </summary> /// <param name="resource">The resource.</param> public GorgonViewCache(GorgonResource resource) { _bufferViews = new Dictionary <ViewKey, GorgonBufferShaderView>(); _textureViews = new Dictionary <ViewKey, GorgonTextureShaderView>(); _targetViews = new Dictionary <ViewKey, GorgonRenderTargetView>(); _unorderedViews = new Dictionary <ViewKey, GorgonUnorderedAccessView>(); _depthViews = new Dictionary <ViewKey, GorgonDepthStencilView>(); _resource = resource; }
/// <summary> /// Initializes a new instance of the <see cref="GorgonBufferUnorderedAccessView"/> class. /// </summary> /// <param name="resource">The buffer to bind to the view.</param> /// <param name="format">The format of the view.</param> /// <param name="firstElement">The first element in the buffer.</param> /// <param name="elementCount">The number of elements to view.</param> /// <param name="isRaw">TRUE if the view should be a raw view, FALSE if not.</param> internal GorgonBufferUnorderedAccessView(GorgonResource resource, BufferFormat format, int firstElement, int elementCount, bool isRaw) : base(resource, format) { IsRaw = isRaw; ElementStart = firstElement; ElementCount = elementCount; _buffer = resource as GorgonBuffer; _indexBuffer = resource as GorgonIndexBuffer; _vertexBuffer = resource as GorgonVertexBuffer; }
/// <summary> /// Initializes a new instance of the <see cref="GorgonBufferShaderView"/> class. /// </summary> /// <param name="buffer">The buffer to bind to the view.</param> /// <param name="format">Format of the view.</param> /// <param name="elementStart">The starting element for the view.</param> /// <param name="elementCount">The number of elements in the view.</param> /// <param name="isRaw">TRUE to use a raw view, FALSE to use a normal view.</param> internal GorgonBufferShaderView(GorgonResource buffer, BufferFormat format, int elementStart, int elementCount, bool isRaw) : base(buffer, format) { IsRaw = isRaw; ElementStart = elementStart; ElementCount = elementCount; _buffer = buffer as GorgonBuffer; _structuredBuffer = buffer as GorgonStructuredBuffer; _indexBuffer = buffer as GorgonIndexBuffer; _vertexBuffer = buffer as GorgonVertexBuffer; }
/// <summary> /// Function unbind all views with the specified resource. /// </summary> /// <param name="resource">Resource to unbind.</param> internal void UnbindResource(GorgonResource resource) { if (resource == null) { return; } var indices = _unorderedViews.Where(item => item != null && item.Resource == resource) .Select(IndexOf) .Where(index => index != -1); foreach (var index in indices) { this[index] = null; } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonDepthStencilView"/> class. /// </summary> /// <param name="resource">The resource to bind to the view.</param> /// <param name="format">The format of the view.</param> /// <param name="mipSlice">The mip level to use for the view.</param> /// <param name="firstArrayIndex">The first array index to use for the view.</param> /// <param name="arrayCount">The number of array indices to use for the view.</param> /// <param name="flags">Depth/stencil view flags.</param> internal GorgonDepthStencilView(GorgonResource resource, BufferFormat format, int mipSlice, int firstArrayIndex, int arrayCount, DepthStencilViewFlags flags) : base(resource, format) { MipSlice = mipSlice; FirstArrayIndex = firstArrayIndex; ArrayCount = arrayCount; Flags = flags; switch (resource.ResourceType) { case ResourceType.Texture1D: _depth1D = (GorgonDepthStencil1D)resource; break; case ResourceType.Texture2D: _depth2D = (GorgonDepthStencil2D)resource; break; } }
/// <summary> /// Function to return the index of an unordered access view bound to a particular resource. /// </summary> /// <param name="resource">Resource to look up.</param> /// <returns>The index of the resource if found, -1 if not.</returns> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="resource"/> parameter is NULL (Nothing in VB.Net).</exception> public int IndexOf(GorgonResource resource) { if (resource == null) { throw new ArgumentNullException("resource"); } for (int i = 0; i < _unorderedViews.Length; i++) { var view = _unorderedViews[i]; if ((view != null) && (view.Resource == resource)) { return(i); } } return(-1); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonTextureUnorderedAccessView"/> class. /// </summary> /// <param name="resource">The resource.</param> /// <param name="format">The format.</param> /// <param name="mipIndex">The first mip level.</param> /// <param name="arrayIndex">Index of the array.</param> /// <param name="arrayCount">The array count.</param> internal GorgonTextureUnorderedAccessView(GorgonResource resource, BufferFormat format, int mipIndex, int arrayIndex, int arrayCount) : base(resource, format) { MipIndex = mipIndex; ArrayOrDepthStart = arrayIndex; ArrayOrDepthCount = arrayCount; switch (resource.ResourceType) { case ResourceType.Texture1D: _texture1D = (GorgonTexture1D)resource; break; case ResourceType.Texture2D: _texture2D = (GorgonTexture2D)resource; break; case ResourceType.Texture3D: _texture3D = (GorgonTexture3D)resource; break; } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonShaderView"/> class. /// </summary> /// <param name="resource">The buffer to bind to the view.</param> /// <param name="format">The format of the view.</param> protected GorgonShaderView(GorgonResource resource, BufferFormat format) : base(resource, format) { }
/// <summary> /// Function to determine if a view is bound and is also bound to the specified resource. /// </summary> /// <param name="resource">Resource to look up.</param> /// <returns>TRUE if found, FALSE if not.</returns> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="resource"/> parameter is NULL (Nothing in VB.Net).</exception> public bool Contains(GorgonResource resource) { return(IndexOf(resource) > -1); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonUnorderedAccessView"/> class. /// </summary> /// <param name="resource">The buffer to bind to the view.</param> /// <param name="format">The format of the view.</param> protected GorgonUnorderedAccessView(GorgonResource resource, BufferFormat format) : base(resource, format) { }
/// <summary> /// Initializes a new instance of the <see cref="GorgonRenderTargetBufferView"/> class. /// </summary> /// <param name="target">The render target to bind.</param> /// <param name="format">The format of the render target view.</param> /// <param name="firstElement">The first element in the buffer to map to the view.</param> /// <param name="elementCount">The number of elements in the buffer to map to the view.</param> internal GorgonRenderTargetBufferView(GorgonResource target, BufferFormat format, int firstElement, int elementCount) : base(target, format) { FirstElement = firstElement; ElementCount = elementCount; }