Exemple #1
0
        public void SetBlendState(H1BlendStateDescription blendState, Int32 numRenderTargets)
        {
            BlendStateDescription blendStateRef = BlendStateDescription.Default();

            blendStateRef.AlphaToCoverageEnable  = blendState.AlphaToCoverageEnable;
            blendStateRef.IndependentBlendEnable = blendState.IndependentBlendEnable;

            for (Int32 i = 0; i < numRenderTargets; ++i)
            {
                RenderTargetBlendDescription   rtBlendDescDest = blendStateRef.RenderTarget[i];
                H1RenderTargetBlendDescription rtBlendDescSrc  = blendState.RenderTargets[i];
                rtBlendDescDest.IsBlendEnabled = rtBlendDescSrc.BlendEnable;
                rtBlendDescDest.LogicOpEnable  = rtBlendDescSrc.LogicOpEnable;

                rtBlendDescDest.SourceBlend      = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.SrcBlend);
                rtBlendDescDest.DestinationBlend = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.DestBlend);
                rtBlendDescDest.BlendOperation   = H1RHIDefinitionHelper.ConvertToBlendOp(rtBlendDescSrc.BlendOp);

                rtBlendDescDest.SourceAlphaBlend      = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.SrcBlendAlpha);
                rtBlendDescDest.DestinationAlphaBlend = H1RHIDefinitionHelper.ConvertToBlend(rtBlendDescSrc.DestBlendAlpha);
                rtBlendDescDest.AlphaBlendOperation   = H1RHIDefinitionHelper.ConvertToBlendOp(rtBlendDescSrc.BlendOpAlpha);

                rtBlendDescDest.LogicOp = H1RHIDefinitionHelper.ConvertToLogicOp(rtBlendDescSrc.LogicOp);
                rtBlendDescDest.RenderTargetWriteMask = H1RHIDefinitionHelper.ConvertToColorWriteMaskFlags(rtBlendDescSrc.RenderTargetWriteMask);
            }

            // newly assign the created blend state
            m_GraphicsPipelineStateDesc.BlendState = blendStateRef;
        }
Exemple #2
0
        public Boolean InitStaticSampler(Int32 register, H1SamplerDescription samplerDesc, ShaderVisibility visibility)
        {
            if (m_NumInitializedStaticSamplers > m_NumSamplers)
            {
                return(false); // there are no available to initialize static samplers
            }
            StaticSamplerDescription staticSamplerDesc = m_SamplerArray[m_NumInitializedStaticSamplers];

            staticSamplerDesc                = new StaticSamplerDescription(visibility, register, 0); // initialize static sampler description
            staticSamplerDesc.Filter         = H1RHIDefinitionHelper.ConvertToFilter(samplerDesc.Filter);
            staticSamplerDesc.AddressU       = H1RHIDefinitionHelper.ConvertToTextureAddressMode(samplerDesc.AddressU);
            staticSamplerDesc.AddressV       = H1RHIDefinitionHelper.ConvertToTextureAddressMode(samplerDesc.AddressV);
            staticSamplerDesc.AddressW       = H1RHIDefinitionHelper.ConvertToTextureAddressMode(samplerDesc.AddressW);
            staticSamplerDesc.MipLODBias     = samplerDesc.MipLODBias;
            staticSamplerDesc.MaxAnisotropy  = samplerDesc.MaxAnisotropy;
            staticSamplerDesc.ComparisonFunc = H1RHIDefinitionHelper.ConvertToComparisonFunc(samplerDesc.ComparisonFunc);
            staticSamplerDesc.BorderColor    = StaticBorderColor.OpaqueWhite;
            staticSamplerDesc.MinLOD         = samplerDesc.MinLOD;
            staticSamplerDesc.MaxLOD         = samplerDesc.MaxLOD;

            if (staticSamplerDesc.AddressU == TextureAddressMode.Border ||
                staticSamplerDesc.AddressV == TextureAddressMode.Border ||
                staticSamplerDesc.AddressW == TextureAddressMode.Border)
            {
                //@TODO - warning for the case, different border color with 'samplerDesc'
            }

            return(true);
        }
Exemple #3
0
        public void SetDepthStencilState(H1DepthStencilDescription depthStencilDesc)
        {
            DepthStencilStateDescription newDepthStencilStateDesc = DepthStencilStateDescription.Default();

            newDepthStencilStateDesc.IsDepthEnabled   = depthStencilDesc.DepthEnable;
            newDepthStencilStateDesc.DepthWriteMask   = H1RHIDefinitionHelper.ConvertToDepthWriteMask(depthStencilDesc.DepthWriteMask);
            newDepthStencilStateDesc.DepthComparison  = H1RHIDefinitionHelper.ConvertToComparisonFunc(depthStencilDesc.DepthFunc);
            newDepthStencilStateDesc.IsStencilEnabled = depthStencilDesc.StencilEnable;
            newDepthStencilStateDesc.StencilReadMask  = depthStencilDesc.StencilReadMask;
            newDepthStencilStateDesc.StencilWriteMask = depthStencilDesc.StencilWriteMask;

            newDepthStencilStateDesc.FrontFace = new DepthStencilOperationDescription();
            newDepthStencilStateDesc.FrontFace.DepthFailOperation = H1RHIDefinitionHelper.ConvertToStencilOp(depthStencilDesc.FrontFace.StencilDepthFailOp);
            newDepthStencilStateDesc.FrontFace.FailOperation      = H1RHIDefinitionHelper.ConvertToStencilOp(depthStencilDesc.FrontFace.StencilFailOp);
            newDepthStencilStateDesc.FrontFace.PassOperation      = H1RHIDefinitionHelper.ConvertToStencilOp(depthStencilDesc.FrontFace.StencilPassOp);
            newDepthStencilStateDesc.FrontFace.Comparison         = H1RHIDefinitionHelper.ConvertToComparisonFunc(depthStencilDesc.FrontFace.StencilFunc);

            newDepthStencilStateDesc.BackFace = new DepthStencilOperationDescription();
            newDepthStencilStateDesc.BackFace.DepthFailOperation = H1RHIDefinitionHelper.ConvertToStencilOp(depthStencilDesc.BackFace.StencilDepthFailOp);
            newDepthStencilStateDesc.BackFace.FailOperation      = H1RHIDefinitionHelper.ConvertToStencilOp(depthStencilDesc.BackFace.StencilFailOp);
            newDepthStencilStateDesc.BackFace.PassOperation      = H1RHIDefinitionHelper.ConvertToStencilOp(depthStencilDesc.BackFace.StencilPassOp);
            newDepthStencilStateDesc.BackFace.Comparison         = H1RHIDefinitionHelper.ConvertToComparisonFunc(depthStencilDesc.BackFace.StencilFunc);

            m_GraphicsPipelineStateDesc.DepthStencilState = newDepthStencilStateDesc;
        }
Exemple #4
0
        public void SetRasterizerState(H1RasterizerDescription rasterizerDesc)
        {
            RasterizerStateDescription newRasterizerStateDesc = RasterizerStateDescription.Default();

            newRasterizerStateDesc.FillMode = H1RHIDefinitionHelper.ConvertToFillMode(rasterizerDesc.FillMode);
            newRasterizerStateDesc.CullMode = H1RHIDefinitionHelper.ConvertToCullMode(rasterizerDesc.CullMode);
            newRasterizerStateDesc.IsFrontCounterClockwise = rasterizerDesc.FrontCounterClockwise;
            newRasterizerStateDesc.DepthBias                = rasterizerDesc.DepthBias;
            newRasterizerStateDesc.DepthBiasClamp           = rasterizerDesc.DepthBiasClamp;
            newRasterizerStateDesc.SlopeScaledDepthBias     = rasterizerDesc.SlopeScaledDepthBias;
            newRasterizerStateDesc.IsDepthClipEnabled       = rasterizerDesc.DepthClipEnable;
            newRasterizerStateDesc.IsMultisampleEnabled     = rasterizerDesc.MultiSampleEnable;
            newRasterizerStateDesc.IsAntialiasedLineEnabled = rasterizerDesc.AntialiasedLineEnable;
            newRasterizerStateDesc.ForcedSampleCount        = rasterizerDesc.ForcedSampleCount;

            if (rasterizerDesc.ConservativeRasterMode == H1ConservativeRasterizationMode.On)
            {
                newRasterizerStateDesc.ConservativeRaster = ConservativeRasterizationMode.On;
            }
            else
            {
                newRasterizerStateDesc.ConservativeRaster = ConservativeRasterizationMode.Off;
            }

            // assign the newly created rasterizer state desc
            m_GraphicsPipelineStateDesc.RasterizerState = newRasterizerStateDesc;
        }
 void ConstructPlatformDependentMembers(Int64 bufferLocation, H1PixelFormat format, Int32 sizeInBytes)
 {
     m_IBVDesc = new IndexBufferView()
     {
         BufferLocation = bufferLocation,
         Format         = H1RHIDefinitionHelper.ConvertToFormat(format),
         SizeInBytes    = sizeInBytes,
     };
 }
        void ConstructPlatformDependentMembers()
        {
            m_Device = H1Global <H1ManagedRenderer> .Instance.Device;

            m_CurrentHeap       = null;
            m_CurrentHandle.Ptr = null;

            // set descriptor size
            m_DescriptorSize = m_Device.GetDescriptorHandleIncrementSize(H1RHIDefinitionHelper.ConvertToDescriptorHeapType(m_HeapType));
        }
Exemple #7
0
        public void SetRenderTargetFormats(H1PixelFormat[] rtvFormats, H1PixelFormat dsvFormat, Int32 msaaCount, Int32 msaaQuality)
        {
            for (Int32 i = 0; i < rtvFormats.Count(); ++i)
            {
                m_GraphicsPipelineStateDesc.RenderTargetFormats[i] = H1RHIDefinitionHelper.ConvertToFormat(rtvFormats[i]);
            }
            for (Int32 i = rtvFormats.Count(); i < m_GraphicsPipelineStateDesc.RenderTargetCount; ++i)
            {
                m_GraphicsPipelineStateDesc.RenderTargetFormats[i] = SharpDX.DXGI.Format.Unknown;
            }

            m_GraphicsPipelineStateDesc.RenderTargetCount         = rtvFormats.Count();
            m_GraphicsPipelineStateDesc.DepthStencilFormat        = H1RHIDefinitionHelper.ConvertToFormat(dsvFormat);
            m_GraphicsPipelineStateDesc.SampleDescription.Count   = msaaCount;
            m_GraphicsPipelineStateDesc.SampleDescription.Quality = msaaQuality;
        }
        public H1InputLayout(H1VertexStream[] streams)
        {
            foreach (H1VertexStream stream in streams)
            {
                H1InputElementDescription inputElement = new H1InputElementDescription();
                inputElement.SemanticName  = stream.SemanticName;
                inputElement.SemanticIndex = stream.SemanticIndex;
                inputElement.Format        = H1RHIDefinitionHelper.ConvertToPixelFormat(stream.VertexElementType);
                inputElement.InputSlot     = Convert.ToInt32(stream.Offset);

                m_InputElements.Add(inputElement);
            }

            // create platform-dependent input-layout
            CreateInputLayout();
        }
        static void CreatePlatformDependent(Vector4 clearValue, H1Texture2D.Description desc, H1SubresourceData initialData, ref H1GpuTexture2D result)
        {
            // get device for directX 12
            Device deviceDX12 = H1Global <H1ManagedRenderer> .Instance.Device;

            H1GpuResourceDesc desc12         = H1RHIDefinitionHelper.Texture2DDescToGpuResourceDesc(desc);
            H1HeapType        heapType       = H1RHIDefinitionHelper.GetHeapTypeFromTexture2DDesc(desc);
            H1ResourceStates  resourceStates = H1RHIDefinitionHelper.GetResourceStatesFromTexture2DDesc(desc);

            // generate resource
            //if (result != null)
            //    result.Resource.CreateResource(heapType, desc12, resourceStates);

            // generate RHI resource description (need resource description for generating UAV or SRV or etc.)
            result.CreateResourceDescription(desc12);
        }
        public static ResourceDescription ConvertToResourceDescDx12(H1GpuResourceDesc resourceDesc)
        {
            ResourceDescription result = new ResourceDescription();

            result.Dimension = (ResourceDimension)DimensionMapper[Convert.ToInt32(resourceDesc.Dimension)];
            result.Alignment = resourceDesc.Alignment;
            result.Width     = resourceDesc.Width;
            result.Height    = Convert.ToInt32(resourceDesc.Height);
            result.MipLevels = Convert.ToInt16(resourceDesc.MipLevels);
            result.SampleDescription.Count   = Convert.ToInt32(resourceDesc.SampleDesc.Count);
            result.SampleDescription.Quality = Convert.ToInt32(resourceDesc.SampleDesc.Quality);
            result.Format           = H1RHIDefinitionHelper.ConvertToFormat(resourceDesc.Format);
            result.Flags            = (ResourceFlags)ResourceFlagsMapper[Convert.ToInt32(resourceDesc.Flags)];
            result.DepthOrArraySize = Convert.ToInt16(resourceDesc.DepthOrArraySize);

            return(result);
        }
        public virtual Boolean CreateResourceDescription(H1GpuResourceDesc desc)
        {
            // API level specific resource description
            m_Description.Alignment                 = desc.Alignment;
            m_Description.DepthOrArraySize          = Convert.ToInt16(desc.DepthOrArraySize);
            m_Description.Dimension                 = (ResourceDimension)H1GpuResource.DimensionMapper[Convert.ToInt32(desc.Dimension)];
            m_Description.Flags                     = H1RHIDefinitionHelper.FormatToResourceFlags(desc.Flags);
            m_Description.Format                    = H1RHIDefinitionHelper.ConvertToFormat(desc.Format);
            m_Description.Width                     = Convert.ToInt32(desc.Width);
            m_Description.Height                    = Convert.ToInt32(desc.Height);
            m_Description.Layout                    = (TextureLayout)H1GpuResource.TextureLayoutMapper[Convert.ToInt32(desc.Layout)];
            m_Description.MipLevels                 = Convert.ToInt16(desc.MipLevels);
            m_Description.SampleDescription.Count   = Convert.ToInt32(desc.SampleDesc.Count);
            m_Description.SampleDescription.Quality = Convert.ToInt32(desc.SampleDesc.Quality);

            return(true);
        }
        Int32 CreateResourcePlatformDependent(H1HeapType heapType, H1GpuResourceDesc resourceDesc, H1ResourceStates defaultUsage)
        {
            HeapProperties heapProps = new HeapProperties();

            heapProps.CPUPageProperty      = CpuPageProperty.Unknown;
            heapProps.MemoryPoolPreference = MemoryPool.Unknown;
            heapProps.CreationNodeMask     = 1;
            heapProps.VisibleNodeMask      = 1;

            // convert to H1HeapType to HeapType for dx12
            switch (heapType)
            {
            case H1HeapType.Default:
                heapProps.Type = HeapType.Default;
                break;

            case H1HeapType.Readback:
                heapProps.Type = HeapType.Readback;
                break;

            case H1HeapType.Upload:
                heapProps.Type = HeapType.Upload;
                break;
            }

            // convert H1ResourceDesc to ResourceDesc for dx12
            ResourceDescription resourceDescDX12 = ConvertToResourceDescDx12(resourceDesc);
            ResourceStates      defaultStates    = (ResourceStates)ResourceStateMapper[Convert.ToInt32(defaultUsage)];

            Device deviceDX11 = H1Global <H1ManagedRenderer> .Instance.Device;

            m_GpuResource = deviceDX11.CreateCommittedResource(heapProps, HeapFlags.None, resourceDescDX12, defaultStates);

            Int32 elementSize = Convert.ToInt32(H1RHIDefinitionHelper.ElementTypeToSize(resourceDesc.Format));

            if (elementSize == 0)
            {
                throw new InvalidOperationException("there is no appropriate format is implemented in ElementTypeToSize()!");
            }

            Int32 totalSizeInBytes = elementSize * Convert.ToInt32(resourceDesc.Width * resourceDesc.Height * resourceDesc.DepthOrArraySize);

            return(totalSizeInBytes);
        }
Exemple #13
0
        public Boolean SetInputLayout(H1InputLayout inputLayout)
        {
            List <InputElement> inputElements = new List <InputElement>();

            foreach (H1InputElementDescription element in inputLayout.InputElements)
            {
                InputElement inputElement = new InputElement();
                inputElement.SemanticName  = element.SemanticName;
                inputElement.SemanticIndex = element.SemanticIndex;
                inputElement.Format        = H1RHIDefinitionHelper.ConvertToFormat(element.Format);
                inputElement.Slot          = element.InputSlot;

                inputElements.Add(inputElement);
            }

            m_GraphicsPipelineStateDesc.InputLayout = new InputLayoutDescription(inputElements.ToArray());

            return(true);
        }
        protected DescriptorHeap RequestNewHeap(H1DescriptorHeapType type)
        {
            DescriptorHeapType typeInDX12 = H1RHIDefinitionHelper.ConvertToDescriptorHeapType(type);

            // @TODO - need to be thread-safe
            DescriptorHeapDescription desc = new DescriptorHeapDescription();

            desc.Type            = typeInDX12;
            desc.DescriptorCount = NumDescriptorsPerHeap;

            // this part is none, but for usage in command context, you need to create new descriptor for shader-visible by UserDescriptorHeap or DynamicDescriptorHeap
            desc.Flags    = DescriptorHeapFlags.None;
            desc.NodeMask = 1;

            DescriptorHeap newHeap = m_Device.CreateDescriptorHeap(desc);

            m_DescriptorHeapPool.Add(newHeap);

            return(newHeap);
        }
        void CreateInputLayout()
        {
            // @TODO - need to modify input element description from H1VertexStream

            // platform-specific implementation
            List <InputElement> inputElements = new List <InputElement>();

            foreach (var stream in m_InputElements)
            {
                InputElement element = new InputElement();
                element.SemanticName  = stream.SemanticName;
                element.SemanticIndex = stream.SemanticIndex;
                element.Format        = H1RHIDefinitionHelper.ConvertToFormat(stream.Format);

                // watch out - I use multiple vertex buffer instead of big vertex buffer indicating by alignbyteoffset
                element.Slot = stream.InputSlot;
                inputElements.Add(element);
            }

            // create input layout based on the resultant list of input elements
            m_InputLayoutDesc = new InputLayoutDescription(inputElements.ToArray());
        }
        public override Boolean CreateView()
        {
            // the description is in invalid state, please check
            if (!m_bHasDesc)
            {
                return(false);
            }

            // get the device
            Device deviceDX12 = H1Global <H1ManagedRenderer> .Instance.Device;

            // get the descriptor handle
            if (m_DescriptorHandle.Ptr == null)
            {
                m_DescriptorHandle = H1Global <H1ManagedRenderer> .Instance.Gen2Layer.AllocateDescriptor(H1DescriptorHeapType.ConstantBufferView_ShaderResourceView_UnorderedAccessView);
            }

            // convert platform-independent description to platform-dependent description
            m_SRVDesc.Format = H1RHIDefinitionHelper.ConvertToFormat(m_Description.Format);

            m_SRVDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;

            // depending on view dimension types, create the corresponding description
            switch (m_Description.ViewDimension)
            {
            case H1ShaderResourceViewDimension.Buffer:
            {
                m_SRVDesc.Dimension = ShaderResourceViewDimension.Buffer;
                // if the buffer description is not filled up, invalid description
                if (m_Description.Buffer == null)
                {
                    return(false);
                }

                m_SRVDesc.Buffer.FirstElement        = m_Description.Buffer.FirstElement;
                m_SRVDesc.Buffer.ElementCount        = m_Description.Buffer.NumElement;
                m_SRVDesc.Buffer.StructureByteStride = m_Description.Buffer.StructuredByteStride;

                switch (m_Description.Buffer.Flags)
                {
                case H1BufferShaderResourceViewFlags.None:
                    m_SRVDesc.Buffer.Flags = BufferShaderResourceViewFlags.None;
                    break;

                case H1BufferShaderResourceViewFlags.Raw:
                    m_SRVDesc.Buffer.Flags = BufferShaderResourceViewFlags.Raw;
                    break;
                }

                break;
            }

            case H1ShaderResourceViewDimension.Texture1D:
            {
                m_SRVDesc.Dimension = ShaderResourceViewDimension.Texture1D;
                if (m_Description.Texture1D == null)
                {
                    return(false);
                }

                m_SRVDesc.Texture1D.MostDetailedMip     = m_Description.Texture1D.MostDetailedMip;
                m_SRVDesc.Texture1D.MipLevels           = m_Description.Texture1D.MipLevels;
                m_SRVDesc.Texture1D.ResourceMinLODClamp = m_Description.Texture1D.ResourceMinLODClamp;

                break;
            }

            case H1ShaderResourceViewDimension.Texture1DArray:
            {
                m_SRVDesc.Dimension = ShaderResourceViewDimension.Texture1DArray;
                if (m_Description.Texture1DArray == null)
                {
                    return(false);
                }

                m_SRVDesc.Texture1DArray.MostDetailedMip     = m_Description.Texture1DArray.MostDetailedMip;
                m_SRVDesc.Texture1DArray.MipLevels           = m_Description.Texture1DArray.MipLevels;
                m_SRVDesc.Texture1DArray.FirstArraySlice     = m_Description.Texture1DArray.FirstArraySlice;
                m_SRVDesc.Texture1DArray.ArraySize           = m_Description.Texture1DArray.ArraySize;
                m_SRVDesc.Texture1DArray.ResourceMinLODClamp = m_Description.Texture1DArray.ResourceMinLODClamp;

                break;
            }

            case H1ShaderResourceViewDimension.Texture2D:
            {
                m_SRVDesc.Dimension = ShaderResourceViewDimension.Texture2D;
                if (m_Description.Texture2D == null)
                {
                    return(false);
                }

                m_SRVDesc.Texture2D.MostDetailedMip     = m_Description.Texture2D.MostDetailedMip;
                m_SRVDesc.Texture2D.MipLevels           = m_Description.Texture2D.MipLevels;
                m_SRVDesc.Texture2D.PlaneSlice          = m_Description.Texture2D.PlaneSlice;
                m_SRVDesc.Texture2D.ResourceMinLODClamp = m_Description.Texture2D.ResourceMinLODClamp;

                break;
            }

            case H1ShaderResourceViewDimension.Texture2DArray:
            {
                m_SRVDesc.Dimension = ShaderResourceViewDimension.Texture2DArray;
                if (m_Description.Texture2DArray == null)
                {
                    return(false);
                }

                m_SRVDesc.Texture2DArray.MostDetailedMip     = m_Description.Texture2DArray.MostDetailedMip;
                m_SRVDesc.Texture2DArray.MipLevels           = m_Description.Texture2DArray.MipLevels;
                m_SRVDesc.Texture2DArray.PlaneSlice          = m_Description.Texture2DArray.PlaneSlice;
                m_SRVDesc.Texture2DArray.ResourceMinLODClamp = m_Description.Texture2DArray.ResourceMinLODClamp;
                m_SRVDesc.Texture2DArray.FirstArraySlice     = m_Description.Texture2DArray.FirstArraySlice;
                m_SRVDesc.Texture2DArray.ArraySize           = m_Description.Texture2DArray.ArraySize;

                break;
            }

            case H1ShaderResourceViewDimension.Texture3D:
            {
                m_SRVDesc.Dimension = ShaderResourceViewDimension.Texture3D;
                if (m_Description.Texture3D == null)
                {
                    return(false);
                }

                m_SRVDesc.Texture3D.MostDetailedMip     = m_Description.Texture3D.MostDetailedMip;
                m_SRVDesc.Texture3D.MipLevels           = m_Description.Texture3D.MipLevels;
                m_SRVDesc.Texture3D.ResourceMinLODClamp = m_Description.Texture3D.ResourceMinLODClamp;

                break;
            }

            default:
                // @TODO - not implemented yet!
                return(false);
            }

            // create view descriptor
            deviceDX12.CreateShaderResourceView(m_ResourceRef.GpuResource, m_SRVDesc, m_DescriptorHandle);

            return(true);
        }
        public override Boolean CreateView()
        {
            // the description is in invalid state, please check
            if (!m_bHasDesc)
            {
                return(false);
            }

            // get the device
            Device deviceDX12 = H1Global <H1ManagedRenderer> .Instance.Device;

            // get the descriptor handle
            if (m_DescriptorHandle.Ptr == null)
            {
                m_DescriptorHandle = H1Global <H1ManagedRenderer> .Instance.Gen2Layer.AllocateDescriptor(H1DescriptorHeapType.ConstantBufferView_ShaderResourceView_UnorderedAccessView);
            }

            // convert platform-independent description to platform-dependent description
            m_RTVDesc.Format = H1RHIDefinitionHelper.ConvertToFormat(m_Description.Format);

            // depending on view dimension types, create the corresponding description
            switch (m_Description.ViewDimension)
            {
            case H1RenderTargetViewDimension.Buffer:
            {
                m_RTVDesc.Dimension = RenderTargetViewDimension.Buffer;
                // if the buffer description is not filled up, invalid description
                if (m_Description.Buffer == null)
                {
                    return(false);
                }

                m_RTVDesc.Buffer.FirstElement = m_Description.Buffer.FirstElement;
                m_RTVDesc.Buffer.ElementCount = m_Description.Buffer.NumElements;

                break;
            }

            case H1RenderTargetViewDimension.Texture1D:
            {
                m_RTVDesc.Dimension = RenderTargetViewDimension.Texture1D;
                if (m_Description.Texture1D == null)
                {
                    return(false);
                }

                m_RTVDesc.Texture1D.MipSlice = m_Description.Texture1D.MipSlice;

                break;
            }

            case H1RenderTargetViewDimension.Texture1DArray:
            {
                m_RTVDesc.Dimension = RenderTargetViewDimension.Texture1DArray;
                if (m_Description.Texture1DArray == null)
                {
                    return(false);
                }

                m_RTVDesc.Texture1DArray.MipSlice        = m_Description.Texture1DArray.MipSlice;
                m_RTVDesc.Texture1DArray.FirstArraySlice = m_Description.Texture1DArray.FirstArraySlice;
                m_RTVDesc.Texture1DArray.ArraySize       = m_Description.Texture1DArray.ArraySize;

                break;
            }

            case H1RenderTargetViewDimension.Texture2D:
            {
                m_RTVDesc.Dimension = RenderTargetViewDimension.Texture2D;
                if (m_Description.Texture2D == null)
                {
                    return(false);
                }

                m_RTVDesc.Texture2D.MipSlice   = m_Description.Texture2D.MipSlice;
                m_RTVDesc.Texture2D.PlaneSlice = m_Description.Texture2D.PlaneSlice;

                break;
            }

            case H1RenderTargetViewDimension.Texture2DArray:
            {
                m_RTVDesc.Dimension = RenderTargetViewDimension.Texture2DArray;
                if (m_Description.Texture2DArray == null)
                {
                    return(false);
                }

                m_RTVDesc.Texture2DArray.MipSlice        = m_Description.Texture2DArray.MipSlice;
                m_RTVDesc.Texture2DArray.PlaneSlice      = m_Description.Texture2DArray.PlaneSlice;
                m_RTVDesc.Texture2DArray.FirstArraySlice = m_Description.Texture2DArray.FirstArraySlice;
                m_RTVDesc.Texture2DArray.ArraySize       = m_Description.Texture2DArray.ArraySize;

                break;
            }

            case H1RenderTargetViewDimension.Texture3D:
            {
                m_RTVDesc.Dimension = RenderTargetViewDimension.Texture3D;
                if (m_Description.Texture3D == null)
                {
                    return(false);
                }

                m_RTVDesc.Texture3D.MipSlice        = m_Description.Texture3D.MipSlice;
                m_RTVDesc.Texture3D.FirstDepthSlice = m_Description.Texture3D.FirstWSlice;
                m_RTVDesc.Texture3D.DepthSliceCount = m_Description.Texture3D.WSize;

                break;
            }

            default:
                // @TODO - not implemented yet!
                return(false);
            }

            // create view descriptor
            deviceDX12.CreateRenderTargetView(m_ResourceRef.GpuResource, m_RTVDesc, m_DescriptorHandle);

            return(true);
        }
        public static H1DX12Texture2D Create(Device device, Vector4 clearValue, H1Texture2D.Description desc, H1SubresourceData[] initialData)
        {
            // converting description to DX12 description
            ResourceDescription desc12 = new ResourceDescription
            {
                Format           = H1RHIDefinitionHelper.ConvertToFormat(desc.Format),
                Width            = Convert.ToInt32(desc.Width),
                Height           = Convert.ToInt32(desc.Height),
                DepthOrArraySize = Convert.ToInt16(desc.ArraySize),
                MipLevels        = Convert.ToInt16(desc.MipLevels),
                Flags            = ResourceFlags.None,
                Layout           = TextureLayout.Unknown,
                Dimension        = ResourceDimension.Texture2D,
            };

            desc12.SampleDescription.Count   = Convert.ToInt32(desc.SampleDesc.Count);
            desc12.SampleDescription.Quality = Convert.ToInt32(desc.SampleDesc.Quality);

            HeapProperties heapProperties  = new HeapProperties(HeapType.Default);
            ResourceStates resourceUsage   = ResourceStates.CopyDestination;
            ClearValue     value           = H1GlobalDX12Definitions.GetDXGIFormatClearValue(desc12.Format, (desc.BindFlags & Convert.ToUInt32(H1BindFlag.DepthStencil)) != 0);
            Boolean        allowClearValue = desc12.Dimension == ResourceDimension.Buffer;

            if (desc.Usage == H1Usage.Immutable)
            {
                heapProperties = new HeapProperties(HeapType.Default);
                resourceUsage  = ResourceStates.CopyDestination;
            }

            else if (desc.Usage == H1Usage.Staging)
            {
                heapProperties = new HeapProperties(HeapType.Readback);
                resourceUsage  = ResourceStates.CopyDestination;
            }

            else if (desc.Usage == H1Usage.Dynamic)
            {
                heapProperties = new HeapProperties(HeapType.Upload);
                resourceUsage  = ResourceStates.GenericRead;
            }

            if (desc.CPUAccessFlags != 0)
            {
                if (desc.CPUAccessFlags == Convert.ToUInt32(H1CPUAccessFlag.Write))
                {
                    heapProperties = new HeapProperties(HeapType.Upload);
                    resourceUsage  = ResourceStates.GenericRead;
                }

                else if (desc.CPUAccessFlags == Convert.ToUInt32(H1CPUAccessFlag.Read))
                {
                    heapProperties = new HeapProperties(HeapType.Readback);
                    resourceUsage  = ResourceStates.CopyDestination;
                }

                else
                {
                    return(null);
                }
            }

            if (clearValue != null)
            {
                if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.DepthStencil)) != 0)
                {
                    value.DepthStencil.Depth   = clearValue.X;
                    value.DepthStencil.Stencil = Convert.ToByte(clearValue.Y);
                }
                else
                {
                    value.Color = clearValue;
                }
            }

            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.UnorderedAccess)) != 0)
            {
                desc12.Flags |= ResourceFlags.AllowUnorderedAccess;
                resourceUsage = ResourceStates.UnorderedAccess;
            }

            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.DepthStencil)) != 0)
            {
                desc12.Flags   |= ResourceFlags.AllowDepthStencil;
                allowClearValue = true;
                resourceUsage   = ResourceStates.DepthWrite;
            }

            if ((desc.BindFlags & Convert.ToUInt32(H1BindFlag.RenderTarget)) != 0)
            {
                desc12.Flags   |= ResourceFlags.AllowRenderTarget;
                allowClearValue = true;
                resourceUsage   = ResourceStates.RenderTarget;
            }

            Resource resource = device.CreateCommittedResource(
                heapProperties,
                HeapFlags.None,
                desc12,
                resourceUsage,
                allowClearValue ? value : default(ClearValue?));

            H1DX12Texture2D newTexture = new H1DX12Texture2D();

            newTexture.m_Resource = new H1DX12Resource(resource, resourceUsage, resource.Description, initialData, Convert.ToUInt32(desc12.DepthOrArraySize * desc12.MipLevels));
            return(newTexture);
        }
Exemple #19
0
 public void SetPrimitiveTopologyType(H1PrimitiveTopologyType primitiveTopologyType)
 {
     m_GraphicsPipelineStateDesc.PrimitiveTopologyType = H1RHIDefinitionHelper.ConvertToPrimitiveTopologyType(primitiveTopologyType);
 }