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))); }
public DataStorageItem AddGeneric(string name, Type dataType, int length) { var methodCall = IntrospectionUtil.GetGenericMethodCallExpression(this, nameof(Add), new Type[] { dataType }, new Expression[] { Expression.Constant(name), Expression.Constant(length) }); return(IntrospectionUtil.CreateFunc <DataStorageItem>(methodCall).Invoke()); }
private Expression GetReadVertexBufferExpression(FieldInfo fieldInfo, int location) { Type returnType = fieldInfo.FieldType; string debugFieldName = string.Format("{0}.{1}", fieldInfo.DeclaringType.Name, fieldInfo.Name); foreach (var attributeDesc in m_context.m_GraphicsPipeline.m_graphicsPipelineCreateInfo.pVertexInputState.pVertexAttributeDescriptions) { if (location == attributeDesc.location) { bool found = false; VkVertexInputBindingDescription inputBindingDesc = new VkVertexInputBindingDescription(); foreach (var item in m_context.m_GraphicsPipeline.m_graphicsPipelineCreateInfo.pVertexInputState.pVertexBindingDescriptions) { if (item.binding == attributeDesc.binding) { inputBindingDesc = item; found = true; break; } } if (!found) { // Binding not found DebugMsg(string.Format( "ERROR: vertex buffer binding={0} not found for location={1} for field {2}", attributeDesc.binding, location, debugFieldName )); return(null); } var vb = m_context.m_CommandBuffer.m_context.m_VertexBuffers[attributeDesc.binding]; var mem = vb.m_deviceMemory; int stride = inputBindingDesc.stride; int offset = attributeDesc.offset; byte[] memory = mem.m_bytes; if (vb.m_VertexBufferCache != null) { // Use vertex buffer cache Expression indexExpression = IntrospectionUtil.GetExpressionFor(() => this.gl_VertexIndex); return(vb.m_VertexBufferCache.GetReadExpression(returnType, offset, stride, indexExpression)); } else { // Read from raw return(IntrospectionUtil.GetGenericMethodCallExpression( this, nameof(ReadVertexBuffer), new Type[] { returnType }, Expression.Constant(memory), Expression.Constant(offset), Expression.Constant(stride))); } } } DebugMsg(string.Format( "ERROR: vertex buffer location={0} not found for field {1}", location, debugFieldName )); return(null); }