private RenderSystemResourceGroupLayout CreateDrawResourceGroupLayout(ResourceGroupDescription resourceGroupDescription, EffectBytecode effectBytecode) { if (resourceGroupDescription.DescriptorSetLayout == null) { return(null); } var result = new RenderSystemResourceGroupLayout { DescriptorSetLayout = DescriptorSetLayout.New(RenderSystem.GraphicsDevice, resourceGroupDescription.DescriptorSetLayout), ConstantBufferReflection = resourceGroupDescription.ConstantBufferReflection, }; if (resourceGroupDescription.ConstantBufferReflection != null) { result.ConstantBufferSize = resourceGroupDescription.ConstantBufferReflection.Size; result.ConstantBufferHash = resourceGroupDescription.ConstantBufferReflection.Hash; } // Resolve slots result.ConstantBufferOffsets = new int[drawCBufferOffsetSlots.Count]; for (int index = 0; index < drawCBufferOffsetSlots.Count; index++) { ResolveCBufferOffset(result, index, drawCBufferOffsetSlots[index].Variable); } return(result); }
/// <summary> /// Adds a <see cref="LogicalGroup"/> layout to a <see cref="ParameterCollectionLayout"/>, so that it is later easy to use with <see cref="UpdateLogicalGroup"/>. /// </summary> /// <param name="parameterCollectionLayout"></param> /// <param name="resourceGroupLayout"></param> /// <param name="logicalGroup"></param> public static void ProcessLogicalGroup(this ParameterCollectionLayout parameterCollectionLayout, RenderSystemResourceGroupLayout resourceGroupLayout, ref LogicalGroup logicalGroup) { for (int index = 0; index < logicalGroup.ConstantBufferMemberCount; ++index) { var member = resourceGroupLayout.ConstantBufferReflection.Members[logicalGroup.ConstantBufferMemberStart + index]; parameterCollectionLayout.LayoutParameterKeyInfos.Add(new ParameterKeyInfo(member.KeyInfo.Key, parameterCollectionLayout.BufferSize + member.Offset - logicalGroup.ConstantBufferOffset, member.Type.Elements > 0 ? member.Type.Elements : 1)); } for (int index = 0; index < logicalGroup.DescriptorEntryCount; ++index) { var layoutEntry = resourceGroupLayout.DescriptorSetLayoutBuilder.Entries[logicalGroup.DescriptorEntryStart + index]; parameterCollectionLayout.LayoutParameterKeyInfos.Add(new ParameterKeyInfo(layoutEntry.Key, parameterCollectionLayout.ResourceCount++)); } parameterCollectionLayout.BufferSize += logicalGroup.ConstantBufferSize; }
private void ResolveCBufferOffset(RenderSystemResourceGroupLayout resourceGroupLayout, int index, string variable) { // Update slot if (resourceGroupLayout.ConstantBufferReflection != null) { foreach (var member in resourceGroupLayout.ConstantBufferReflection.Members) { if (member.KeyInfo.KeyName == variable) { resourceGroupLayout.ConstantBufferOffsets[index] = member.Offset; return; } } } // Not found? resourceGroupLayout.ConstantBufferOffsets[index] = -1; }
private RenderSystemResourceGroupLayout CreateDrawResourceGroupLayout(ResourceGroupDescription resourceGroupDescription, RenderEffectState effectState) { if (resourceGroupDescription.DescriptorSetLayout == null) return null; var result = new RenderSystemResourceGroupLayout { DescriptorSetLayoutBuilder = resourceGroupDescription.DescriptorSetLayout, DescriptorSetLayout = DescriptorSetLayout.New(RenderSystem.GraphicsDevice, resourceGroupDescription.DescriptorSetLayout), ConstantBufferReflection = resourceGroupDescription.ConstantBufferReflection, }; result.State = effectState; if (resourceGroupDescription.ConstantBufferReflection != null) { result.ConstantBufferSize = resourceGroupDescription.ConstantBufferReflection.Size; result.ConstantBufferHash = resourceGroupDescription.ConstantBufferReflection.Hash; } // Resolve slots result.ConstantBufferOffsets = new int[drawCBufferOffsetSlots.Count]; for (int index = 0; index < drawCBufferOffsetSlots.Count; index++) { ResolveCBufferOffset(result, index, drawCBufferOffsetSlots[index].Variable); } // Resolve logical groups result.LogicalGroups = new LogicalGroup[drawLogicalGroups.Count]; for (int index = 0; index < drawLogicalGroups.Count; index++) { ResolveLogicalGroup(result, index, drawLogicalGroups[index].Variable); } return result; }
private void ResolveLogicalGroup(RenderSystemResourceGroupLayout resourceGroupLayout, int index, string logicalGroupName) { // Update slot resourceGroupLayout.LogicalGroups[index] = resourceGroupLayout.CreateLogicalGroup(logicalGroupName); }