Btw. Why didn't they make another function of this, as they waste processing power by checking if the number of render targets is 0?
I know it's such a small operation, but everything counts.
Is there any specific reason for this?
-MIGI0027
Btw. Why didn't they make another function of this, as they waste processing power by checking if the number of render targets is 0?
I know it's such a small operation, but everything counts.
Is there any specific reason for this?
-MIGI0027
An error has come up, which I am for now unable to understand (I understand it, just don't know why ).
Error:
maximum ps_5_0 UAV register index (8) exceeded - note that the minimum index is 5.
Relevant shader code: (Some resources are repeated or have some weird name, but that's because I'm moving stuff around)
RWTexture3D<float> t_gi0 : register(t0); // GD: These are all faces of a cube map
RWTexture3D<float> t_gi1 : register(t1); // Though i could construct them to one final cube map
RWTexture3D<float> t_gi2 : register(t2); // But I'm too lazy to do that now...
RWTexture3D<float> t_gi3 : register(t3); // After it works I might change it
RWTexture3D<float> t_gi4 : register(t4); // These are only for reading
RWTexture3D<float> t_gi5 : register(t5); // They have already been written to...
// pos and dir are in texture space
// dir is the direction from the center of the voxel outward
// dir should be normalized
float4 voxelFetch(float3 pos, float3 dir, float lod)
{
float4 sampleX =
dir.x < 0.0
? t_gi0[pos]
: t_gi1[pos];
float4 sampleY =
dir.y < 0.0
? t_gi2[pos]
: t_gi3[pos];
float4 sampleZ =
dir.z < 0.0
? t_gi4[pos]
: t_gi5[pos];
float3 sampleWeights = abs(dir);
float invSampleMag = 1.0 / (sampleWeights.x + sampleWeights.y + sampleWeights.z + .0001);
sampleWeights *= invSampleMag;
float4 filtered =
sampleX * sampleWeights.x
+ sampleY * sampleWeights.y
+ sampleZ * sampleWeights.z;
return filtered;
}
// origin, dir, and maxDist are in texture space
// dir should be normalized
// coneRatio is the cone diameter to height ratio (2.0 for 90-degree cone)
float4 voxelTraceCone(float3 origin, float3 dir, float coneRatio, float maxDist)
{
float3 samplePos = origin;
float4 accum = float4(0, 0, 0, 0);
// the starting sample diameter
float minDiameter = minVoxelDiameter;
// push out the starting point to avoid self-intersection
float startDist = minDiameter;
float dist = startDist;
[loop]
[allow_uav_condition]
while (dist <= maxDist && accum.w < 1.0)
{
// ensure the sample diameter is no smaller than the min
// desired diameter for this cone (ensuring we always
// step at least minDiameter each iteration, even for tiny
// cones - otherwise lots of overlapped samples)
float sampleDiameter = max(minDiameter, coneRatio * dist);
// convert diameter to LOD
// for example:
// log2(1/256 * 256) = 0
// log2(1/128 * 256) = 1
// log2(1/64 * 256) = 2
float sampleLOD = log2(sampleDiameter * minVoxelDiameterInv);
float3 samplePos = origin + dir * dist;
float4 sampleValue = voxelFetch(samplePos, -dir, sampleLOD);
float sampleWeight = (1.0 - accum.w);
accum += sampleValue * sampleWeight;
dist += sampleDiameter;
}
// decompress color range to decode limited HDR
accum.xyz *= 2.0;
return accum;
}
#endif
Texture2D t_alphamap : register(t0);
Texture2D t_dffalpha : register(t1);
Texture2D gBuffer_Shadows : register(t2);
Texture2D t_rFront : register(t3);
Texture2D t_rBack : register(t4);
#if COMPILENORMALMAP == 1
Texture2D t_norm : register(t5);
#endif
#if COMPILESPECULARMAP == 1
Texture2D t_spec : register(t6);
#endif
#if COMPILEMASKMAP == 1
Texture2D t_mask : register(t7);
#endif
SamplerState ss;
Now what on earth did I do wrong?
-MIGI0027
You can't tell me it's impossible to send more than 6 UAVs, or maybe I'm setting it to the wrong slots, with the wrong range.
OpenGL GLSL for what I'm trying to achieve:
layout(binding = 3) uniform sampler3D voxelTex[6];
HLSL:
RWTexture3D<float> t_gi[6];
Buffer<float> In1 : register(u0); // WRONG: It should be t#
RWBuffer<float> Out1: register(t0); // AGAIN WRONG: It should be u#
RWBuffer<float> Out2: register(t1);
RWBuffer<float> Out3: register(t2);
RWBuffer<float> Out4: register(t3);
RWBuffer<float> Out5: register(t4);
RWBuffer<float> Out6: register(t5);
RWBuffer<float> Out7: register(t6);
RWBuffer<float> Out8: register(t7);
[numthreads(4,4,4)]
void main(uint3 tid : SV_DispatchThreadID)
{
uint index = dot(tid, uint3(1, 8, 256)); // whatever
Out1[index] = In1[index] +
Out2[index] +
Out3[index] +
Out4[index] +
Out5[index] +
Out6[index] +
Out7[index] +
Out8[index];
}
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229
//
//
// fxc /Zi /T cs_5_0 /Fo stub.fxo /Fx stub.asm stub.fx
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// In1 texture float buf 0 1
// Out1 UAV float buf 0 1
// Out2 UAV float buf 1 1
// Out3 UAV float buf 2 1
// Out4 UAV float buf 3 1
// Out5 UAV float buf 4 1
// Out6 UAV float buf 5 1
// Out7 UAV float buf 6 1
// Out8 UAV float buf 7 1
(Resource type texture means t# register, hence the t).Thanks, first time using UAVs .
Though I have a problem, the u's seemed to solve some problems, the pixel shader outputs to 5 different render targets (Can be boiled down to 3-4). So then the UAVs expect to start at an index of at least u5, but the max UAV register index is 8, and I need six slots, but this doesn't obey the laws.
UAV registers live in the same name space as outputs, so they must be bound to at least u5, manual bind to slot u0 failed
What would be your suggestion?
Ah-ha, there's the culprit. Learned something new then - haven't used UAVs in pixel shaders so far.
Seems you have to tailor your setup accordingly. Multiple passes ? Combine two or more resources into one (say, use a bigger texture and "atlas"/split manually) ? How's it done in OpenGL ? Is there no such limit ?
For multiple passes look into both stream out (geometry shader) and append/consume buffers (special UAVs, hopefully they work in pixel shaders) maybe they can help you split the problem.
Admittedly, these are hints from a bird's eye view. This really sounds like a challenging problem. Look into alternatives: If something gets too cumbersome another approach is likely better than "shoehorning" it into a unsuitable API. That thesis I linked looks feasable with D3D11 (first variant using geometry shaders and three passes).