public ITextureFilter CreateChromaFilter(ITextureFilter lumaInput, ITextureFilter chromaInput, TextureSize targetSize, Vector2 chromaOffset) { DisposeHelper.Dispose(ref m_Buffer1); DisposeHelper.Dispose(ref m_Buffer2); if (!Renderer.IsOpenClAvail || Renderer.RenderQuality.PerformanceMode()) { Renderer.FallbackOccurred = true; // Warn user via player stats OSD return(null); // OpenCL is not available; fallback } var lumaSize = lumaInput.Output.Size; var chromaSize = chromaInput.Output.Size; if (lumaSize.Width != 2 * chromaSize.Width || lumaSize.Height != 2 * chromaSize.Height) { return(null); // Chroma shouldn't be doubled; fallback } Func <TextureSize, TextureSize> transformWidth = s => new TextureSize(2 * s.Width, s.Height); Func <TextureSize, TextureSize> transformHeight = s => new TextureSize(s.Width, 2 * s.Height); var kernelU = CompileKernel(true); var kernelV = CompileKernel(false); var shaderUh = kernelU.Configure(transform: transformWidth); var shaderUv = kernelU.Configure(transform: transformHeight); var shaderVh = kernelV.Configure(transform: transformWidth); var shaderVv = kernelV.Configure(transform: transformHeight); var neuronCount1 = s_NeuronCount[(int)Neurons1]; var neuronCount2 = s_NeuronCount[(int)Neurons2]; var weights1 = s_Weights[(int)Neurons1]; m_Buffer1 = Renderer.CreateClBuffer(weights1); var differentWeights = neuronCount1 != neuronCount2; if (differentWeights) { var weights2 = s_Weights[(int)Neurons2]; m_Buffer2 = Renderer.CreateClBuffer(weights2); } var localWorkSizes = new[] { 8, 8 }; var nnedi3Uh = new NNedi3HKernelFilter(shaderUh, m_Buffer1, neuronCount1, new TextureSize(chromaSize.Width, chromaSize.Height), localWorkSizes, chromaInput); var nnedi3Uv = new NNedi3VKernelFilter(shaderUv, m_Buffer2, neuronCount2, differentWeights, new TextureSize(nnedi3Uh.Output.Size.Width, nnedi3Uh.Output.Size.Height), localWorkSizes, nnedi3Uh); var nnedi3Vh = new NNedi3HKernelFilter(shaderVh, m_Buffer1, neuronCount1, new TextureSize(chromaSize.Width, chromaSize.Height), localWorkSizes, chromaInput); var nnedi3Vv = new NNedi3VKernelFilter(shaderVv, m_Buffer2, neuronCount2, differentWeights, new TextureSize(nnedi3Vh.Output.Size.Width, nnedi3Vh.Output.Size.Height), localWorkSizes, nnedi3Vh); return(lumaInput.MergeWith(nnedi3Uv, nnedi3Vv).ConvertToRgb()); }
public static ITextureFilter ScaleChroma(ITextureFilter luma, ITextureFilter chroma, TextureSize targetSize, Vector2 chromaOffset) { luma = luma.SetSize(targetSize); var resizedLuma = luma as ResizeFilter; if (resizedLuma != null) { resizedLuma.AddLabel(resizedLuma.ScaleDescription.AddPrefixToDescription("Luma: ")); } if (chroma.Size() != luma.Size()) { var resizedChroma = new ResizeFilter(chroma, luma.Size(), TextureChannels.ChromaOnly, chromaOffset, Renderer.ChromaUpscaler, Renderer.ChromaDownscaler); resizedChroma.AddLabel(resizedChroma.ScaleDescription.AddPrefixToDescription("Chroma: ")); chroma = resizedChroma; } return(luma .MergeWith(chroma) .ConvertToRgb()); }
public ITextureFilter CreateChromaFilter(ITextureFilter lumaInput, ITextureFilter chromaInput, TextureSize targetSize, Vector2 chromaOffset) { if (!Renderer.IsDx11Avail) { Renderer.FallbackOccurred = true; // Warn user via player stats OSD return(null); // DX11 is not available; fallback } var lumaSize = lumaInput.Output.Size; var chromaSize = chromaInput.Output.Size; if (lumaSize.Width != 2 * chromaSize.Width || lumaSize.Height != 2 * chromaSize.Height) { return(null); // Chroma shouldn't be doubled; fallback } Func <TextureSize, TextureSize> transform = s => new TextureSize(2 * s.Height, s.Width); var shaderUPass1 = LoadShader11(GetShaderFileName(Neurons1, true)); var shaderUPass2 = LoadShader11(GetShaderFileName(Neurons2, true)); var shaderVPass1 = LoadShader11(GetShaderFileName(Neurons1, false)); var shaderVPass2 = LoadShader11(GetShaderFileName(Neurons2, false)); var interleaveU = CompileShader("Interleave.hlsl", macroDefinitions: "CHROMA_U=1").Configure(transform: transform); var interleaveV = CompileShader("Interleave.hlsl", macroDefinitions: "CHROMA_V=1").Configure(transform: transform); var uFilter1 = NNedi3Helpers.CreateFilter(shaderUPass1, chromaInput, Neurons1, Structured); var resultU = interleaveU.ApplyTo(chromaInput, uFilter1); var uFilter2 = NNedi3Helpers.CreateFilter(shaderUPass2, resultU, Neurons2, Structured); var u = interleaveU.ApplyTo(resultU, uFilter2); var vFilter1 = NNedi3Helpers.CreateFilter(shaderVPass1, chromaInput, Neurons1, Structured); var resultV = interleaveV.ApplyTo(chromaInput, vFilter1); var vFilter2 = NNedi3Helpers.CreateFilter(shaderVPass2, resultV, Neurons2, Structured); var v = interleaveV.ApplyTo(resultV, vFilter2); return(lumaInput.MergeWith(u, v).ConvertToRgb()); }