public static EffectDescriptorSetReflection New(GraphicsDevice graphicsDevice, EffectBytecode effectBytecode, List <string> effectDescriptorSetSlots, string defaultSetSlot) { // Find resource groups // TODO: We should precompute most of that at compile time in BytecodeReflection // just waiting for format to be more stable var descriptorSetLayouts = new EffectDescriptorSetReflection(); foreach (var effectDescriptorSetSlot in effectDescriptorSetSlots) { // Find all resources related to this slot name var descriptorSetLayoutBuilder = new DescriptorSetLayoutBuilder(); bool hasBindings = false; foreach (var resourceBinding in effectBytecode.Reflection.ResourceBindings .Where(x => x.Param.ResourceGroup == effectDescriptorSetSlot || (effectDescriptorSetSlot == defaultSetSlot && (x.Param.ResourceGroup == null || x.Param.ResourceGroup == "Globals"))) .GroupBy(x => new { Key = x.Param.Key, Class = x.Param.Class, SlotCount = x.SlotCount }) .OrderBy(x => x.Key.Class == EffectParameterClass.ConstantBuffer ? 0 : 1)) // Note: Putting cbuffer first for now { SamplerState samplerState = null; if (resourceBinding.Key.Class == EffectParameterClass.Sampler) { var matchingSamplerState = effectBytecode.Reflection.SamplerStates.FirstOrDefault(x => x.Key == resourceBinding.Key.Key); if (matchingSamplerState != null) { samplerState = SamplerState.New(graphicsDevice, matchingSamplerState.Description); } } hasBindings = true; descriptorSetLayoutBuilder.AddBinding(resourceBinding.Key.Key, resourceBinding.Key.Class, resourceBinding.Key.SlotCount, samplerState); } descriptorSetLayouts.AddLayout(effectDescriptorSetSlot, hasBindings ? descriptorSetLayoutBuilder : null); } return(descriptorSetLayouts); }
/// <summary> /// Initializes a new instance of the <see cref="SamplerStateFactory"/> class. /// </summary> /// <param name="device">The device.</param> internal SamplerStateFactory(GraphicsDevice device) : base(device) { PointWrap = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Point, TextureAddressMode.Wrap)).DisposeBy(this); PointWrap.Name = "SamplerState.PointWrap"; PointClamp = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Point, TextureAddressMode.Clamp)).DisposeBy(this); PointClamp.Name = "SamplerState.PointClamp"; LinearWrap = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Wrap)).DisposeBy(this); LinearWrap.Name = "SamplerState.LinearWrap"; LinearClamp = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Clamp)).DisposeBy(this); LinearClamp.Name = "SamplerState.LinearClamp"; AnisotropicWrap = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Anisotropic, TextureAddressMode.Wrap)).DisposeBy(this); AnisotropicWrap.Name = "SamplerState.AnisotropicWrap"; AnisotropicClamp = SamplerState.New(device, new SamplerStateDescription(TextureFilter.Anisotropic, TextureAddressMode.Clamp)).DisposeBy(this); AnisotropicClamp.Name = "SamplerState.AnisotropicClamp"; }
private ParameterKey UpdateResourceBindingKey(ref EffectParameterResourceData binding) { var keyName = binding.Param.KeyName; switch (binding.Param.Class) { case EffectParameterClass.Sampler: var newSamplerKey = (ParameterKey <SamplerState>)FindOrCreateResourceKey <SamplerState>(keyName); binding.Param.Key = newSamplerKey; var samplerBinding = reflection.SamplerStates.FirstOrDefault(x => x.KeyName == keyName); if (samplerBinding != null) { samplerBinding.Key = newSamplerKey; var samplerDescription = samplerBinding.Description; defaultParameters.Set(newSamplerKey, SamplerState.New(graphicsDeviceDefault, samplerDescription)); } break; case EffectParameterClass.ConstantBuffer: case EffectParameterClass.TextureBuffer: case EffectParameterClass.ShaderResourceView: case EffectParameterClass.UnorderedAccessView: switch (binding.Param.Type) { case EffectParameterType.Buffer: case EffectParameterType.ConstantBuffer: case EffectParameterType.TextureBuffer: case EffectParameterType.AppendStructuredBuffer: case EffectParameterType.ByteAddressBuffer: case EffectParameterType.ConsumeStructuredBuffer: case EffectParameterType.StructuredBuffer: case EffectParameterType.RWBuffer: case EffectParameterType.RWStructuredBuffer: case EffectParameterType.RWByteAddressBuffer: binding.Param.Key = FindOrCreateResourceKey <Buffer>(keyName); break; case EffectParameterType.Texture: case EffectParameterType.Texture1D: case EffectParameterType.Texture1DArray: case EffectParameterType.RWTexture1D: case EffectParameterType.RWTexture1DArray: case EffectParameterType.Texture2D: case EffectParameterType.Texture2DArray: case EffectParameterType.Texture2DMultisampled: case EffectParameterType.Texture2DMultisampledArray: case EffectParameterType.RWTexture2D: case EffectParameterType.RWTexture2DArray: case EffectParameterType.TextureCube: case EffectParameterType.TextureCubeArray: case EffectParameterType.RWTexture3D: case EffectParameterType.Texture3D: binding.Param.Key = FindOrCreateResourceKey <Texture>(keyName); break; } break; } if (binding.Param.Key == null) { throw new InvalidOperationException(string.Format("Unable to find/generate key [{0}] with unsupported type [{1}/{2}]", binding.Param.KeyName, binding.Param.Class, binding.Param.Type)); } return(binding.Param.Key); }