Пример #1
0
        private Expression GetReadUniformBufferExpression(FieldInfo fieldInfo, int binding, int set)
        {
            string debugFieldName = string.Format("{0}.{1}", fieldInfo.DeclaringType.Name, fieldInfo.Name);
            Type   returnType     = fieldInfo.FieldType;

            var bufferInfo = m_context.m_DescriptorSets[set].m_BufferInfo[binding];

            if (bufferInfo.buffer == null)
            {
                DebugMsg(string.Format("ERROR: no buffer bound to uniform set={0} binding={1} for field {2}",
                                       set, binding, debugFieldName));
                return(null);
            }

            SoftwareBuffer softwareBuffer = (SoftwareBuffer)bufferInfo.buffer;

            if (softwareBuffer.m_deviceMemory == null)
            {
                DebugMsg(string.Format("ERROR: no memory bound to buffer on uniform set={0} binding={1} for field {2}",
                                       set, binding, debugFieldName));
                return(null);
            }

            SoftwareDeviceMemory mem = softwareBuffer.m_deviceMemory;

            byte[] memory = mem.m_bytes;
            int    offset = bufferInfo.offset + softwareBuffer.m_memoryOffset;
            int    size   = Marshal.SizeOf(returnType);

            return(IntrospectionUtil.GetGenericMethodCallExpression(
                       this, nameof(ReadUniform),
                       new Type[] { returnType },
                       Expression.Constant(memory), Expression.Constant(offset), Expression.Constant(size)));
        }
Пример #2
0
        public void DrawIndexed(int indexCount, int instanceCount, int firstIndex, int vertexOffset, int firstInstance)
        {
            m_CompiledPipelineProgram.InitializePipeline();

            this.gl_InstanceIndex = firstInstance;
            this.CurrentStage     = StageType.InputAssembler;

            int indiceIndex = firstIndex;

            int[]                vertexIndex32 = new int[1];
            UInt16[]             vertexIndex16 = new ushort[1];
            SoftwareDeviceMemory sdmIndex      = (SoftwareDeviceMemory)m_context.m_CommandBuffer.m_context.m_IndexBuffer.m_deviceMemory;
            int        indexMemOffset          = m_context.m_CommandBuffer.m_context.m_IndexBuffer.m_memoryOffset;
            Func <int> getIndiceFunc;

            switch (m_context.m_CommandBuffer.m_context.m_IndexBufferType)
            {
            case VkIndexType.VK_INDEX_TYPE_UINT16:
                getIndiceFunc = () =>
                {
                    int srcOffset = indexMemOffset + (indiceIndex * 2);
                    Buffer.BlockCopy(sdmIndex.m_bytes, srcOffset, vertexIndex16, 0, 2);
                    return(vertexIndex16[0]);
                };
                break;

            case VkIndexType.VK_INDEX_TYPE_UINT32:
                getIndiceFunc = () =>
                {
                    int srcOffset = indexMemOffset + (indiceIndex * 4);
                    Buffer.BlockCopy(sdmIndex.m_bytes, srcOffset, vertexIndex32, 0, 4);
                    return(vertexIndex32[0]);
                };
                break;

            default:
                return;
            }

            for (int instanceNum = 0; instanceNum < instanceCount; instanceNum++)
            {
                indiceIndex = firstIndex;

                while (indexCount >= PrimitiveLength)
                {
                    for (int i = 0; i < PrimitiveLength; i++)
                    {
                        this.PrimitiveVertexIndex = i;
                        this.gl_VertexIndex       = getIndiceFunc();
                        m_CompiledPipelineProgram.VertexShader();
                        indiceIndex++;
                    }
                    RasterizeTriangle();
                    indexCount -= this.PrimitiveLength;
                }
                this.gl_InstanceIndex++;
            }
        }
Пример #3
0
        public override void Execute(SoftwareExecutionContext context)
        {
            SoftwareDeviceMemory srcMem = srcBuffer.m_deviceMemory;
            SoftwareDeviceMemory dstMem = dstBuffer.m_deviceMemory;

            for (int i = 0; i < regionCount; i++)
            {
                int srcOffset = srcBuffer.m_memoryOffset + pRegions[i].srcOffset;
                int dstOffset = dstBuffer.m_memoryOffset + pRegions[i].dstOffset;
                Buffer.BlockCopy(srcMem.m_bytes, srcOffset, dstMem.m_bytes, dstOffset, pRegions[i].size);
            }
        }
Пример #4
0
        private T ReadUniform <T>(int binding, int set) where T : struct
        {
            var layout     = m_context.m_CommandBuffer.m_context.m_DescriptorSets[set].m_Bindings[binding];
            var bufferInfo = m_context.m_CommandBuffer.m_context.m_DescriptorSets[set].m_BufferInfo[binding];

            SoftwareBuffer       softwareBuffer = (SoftwareBuffer)bufferInfo.buffer;
            SoftwareDeviceMemory mem            = softwareBuffer.m_deviceMemory;
            int startIndex = bufferInfo.offset + softwareBuffer.m_memoryOffset;
            T   ret        = new T();

            MemoryCopyHelper.ReadStructure(mem.m_bytes, startIndex, ref ret);
            return(ret);
        }