public void OnWindowResize(DXManager dxman) { DisposeBuffers(); var device = dxman.device; int sc = dxman.multisamplecount; int sq = dxman.multisamplequality; Multisampled = (sc > 1); int uw = Width = dxman.backbuffer.Description.Width; int uh = Height = dxman.backbuffer.Description.Height; Viewport = new ViewportF(); Viewport.Width = (float)uw; Viewport.Height = (float)uh; Viewport.MinDepth = 0.0f; Viewport.MaxDepth = 1.0f; Viewport.X = 0.0f; Viewport.Y = 0.0f; Format f = Format.R32G32B32A32_Float; Format df = Format.D32_Float; Primary = new GpuTexture(device, uw, uh, f, sc, sq, true, df); WindowSizeVramUsage += Primary.VramUsage; int rc = (int)(Math.Ceiling(uw / 8.0f) * Math.Ceiling(uh / 8.0f)); Reduction0 = new GpuBuffer <float>(device, 1, rc); Reduction1 = new GpuBuffer <float>(device, 1, rc); WindowSizeVramUsage += sizeof(float) * rc * 2; LumBlendResult = new GpuBuffer <float>(device, 1, 1); WindowSizeVramUsage += sizeof(float); //because 4 bytes matter int tw = uw / 8; int th = uh / 8; rc = tw * th; f = Format.R8G8B8A8_UNorm; Bloom0 = new GpuBuffer <Vector4>(device, 1, rc); Bloom1 = new GpuBuffer <Vector4>(device, 1, rc); WindowSizeVramUsage += /*sizeof(V4F)*/ 16 * rc * 2; Bloom = new GpuTexture(device, tw, th, f, 1, 0, false, df); WindowSizeVramUsage += Bloom.VramUsage; }
public void DisposeBuffers() { if (Bloom != null) { Bloom.Dispose(); Bloom = null; } if (Bloom0 != null) { Bloom0.Dispose(); Bloom0 = null; } if (Bloom1 != null) { Bloom1.Dispose(); Bloom1 = null; } if (LumBlendResult != null) { LumBlendResult.Dispose(); LumBlendResult = null; } if (Reduction0 != null) { Reduction0.Dispose(); Reduction0 = null; } if (Reduction1 != null) { Reduction1.Dispose(); Reduction1 = null; } if (Primary != null) { Primary.Dispose(); Primary = null; } WindowSizeVramUsage = 0; }
private void ProcessLuminance(DeviceContext context) { var srv = SceneColourSRV; uint dimx, dimy; if (CS_FULL_PIXEL_REDUCTION) { dimx = (uint)(Math.Ceiling(Width / 8.0f)); dimx = (uint)(Math.Ceiling(dimx / 2.0f)); dimy = (uint)(Math.Ceiling(Height / 8.0f)); dimy = (uint)(Math.Ceiling(dimy / 2.0f)); } else { dimx = (uint)(Math.Ceiling(81.0f / 8.0f)); //ToneMappingTexSize = (int)pow(3.0f, NUM_TONEMAP_TEXTURES-1); dimy = dimx; } ReduceCSVars.Vars.dimx = dimx; ReduceCSVars.Vars.dimy = dimy; ReduceCSVars.Vars.Width = (uint)Width; ReduceCSVars.Vars.Height = (uint)Height; ReduceCSVars.Update(context); Compute(context, ReduceTo1DCS, ReduceCSVars.Buffer, Reduction0.UAV, (int)dimx, (int)dimy, 1, srv); uint dim = dimx * dimy; uint nNumToReduce = dim; dim = (uint)(Math.Ceiling(dim / 128.0f)); if (nNumToReduce > 1) { for (;;) { ReduceCSVars.Vars.dimx = nNumToReduce; ReduceCSVars.Vars.dimy = dim; ReduceCSVars.Vars.Width = 0; ReduceCSVars.Vars.Height = 0; ReduceCSVars.Update(context); Compute(context, ReduceTo0DCS, ReduceCSVars.Buffer, Reduction1.UAV, (int)dim, 1, 1, Reduction0.SRV); nNumToReduce = dim; dim = (uint)(Math.Ceiling(dim / 128.0f)); if (nNumToReduce == 1) { break; } var r0 = Reduction0; Reduction0 = Reduction1; Reduction1 = r0; } } else { var r0 = Reduction0; Reduction0 = Reduction1; Reduction1 = r0; } LumBlendCSVars.Vars.blend = new Vector4(Math.Min(ElapsedTime * LumBlendSpeed, 1.0f)); LumBlendCSVars.Update(context); Compute(context, LumBlendCS, LumBlendCSVars.Buffer, LumBlendResult.UAV, 1, 1, 1, Reduction1.SRV); }