public DX11SliceRenderTarget(DX11RenderContext context, DX11Texture2D texture, int sliceindex)
        {
            this.isowner = false;
            this.context = context;
            this.parent = texture;
            this.desc = texture.Description;

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                ArraySize = 1,
                Dimension = RenderTargetViewDimension.Texture2DArray,
                Format = texture.Format,
                MipSlice = 0,
                FirstArraySlice = sliceindex,
            };

            this.RTV = new RenderTargetView(context.Device, this.parent.Resource, rtd);

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                ArraySize = 1,
                Dimension = ShaderResourceViewDimension.Texture2DArray,
                Format = texture.Format,
                FirstArraySlice = sliceindex,
                MipLevels = texture.Resource.Description.MipLevels,
                MostDetailedMip = 0
            };

            this.SRV = new ShaderResourceView(context.Device, this.parent.Resource, srvd);
        }
 public DX11VertexGeometry(DX11RenderContext context)
     : base(context)
 {
     this.drawer = new DX11DefaultVertexDrawer();
     this.drawer.Assign(this);
     this.ownsvbo = true;
 }
        public DX11MipSliceRenderTarget2D(DX11RenderContext context, DX11Texture2D texture, int mipindex, int w, int h)
        {
            this.context = context;
            this.Resource = texture.Resource;

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                Dimension = RenderTargetViewDimension.Texture2D,
                Format = texture.Format,
                MipSlice = mipindex
            };

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Dimension = UnorderedAccessViewDimension.Texture2D,
                Format = texture.Format,
                MipSlice = mipindex,
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription();
            srvd.Dimension = ShaderResourceViewDimension.Texture2D;
            srvd.MipLevels = 1;
            srvd.MostDetailedMip = mipindex;
            srvd.Format = texture.Format;

            this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd);
        }
Exemple #4
0
        public DX11VertexBuffer(DX11RenderContext context, int verticescount, int vertexsize, bool allowstreamout)
        {
            this.context = context;
            this.TotalSize = verticescount * vertexsize;
            this.AllowStreamOutput = allowstreamout;

            BindFlags flags = BindFlags.VertexBuffer;

            if (allowstreamout)
            {
                flags |= BindFlags.StreamOutput;
            }

            BufferDescription bd = new BufferDescription()
            {
                BindFlags = flags,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = this.TotalSize,
                Usage = ResourceUsage.Default
            };

            this.Buffer = new SlimDX.Direct3D11.Buffer(context.Device, bd);
            this.VertexSize = vertexsize;
            this.VerticesCount = verticescount;
        }
Exemple #5
0
        public DX11RenderMip3D(DX11RenderContext context, int w, int h,int d, Format format) : base(context)
        {
            int levels = this.CountMipLevels(w,h,d);
            var texBufferDesc = new Texture3DDescription
            {
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = h,
                Width = w,
                Depth = d,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
                MipLevels = levels,
            };

            this.Resource = new Texture3D(context.Device, texBufferDesc);
            this.Width = w;
            this.Height = h;
            this.Depth = d;

            this.SRV = new ShaderResourceView(context.Device, this.Resource);

            this.Slices = new DX11MipSliceRenderTarget[levels];

            int sw = w;
            int sh = h;
            int sd = d;

            for (int i = 0; i < levels; i++)
            {
                this.Slices[i] = new DX11MipSliceRenderTarget(this.context, this, i, w, h,d);
                w /= 2; h /= 2; d /= 2;
            }
        }
        public DX11MipSliceRenderTarget(DX11RenderContext context, DX11Texture3D texture, int mipindex,int w, int h,int d)
        {
            this.context = context;

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                Dimension = RenderTargetViewDimension.Texture3D,
                Format = texture.Format,
                MipSlice = mipindex,
                DepthSliceCount = d           
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription();
            srvd.Dimension = ShaderResourceViewDimension.Texture3D;
            srvd.MipLevels = 1;
            srvd.MostDetailedMip = mipindex;
            srvd.Format = texture.Format;

            this.RTV = new RenderTargetView(context.Device, texture.Resource, rtd);
            this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd);

            this.Width = w;
            this.Height = h;
            this.Depth = d;
        }
Exemple #7
0
        public DX11RenderMip2D(DX11RenderContext context, int w, int h, Format format)
        {
            this.context = context;
            int levels = this.CountMipLevels(w,h);
            var texBufferDesc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = h,
                Width = w,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                MipLevels = levels,
            };

            
            this.Resource = new Texture2D(context.Device, texBufferDesc);
            this.desc = this.Resource.Description;

            this.SRV = new ShaderResourceView(context.Device, this.Resource);

            this.Slices = new DX11MipSliceRenderTarget[levels];

            int sw = w;
            int sh = h;

            for (int i = 0; i < levels; i++)
            {
                this.Slices[i] = new DX11MipSliceRenderTarget(this.context, this, i, w, h);
                w /= 2; h /= 2;
            }
        }
Exemple #8
0
 public DX11IndexBuffer(DX11RenderContext context, IntPtr ptr, int indicescount)
 {
     this.context = context;
     format = SlimDX.DXGI.Format.R32_UInt;
     this.Buffer = SlimDX.Direct3D11.Buffer.FromPointer(ptr);
     this.IndicesCount = indicescount;
 }
Exemple #9
0
        public DX11SwapChain(DX11RenderContext context, IntPtr handle, Format format, SampleDescription sampledesc)
        {
            this.context = context;
            this.handle = handle;

            SwapChainDescription sd = new SwapChainDescription()
            {
                BufferCount = 1,
                ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), format),
                IsWindowed = true,
                OutputHandle = handle,
                SampleDescription = sampledesc,
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput | Usage.ShaderInput,
                Flags = SwapChainFlags.None
            };

            if (sd.SampleDescription.Count == 1 && context.IsFeatureLevel11)
            {
                sd.Usage |= Usage.UnorderedAccess;
                this.allowuav = true;
            }

            this.swapchain = new SwapChain(context.Device.Factory, context.Device, sd);

            this.Resource = Texture2D.FromSwapChain<Texture2D>(this.swapchain, 0);

            this.context.Factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAltEnter);

            this.RTV = new RenderTargetView(context.Device, this.Resource);
            this.SRV = new ShaderResourceView(context.Device, this.Resource);
            if (this.allowuav) { this.UAV = new UnorderedAccessView(context.Device, this.Resource); }

            this.desc = this.Resource.Description;
        }
        public DX11CubeDepthStencil(DX11RenderContext context, int size, SampleDescription sd, Format format)
        {
            this.context = context;

            var texBufferDesc = new Texture2DDescription
            {
                ArraySize = 6,
                BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = DepthFormatsHelper.GetGenericTextureFormat(format),
                Height = size,
                Width = size,
                OptionFlags = ResourceOptionFlags.TextureCube,
                SampleDescription = sd,
                Usage = ResourceUsage.Default,
                MipLevels = 1
            };

            this.Resource = new Texture2D(context.Device, texBufferDesc);

            this.desc = texBufferDesc;

            //Create faces SRV/RTV
            this.SliceDSV = new DX11SliceDepthStencil[6];

            ShaderResourceViewDescription svd = new ShaderResourceViewDescription()
            {
                Dimension = ShaderResourceViewDimension.TextureCube,
                Format = DepthFormatsHelper.GetSRVFormat(format),
                MipLevels = 1,
                MostDetailedMip = 0,
                First2DArrayFace = 0
            };

            DepthStencilViewDescription dsvd = new DepthStencilViewDescription()
            {
                ArraySize= 6,
                Dimension = DepthStencilViewDimension.Texture2DArray,
                FirstArraySlice = 0,
                Format = DepthFormatsHelper.GetDepthFormat(format),
                MipSlice = 0
            };

            this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd);

            if (context.IsFeatureLevel11)
            {
                dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth;
                if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; }

                this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd);
            }

            this.SRV = new ShaderResourceView(context.Device, this.Resource, svd);

            for (int i = 0; i < 6; i++)
            {
                this.SliceDSV[i] = new DX11SliceDepthStencil(context, this, i, DepthFormatsHelper.GetDepthFormat(format));
            }
        }
Exemple #11
0
        public DX11IndexBuffer(DX11RenderContext context, DataStream initial,bool dynamic, bool dispose)
        {
            this.context = context;
            format = SlimDX.DXGI.Format.R32_UInt;

            BindFlags flags = BindFlags.IndexBuffer;

            if (context.IsFeatureLevel11) { flags |= BindFlags.ShaderResource; }

            BufferDescription bd = new BufferDescription()
            {
                BindFlags = flags,
                CpuAccessFlags = dynamic ? CpuAccessFlags.Write : CpuAccessFlags.None,
                OptionFlags = context.IsFeatureLevel11 ? ResourceOptionFlags.RawBuffer : ResourceOptionFlags.None,
                SizeInBytes = (int)initial.Length,
                Usage = dynamic ? ResourceUsage.Dynamic : ResourceUsage.Default,
            };

            initial.Position = 0;
            this.IndicesCount = (int)initial.Length / 4;
            this.Buffer = new SlimDX.Direct3D11.Buffer(context.Device, initial, bd);

            this.CreateSRV();

            if (dispose) { initial.Dispose(); }
        }
        public DX11RenderTexture3D(DX11RenderContext context, int w, int h, int d, Format format)
            : base(context)
        {
            Texture3DDescription desc = new Texture3DDescription()
            {
                BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags = CpuAccessFlags.None,
                Depth = d,
                Format = format,
                Height = h,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                Usage = ResourceUsage.Default,
                Width = w
            };

            RenderTargetViewDescription rtvd = new RenderTargetViewDescription();
            rtvd.Dimension = RenderTargetViewDimension.Texture3D;
            rtvd.MipSlice = 0;
            rtvd.FirstDepthSlice = 0;
            rtvd.DepthSliceCount = d;

            this.Resource = new Texture3D(context.Device, desc);
            this.SRV = new ShaderResourceView(context.Device, this.Resource);
            this.UAV = new UnorderedAccessView(context.Device, this.Resource);
            this.RTV = new RenderTargetView(context.Device, this.Resource, rtvd);

            this.Width = desc.Width;
            this.Height = desc.Height;
            this.Format = desc.Format;
            this.Depth = desc.Depth;
        }
        public DX11RenderTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format)
        {
            this.context = context;

            var texBufferDesc = new Texture2DDescription
            {
                ArraySize = elemcnt,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = h,
                Width = w,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1,0),
                Usage = ResourceUsage.Default,
            };

            this.Resource = new Texture2D(context.Device, texBufferDesc);

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                ArraySize = elemcnt,
                FirstArraySlice = 0,
                Dimension = RenderTargetViewDimension.Texture2DArray,
                Format = format
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                ArraySize = elemcnt,
                FirstArraySlice = 0,
                Dimension = ShaderResourceViewDimension.Texture2DArray,
                Format = format,
                MipLevels = 1,
                MostDetailedMip = 0
            };

            this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd);
            this.RTV = new RenderTargetView(context.Device, this.Resource, rtd);

            this.SRVArray = new ShaderResourceView[elemcnt];

            ShaderResourceViewDescription srvad = new ShaderResourceViewDescription()
            {
                ArraySize = 1,
                Dimension = ShaderResourceViewDimension.Texture2DArray,
                Format = format,
                MipLevels = 1,
                MostDetailedMip = 0
            };

            for (int i = 0; i < elemcnt; i++)
            {
                srvad.FirstArraySlice = i;
                this.SRVArray[i] = new ShaderResourceView(context.Device, this.Resource, srvad);
            }

            this.desc = texBufferDesc;
        }
 public DX11NullGeometry(DX11RenderContext context, IDX11GeometryDrawer<DX11NullGeometry> drawer)
     : base(context)
 {
     this.drawer = drawer;
     this.drawer.Assign(this);
     this.InputLayout = new InputElement[0];
     this.Topology = PrimitiveTopology.PointList;
 }
        public DX11RenderTarget2D(DX11RenderContext context, Texture2D tex)
        {
            this.context = context;
            this.Resource = tex;

            this.SRV = new ShaderResourceView(context.Device, tex);

            this.RTV = new RenderTargetView(context.Device, tex);
        }
        public DX11RenderTexture3D(DX11RenderContext context, Texture3D tex, ShaderResourceView srv, UnorderedAccessView uav)
            : base(context)
        {
            this.Resource = tex;

            this.SRV = srv;

            this.UAV = uav;
        }
        public DX11RenderTexture3D(DX11RenderContext context, Texture3D tex)
            : base(context)
        {
            this.Resource = tex;

            this.SRV = new ShaderResourceView(context.Device, tex);

            this.UAV = new UnorderedAccessView(context.Device, tex);
        }
 private RawBufferGeometry(RawBufferGeometry self)
 {
     this.buffer = self.buffer;
     this.context = self.context;
     this.BoundingBox = self.BoundingBox;
     this.InputLayout = self.InputLayout;
     this.props = self.props;
     this.Tag = self.Tag;
     this.Topology = self.Topology;
 }
Exemple #19
0
        public DX11PipelineQuery(DX11RenderContext context)
        {
            this.context = context;

            QueryDescription qd = new QueryDescription();
            qd.Flags = QueryFlags.None;
            qd.Type = QueryType.PipelineStatistics;

            this.query = new Query(context.Device, qd);
        }
Exemple #20
0
        public static void SaveToFileCompressed(DX11RenderContext device, DX11Texture2D texture, string path, DdsBlockType blockType)
        {
            long retcode = NativeMethods.SaveCompressedTextureToFile(device.Device.ComPointer, device.CurrentDeviceContext.ComPointer,
                texture.Resource.ComPointer, path, (int)blockType);

            if (retcode < 0)
            {
                throw new Exception("Failed to Save Texture");
            }
        }
Exemple #21
0
        public static void SaveToMemoryCompressed(DX11RenderContext device, DX11Texture2D texture, DdsBlockType blockType, out IntPtr data, out int size, out IntPtr blob)
        {
            long retcode = NativeMethods.SaveCompressedTextureToMemory(device.Device.ComPointer, device.CurrentDeviceContext.ComPointer,
                texture.Resource.ComPointer, (int)blockType, out data, out size,out blob);

            if (retcode < 0)
            {
                throw new Exception("Failed to Save Texture");
            }
        }
        public DX11StreamOutQuery(DX11RenderContext context)
        {
            this.context = context;

            QueryDescription qd = new QueryDescription();
            qd.Flags = QueryFlags.None;
            qd.Type = QueryType.StreamOutputStatistics;

            this.query = new Query(context.Device, qd);
        }
        public DX11OcclusionQuery(DX11RenderContext context)
        {
            this.context = context;

            QueryDescription qd = new QueryDescription();
            qd.Flags = QueryFlags.None;
            qd.Type = QueryType.Occlusion;

            this.query = new Query(context.Device, qd);
        }
        public DX11IndexOnlyGeometry(DX11RenderContext context)
            : base(context)
        {
            this.drawer = new DX11DefaultIndexOnlyDrawer();
            this.drawer.Assign(this);

            this.ownsido = true;
            this.LargeIndexFormat = true;
            this.InputLayout = new InputElement[0];
            this.Topology = PrimitiveTopology.TriangleList;
        }
        public DX11NullGeometry(DX11RenderContext context, int VertexCount)
            : base(context)
        {
            DX11NullDrawer d = new DX11NullDrawer();
            d.VertexCount = VertexCount;
            this.drawer = d;
            this.drawer.Assign(this);

            this.InputLayout = new InputElement[0];
            this.Topology = PrimitiveTopology.PointList;
        }
        public DX11RenderTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format, bool buildslices = true, int miplevels = 0)
        {
            this.context = context;

            var texBufferDesc = new Texture2DDescription
            {
                ArraySize = elemcnt,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = h,
                Width = w,
                OptionFlags = miplevels == 0 ? ResourceOptionFlags.GenerateMipMaps : ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1,0),
                Usage = ResourceUsage.Default,
                MipLevels= miplevels
            };

            this.Resource = new Texture2D(context.Device, texBufferDesc);

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                ArraySize = elemcnt,
                FirstArraySlice = 0,
                Dimension = RenderTargetViewDimension.Texture2DArray,
                Format = format
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                ArraySize = elemcnt,
                FirstArraySlice = 0,
                Dimension = ShaderResourceViewDimension.Texture2DArray,
                Format = format,
                MipLevels = this.Resource.Description.MipLevels,
                MostDetailedMip = 0
            };

            this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd);
            this.RTV = new RenderTargetView(context.Device, this.Resource, rtd);

            this.desc = texBufferDesc;

            this.SliceRTV = new DX11SliceRenderTarget[this.ElemCnt];

            if (buildslices)
            {
                for (int i = 0; i < this.ElemCnt; i++)
                {
                    this.SliceRTV[i] = new DX11SliceRenderTarget(this.context, this, i);
                }
            }
        }
Exemple #27
0
 public static Buffer CreateDynamicVertexBuffer(DX11RenderContext context, int size)
 {
     var vertices = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription()
     {
         BindFlags = BindFlags.VertexBuffer,
         CpuAccessFlags = CpuAccessFlags.Write,
         OptionFlags = ResourceOptionFlags.None,
         SizeInBytes = size,
         Usage = ResourceUsage.Dynamic
     });
     return vertices;
 }
        public void Update(DX11RenderContext context,int defaultvertexcount, int defaultinstancecount)
        {
            if (this.indbuffer != null) { this.indbuffer.Dispose(); }

            DrawInstancedArgs args = new DrawInstancedArgs();
            args.InstanceCount = defaultinstancecount;
            args.StartInstanceLocation = 0;
            args.StartVertexLocation = 0;
            args.VertexCount = defaultvertexcount;

            this.indbuffer = new InstancedIndirectBuffer(context, args);

        }
        public DX11DepthTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format)
        {
            this.context = context;

            this.original = format;

            var texBufferDesc = new Texture2DDescription
            {
                ArraySize = elemcnt,
                BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = DepthFormatsHelper.GetGenericTextureFormat(format),
                Height = h,
                Width = w,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1,0),
                Usage = ResourceUsage.Default,
            };

            this.Resource = new Texture2D(context.Device, texBufferDesc);

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                ArraySize = elemcnt,
                FirstArraySlice = 0,
                Dimension = ShaderResourceViewDimension.Texture2DArray,
                Format = DepthFormatsHelper.GetSRVFormat(format),
                MipLevels = 1,
                MostDetailedMip = 0
            };

            this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd);

            DepthStencilViewDescription dsvd = new DepthStencilViewDescription()
            {
                ArraySize = elemcnt,
                FirstArraySlice = 0,
                Format = DepthFormatsHelper.GetDepthFormat(format),// Format.D32_Float,
                Dimension = DepthStencilViewDimension.Texture2DArray,
                MipSlice = 0
            };

            this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd);

            dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth;
            if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; }

            this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd);

            this.desc = texBufferDesc;
        }
        public DX11DepthStencil(DX11RenderContext context, int w, int h, SampleDescription sd, Format format)
        {
            this.context = context;
            var depthBufferDesc = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = DepthFormatsHelper.GetGenericTextureFormat(format),
                Height = h,
                Width = w,
                MipLevels = 1,
                OptionFlags = ResourceOptionFlags.None,
                SampleDescription = sd,
                Usage = ResourceUsage.Default
            };

            this.Resource = new Texture2D(context.Device, depthBufferDesc);

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                ArraySize = 1,
                Format = DepthFormatsHelper.GetSRVFormat(format),
                Dimension = sd.Count == 1 ? ShaderResourceViewDimension.Texture2D : ShaderResourceViewDimension.Texture2DMultisampled,
                MipLevels = 1,
                MostDetailedMip = 0
            };

            this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd);

            DepthStencilViewDescription dsvd = new DepthStencilViewDescription()
            {
                Format = DepthFormatsHelper.GetDepthFormat(format),
                Dimension = sd.Count == 1 ? DepthStencilViewDimension.Texture2D : DepthStencilViewDimension.Texture2DMultisampled,
                MipSlice = 0
            };

            this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd);

            //Read only dsv only supported in dx11 minimum
            if (context.IsFeatureLevel11)
            {
                dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth;
                if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; }

                this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd);
            }

            this.desc = depthBufferDesc;
            this.isowner = true;
        }
Exemple #31
0
 public void AttachContext(DX11RenderContext renderContext)
 {
     this.attachedContext = renderContext;
 }
 protected override void AfterRender(DX11GraphicsRenderer renderer, DX11RenderContext context)
 {
 }
 public void Destroy(IPluginIO pin, DX11RenderContext context, bool force)
 {
     //Not ownding resource eg: do nothing
 }
 public void Update(DX11RenderContext context)
 {
     this.lastUpdate = true;
 }
        public void Update(DX11RenderContext context)
        {
            if (!this.FTextureOutput[0].Contains(context))
            {
                this.FTextureOutput[0][context] = new DX11DynamicTexture2D(context, this.width, this.height, SlimDX.DXGI.Format.R8G8B8A8_UNorm);
                this.FPCOut[0][context]         = new DX11DynamicStructuredBuffer <float>(context, 640 * 480 * 6);
            }

            if (this.FInvalidate)
            {
                fixed(int *f = &this.pic[0])
                {
                    IntPtr ptr = new IntPtr(f);

                    this.FTextureOutput[0][context].WriteData(ptr, this.width * this.height * 4);
                }

                /*fixed (float* f = &this.piccloud[0])
                 * {*
                 *  IntPtr ptr = new IntPtr(f);*/

                DX11DynamicStructuredBuffer <float> db = (DX11DynamicStructuredBuffer <float>) this.FPCOut[0][context];

                db.WriteData(this.piccloud);
                //}

                this.FInvalidate = false;
            }

            if (this.FInVoxels[0])
            {
                if (this.FOutVoxels[0].Contains(context))
                {
                    this.FOutVoxels[0].Dispose(context);
                }

                short[] data = new short[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ];

                this.volume.ExportVolumeBlock(0, 0, 0, this.VoxelResolutionX, this.VoxelResolutionY, this.VoxelResolutionZ, 1, data);

                DX11DynamicStructuredBuffer <int> b = new DX11DynamicStructuredBuffer <int>(context, this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ);

                int[] idata = new int[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ];

                for (int i = 0; i < this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ; i++)
                {
                    idata[i] = data[i];
                }

                b.WriteData(idata);

                this.FOutVoxels[0][context] = b;
            }

            if (this.FInExport[0])
            {
                if (this.FGeomOut[0].Contains(context))
                {
                    this.FGeomOut[0].Dispose(context);
                }

                if (this.volume != null)
                {
                    Mesh m = this.volume.CalculateMesh(this.FInGeomVoxelStep[0]);

                    DX11IndexedGeometry geom = new DX11IndexedGeometry(context);

                    ReadOnlyCollection <int> inds = m.GetTriangleIndexes();

                    DataStream ds = new DataStream(inds.Count * 4, true, true);
                    ds.WriteRange <int>(inds.ToArray());
                    ds.Position = 0;

                    DX11IndexBuffer ibo = new DX11IndexBuffer(context, ds, false, true);

                    ReadOnlyCollection <Microsoft.Kinect.Fusion.Vector3> pos  = m.GetVertices();
                    ReadOnlyCollection <Microsoft.Kinect.Fusion.Vector3> norm = m.GetNormals();
                    //ReadOnlyCollection<int> col = m.GetColors();

                    DataStream dsv = new DataStream(Pos3Norm3Vertex.VertexSize * pos.Count, true, true);

                    SlimDX.Vector3 bmin = new SlimDX.Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                    SlimDX.Vector3 bmax = new SlimDX.Vector3(float.MinValue, float.MinValue, float.MinValue);

                    for (int i = 0; i < pos.Count; i++)
                    {
                        Microsoft.Kinect.Fusion.Vector3 p = pos[i];
                        Microsoft.Kinect.Fusion.Vector3 n = norm[i];

                        dsv.Write <Microsoft.Kinect.Fusion.Vector3>(p);
                        dsv.Write <Microsoft.Kinect.Fusion.Vector3>(n);
                        //dsv.Write<int>(col[i]);

                        if (p.X < bmin.X)
                        {
                            bmin.X = p.X;
                        }
                        if (p.Y < bmin.Y)
                        {
                            bmin.Y = p.Y;
                        }
                        if (p.Z < bmin.Z)
                        {
                            bmin.Z = p.Z;
                        }

                        if (p.X > bmax.X)
                        {
                            bmax.X = p.X;
                        }
                        if (p.Y > bmax.Y)
                        {
                            bmax.Y = p.Y;
                        }
                        if (p.Z > bmax.Z)
                        {
                            bmax.Z = p.Z;
                        }
                    }

                    geom.IndexBuffer    = ibo;
                    geom.HasBoundingBox = true;
                    geom.InputLayout    = Pos3Norm3Vertex.Layout;     // FusionColoredVertex.Layout;
                    geom.Topology       = SlimDX.Direct3D11.PrimitiveTopology.TriangleList;
                    geom.VertexSize     = Pos3Norm3Vertex.VertexSize; // FusionColoredVertex.VertexSize;
                    geom.VertexBuffer   = BufferHelper.CreateVertexBuffer(context, dsv, false, true);
                    geom.VerticesCount  = pos.Count;
                    geom.BoundingBox    = new BoundingBox(bmin, bmax);


                    this.FGeomOut[0][context] = geom;

                    m.Dispose();
                }
            }
        }
 public DispatchIndirectBuffer(DX11RenderContext context, DispatchArgs args) : base(context, args)
 {
 }
 public DispatchIndirectBuffer(DX11RenderContext context) : this(context, new DispatchArgs(1, 1, 1))
 {
 }
Exemple #38
0
 public void Destroy(DX11RenderContext context, bool force)
 {
     this.marginalTexture[0].Dispose(context);
 }
Exemple #39
0
 private void Render(DX11RenderContext context, DX11RenderSettings settings)
 {
     this.lastRender++;
 }
Exemple #40
0
 public void Destroy(DX11RenderContext context, bool force)
 {
     this.swapchain.Dispose(context);
 }
Exemple #41
0
 public void Destroy(IPluginIO pin, DX11RenderContext OnDevice, bool force)
 {
 }
Exemple #42
0
 public void Destroy(IPluginIO pin, DX11RenderContext context, bool force)
 {
     this.FTextureOutput[0].Dispose(context);
 }
        public void Evaluate(int SpreadMax)
        {
            if (this.FTextureIn.PluginIO.IsConnected)
            {
                if (this.RenderRequest != null)
                {
                    this.RenderRequest(this, this.FHost);
                }

                if (this.AssignedContext == null)
                {
                    this.SetNull(); return;
                }

                this.FPointer.SliceCount = SpreadMax;

                DX11RenderContext context = this.AssignedContext;


                try
                {
                    if (this.FTextureIn[0].Contains(context))
                    {
                        if (tex != null)
                        {
                            Texture2D t = this.FTextureIn[0][context].Resource;
                            if (t.Description.Width != this.tex.Description.Width ||
                                t.Description.Height != this.tex.Description.Height ||
                                t.Description.Format != this.tex.Description.Format)
                            {
                                this.SharedResource.Dispose();
                                this.SharedResource = null;
                                this.tex.Dispose();
                                this.tex = null;
                            }
                        }
                        //Convert texture so it has no mips
                        if (tex == null)
                        {
                            Texture2D            t    = this.FTextureIn[0][context].Resource;
                            Texture2DDescription desc = t.Description;
                            desc.BindFlags      = BindFlags.ShaderResource | BindFlags.RenderTarget;
                            desc.OptionFlags    = ResourceOptionFlags.Shared;
                            desc.MipLevels      = 1;
                            this.tex            = new Texture2D(context.Device, desc);
                            this.SharedResource = new SlimDX.DXGI.Resource(this.tex);
                            this.FPointer[0]    = (ulong)SharedResource.SharedHandle;
                        }

                        this.AssignedContext.CurrentDeviceContext.CopyResource(this.FTextureIn[0][context].Resource, this.tex);
                    }
                    else
                    {
                        this.SetDefault(0);
                    }
                }
                catch
                {
                    this.SetDefault(0);
                }
            }
            else
            {
                this.SetNull();
            }
        }
Exemple #44
0
        public void Update(DX11RenderContext context)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            if (!this.deviceshaderdata.Contains(context))
            {
                this.deviceshaderdata[context] = new DX11ShaderData(context, this.FShader);
            }
            if (!this.shaderVariableCache.Contains(context))
            {
                this.shaderVariableCache[context] = new DX11ShaderVariableCache(context, this.deviceshaderdata[context].ShaderInstance, this.varmanager);
            }
            if (!this.imageShaderInfo.Contains(context))
            {
                this.imageShaderInfo[context] = new ImageShaderInfo(this.deviceshaderdata[context].ShaderInstance);
            }

            DX11ShaderData  shaderdata = this.deviceshaderdata[context];
            ImageShaderInfo shaderInfo = this.imageShaderInfo[context];

            context.RenderStateStack.Push(new DX11RenderState());

            this.OnBeginQuery(context);


            //Clear shader stages
            shaderdata.ResetShaderStages(ctx);
            context.Primitives.ApplyFullTriVS();

            for (int i = 0; i < this.previousFrameResults.SliceCount; i++)
            {
                if (this.FInEnabled[i] || this.FInPreserveOnDisable[i] == false)
                {
                    this.previousFrameResults[i]?.UnLock();
                    this.previousFrameResults[i] = null;
                }
            }


            int wi, he;
            DX11ResourcePoolEntry <DX11RenderTarget2D> preservedtarget = null;

            renderSettings.CustomSemantics.Clear();
            renderSettings.ResourceSemantics.Clear();

            if (this.FInSemantics.IsConnected)
            {
                renderSettings.CustomSemantics.AddRange(this.FInSemantics.ToArray());
            }
            if (this.FInResSemantics.IsConnected)
            {
                renderSettings.ResourceSemantics.AddRange(this.FInResSemantics.ToArray());
            }

            for (int textureIndex = 0; textureIndex < this.spmax; textureIndex++)
            {
                int passcounter = 0;

                if (this.FInEnabled[textureIndex])
                {
                    List <DX11ResourcePoolEntry <DX11RenderTarget2D> > locktargets = new List <DX11ResourcePoolEntry <DX11RenderTarget2D> >();

                    #region Manage size
                    DX11Texture2D initial;
                    if (this.FIn.IsConnected)
                    {
                        if (this.FInUseDefaultSize[0])
                        {
                            if (this.FIn[textureIndex].Contains(context) && this.FIn[textureIndex][context] != null)
                            {
                                initial = this.FIn[textureIndex][context];
                            }
                            else
                            {
                                initial = context.DefaultTextures.WhiteTexture;
                            }
                            wi = (int)this.FInSize[0].X;
                            he = (int)this.FInSize[0].Y;
                        }
                        else
                        {
                            initial = this.FIn[textureIndex].Contains(context) ? this.FIn[textureIndex][context] : null;
                            if (initial != null)
                            {
                                wi = initial.Width;
                                he = initial.Height;
                            }
                            else
                            {
                                initial = context.DefaultTextures.WhiteTexture;
                                wi      = (int)this.FInSize[textureIndex].X;
                                he      = (int)this.FInSize[textureIndex].Y;
                            }
                        }
                    }
                    else
                    {
                        initial = context.DefaultTextures.WhiteTexture;
                        wi      = (int)this.FInSize[textureIndex].X;
                        he      = (int)this.FInSize[textureIndex].Y;
                    }
                    #endregion

                    renderSettings.RenderWidth  = wi;
                    renderSettings.RenderHeight = he;


                    this.varmanager.SetGlobalSettings(shaderdata.ShaderInstance, renderSettings);
                    var variableCache = this.shaderVariableCache[context];
                    variableCache.ApplyGlobals(renderSettings);


                    DX11ResourcePoolEntry <DX11RenderTarget2D> lasttmp = null;

                    List <DX11Texture2D> rtlist = new List <DX11Texture2D>();

                    //Go trough all passes
                    int tid = this.FInTechnique[textureIndex].Index;
                    ImageShaderTechniqueInfo techniqueInfo = shaderInfo.GetTechniqueInfo(tid);

                    //Now we need to add optional extra pass in case we want mip chain (only in case it's not needed, if texture has mips we just ignore)
                    if (techniqueInfo.WantMips)
                    {
                        //Single level and bigger than 1 should get a mip generation pass
                        if (initial.Width > 1 && initial.Height > 1 && initial.Resource.Description.MipLevels == 1)
                        {
                            //Texture might now be an allowed render target format, so we at least need to check that, and default to rgba8 unorm
                            //also check for auto mip map gen
                            var mipTargetFmt = initial.Format;
                            if (!context.IsSupported(FormatSupport.RenderTarget, mipTargetFmt) ||
                                !context.IsSupported(FormatSupport.MipMapAutoGeneration, mipTargetFmt) ||
                                !context.IsSupported(FormatSupport.UnorderedAccessView, mipTargetFmt))
                            {
                                mipTargetFmt = Format.R8G8B8A8_UNorm;
                            }



                            DX11ResourcePoolEntry <DX11RenderTarget2D> mipTarget = context.ResourcePool.LockRenderTarget(initial.Width, initial.Height, mipTargetFmt, new SampleDescription(1, 0), true, 0);
                            locktargets.Add(mipTarget);

                            context.RenderTargetStack.Push(mipTarget.Element);

                            context.BasicEffects.PointSamplerPixelPass.Apply(initial.SRV);

                            context.CurrentDeviceContext.Draw(3, 0);

                            context.RenderTargetStack.Pop();

                            context.CurrentDeviceContext.GenerateMips(mipTarget.Element.SRV);

                            //Replace initial by our new texture
                            initial = mipTarget.Element;
                        }
                    }

                    //Bind Initial (once only is ok) and mark for previous usage too
                    DX11Texture2D lastrt = initial;
                    shaderInfo.ApplyInitial(initial.SRV);

                    for (int passIndex = 0; passIndex < techniqueInfo.PassCount; passIndex++)
                    {
                        ImageShaderPassInfo passInfo = techniqueInfo.GetPassInfo(passIndex);
                        bool isLastPass = passIndex == techniqueInfo.PassCount - 1;


                        Format fmt = initial.Format;
                        if (passInfo.CustomFormat)
                        {
                            fmt = passInfo.Format;
                        }
                        bool mips = passInfo.Mips || (isLastPass && FInMipLastPass[textureIndex]);

                        int w, h;
                        if (passIndex == 0)
                        {
                            h = he;
                            w = wi;
                        }
                        else
                        {
                            h = passInfo.Reference == ImageShaderPassInfo.eImageScaleReference.Initial ? he : lastrt.Height;
                            w = passInfo.Reference == ImageShaderPassInfo.eImageScaleReference.Initial ? wi : lastrt.Width;
                        }

                        if (passInfo.DoScale)
                        {
                            if (passInfo.Absolute)
                            {
                                w = Convert.ToInt32(passInfo.ScaleVector.X);
                                h = Convert.ToInt32(passInfo.ScaleVector.Y);
                            }
                            else
                            {
                                w = Convert.ToInt32((float)w * passInfo.ScaleVector.X);
                                h = Convert.ToInt32((float)h * passInfo.ScaleVector.Y);
                            }

                            w = Math.Max(w, 1);
                            h = Math.Max(h, 1);
                        }

                        //Check format support for render target, and default to rgb8 if not
                        if (!context.IsSupported(FormatSupport.RenderTarget, fmt))
                        {
                            fmt = Format.R8G8B8A8_UNorm;
                        }

                        //To avoid uav issue
                        if (fmt == Format.B8G8R8A8_UNorm)
                        {
                            fmt = Format.R8G8B8A8_UNorm;
                        }

                        DX11ResourcePoolEntry <DX11RenderTarget2D> elem;
                        if (preservedtarget != null)
                        {
                            elem = preservedtarget;
                        }
                        else
                        {
                            elem = context.ResourcePool.LockRenderTarget(w, h, fmt, new SampleDescription(1, 0), mips, 0);
                            locktargets.Add(elem);
                        }
                        DX11RenderTarget2D rt = elem.Element;


                        if (this.FDepthIn.IsConnected && passInfo.UseDepth)
                        {
                            context.RenderTargetStack.Push(this.FDepthIn[0][context], true, elem.Element);
                        }
                        else
                        {
                            context.RenderTargetStack.Push(elem.Element);
                        }

                        if (passInfo.Clear)
                        {
                            elem.Element.Clear(new Color4(0, 0, 0, 0));
                        }

                        #region Check for depth/blend preset
                        bool validdepth = false;
                        bool validblend = false;

                        DepthStencilStateDescription ds = new DepthStencilStateDescription();
                        BlendStateDescription        bs = new BlendStateDescription();

                        if (passInfo.DepthPreset != "")
                        {
                            try
                            {
                                ds         = DX11DepthStencilStates.GetState(passInfo.DepthPreset);
                                validdepth = true;
                            }
                            catch
                            {
                            }
                        }

                        if (passInfo.BlendPreset != "")
                        {
                            try
                            {
                                bs         = DX11BlendStates.GetState(passInfo.BlendPreset);
                                validblend = true;
                            }
                            catch
                            {
                            }
                        }
                        #endregion

                        if (validdepth || validblend)
                        {
                            DX11RenderState state = new DX11RenderState();
                            if (validdepth)
                            {
                                state.DepthStencil = ds;
                            }
                            if (validblend)
                            {
                                state.Blend = bs;
                            }
                            context.RenderStateStack.Push(state);
                        }

                        renderSettings.RenderWidth  = w;
                        renderSettings.RenderHeight = h;
                        renderSettings.BackBuffer   = elem.Element;

                        //Apply settings (we do both here, as texture size semantic might ahve
                        variableCache.ApplyGlobals(renderSettings);
                        variableCache.ApplySlice(objectSettings, textureIndex);
                        //Bind last render target

                        shaderInfo.ApplyPrevious(lastrt.SRV);

                        this.BindPassIndexSemantic(shaderdata.ShaderInstance.Effect, passIndex);

                        if (this.FDepthIn.IsConnected)
                        {
                            if (this.FDepthIn[0].Contains(context))
                            {
                                shaderInfo.ApplyDepth(this.FDepthIn[0][context].SRV);
                            }
                        }

                        for (int list = 0; list < this.FinPrePostActions.SliceCount; list++)
                        {
                            if (this.FinPrePostActions[list] != null)
                            {
                                this.FinPrePostActions[list].OnBeginPass(context, passIndex);
                            }
                        }

                        //Apply pass and draw quad
                        passInfo.Apply(ctx);

                        if (passInfo.ComputeData.Enabled)
                        {
                            passInfo.ComputeData.Dispatch(context, w, h);
                            context.CleanUpCS();
                        }
                        else
                        {
                            ctx.ComputeShader.Set(null);
                            context.Primitives.FullScreenTriangle.Draw();
                            ctx.OutputMerger.SetTargets(this.nullrtvs);
                        }

                        //Generate mips if applicable
                        if (mips)
                        {
                            ctx.GenerateMips(rt.SRV);
                        }

                        if (!passInfo.KeepTarget)
                        {
                            rtlist.Add(rt);
                            lastrt          = rt;
                            lasttmp         = elem;
                            preservedtarget = null;
                            passcounter++;
                        }
                        else
                        {
                            preservedtarget = elem;
                        }


                        context.RenderTargetStack.Pop();

                        //Apply pass result semantic if applicable (after pop)
                        shaderInfo.ApplyPassResult(lasttmp.Element.SRV, passIndex);

                        if (validblend || validdepth)
                        {
                            context.RenderStateStack.Pop();
                        }

                        if (passInfo.HasState)
                        {
                            context.RenderStateStack.Apply();
                        }

                        for (int list = 0; list < this.FinPrePostActions.SliceCount; list++)
                        {
                            if (this.FinPrePostActions[list] != null)
                            {
                                this.FinPrePostActions[list].OnEndPass(context, passIndex);
                            }
                        }
                    }

                    //Set last render target
                    this.FOut[textureIndex][context] = lastrt;

                    //Unlock all resources
                    foreach (DX11ResourcePoolEntry <DX11RenderTarget2D> lt in locktargets)
                    {
                        lt.UnLock();
                    }

                    //Keep lock on last rt, since don't want it overidden
                    lasttmp.Lock();

                    this.previousFrameResults[textureIndex] = lasttmp;
                }
                else
                {
                    if (this.FInPreserveOnDisable[textureIndex])
                    {
                        //We kept it locked on top
                        this.FOut[textureIndex][context] = this.previousFrameResults[textureIndex] != null ? this.previousFrameResults[textureIndex].Element : null;
                    }
                    else
                    {
                        this.FOut[textureIndex][context] = this.FIn[textureIndex][context];
                    }
                }
            }

            context.RenderStateStack.Pop();

            this.OnEndQuery(context);
        }
 public FileTexture3DLoadTask(DX11RenderContext context, int slice, string path)
     : base(context, slice, path)
 {
 }
 public void Update(IPluginIO pin, DX11RenderContext context)
 {
 }
 public void Destroy(IPluginIO pin, DX11RenderContext context, bool force)
 {
 }
Exemple #48
0
 public DX11RenderTarget2D(DX11RenderContext context, int w, int h, SampleDescription sd, Format format) :
     this(context, w, h, sd, format, false, 1)
 {
 }
 public void Update(DX11RenderContext context)
 {
 }
 protected override ShaderResourceView GetDefaultSRV(DX11RenderContext context)
 {
     return(context.DefaultTextures.WhiteTexture.SRV);
 }
Exemple #51
0
        public void Render(IPluginIO pin, DX11RenderContext context, DX11RenderSettings settings)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            bool popstate = false;

            bool multistate = this.FInState.IsConnected && this.FInState.SliceCount > 1;

            if (this.FInEnabled[0])
            {
                //In that case we do not care about geometry, but only apply pass for globals
                if (settings.RenderHint == eRenderHint.ApplyOnly)
                {
                    DX11ShaderData sdata = this.deviceshaderdata[context];
                    this.varmanager.SetGlobalSettings(sdata.ShaderInstance, settings);
                    this.varmanager.ApplyGlobal(sdata.ShaderInstance);

                    DX11ObjectRenderSettings oset = new DX11ObjectRenderSettings();
                    oset.DrawCallIndex  = 0;
                    oset.Geometry       = null;
                    oset.IterationCount = 1;
                    oset.IterationIndex = 0;
                    oset.WorldTransform = this.mworld[0 % this.mworldcount];
                    this.varmanager.ApplyPerObject(context, sdata.ShaderInstance, oset, 0);
                    sdata.ApplyPass(ctx);


                    if (this.FInLayer.IsConnected)
                    {
                        this.FInLayer[0][context].Render(this.FInLayer.PluginIO, context, settings);
                    }

                    return;
                }

                if (settings.RenderHint == eRenderHint.Collector)
                {
                    if (this.FGeometry.PluginIO.IsConnected)
                    {
                        DX11ObjectGroup group = new DX11ObjectGroup();
                        group.ShaderName = this.Source.Name;
                        group.Semantics.AddRange(settings.CustomSemantics);

                        if (this.FGeometry.SliceCount == 1)
                        {
                            IDX11Geometry g = this.FGeometry[0][context];
                            if (g.Tag != null)
                            {
                                DX11RenderObject o = new DX11RenderObject();
                                o.ObjectType = g.PrimitiveType;
                                o.Descriptor = g.Tag;
                                o.Transforms = new Matrix[spmax];
                                for (int i = 0; i < this.spmax; i++)
                                {
                                    o.Transforms[i] = this.mworld[i % this.mworldcount];
                                }
                                group.RenderObjects.Add(o);

                                settings.SceneDescriptor.Groups.Add(group);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < this.spmax; i++)
                            {
                                IDX11Geometry g = this.FGeometry[i][context];
                                if (g.Tag != null)
                                {
                                    DX11RenderObject o = new DX11RenderObject();
                                    o.ObjectType    = g.PrimitiveType;
                                    o.Descriptor    = g.Tag;
                                    o.Transforms    = new Matrix[1];
                                    o.Transforms[0] = this.mworld[i % this.mworldcount];
                                    group.RenderObjects.Add(o);
                                }
                            }

                            settings.SceneDescriptor.Groups.Add(group);
                        }
                    }
                    return;
                }

                DX11ShaderData shaderdata = this.deviceshaderdata[context];
                if ((shaderdata.IsValid &&
                     (this.geomconnected || settings.Geometry != null) &&
                     this.spmax > 0 && this.varmanager.SetGlobalSettings(shaderdata.ShaderInstance, settings)) ||
                    this.FInApplyOnly[0])
                {
                    this.OnBeginQuery(context);

                    //Select preferred technique if available
                    if (settings.PreferredTechniques.Count == 0 && this.techniqueindex != this.FInTechnique[0].Index)
                    {
                        this.techniqueindex   = this.FInTechnique[0].Index;
                        this.techniquechanged = true;
                    }
                    else if (settings.PreferredTechniques.Count > 0)
                    {
                        int i = settings.GetPreferredTechnique(this.FShader);
                        if (i == -1)
                        {
                            i = this.FInTechnique[0].Index;
                        }
                        if (i != this.techniqueindex)
                        {
                            this.techniqueindex   = i;
                            this.techniquechanged = true;
                        }
                    }

                    //Need to build input layout
                    if (this.FGeometry.IsChanged || this.techniquechanged || shaderdata.LayoutValid.Count == 0)
                    {
                        shaderdata.Update(this.techniqueindex, 0, this.FGeometry);
                        this.FOutLayoutValid.AssignFrom(shaderdata.LayoutValid);
                        this.FOutLayoutMsg.AssignFrom(shaderdata.LayoutMsg);

                        int           errorCount = 0;
                        StringBuilder sbMsg      = new StringBuilder();
                        sbMsg.Append("Invalid layout detected for slices:");
                        for (int i = 0; i < shaderdata.LayoutValid.Count; i++)
                        {
                            if (shaderdata.LayoutValid[i] == false)
                            {
                                errorCount++;
                                sbMsg.Append(i + ",");
                            }
                        }

                        if (errorCount > 0)
                        {
                            this.FHost.Log(TLogType.Warning, sbMsg.ToString());
                        }

                        this.techniquechanged = false;
                    }

                    if (this.stateconnected && !multistate)
                    {
                        context.RenderStateStack.Push(this.FInState[0]);
                        popstate = true;
                    }

                    ShaderPipelineState pipelineState = null;
                    if (!settings.PreserveShaderStages)
                    {
                        shaderdata.ResetShaderStages(ctx);
                    }
                    else
                    {
                        pipelineState = new ShaderPipelineState(context);
                    }

                    settings.DrawCallCount = spmax; //Set number of draw calls

                    this.varmanager.ApplyGlobal(shaderdata.ShaderInstance);

                    //IDX11Geometry drawgeom = null;
                    objectsettings.Geometry = null;
                    DX11Resource <IDX11Geometry> pg = null;
                    bool       doOrder       = false;
                    List <int> orderedSlices = null;
                    if (settings.LayerOrder != null && settings.LayerOrder.Enabled)
                    {
                        this.orderedObjectSettings.Clear();
                        for (int i = 0; i < this.spmax; i++)
                        {
                            DX11ObjectRenderSettings objSettings = new DX11ObjectRenderSettings();
                            objSettings.DrawCallIndex  = i;
                            objSettings.Geometry       = null;
                            objSettings.IterationCount = 1;
                            objSettings.IterationIndex = 0;
                            objSettings.WorldTransform = this.mworld[i % this.mworldcount];

                            this.orderedObjectSettings.Add(objSettings);
                        }

                        orderedSlices = settings.LayerOrder.Reorder(settings, orderedObjectSettings);
                        doOrder       = true;
                    }

                    int drawCount = doOrder ? orderedSlices.Count : this.spmax;

                    if (this.spmax == 0)
                    {
                        drawCount = 0;
                    }

                    for (int i = 0; i < drawCount; i++)
                    {
                        int idx = doOrder ? orderedSlices[i] : i;
                        if (multistate)
                        {
                            context.RenderStateStack.Push(this.FInState[idx]);
                        }

                        if (shaderdata.IsLayoutValid(idx) || settings.Geometry != null)
                        {
                            objectsettings.IterationCount = this.FIter[idx];

                            for (int k = 0; k < objectsettings.IterationCount; k++)
                            {
                                objectsettings.IterationIndex = k;
                                if (settings.Geometry == null)
                                {
                                    if (this.FGeometry[idx] != pg)
                                    {
                                        pg = this.FGeometry[idx];

                                        objectsettings.Geometry = pg[context];

                                        shaderdata.SetInputAssembler(ctx, objectsettings.Geometry, idx);
                                    }
                                }
                                else
                                {
                                    objectsettings.Geometry = settings.Geometry;
                                    shaderdata.SetInputAssembler(ctx, objectsettings.Geometry, idx);
                                }

                                //Prepare settings
                                objectsettings.DrawCallIndex  = idx;
                                objectsettings.WorldTransform = this.mworld[idx % this.mworldcount];

                                if (settings.ValidateObject(objectsettings))
                                {
                                    this.varmanager.ApplyPerObject(context, shaderdata.ShaderInstance, this.objectsettings, idx);

                                    shaderdata.ApplyPass(ctx);

                                    if (settings.DepthOnly)
                                    {
                                        ctx.PixelShader.Set(null);
                                    }

                                    if (settings.PostPassAction != null)
                                    {
                                        settings.PostPassAction(context);
                                    }


                                    objectsettings.Geometry.Draw();
                                    shaderdata.ShaderInstance.CleanUp();
                                }
                            }
                        }

                        if (multistate)
                        {
                            context.RenderStateStack.Pop();
                        }

                        if (settings.PostShaderAction != null)
                        {
                            settings.PostShaderAction(context);
                        }
                    }

                    if (pipelineState != null)
                    {
                        pipelineState.Restore(context);
                    }


                    this.OnEndQuery(context);
                }
                //this.query.End();
            }

            if (popstate)
            {
                context.RenderStateStack.Pop();
            }
            else
            {
                //Since shaders can define their own states, reapply top of the stack
                context.RenderStateStack.Apply();
            }

            if (this.FInLayer.IsConnected && this.FInEnabled[0])
            {
                this.FInLayer[0][context].Render(this.FInLayer.PluginIO, context, settings);
            }
        }
 public void Update(DX11RenderContext context)
 {
     this.FTextureOutput[0][context] = null;
 }
Exemple #53
0
 public DX11RenderTarget2D(DX11RenderContext context, int w, int h, SampleDescription sd, Format format, bool genMipMaps, int mmLevels) :
     this(context, w, h, sd, format, genMipMaps, mmLevels, true, false)
 {
 }
Exemple #54
0
 protected override IDX11RWResource GetMainTarget(DX11RenderContext context)
 {
     return(this.FOutBuffers[0][context] as IDX11RWResource);
 }
 protected override void OnDestroy(DX11RenderContext context, bool force)
 {
     this.FOutBackBuffer[0].Dispose(context);
 }
 public void Destroy(DX11RenderContext context, bool force)
 {
     this.FOutGeom.SafeDisposeAll(context);
 }
 public DX11DeviceRenderer(DX11RenderContext context, DX11Graph graph, ILogger logger)
 {
     this.logger  = logger;
     this.context = context;
     this.graph   = graph;
 }
Exemple #58
0
 public void Destroy(DX11RenderContext context, bool force)
 {
 }
        public TexInfo GetRenderTarget(DX11RenderContext context)
        {
            TexInfo ti = new TexInfo();

            if (this.currentmode == eRenderFormatMode.Inherit)
            {
                if (this.texinputpin.IOObject.IsConnected)
                {
                    DX11Texture2D t = this.texinputpin.IOObject[0][context];

                    if (t.Resource != null)
                    {
                        ti.w = t.Width;
                        ti.h = t.Height;
                        if (DX11EnumFormatHelper.NullDeviceFormats.GetAllowedFormats(FormatSupport.RenderTarget).Contains(t.Format.ToString()))
                        {
                            ti.format = t.Format;
                        }
                        else
                        {
                            ti.format = DeviceFormatHelper.GetFormat(this.FInFormat.IOObject[0]);
                        }
                    }
                    else
                    {
                        ti.w      = (int)this.FInTextureSize.IOObject[0].x;
                        ti.h      = (int)this.FInTextureSize.IOObject[0].y;
                        ti.format = DeviceFormatHelper.GetFormat(this.FInFormat.IOObject[0]);
                    }
                }
                else
                {
                    ti.w      = (int)this.FInTextureSize.IOObject[0].x;
                    ti.h      = (int)this.FInTextureSize.IOObject[0].y;
                    ti.format = DeviceFormatHelper.GetFormat(this.FInFormat.IOObject[0]);
                }
            }

            if (this.currentmode == eRenderFormatMode.InheritSize)
            {
                if (this.texinputpin.IOObject.IsConnected)
                {
                    DX11Texture2D t = this.texinputpin.IOObject[0][context];

                    if (t.Resource != null)
                    {
                        ti.w = t.Width;
                        ti.h = t.Height;
                    }
                    else
                    {
                        ti.w = (int)this.FInTextureSize.IOObject[0].x;
                        ti.h = (int)this.FInTextureSize.IOObject[0].y;
                    }
                }
                else
                {
                    ti.w = (int)this.FInTextureSize.IOObject[0].x;
                    ti.h = (int)this.FInTextureSize.IOObject[0].y;
                }

                ti.format = DeviceFormatHelper.GetFormat(this.FInFormat.IOObject[0]);
            }

            if (this.currentmode == eRenderFormatMode.Manual)
            {
                ti.w      = (int)this.FInTextureSize.IOObject[0].x;
                ti.h      = (int)this.FInTextureSize.IOObject[0].y;
                ti.format = DeviceFormatHelper.GetFormat(this.FInFormat.IOObject[0]);
            }

            ti.w = Convert.ToInt32((double)ti.w * this.FInTextureScale.IOObject[0].x);
            ti.h = Convert.ToInt32((double)ti.h * this.FInTextureScale.IOObject[0].y);

            return(ti);
        }
Exemple #60
0
        public void Render(DX11RenderContext context)
        {
            if (this.lasthandle != this.Handle)
            {
                if (this.swapchain != null)
                {
                    if (this.swapchain.Contains(context))
                    {
                        this.swapchain.Dispose(context);
                    }
                }
                this.lasthandle = this.Handle;
            }

            if (!this.swapchain.Contains(context))
            {
                this.swapchain[context] = new DX11SwapChain(context, this.Handle, SlimDX.DXGI.Format.R8G8B8A8_UNorm, new SampleDescription(1, 0), 60, 1, false);
            }

            if (this.resized)
            {
                this.swapchain[context].Resize();
            }

            if (this.FEnabled[0])
            {
                context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, new SlimDX.Color4(0, 0, 0, 0));
            }

            if (this.FIn.IsConnected && this.spreadMax > 0 && this.FEnabled[0])
            {
                int id = this.FIndex[0];
                if (this.FIn[id].Contains(context) && this.FIn[id][context] != null)
                {
                    context.RenderTargetStack.Push(this.swapchain[context]);
                    var rs = new DX11RenderState();

                    if (FAlpha[0])
                    {
                        rs.Blend = DX11BlendStates.Instance.GetState("Blend");
                        context.CurrentDeviceContext.ClearRenderTargetView(this.swapchain[context].RTV, FInBgColor[0].Color);
                    }
                    context.RenderStateStack.Push(rs);
                    context.CleanShaderStages();

                    context.Primitives.FullTriVS.GetVariableBySemantic("TEXTURE").AsResource().SetResource(this.FIn[id][context].SRV);

                    EffectSamplerVariable samplervariable = context.Primitives.FullTriVS.GetVariableByName("linSamp").AsSampler();
                    SamplerState          state           = null;
                    if (this.FInSamplerState.IsConnected)
                    {
                        state = SamplerState.FromDescription(context.Device, this.FInSamplerState[0]);
                        samplervariable.SetSamplerState(0, state);
                    }
                    else
                    {
                        samplervariable.UndoSetSamplerState(0);
                    }

                    context.Primitives.FullScreenTriangle.Bind(null);
                    context.Primitives.ApplyFullTri();
                    context.Primitives.FullScreenTriangle.Draw();

                    context.RenderStateStack.Pop();
                    context.RenderTargetStack.Pop();
                    context.CleanUpPS();
                    samplervariable.UndoSetSamplerState(0);  //undo as can be used in other places

                    if (state != null)
                    {
                        state.Dispose();
                    }
                }
            }
        }