Exemplo n.º 1
0
    public static Result D3D11On12CreateDevice(
        IUnknown d3d12Device,
        DeviceCreationFlags flags,
        FeatureLevel[] featureLevels,
        IUnknown[] commandQueues,
        int nodeMask,
        out ID3D11Device device,
        out ID3D11DeviceContext immediateContext,
        out FeatureLevel chosenFeatureLevel)
    {
        Result result = D3D11On12CreateDevice(d3d12Device,
                                              flags,
                                              featureLevels, featureLevels.Length,
                                              commandQueues, commandQueues.Length,
                                              nodeMask,
                                              out device, out immediateContext, out chosenFeatureLevel);

        if (result.Failure)
        {
            return(result);
        }

        if (immediateContext != null)
        {
            device.AddRef();
            device.ImmediateContext__ = immediateContext;
            immediateContext.Device__ = device;
        }

        return(result);
    }
Exemplo n.º 2
0
 public override void InitBuffers(ID3D11Device d3d, ID3D11DeviceContext context)
 {
     if (vertices.Length != 0)
     {
         vertexBuffer = d3d.CreateBuffer(BindFlags.VertexBuffer, vertices, 0, ResourceUsage.Dynamic, CpuAccessFlags.Write);
     }
 }
Exemplo n.º 3
0
 public void RenderPrimitives(ID3D11Device InDevice, ID3D11DeviceContext InDeviceContext, Camera InCamera)
 {
     foreach (PrimitiveBatch Batch in Batches.Values)
     {
         Batch.RenderBatch(InDevice, InDeviceContext, InCamera);
     }
 }
Exemplo n.º 4
0
        public override void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
        {
            if (!DoRender)
            {
                return;
            }

            //if (!camera.CheckBBoxFrustum(Transform.TranslationVector, BoundingBox))
            //     return;

            VertexBufferView VertexBufferView = new VertexBufferView(vertexBuffer, Unsafe.SizeOf <VertexLayouts.NormalLayout.Vertex>(), 0);

            deviceContext.IASetVertexBuffers(0, VertexBufferView);
            deviceContext.IASetIndexBuffer(indexBuffer, Vortice.DXGI.Format.R32_UInt, 0);
            deviceContext.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
            deviceContext.PSSetShaderResource(2, AOTexture);

            for (int i = 0; i != LODs[0].ModelParts.Length; i++)
            {
                ModelPart Segment = LODs[0].ModelParts[i];
                Segment.Shader.SetShaderParameters(device, deviceContext, new MaterialParameters(Segment.Material, SelectionColour.Normalize()));
                Segment.Shader.SetSceneVariables(deviceContext, Transform, camera);
                Segment.Shader.Render(deviceContext, PrimitiveTopology.TriangleList, (int)(Segment.NumFaces * 3), Segment.StartIndex);
            }
        }
Exemplo n.º 5
0
        public void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
        {
            if (bIsReady)
            {
                if (currentCell != -1)
                {
                    cells[currentCell].Render(device, deviceContext, camera);
                }


                foreach (var cell in cells)
                {
                    cell.Render(device, deviceContext, camera);
                }

                /*cellBoundingBox.Render(device, deviceContext, camera);
                 * currentCell = GetCell(camera.Position);
                 * //cells[currentCell].Render(device, deviceContext, camera);
                 * //Debug.WriteLine(cells[currentCell].BoundingBox.ToString());
                 * if (previousCell != currentCell)
                 * {
                 *  BoundingBox newBounds = cells[currentCell].BoundingBox;
                 *  newBounds.Minimum.Z = gridBounds.Minimum.Z;
                 *  newBounds.Maximum.Z = gridBounds.Maximum.Z;
                 *
                 *  cellBoundingBox.Update(newBounds);
                 *  cellBoundingBox.UpdateBuffers(device, deviceContext);
                 *  previousCell = currentCell;
                 * }
                 * boundingBox.Render(device, deviceContext, camera);
                 */
            }
        }
Exemplo n.º 6
0
        void SetupRenderState(ImDrawDataPtr drawData, ID3D11DeviceContext ctx)
        {
            var viewport = new Viewport
            {
                Width    = drawData.DisplaySize.X,
                Height   = drawData.DisplaySize.Y,
                MinDepth = 0.0f,
                MaxDepth = 1.0f,
            };

            ctx.RSSetViewports(viewport);

            int stride = sizeof(ImDrawVert);
            int offset = 0;

            ctx.IASetInputLayout(inputLayout);
            ctx.IASetVertexBuffers(0, 1, new[] { vertexBuffer }, new[] { stride }, new[] { offset });
            ctx.IASetIndexBuffer(indexBuffer, sizeof(ImDrawIdx) == 2 ? Format.R16_UInt : Format.R32_UInt, 0);
            ctx.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
            ctx.VSSetShader(vertexShader);
            ctx.VSSetConstantBuffers(0, constantBuffer);
            ctx.PSSetShader(pixelShader);
            ctx.PSSetSamplers(0, fontSampler);
            ctx.GSSetShader(null);
            ctx.HSSetShader(null);
            ctx.DSSetShader(null);
            ctx.CSSetShader(null);

            ctx.OMSetBlendState(blendState);
            ctx.OMSetDepthStencilState(depthStencilState);
            ctx.RSSetState(rasterizerState);
        }
Exemplo n.º 7
0
        public override void InitBuffers(ID3D11Device d3d, ID3D11DeviceContext d3dContext)
        {
            vertexBuffer = d3d.CreateBuffer(BindFlags.VertexBuffer, LODs[0].Vertices, 0, ResourceUsage.Default, CpuAccessFlags.None);
            indexBuffer  = d3d.CreateBuffer(BindFlags.IndexBuffer, LODs[0].Indices, 0, ResourceUsage.Default, CpuAccessFlags.None);

            InitTextures(d3d, d3dContext);
        }
Exemplo n.º 8
0
 internal static void SetUnorderedAccessViewsKeepRTV(this ID3D11DeviceContext context, int startSlot, int numBuffers, IntPtr unorderedAccessBuffer, IntPtr uavCount)
 {
     context.OMSetRenderTargetsAndUnorderedAccessViews(
         ID3D11DeviceContext.KeepRenderTargetsAndDepthStencil,
         IntPtr.Zero, null, startSlot, numBuffers,
         unorderedAccessBuffer, uavCount);
 }
Exemplo n.º 9
0
 public void Initialise(ID3D11Device device, ID3D11DeviceContext deviceContext)
 {
     foreach (KeyValuePair <int, IRenderer> entry in assets)
     {
         entry.Value.InitBuffers(device, deviceContext);
     }
 }
Exemplo n.º 10
0
 public D3D11Device(IntPtr handle, D3DFeatureLevel featureLevel, ID3D11SwapChain swapChain, ID3D11DeviceContext context)
 {
     _handle      = handle;
     FeatureLevel = featureLevel;
     SwapChain    = swapChain;
     Context      = context;
 }
Exemplo n.º 11
0
        public virtual void Render(ID3D11DeviceContext context, PrimitiveTopology type, int size, uint offset)
        {
            context.IASetInputLayout(Layout);

            // set shaders only if available
            if (OurVertexShader != null)
            {
                context.VSSetShader(OurVertexShader);
            }

            if (OurVertexShader != null)
            {
                context.PSSetShader(OurPixelShader);
                context.PSSetSampler(0, SamplerState);
            }

            if (OurVertexShader != null)
            {
                context.GSSetShader(OurGeometryShader);
            }

            context.DrawIndexed(size, (int)offset, 0);

            Profiler.NumDrawCallsThisFrame++;
        }
Exemplo n.º 12
0
        public virtual void SetShaderParameters(ID3D11Device device, ID3D11DeviceContext deviceContext, MaterialParameters matParams)
        {
            if (!previousEditorParams.Equals(matParams.SelectionColour))
            {
                var editorParams = new EditorParameterBuffer()
                {
                    selectionColour = matParams.SelectionColour
                };

                ConstantBufferFactory.UpdatePixelBuffer(deviceContext, ConstantEditorParamsBuffer, 1, editorParams);
                previousEditorParams = editorParams.selectionColour;
            }

            //experiments with samplers; currently the toolkit doesn't not support any types.

            /*SamplerStateDescription samplerDesc = new SamplerStateDescription()
             * {
             *  Filter = Filter.Anisotropic,
             *  AddressU = (material != null) ? (TextureAddressMode)material.Samplers["S000"].SamplerStates[0] : TextureAddressMode.Wrap,
             *  AddressV = (material != null) ? (TextureAddressMode)material.Samplers["S000"].SamplerStates[1] : TextureAddressMode.Wrap,
             *  AddressW = (material != null) ? (TextureAddressMode)material.Samplers["S000"].SamplerStates[2] : TextureAddressMode.Wrap,
             *  MipLodBias = 0,
             *  MaximumAnisotropy = 16,
             *  ComparisonFunction = Comparison.Always,
             *  BorderColor = new Color4(0, 0, 0, 0),
             *  MinimumLod = 0,
             *  MaximumLod = float.MaxValue
             * };
             *
             * SamplerState = new SamplerState(device, samplerDesc);*/
        }
 public override void UpdateBuffers(ID3D11Device device, ID3D11DeviceContext deviceContext)
 {
     if (bIsUpdatedNeeded)
     {
         //todo: implement this!
     }
 }
Exemplo n.º 14
0
        public void Setup(ID3D11Device device, ID3D11DeviceContext context)
        {
            if (!m_vertexAttributes.Any())
            {
                return;
            }

            if (!m_inputLayout)
            {
                var hr = device.CreateVertexShader(m_vs_blob.GetBufferPointer(), m_vs_blob.GetBufferSize(), null, out m_vs);
                hr.ThrowIfFailed();
                hr = device.CreatePixelShader(m_ps_blob.GetBufferPointer(), m_ps_blob.GetBufferSize(), null, out m_ps);
                hr.ThrowIfFailed();

                hr = device.CreateInputLayout(ref m_layout[0], (uint)m_layout.Length,
                                              m_vs_blob.GetBufferPointer(), m_vs_blob.GetBufferSize(), out m_inputLayout);
                hr.ThrowIfFailed();
            }

            // setup shader pipeline
            Span <IntPtr> classes = stackalloc IntPtr[] { };

            context.VSSetShader(m_vs, ref MemoryMarshal.GetReference(classes), (uint)classes.Length);
            context.PSSetShader(m_ps, ref MemoryMarshal.GetReference(classes), (uint)classes.Length);
            context.IASetInputLayout(m_inputLayout);
        }
Exemplo n.º 15
0
 public override void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
 {
     if (DoRender != false)
     {
         BBox.Render(device, deviceContext, camera);
         Path.Render(device, deviceContext, camera);
     }
 }
Exemplo n.º 16
0
        unsafe public static void UpdateVertexBuffer <T>(ID3D11DeviceContext context, ID3D11Buffer buffer, int slot, T data) where T : struct
        {
            MappedSubresource mappedResource = context.Map(buffer, MapMode.WriteDiscard, MapFlags.None);

            Unsafe.Write((void *)mappedResource.DataPointer, data);
            context.Unmap(buffer);
            context.VSSetConstantBuffer(slot, buffer);
        }
Exemplo n.º 17
0
 public void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
 {
     /*foreach (KeyValuePair<int, IRenderer> entry in assets)
      * {
      *  entry.Value.UpdateBuffers(device, deviceContext);
      *  entry.Value.Render(device, deviceContext, camera);
      * }*/
 }
Exemplo n.º 18
0
 public override void UpdateBuffers(ID3D11Device device, ID3D11DeviceContext deviceContext)
 {
     if (bIsUpdatedNeeded)
     {
         SetupShaders();
         InitTextures(device, deviceContext);
         bIsUpdatedNeeded = false;
     }
 }
        public static void DrawIndexed(this ID3D11DeviceContext context, int indexCount, int startIndexLocation, int baseVertexLocation)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.DrawIndexed((uint)indexCount, (uint)startIndexLocation, baseVertexLocation);
        }
        public static void IASetPrimitiveTopology(this ID3D11DeviceContext context, D3D_PRIMITIVE_TOPOLOGY topology)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.IASetPrimitiveTopology(topology);
        }
Exemplo n.º 21
0
 public override void UpdateBuffers(ID3D11Device device, ID3D11DeviceContext deviceContext)
 {
     if (vertexBuffer != null)
     {
         vertexBuffer.Dispose();
         vertexBuffer = null;
     }
     InitBuffers(device, deviceContext);
     bIsUpdatedNeeded = false;
 }
Exemplo n.º 22
0
        public override void Render(ID3D11Device device, ID3D11DeviceContext deviceContext, Camera camera)
        {
            if (!DoRender)
            {
                return;
            }

            instance.SetTransform(Transform);
            instance.Render(device, deviceContext, camera);
        }
Exemplo n.º 23
0
        private void UpdateBBox(ID3D11Device InDevice, ID3D11DeviceContext InDContext)
        {
            // Update vertex buffer
            VertexLayouts.BasicLayout.Vertex[] BBoxVertices = new VertexLayouts.BasicLayout.Vertex[Objects.Count * 8];

            int CurrentBBoxIndex = 0;

            foreach (RenderBoundingBox BBox in Objects.Values)
            {
                VertexLayouts.BasicLayout.Vertex[] Cached = BBox.GetTransformVertices();
                System.Array.Copy(Cached, 0, BBoxVertices, CurrentBBoxIndex * Cached.Length, Cached.Length);
                CurrentBBoxIndex++;
            }

            // Update index buffer
            uint[] BBoxIndices = new uint[Objects.Count * 24];

            CurrentBBoxIndex = 0;
            foreach (RenderBoundingBox BBox in Objects.Values)
            {
                uint[] CopiedIndices = new uint[BBox.Indices.Length];
                for (int i = 0; i < CopiedIndices.Length; i++)
                {
                    int BBoxOffset = (CurrentBBoxIndex * 8);
                    CopiedIndices[i] = (ushort)(BBox.Indices[i] + BBoxOffset);
                }

                System.Array.Copy(CopiedIndices, 0, BBoxIndices, CurrentBBoxIndex * BBox.Indices.Length, BBox.Indices.Length);
                CurrentBBoxIndex++;
            }

            SizeToRender = Objects.Count * 24;
            if (VertexBuffer == null && IndexBuffer == null)
            {
                VertexBuffer = InDevice.CreateBuffer(BindFlags.VertexBuffer, BBoxVertices, 0, ResourceUsage.Dynamic, CpuAccessFlags.Write);
                IndexBuffer  = InDevice.CreateBuffer(BindFlags.IndexBuffer, BBoxIndices, 0, ResourceUsage.Dynamic, CpuAccessFlags.Write);
            }
            else
            {
                // TODO: Templatize this
                MappedSubresource mappedResource = InDContext.Map(VertexBuffer, MapMode.WriteDiscard, MapFlags.None);
                unsafe
                {
                    UnsafeUtilities.Write(mappedResource.DataPointer, BBoxVertices);
                }
                InDContext.Unmap(VertexBuffer);

                mappedResource = InDContext.Map(IndexBuffer, MapMode.WriteDiscard, MapFlags.None);
                unsafe
                {
                    UnsafeUtilities.Write(mappedResource.DataPointer, BBoxIndices);
                }
                InDContext.Unmap(IndexBuffer);
            }
        }
Exemplo n.º 24
0
        public void Draw(ID3D11Device device, ID3D11DeviceContext context, Span <D3D11_INPUT_ELEMENT_DESC> _layout)
        {
            if (!m_vertexBuffer)
            {
                using (var pin = PinPtr.Create(m_vertices))
                {
                    var desc = new D3D11_BUFFER_DESC
                    {
                        ByteWidth = (uint)m_vertices.Length,
                        Usage     = D3D11_USAGE._DEFAULT,
                        BindFlags = (uint)D3D11_BIND_FLAG._VERTEX_BUFFER,
                    };
                    var data = new D3D11_SUBRESOURCE_DATA
                    {
                        pSysMem = pin.Ptr
                    };
                    device.CreateBuffer(ref desc, ref data,
                                        out m_vertexBuffer).ThrowIfFailed();
                }
            }
            Span <IntPtr> pBufferTbl = stackalloc IntPtr[] { m_vertexBuffer.Ptr };
            Span <uint>   SizeTbl    = stackalloc uint[] { (uint)m_vertexSize };
            Span <uint>   OffsetTbl  = stackalloc uint[] { 0 };

            context.IASetVertexBuffers(0, 1,
                                       ref MemoryMarshal.GetReference(pBufferTbl),
                                       ref MemoryMarshal.GetReference(SizeTbl),
                                       ref MemoryMarshal.GetReference(OffsetTbl));

            if (!m_indexBuffer)
            {
                using (var pin = PinPtr.Create(m_indices))
                {
                    var desc = new D3D11_BUFFER_DESC
                    {
                        ByteWidth = (uint)m_indices.Length,
                        Usage     = D3D11_USAGE._DEFAULT,
                        BindFlags = (uint)D3D11_BIND_FLAG._INDEX_BUFFER,
                    };
                    var data = new D3D11_SUBRESOURCE_DATA
                    {
                        pSysMem = pin.Ptr
                    };
                    device.CreateBuffer(ref desc, ref data,
                                        out m_indexBuffer).ThrowIfFailed();
                }
            }
            context.IASetIndexBuffer(m_indexBuffer, m_indexFormat, 0);

            context.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY._TRIANGLELIST);
            context.DrawIndexed((uint)m_indexCount, 0, 0);
        }
    }
}
Exemplo n.º 25
0
 public static extern void D3D11CreateDevice(
     [In, MarshalAs(UnmanagedType.IUnknown)] object adapter,
     [In] D3D11DriverType driverType,
     [In] IntPtr software,
     [In] D3D11CreateDeviceOptions options,
     [In, MarshalAs(UnmanagedType.LPArray)] D3D11FeatureLevel[] featureLevels,
     [In] uint numFeatureLevels,
     [In] uint sdkVersion,
     [Out] out ID3D11Device device,
     [Out] out D3D11FeatureLevel featureLevel,
     [Out] out ID3D11DeviceContext immediateContext);
Exemplo n.º 26
0
 public static extern int D3D11CreateDevice(
     [MarshalAs(UnmanagedType.Interface)] IDXGIAdapter pAdapter,
     D3D_DRIVER_TYPE DriverType,
     IntPtr Software,
     D3D11_CREATE_DEVICE_FLAG Flags,
     D3D_FEATURE_LEVEL[] pFeatureLevels,
     UINT FeatureLevels,
     UINT SDKVersion,
     [MarshalAs(UnmanagedType.Interface)] out ID3D11Device ppDevice,
     out D3D_FEATURE_LEVEL pFeatureLevel,
     [MarshalAs(UnmanagedType.Interface)] out ID3D11DeviceContext ppImmediateContext
     );
Exemplo n.º 27
0
        /// <summary>To be documented.</summary>
        public readonly int ValidateContextForDispatch(ref ID3D11DeviceContext pContext)
        {
            var @this = (ID3D11Debug *)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
            int ret   = default;

            fixed(ID3D11DeviceContext *pContextPtr = &pContext)
            {
                ret = ((delegate * unmanaged[Cdecl] < ID3D11Debug *, ID3D11DeviceContext *, int >)LpVtbl[11])(@this, pContextPtr);
            }

            return(ret);
        }
Exemplo n.º 28
0
 public override void UpdateBuffers(ID3D11Device device, ID3D11DeviceContext deviceContext)
 {
     if (bIsUpdatedNeeded)
     {
         MappedSubresource mappedResource = deviceContext.Map(vertexBuffer, MapMode.WriteDiscard, MapFlags.None);
         unsafe
         {
             UnsafeUtilities.Write(mappedResource.DataPointer, vertices);
         }
         deviceContext.Unmap(vertexBuffer, 0);
         bIsUpdatedNeeded = false;
     }
 }
Exemplo n.º 29
0
        private void RenderLines(ID3D11DeviceContext InDeviceContext, Camera InCamera)
        {
            VertexBufferView BufferView = new VertexBufferView(VertexBuffer, Unsafe.SizeOf <VertexLayouts.BasicLayout.Vertex>(), 0);

            InDeviceContext.IASetVertexBuffers(0, BufferView);
            InDeviceContext.IASetIndexBuffer(IndexBuffer, Vortice.DXGI.Format.R16_UInt, 0);
            InDeviceContext.IASetPrimitiveTopology(PrimitiveTopology.LineStrip);

            BaseShader Shader = RenderStorageSingleton.Instance.ShaderManager.shaders[1];

            Shader.SetSceneVariables(InDeviceContext, Matrix4x4.Identity, InCamera);
            Shader.Render(InDeviceContext, PrimitiveTopology.LineList, SizeToRender, 0);
        }
Exemplo n.º 30
0
        public virtual void GetImmediateContext(
            out ID3D11DeviceContext ppImmediateContext
            )
        {
            var fp = GetFunctionPointer(40);

            if (m_GetImmediateContextFunc == null)
            {
                m_GetImmediateContextFunc = (GetImmediateContextFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(GetImmediateContextFunc));
            }
            ppImmediateContext = new ID3D11DeviceContext();
            m_GetImmediateContextFunc(m_ptr, out ppImmediateContext.PtrForNew);
        }