rawbuffer vertex fetch
This commit is contained in:
@@ -93,6 +93,9 @@
|
||||
|
||||
// Automatically binds resources on the shader side:
|
||||
|
||||
#define RAWBUFFER(name,slot) ByteAddressBuffer name : register(t ## slot)
|
||||
#define RWRAWBUFFER(name,slot) RWByteAddressBuffer name : register(u ## slot)
|
||||
|
||||
#define TYPEDBUFFER(name, type, slot) Buffer< type > name : register(t ## slot)
|
||||
#define RWTYPEDBUFFER(name, type, slot) RWBuffer< type > name : register(u ## slot)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_1);
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ struct GS_CUBEMAP_IN
|
||||
GS_CUBEMAP_IN main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Shadow_POS input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_TEX, float4, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_TEX, VBSLOT_1);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_2);
|
||||
|
||||
struct GS_CUBEMAP_IN
|
||||
@@ -16,9 +16,10 @@ struct GS_CUBEMAP_IN
|
||||
GS_CUBEMAP_IN main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Shadow_POS_TEX input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.tex = vertexBuffer_TEX[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.tex = asfloat(vertexBuffer_TEX.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_NOR, float4, VBSLOT_1);
|
||||
TYPEDBUFFER(vertexBuffer_TEX, float4, VBSLOT_2);
|
||||
TYPEDBUFFER(vertexBuffer_PRE, float4, VBSLOT_3);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_NOR, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_TEX, VBSLOT_2);
|
||||
RAWBUFFER(vertexBuffer_PRE, VBSLOT_3);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_4);
|
||||
STRUCTUREDBUFFER(instanceBuffer_Prev, Input_InstancePrev, VBSLOT_5);
|
||||
|
||||
@@ -13,11 +13,12 @@ STRUCTUREDBUFFER(instanceBuffer_Prev, Input_InstancePrev, VBSLOT_5);
|
||||
PixelInputType main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Object_ALL input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.nor = vertexBuffer_NOR[vID];
|
||||
input.tex = vertexBuffer_TEX[vID];
|
||||
input.pre = vertexBuffer_PRE[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.nor = asfloat(vertexBuffer_NOR.Load4(fetchAddress));
|
||||
input.tex = asfloat(vertexBuffer_TEX.Load4(fetchAddress));
|
||||
input.pre = asfloat(vertexBuffer_PRE.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
input.instancePrev = instanceBuffer_Prev[instanceID];
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_NOR, float4, VBSLOT_1);
|
||||
TYPEDBUFFER(vertexBuffer_TEX, float4, VBSLOT_2);
|
||||
TYPEDBUFFER(vertexBuffer_PRE, float4, VBSLOT_3);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_NOR, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_TEX, VBSLOT_2);
|
||||
RAWBUFFER(vertexBuffer_PRE, VBSLOT_3);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_4);
|
||||
STRUCTUREDBUFFER(instanceBuffer_Prev, Input_InstancePrev, VBSLOT_5);
|
||||
|
||||
@@ -24,11 +24,12 @@ struct HullInputType
|
||||
HullInputType main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Object_ALL input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.nor = vertexBuffer_NOR[vID];
|
||||
input.tex = vertexBuffer_TEX[vID];
|
||||
input.pre = vertexBuffer_PRE[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.nor = asfloat(vertexBuffer_NOR.Load4(fetchAddress));
|
||||
input.tex = asfloat(vertexBuffer_TEX.Load4(fetchAddress));
|
||||
input.pre = asfloat(vertexBuffer_PRE.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
input.instancePrev = instanceBuffer_Prev[instanceID];
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "globals.hlsli"
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
|
||||
float4 main( uint vID : SV_VERTEXID ) : SV_POSITION
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
float4 pos = vertexBuffer_POS[vID];
|
||||
const uint fetchAddress = vID * 16;
|
||||
float4 pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
|
||||
return mul(float4(pos.xyz, 1), g_xTransform);
|
||||
}
|
||||
@@ -2,14 +2,15 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_1);
|
||||
|
||||
float4 main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID) : SV_POSITION
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Object_POS input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
|
||||
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_TEX, float4, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_TEX, VBSLOT_1);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_2);
|
||||
|
||||
PixelInputType_Simple main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Object_POS_TEX input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.tex = vertexBuffer_TEX[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.tex = asfloat(vertexBuffer_TEX.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_NOR, float4, VBSLOT_1);
|
||||
TYPEDBUFFER(vertexBuffer_TEX, float4, VBSLOT_2);
|
||||
TYPEDBUFFER(vertexBuffer_PRE, float4, VBSLOT_3);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_NOR, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_TEX, VBSLOT_2);
|
||||
RAWBUFFER(vertexBuffer_PRE, VBSLOT_3);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_4);
|
||||
STRUCTUREDBUFFER(instanceBuffer_Prev, Input_InstancePrev, VBSLOT_5);
|
||||
|
||||
@@ -24,11 +24,12 @@ struct HullInputType
|
||||
HullInputType main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Object_ALL input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.nor = vertexBuffer_NOR[vID];
|
||||
input.tex = vertexBuffer_TEX[vID];
|
||||
input.pre = vertexBuffer_PRE[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.nor = asfloat(vertexBuffer_NOR.Load4(fetchAddress));
|
||||
input.tex = asfloat(vertexBuffer_TEX.Load4(fetchAddress));
|
||||
input.pre = asfloat(vertexBuffer_PRE.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
input.instancePrev = instanceBuffer_Prev[instanceID];
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_NOR, float4, VBSLOT_1);
|
||||
TYPEDBUFFER(vertexBuffer_TEX, float4, VBSLOT_2);
|
||||
TYPEDBUFFER(vertexBuffer_PRE, float4, VBSLOT_3);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_NOR, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_TEX, VBSLOT_2);
|
||||
RAWBUFFER(vertexBuffer_PRE, VBSLOT_3);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_4);
|
||||
STRUCTUREDBUFFER(instanceBuffer_Prev, Input_InstancePrev, VBSLOT_5);
|
||||
|
||||
@@ -20,11 +20,12 @@ struct VSOut
|
||||
VSOut main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Object_ALL input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.nor = vertexBuffer_NOR[vID];
|
||||
input.tex = vertexBuffer_TEX[vID];
|
||||
input.pre = vertexBuffer_PRE[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.nor = asfloat(vertexBuffer_NOR.Load4(fetchAddress));
|
||||
input.tex = asfloat(vertexBuffer_TEX.Load4(fetchAddress));
|
||||
input.pre = asfloat(vertexBuffer_PRE.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
input.instancePrev = instanceBuffer_Prev[instanceID];
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_1);
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ struct VertexOut
|
||||
VertexOut main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Shadow_POS input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
|
||||
// Vertex layout declaration:
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_TEX, float4, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_TEX, VBSLOT_1);
|
||||
STRUCTUREDBUFFER(instanceBuffer, Input_Instance, VBSLOT_2);
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ struct VertexOut
|
||||
VertexOut main(uint vID : SV_VERTEXID, uint instanceID : SV_INSTANCEID)
|
||||
{
|
||||
// Custom fetch vertex buffer:
|
||||
const uint fetchAddress = vID * 16;
|
||||
Input_Object_ALL input;
|
||||
input.pos = vertexBuffer_POS[vID];
|
||||
input.tex = vertexBuffer_TEX[vID];
|
||||
input.pos = asfloat(vertexBuffer_POS.Load4(fetchAddress));
|
||||
input.tex = asfloat(vertexBuffer_TEX.Load4(fetchAddress));
|
||||
input.instance = instanceBuffer[instanceID];
|
||||
|
||||
|
||||
|
||||
@@ -1,29 +1,39 @@
|
||||
#include "globals.hlsli"
|
||||
#include "skinningHF.hlsli"
|
||||
|
||||
TYPEDBUFFER(vertexBuffer_POS, float4, VBSLOT_0);
|
||||
TYPEDBUFFER(vertexBuffer_NOR, float4, VBSLOT_1);
|
||||
TYPEDBUFFER(vertexBuffer_WEI, float4, VBSLOT_2);
|
||||
TYPEDBUFFER(vertexBuffer_BON, float4, VBSLOT_3);
|
||||
RAWBUFFER(vertexBuffer_POS, VBSLOT_0);
|
||||
RAWBUFFER(vertexBuffer_NOR, VBSLOT_1);
|
||||
RAWBUFFER(vertexBuffer_WEI, VBSLOT_2);
|
||||
RAWBUFFER(vertexBuffer_BON, VBSLOT_3);
|
||||
|
||||
RWTYPEDBUFFER(streamoutBuffer_POS, float4, 0);
|
||||
RWTYPEDBUFFER(streamoutBuffer_NOR, float4, 1);
|
||||
RWTYPEDBUFFER(streamoutBuffer_PRE, float4, 2);
|
||||
RWRAWBUFFER(streamoutBuffer_POS, 0);
|
||||
RWRAWBUFFER(streamoutBuffer_NOR, 1);
|
||||
RWRAWBUFFER(streamoutBuffer_PRE, 2);
|
||||
|
||||
[numthreads(SKINNING_COMPUTE_THREADCOUNT, 1, 1)]
|
||||
void main( uint3 DTid : SV_DispatchThreadID )
|
||||
{
|
||||
const uint vertexID = DTid.x;
|
||||
const uint fetchAddress = DTid.x * 16;
|
||||
|
||||
float4 pos = vertexBuffer_POS[vertexID];
|
||||
uint4 pos_u = vertexBuffer_POS.Load4(fetchAddress);
|
||||
uint4 nor_u = vertexBuffer_NOR.Load4(fetchAddress);
|
||||
uint4 wei_u = vertexBuffer_WEI.Load4(fetchAddress);
|
||||
uint4 bon_u = vertexBuffer_BON.Load4(fetchAddress);
|
||||
uint4 pre_u;
|
||||
|
||||
float4 pos = asfloat(pos_u);
|
||||
float4 nor = asfloat(nor_u);
|
||||
float4 wei = asfloat(wei_u);
|
||||
float4 bon = asfloat(bon_u);
|
||||
float4 pre = pos;
|
||||
float4 nor = vertexBuffer_NOR[vertexID];
|
||||
float4 wei = vertexBuffer_WEI[vertexID];
|
||||
float4 bon = vertexBuffer_BON[vertexID];
|
||||
|
||||
Skinning(pos, pre, nor, bon, wei);
|
||||
|
||||
streamoutBuffer_POS[vertexID] = pos;
|
||||
streamoutBuffer_NOR[vertexID] = nor;
|
||||
streamoutBuffer_PRE[vertexID] = pre;
|
||||
pos_u = asuint(pos);
|
||||
nor_u = asuint(nor);
|
||||
pre_u = asuint(pre);
|
||||
|
||||
streamoutBuffer_POS.Store4(fetchAddress, pos_u);
|
||||
streamoutBuffer_NOR.Store4(fetchAddress, nor_u);
|
||||
streamoutBuffer_PRE.Store4(fetchAddress, pre_u);
|
||||
}
|
||||
@@ -2024,8 +2024,7 @@ void Mesh::CreateBuffers(Object* object)
|
||||
bd.CPUAccessFlags = (softBody ? CPU_ACCESS_WRITE : 0);
|
||||
bd.ByteWidth = (UINT)(sizeof(XMFLOAT4) * vertices[vprop].size());
|
||||
bd.BindFlags = BIND_SHADER_RESOURCE;
|
||||
bd.StructureByteStride = sizeof(XMFLOAT4);
|
||||
bd.Format = FORMAT_R32G32B32A32_FLOAT;
|
||||
bd.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
|
||||
ZeroMemory(&InitData, sizeof(InitData));
|
||||
InitData.pSysMem = vertices[vprop].data();
|
||||
wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffers[vprop]);
|
||||
@@ -2036,8 +2035,7 @@ void Mesh::CreateBuffers(Object* object)
|
||||
bd.ByteWidth = (UINT)(sizeof(XMFLOAT4) * vertices[vprop].size());
|
||||
bd.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS;
|
||||
bd.CPUAccessFlags = 0;
|
||||
bd.StructureByteStride = sizeof(XMFLOAT4);
|
||||
bd.Format = FORMAT_R32G32B32A32_FLOAT;
|
||||
bd.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
|
||||
wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffers[vprop]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user