public static void initState(iPipelineStateFactory stateFactory, iShaderFactory shaderFactory, iStorageFolder assets, IShader vs, string ps, string name) { stateFactory.clear(); stateFactory.setName(name + " PSO"); // VS input layout LayoutElement elt = new LayoutElement(false) { InputIndex = 0, BufferSlot = 0, NumComponents = 2, ValueType = GpuValueType.Float32, IsNormalized = false }; stateFactory.graphicsLayoutElement(elt); // Shaders stateFactory.graphicsVertexShader(vs); using (var shader = shaderFactory.compileHlslFile(assets, ps, ShaderType.Pixel, name + " PS")) stateFactory.graphicsPixelShader(shader); // Mutable texture variable stateFactory.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Mutable, "g_Texture"); // Static sampler SamplerDesc samplerDesc = new SamplerDesc(false) { MinFilter = FilterType.Point, MagFilter = FilterType.Point, MipFilter = FilterType.Point, }; stateFactory.layoutStaticSampler(ShaderType.Pixel, ref samplerDesc, "g_Texture"); }
static SamplerDesc samplerDesc() { var s = new SamplerDesc(false); s.MinFilter = s.MagFilter = s.MipFilter = FilterType.Point; return(s); }
// Copy constructor: public SamplerDesc(SamplerDesc desc) { m_Type = desc.m_Type; m_Name = desc.m_Name; m_Description = desc.m_Description; m_ShapeDefaultTransform = desc.m_ShapeDefaultTransform; }
public override bool Equals(object other) { SamplerDesc desc = other as SamplerDesc; if (desc == null) { return(false); } return(this == desc); }
public RenderBase(IRenderDevice device, CSize renderTargetSize, SwapChainFormats formats, Vector4 borderColor, sDecodedVideoSize videoSize) { this.videoSize = videoSize; // Create vertex buffer vertexBuffer = createVideoVertexBuffer(device, renderTargetSize, ref videoSize); // Create pipeline state var pso = new PipelineStateDesc(false); pso.GraphicsPipeline.DepthStencilDesc.DepthEnable = false; pso.GraphicsPipeline.PrimitiveTopology = PrimitiveTopology.TriangleList; pso.GraphicsPipeline.NumRenderTargets = 1; pso.GraphicsPipeline.setRTVFormat(0, formats.color); pso.GraphicsPipeline.DSVFormat = formats.depth; pso.ResourceLayout.DefaultVariableType = ShaderResourceVariableType.Static; var compiler = device.GetShaderFactory(); iStorageFolder assets = StorageFolder.embeddedResources(System.Reflection.Assembly.GetExecutingAssembly(), resourceFolder); using (var psf = device.CreatePipelineStateFactory()) { psf.setName("Video PSO"); setupVideoInputLayout(psf); using (var vs = compiler.compileHlslFile(assets, "VideoVS.hlsl", ShaderType.Vertex)) psf.graphicsVertexShader(vs); (string uvMin, string uvMax) = videoUvCroppedRect(ref videoSize); string colorString = Utils.printFloat4(borderColor); using (var ps = compilePixelShader(compiler, assets, uvMin, uvMax, colorString)) psf.graphicsPixelShader(ps); psf.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Dynamic, varTexture); var sampler = new SamplerDesc(false) { MipFilter = FilterType.Point, }; psf.layoutStaticSampler(ShaderType.Pixel, ref sampler, varTexture); psf.apply(ref pso); pipelineState = device.CreatePipelineState(ref pso); } // Create resource binding and cache the variable, we gonna need both on every frame rendered binding = pipelineState.CreateShaderResourceBinding(true); textureVariable = binding.GetVariableByName(ShaderType.Pixel, varTexture); }
public VrmacStateBase(GpuResources resources, IRenderDevice device, ref PipelineStateDesc desc, iPipelineStateFactory stateFactory, eShaderMacros macros) { this.resources = resources; shaderMacros = macros; layoutUniforms(stateFactory); stateFactory.setName($"2D state { macros }"); stateFactory.layoutVariable(ShaderType.Vertex, ShaderResourceVariableType.Mutable, varPaletteTexture); stateFactory.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Mutable, varPaletteTexture); if (macros.HasFlag(eShaderMacros.TextureAtlas)) { stateFactory.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Mutable, varSpriteAtlas); SamplerDesc samplerDesc = new SamplerDesc(false); stateFactory.layoutStaticSampler(ShaderType.Pixel, ref samplerDesc, varSpriteAtlas); resources.context.drawDevice.textureAtlas.resized.add(this, dropResourceBindings); } if (macros.HasFlag(eShaderMacros.TextRendering)) { stateFactory.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Mutable, varGrayscaleFontAtlas); SamplerDesc samplerDesc = new SamplerDesc(false); stateFactory.layoutStaticSampler(ShaderType.Pixel, ref samplerDesc, varGrayscaleFontAtlas); stateFactory.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Mutable, varCleartypeFontAtlas); resources.initTextCBuffer(); } declareResources(stateFactory); stateFactory.apply(ref desc); setupDepthState(ref desc, macros); pipelineState = device.CreatePipelineState(ref desc); resources.context.swapChainResized.add(this, (CSize s, double d) => dropResourceBindings()); resources.paletteTexture.textureResized.add(this, dropResourceBindings); }
void createPipelineState(IRenderDevice device, iStorageFolder assets) { PipelineStateDesc PSODesc = new PipelineStateDesc(false); PSODesc.setBufferFormats(context); // Primitive topology defines what kind of primitives will be rendered by this pipeline state PSODesc.GraphicsPipeline.PrimitiveTopology = PrimitiveTopology.TriangleList; // Cull back faces PSODesc.GraphicsPipeline.RasterizerDesc.CullMode = CullMode.Back; // Enable depth testing PSODesc.GraphicsPipeline.DepthStencilDesc.DepthEnable = true; iShaderFactory shaderFactory = device.GetShaderFactory(); // We won't be using the factory object after this, `using` to release the COM interface once finished using (iPipelineStateFactory stateFactory = device.CreatePipelineStateFactory()) { stateFactory.setName("Cube PSO"); // Compile the two shaders ShaderSourceInfo sourceInfo = new ShaderSourceInfo(ShaderType.Vertex, ShaderSourceLanguage.Hlsl); sourceInfo.combinedTextureSamplers = true; // This appears to be the requirement of OpenGL backend. // In this tutorial, we will load shaders from resources embedded into this .NET DLL. var vs = shaderFactory.compileFromFile(assets, "cube.vsh", sourceInfo, "Cube VS"); stateFactory.graphicsVertexShader(vs); // Create dynamic uniform buffer that will store our transformation matrix. Dynamic buffers can be frequently updated by the CPU. BufferDesc CBDesc = new BufferDesc(false); CBDesc.uiSizeInBytes = Marshal.SizeOf <Matrix4x4>(); CBDesc.Usage = Usage.Dynamic; CBDesc.BindFlags = BindFlags.UniformBuffer; CBDesc.CPUAccessFlags = CpuAccessFlags.Write; vsConstants = device.CreateBuffer(CBDesc, "VS constants CB"); // Create a pixel shader sourceInfo.shaderType = ShaderType.Pixel; var ps = shaderFactory.compileFromFile(assets, "cube.psh", sourceInfo, "Cube PS"); stateFactory.graphicsPixelShader(ps); // Define vertex shader input layout // Attribute 0 - vertex position LayoutElement elt = new LayoutElement(false) { InputIndex = 0, BufferSlot = 0, NumComponents = 3, ValueType = GpuValueType.Float32, IsNormalized = false }; stateFactory.graphicsLayoutElement(elt); // Attribute 1 - texture coordinates elt.InputIndex = 1; elt.NumComponents = 2; stateFactory.graphicsLayoutElement(elt); // Define variable type that will be used by default PSODesc.ResourceLayout.DefaultVariableType = ShaderResourceVariableType.Static; // Shader variables should typically be mutable, which means they are expected to change on a per-instance basis stateFactory.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Mutable, "g_Texture"); // Define static sampler for g_Texture. Static samplers should be used whenever possible. // The default constructor is good enough, it sets FilterType.Linear and TextureAddressMode.Clamp for all 3 coordinates. SamplerDesc samplerDesc = new SamplerDesc(false); stateFactory.layoutStaticSampler(ShaderType.Pixel, ref samplerDesc, "g_Texture"); stateFactory.apply(ref PSODesc); pipelineState = device.CreatePipelineState(ref PSODesc); } // Since we did not explicitly specify the type for 'Constants' variable, default // type (SHADER_RESOURCE_VARIABLE_TYPE_STATIC) will be used. Static variables never // change and are bound directly through the pipeline state object. pipelineState.GetStaticVariableByName(ShaderType.Vertex, "Constants").Set(vsConstants); // Since we are using mutable variable, we must create a shader resource binding object // http://diligentgraphics.com/2016/03/23/resource-binding-model-in-diligent-engine-2-0/ resourceBinding = pipelineState.CreateShaderResourceBinding(true); }
public override SamplerState CreateSamplerState(SamplerDesc desc) { throw new NotImplementedException(); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SamplerDesc obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }