forked from mrvux/dx11-vvvv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleHoldNodes.cs
150 lines (122 loc) · 6.38 KB
/
SampleHoldNodes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VVVV.PluginInterfaces.V2;
using FeralTic.DX11.Resources;
using FeralTic.DX11;
using SlimDX.Direct3D11;
using SlimDX.DXGI;
namespace VVVV.DX11.Nodes
{
[PluginInfo(Name = "S+H", Category = "DX11.Texture", Version = "2d", Author = "vux", Help = "Sample and Hold - if set is 1 just passes the input through(makes a copy of it), when set is 0 keeps the copy instead(and block upwards evaluation and rendering")]
public class SampleHoldTexture2DNode : SampleHoldResourceNode<DX11Texture2D>
{
private Texture2DDescription currentDescription;
protected override void ProcessResource(DX11RenderContext context, DX11Texture2D inputResource, ref DX11Texture2D outputResource)
{
if (outputResource != null)
{
if (currentDescription != outputResource.Description)
{
outputResource.Dispose();
outputResource = null;
}
}
if (outputResource == null)
{
this.currentDescription = inputResource.Description;
/*make default pool, disallow cpu access and only allow shader view flag (as we will not write to it) */
Texture2DDescription desc = this.currentDescription;
desc.Usage = ResourceUsage.Default;
desc.BindFlags = BindFlags.ShaderResource;
desc.CpuAccessFlags = CpuAccessFlags.None;
outputResource = DX11Texture2D.FromDescription(context, desc);
}
context.CurrentDeviceContext.CopyResource(inputResource.Resource, outputResource.Resource);
}
}
[PluginInfo(Name = "S+H", Category = "DX11.DepthStencil", Version = "2d", Author = "vux", Help = "Sample and Hold - if set is 1 just passes the input through(makes a copy of it), when set is 0 keeps the copy instead(and block upwards evaluation and rendering")]
public class SampleHoldDepthStencilNode : SampleHoldResourceNode<DX11DepthStencil>
{
private Texture2DDescription currentDescription;
protected override void ProcessResource(DX11RenderContext context, DX11DepthStencil inputResource, ref DX11DepthStencil outputResource)
{
if (outputResource != null)
{
//currentDescription = inputResource.Description;
if (currentDescription != inputResource.Description)
{
outputResource.Dispose();
outputResource = null;
}
}
if (outputResource == null || apply[0])
{
this.currentDescription = inputResource.Description;
/*make default pool, disallow cpu access and only allow shader view flag (as we will not write to it) */
Texture2DDescription desc = this.currentDescription;
desc.Usage = ResourceUsage.Default;
desc.BindFlags = BindFlags.ShaderResource;
desc.CpuAccessFlags = CpuAccessFlags.None;
// works:
//outputResource = DX11DepthStencil.FromDescription(context, desc, Format.D24_UNorm_S8_UInt);
// works without adding method to DX11DepthStencil
outputResource = new DX11DepthStencil(context, desc.Width, desc.Height, desc.SampleDescription, Format.D24_UNorm_S8_UInt);
}
context.CurrentDeviceContext.CopyResource(inputResource.Resource, outputResource.Resource);
}
}
[PluginInfo(Name = "S+H", Category = "DX11.Buffer", Version = "Structured", Author = "vux", Help ="Sample and Hold - if set is 1 just passes the input through(makes a copy of it), when set is 0 keeps the copy instead(and block upwards evaluation and rendering")]
public class SampleHoldStructuredNode : SampleHoldResourceNode<IDX11ReadableStructureBuffer>
{
private BufferDescription currentDescription;
protected override void ProcessResource(DX11RenderContext context, IDX11ReadableStructureBuffer inputResource, ref IDX11ReadableStructureBuffer outputResource)
{
if (outputResource != null)
{
if (currentDescription != outputResource.Buffer.Description)
{
outputResource.Dispose();
outputResource = null;
}
}
if (outputResource == null)
{
this.currentDescription = inputResource.Buffer.Description;
BufferDescription desc = this.currentDescription;
desc.Usage = ResourceUsage.Default;
desc.BindFlags = BindFlags.ShaderResource;
desc.CpuAccessFlags = CpuAccessFlags.None;
outputResource = new DX11CopyDestStructuredBuffer(context.Device, desc);
}
context.CurrentDeviceContext.CopyResource(inputResource.Buffer, outputResource.Buffer);
}
}
[PluginInfo(Name = "S+H", Category = "DX11.Texture", Version = "3d", Author = "vux", Help = "Sample and Hold - if set is 1 just passes the input through(makes a copy of it), when set is 0 keeps the copy instead(and block upwards evaluation and rendering")]
public class SampleHoldTexture3DNode : SampleHoldResourceNode<DX11Texture3D>
{
private Texture3DDescription currentDescription;
protected override void ProcessResource(DX11RenderContext context, DX11Texture3D inputResource, ref DX11Texture3D outputResource)
{
if (outputResource != null)
{
if (currentDescription != outputResource.Resource.Description)
{
outputResource.Dispose();
outputResource = null;
}
}
if (outputResource == null)
{
this.currentDescription = inputResource.Resource.Description;
Texture3DDescription desc = this.currentDescription;
desc.Usage = ResourceUsage.Default;
desc.BindFlags = BindFlags.ShaderResource;
desc.CpuAccessFlags = CpuAccessFlags.None;
outputResource = DX11Texture3D.FromDescription(context, desc);
}
context.CurrentDeviceContext.CopyResource(inputResource.Resource, outputResource.Resource);
}
}
}