예제 #1
0
        public ShaderD3D11(DeviceD3D11 device, ShaderBytecode bytecode)
            : base(device, bytecode)
        {
            switch (bytecode.Stage)
            {
            case ShaderStages.Vertex:
                Bytecode    = (byte[])bytecode.Data.Clone();
                D3D11Shader = device.D3D11Device.CreateVertexShader(bytecode.Data);
                break;

            case ShaderStages.Hull:
                D3D11Shader = device.D3D11Device.CreateHullShader(bytecode.Data);
                break;

            case ShaderStages.Domain:
                D3D11Shader = device.D3D11Device.CreateDomainShader(bytecode.Data);
                break;

            case ShaderStages.Geometry:
                D3D11Shader = device.D3D11Device.CreateGeometryShader(bytecode.Data);
                break;

            case ShaderStages.Pixel:
                D3D11Shader = device.D3D11Device.CreatePixelShader(bytecode.Data);
                break;

            case ShaderStages.Compute:
                D3D11Shader = device.D3D11Device.CreateComputeShader(bytecode.Data);
                break;
            }
        }
예제 #2
0
 public SwapchainD3D11(DeviceD3D11 device, in SwapChainDescriptor descriptor)
예제 #3
0
 public PipelineStateD3D11(DeviceD3D11 device, in RenderPipelineDescriptor descriptor)
예제 #4
0
 public SamplerD3D11(DeviceD3D11 device, ref SamplerDescriptor descriptor)
     : base(device, ref descriptor)
 {
 }
예제 #5
0
 public CommandQueueD3D11(DeviceD3D11 device, CommandQueueType queueType)
     : base(device, queueType)
 {
     _context = device.D3D11Device.CreateDeferredContext();
 }
예제 #6
0
 public CommandQueueD3D11(DeviceD3D11 device, ID3D11DeviceContext context)
     : base(device, CommandQueueType.Graphics)
 {
     _context     = context;
     _isImmediate = context.GetContextType() == DeviceContextType.Immediate;
 }
예제 #7
0
        public FramebufferD3D11(DeviceD3D11 device, FramebufferAttachment[] colorAttachments, FramebufferAttachment?depthStencilAttachment)
            : base(device, colorAttachments, depthStencilAttachment)
        {
            if (colorAttachments.Length > 0)
            {
                RenderTargetViews = new ID3D11RenderTargetView[colorAttachments.Length];
                for (var i = 0; i < colorAttachments.Length; i++)
                {
                    var  attachment  = colorAttachments[i];
                    var  texture     = attachment.Texture;
                    var  arraySize   = texture.ArrayLayers - attachment.Slice;
                    bool isTextureMs = (int)texture.Samples > 1;

                    var d3dTexture = (TextureD3D11)texture;
                    var viewDesc   = new RenderTargetViewDescription
                    {
                        Format = d3dTexture.DXGIFormat
                    };

                    switch (texture.TextureType)
                    {
                    case TextureType.Texture1D:
                        if (arraySize > 1)
                        {
                            viewDesc.ViewDimension                  = RenderTargetViewDimension.Texture1DArray;
                            viewDesc.Texture1DArray.MipSlice        = attachment.MipLevel;
                            viewDesc.Texture1DArray.FirstArraySlice = attachment.Slice;
                            viewDesc.Texture1DArray.ArraySize       = arraySize;
                        }
                        else
                        {
                            viewDesc.ViewDimension      = RenderTargetViewDimension.Texture1D;
                            viewDesc.Texture1D.MipSlice = attachment.MipLevel;
                        }
                        break;

                    case TextureType.Texture2D:
                        if (arraySize > 1)
                        {
                            if (isTextureMs)
                            {
                                viewDesc.ViewDimension = RenderTargetViewDimension.Texture2DMultisampledArray;
                                viewDesc.Texture2DMSArray.FirstArraySlice = attachment.Slice;
                                viewDesc.Texture2DMSArray.ArraySize       = arraySize;
                            }
                            else
                            {
                                viewDesc.ViewDimension                  = RenderTargetViewDimension.Texture2DArray;
                                viewDesc.Texture2DArray.MipSlice        = attachment.MipLevel;
                                viewDesc.Texture2DArray.FirstArraySlice = attachment.Slice;
                                viewDesc.Texture2DArray.ArraySize       = arraySize;
                            }
                        }
                        else
                        {
                            if (isTextureMs)
                            {
                                viewDesc.ViewDimension = RenderTargetViewDimension.Texture2DMultisampled;
                            }
                            else
                            {
                                viewDesc.ViewDimension      = RenderTargetViewDimension.Texture2D;
                                viewDesc.Texture2D.MipSlice = attachment.MipLevel;
                            }
                        }
                        break;

                    case TextureType.Texture3D:
                        // TODO: Add RenderPassAttachment.DepthPlane
                        viewDesc.ViewDimension         = RenderTargetViewDimension.Texture3D;
                        viewDesc.Texture3D.MipSlice    = attachment.MipLevel;
                        viewDesc.Texture3D.FirstWSlice = attachment.Slice;
                        viewDesc.Texture3D.WSize       = texture.Depth;
                        break;

                    case TextureType.TextureCube:
                        if (isTextureMs)
                        {
                            viewDesc.ViewDimension = RenderTargetViewDimension.Texture2DMultisampledArray;
                            viewDesc.Texture2DMSArray.FirstArraySlice = attachment.Slice * 6;
                            viewDesc.Texture2DMSArray.ArraySize       = arraySize * 6;
                        }
                        else
                        {
                            viewDesc.ViewDimension                  = RenderTargetViewDimension.Texture2DArray;
                            viewDesc.Texture2DArray.MipSlice        = attachment.MipLevel;
                            viewDesc.Texture2DArray.FirstArraySlice = attachment.Slice * 6;
                            viewDesc.Texture2DArray.ArraySize       = arraySize * 6;
                        }
                        break;
                    }

                    RenderTargetViews[i] = device.Device.CreateRenderTargetView(d3dTexture.Resource, viewDesc);
                }
            }
            else
            {
                RenderTargetViews = new ID3D11RenderTargetView[0];
            }

            if (depthStencilAttachment != null)
            {
                var  attachment  = depthStencilAttachment.Value;
                var  texture     = attachment.Texture;
                var  d3dTexture  = (TextureD3D11)texture;
                var  arraySize   = texture.ArrayLayers - attachment.Slice;
                bool isTextureMs = (int)texture.Samples > 1;

                var viewDesc = new DepthStencilViewDescription
                {
                    Format = d3dTexture.DXGIFormat,
                    Flags  = DepthStencilViewFlags.None
                };

                switch (texture.TextureType)
                {
                case TextureType.Texture1D:
                    if (arraySize > 1)
                    {
                        viewDesc.ViewDimension                  = DepthStencilViewDimension.Texture1DArray;
                        viewDesc.Texture1DArray.MipSlice        = attachment.MipLevel;
                        viewDesc.Texture1DArray.FirstArraySlice = attachment.Slice;
                        viewDesc.Texture1DArray.ArraySize       = arraySize;
                    }
                    else
                    {
                        viewDesc.ViewDimension      = DepthStencilViewDimension.Texture1D;
                        viewDesc.Texture1D.MipSlice = attachment.MipLevel;
                    }
                    break;

                case TextureType.Texture2D:
                    if (arraySize > 1)
                    {
                        if (isTextureMs)
                        {
                            viewDesc.ViewDimension = DepthStencilViewDimension.Texture2DMultisampledArray;
                            viewDesc.Texture2DMSArray.FirstArraySlice = attachment.Slice;
                            viewDesc.Texture2DMSArray.ArraySize       = arraySize;
                        }
                        else
                        {
                            viewDesc.ViewDimension                  = DepthStencilViewDimension.Texture2DArray;
                            viewDesc.Texture2DArray.MipSlice        = attachment.MipLevel;
                            viewDesc.Texture2DArray.FirstArraySlice = attachment.Slice;
                            viewDesc.Texture2DArray.ArraySize       = arraySize;
                        }
                    }
                    else
                    {
                        if (isTextureMs)
                        {
                            viewDesc.ViewDimension = DepthStencilViewDimension.Texture2DMultisampled;
                        }
                        else
                        {
                            viewDesc.ViewDimension      = DepthStencilViewDimension.Texture2D;
                            viewDesc.Texture2D.MipSlice = attachment.MipLevel;
                        }
                    }

                    break;

                case TextureType.TextureCube:
                    if (isTextureMs)
                    {
                        viewDesc.ViewDimension = DepthStencilViewDimension.Texture2DMultisampledArray;
                        viewDesc.Texture2DMSArray.FirstArraySlice = attachment.Slice * 6;
                        viewDesc.Texture2DMSArray.ArraySize       = arraySize * 6;
                    }
                    else
                    {
                        viewDesc.ViewDimension                  = DepthStencilViewDimension.Texture2DArray;
                        viewDesc.Texture2DArray.MipSlice        = attachment.MipLevel * 6;
                        viewDesc.Texture2DArray.FirstArraySlice = attachment.Slice * 6;
                        viewDesc.Texture2DArray.ArraySize       = arraySize * 6;
                    }
                    break;

                case TextureType.Texture3D:
                    viewDesc.ViewDimension                  = DepthStencilViewDimension.Texture2DArray;
                    viewDesc.Texture2DArray.MipSlice        = attachment.MipLevel;
                    viewDesc.Texture2DArray.FirstArraySlice = attachment.Slice;
                    viewDesc.Texture2DArray.ArraySize       = texture.Depth;
                    break;

                default:
                    viewDesc.ViewDimension = DepthStencilViewDimension.Unknown;
                    Log.Error("Invalid texture type");
                    break;
                }

                DepthStencilView = device.Device.CreateDepthStencilView(d3dTexture.Resource, viewDesc);
            }
        }
예제 #8
0
 public BufferD3D11(DeviceD3D11 device, in BufferDescriptor descriptor, IntPtr initialData)
예제 #9
0
        public TextureD3D11(DeviceD3D11 device, ref TextureDescriptor descriptor)
            : base(device, ref descriptor)
        {
            // Create new one.
            DXGIFormat = descriptor.Format.ToDirectX();

            var cpuFlags      = CpuAccessFlags.None;
            var resourceUsage = Vortice.DirectX.Direct3D11.Usage.Default;
            var bindFlags     = descriptor.Usage.ToDirectX(descriptor.Format);
            var optionFlags   = ResourceOptionFlags.None;

            var arraySize = descriptor.ArrayLayers;

            if (descriptor.TextureType == TextureType.TextureCube)
            {
                arraySize  *= 6;
                optionFlags = ResourceOptionFlags.TextureCube;
            }

            switch (descriptor.TextureType)
            {
            case TextureType.Texture1D:
            {
                var d3dTextureDesc = new Texture1DDescription()
                {
                    Width          = descriptor.Width,
                    MipLevels      = descriptor.MipLevels,
                    ArraySize      = descriptor.ArrayLayers,
                    Format         = DXGIFormat,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuFlags,
                    Usage          = resourceUsage,
                    OptionFlags    = optionFlags,
                };

                Resource = device.D3D11Device.CreateTexture1D(d3dTextureDesc);
            }
            break;

            case TextureType.Texture2D:
            case TextureType.TextureCube:
            {
                var d3dTextureDesc = new Texture2DDescription()
                {
                    Width             = descriptor.Width,
                    Height            = descriptor.Height,
                    MipLevels         = descriptor.MipLevels,
                    ArraySize         = descriptor.ArrayLayers,
                    Format            = DXGIFormat,
                    BindFlags         = bindFlags,
                    CpuAccessFlags    = cpuFlags,
                    Usage             = resourceUsage,
                    SampleDescription = new SampleDescription((int)descriptor.Samples, 0),
                    OptionFlags       = optionFlags,
                };

                Resource = device.D3D11Device.CreateTexture2D(d3dTextureDesc);
            }
            break;

            case TextureType.Texture3D:
            {
                var d3dTextureDesc = new Texture3DDescription()
                {
                    Width          = descriptor.Width,
                    Height         = descriptor.Height,
                    Depth          = descriptor.Depth,
                    MipLevels      = descriptor.MipLevels,
                    Format         = DXGIFormat,
                    BindFlags      = bindFlags,
                    CpuAccessFlags = cpuFlags,
                    Usage          = resourceUsage,
                    OptionFlags    = optionFlags,
                };

                Resource = device.D3D11Device.CreateTexture3D(d3dTextureDesc);
            }
            break;
            }
        }
예제 #10
0
        //private readonly Dictionary<TextureViewDescriptor, TextureViewD3D11> _views = new Dictionary<TextureViewDescriptor, TextureViewD3D11>();

        public TextureD3D11(DeviceD3D11 device, ref TextureDescriptor descriptor, ID3D11Texture2D nativeTexture, Format dxgiFormat)
            : base(device, ref descriptor)
        {
            Resource   = nativeTexture;
            DXGIFormat = dxgiFormat;
        }