public H1Texture2D(H1GPUResourceManager manager, uint index, H1PixelFormat elementType, int width, int height)
     : base(manager, Convert.ToUInt32(H1RHIDefinitionHelper.ElementTypeToSize(elementType) * width * height))
 {
     m_Index = index;
     m_Description.Format = elementType;
     m_Description.Width  = Convert.ToUInt32(width);
     m_Description.Height = Convert.ToUInt32(height);
     // @TODO - I need to add initial variables like NumMips, NumSamples and TextureName
 }
Beispiel #2
0
        public void Initialize(int height, int width, IntPtr handle)
        {
            m_Height = height;
            m_Width  = width;

            m_Viewport.Width    = m_Width;
            m_Viewport.Height   = m_Height;
            m_Viewport.MaxDepth = 1.0f;

            m_SissorRect.Right  = m_Width;
            m_SissorRect.Bottom = m_Height;

#if DEBUG
            // enable the d3d12 debug layer
            DebugInterface.Get().EnableDebugLayer();
#endif
            m_DeviceContext = new Direct3D12.H1DX12DeviceContext();
            m_DeviceContext.Intialize();

            m_SwapChainDX12 = new Direct3D12.H1SwapChain(null, m_DeviceContext.MainCommandListPool);
            m_SwapChainDX12.Initialize(m_Width, m_Height, handle);

            // create Gen2Layer
#if SGD_DX12
            m_Gen2Layer = new Gen2Layer.H1Gen2Layer();
            m_Gen2Layer.Initialize();
#endif

            var cbvHeapDesc = new DescriptorHeapDescription()
            {
                DescriptorCount = 2,
                Flags           = DescriptorHeapFlags.ShaderVisible,
                Type            = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
            };

            m_ConstantBufferViewHeap       = Device.CreateDescriptorHeap(cbvHeapDesc);
            m_ConstantBufferDescriptorSize = Device.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);

            // create resource manager
            m_ResourceManager = new H1GPUResourceManager();
            m_ResourceManager.Initialize(this); // set the owner as this renderer

            m_ShaderManager = new H1ShaderManager();
            m_ShaderManager.Initialize(this);

            // temp
            //m_TempStaticMesh = new H1StaticMesh(H1Global<H1AssimpImporter>.Instance.asset.GetModel(2));

            // load assets
            //LoadAssets();

            // setting for physics
            SettingForPhysics();
        }
Beispiel #3
0
        public void CopyTextureRegion(H1Texture2D texObject, H1GeneralBuffer generalBuffer)
        {
            // reuse the memory associated with command recording
            // we can only reset when the associated command lists have finished execution on the GPU
            m_CommandList.CommandAllocator.Reset();

            // a command list can be reset after it has been added to the command queue via ExecuteCommandList
            m_CommandList.CommandList.Reset(m_CommandList.CommandAllocator, null);

            // @TODO - I need to change this into parallel copy texture region by managing multiple command queue
            H1GPUResourceManager refResourceManager = H1Global <H1ManagedRenderer> .Instance.ResourceManager;

            // create destination and source locations
            // TextureCopyLocation - describe a portion of texture for the purpose of texture copies
            TextureCopyLocation destLocation = new TextureCopyLocation(refResourceManager.GetTexture2D(Convert.ToInt32(texObject.Index)), 0);
            TextureCopyLocation srcLocation  = new TextureCopyLocation(generalBuffer.Resource,
                                                                       new PlacedSubResourceFootprint() // describes the footprint of a placed subresource, including the offset and the D3D12_SUBRESOURCE_FOOTPRINT
            {
                Offset    = 0,                                                                          // the offset of the subresource within the parent resource in bytes
                Footprint = new SubResourceFootprint()                                                  // describes the format, with, height, depth and row-pitch of the subresource into the parent resource
                {
                    Width    = Convert.ToInt32(texObject.Width),
                    Height   = Convert.ToInt32(texObject.Height),
                    Depth    = 1,
                    Format   = H1RHIDefinitionHelper.ConvertToFormat(texObject.PixelFormat),
                    RowPitch = Convert.ToInt32(texObject.Stride),
                }
            });

            m_CommandList.CommandList.ResourceBarrierTransition(texObject.Resource, ResourceStates.GenericRead, ResourceStates.CopyDestination);
            m_CommandList.CommandList.CopyTextureRegion(destLocation, 0, 0, 0, srcLocation, null);
            m_CommandList.CommandList.ResourceBarrierTransition(texObject.Resource, ResourceStates.CopyDestination, ResourceStates.GenericRead);

            m_CommandList.CommandList.Close();

            m_DeviceContext.MainCommandListPool.CommandQueue.ExecuteCommandList(m_CommandList.CommandList);
        }
 public H1Resource(H1GPUResourceManager resourceManager, uint sizeInBytes)
 {
     m_ResourceManagerRef = resourceManager;
     m_SizeInBytes        = sizeInBytes;
 }
Beispiel #5
0
 public H1VertexBuffer(H1GPUResourceManager manager, uint index, uint sizeInBytes, uint strideInBytes)
     : base(manager, sizeInBytes)
 {
     m_Index         = index;
     m_StrideInBytes = strideInBytes;
 }
 public H1IndexBuffer(H1GPUResourceManager manager, uint index, uint sizeInBytes)
     : base(manager, sizeInBytes)
 {
     m_Index        = index;
     m_IndicesCount = sizeInBytes / sizeof(UInt32);
 }
 public H1GeneralBuffer(H1GPUResourceManager manager, uint index, uint sizeInBytes)
     : base(manager, sizeInBytes)
 {
     m_Index = index;
 }