2012-12-13 18:22:30 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-12-13 18:22:30 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-12-13 18:22:30 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-12-13 18:22:30 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-12-13 18:22:30 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-12-13 18:22:30 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
interface IComputeKernel {
|
|
|
|
void runKernel( uint3 ID );
|
|
|
|
};
|
|
|
|
IComputeKernel kernel;
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
cbuffer KernelUniformArgs : register( b0 ) {
|
|
|
|
int batchStart,
|
|
|
|
batchEnd,
|
|
|
|
primvarOffset,
|
|
|
|
numCVs;
|
2012-12-13 18:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RWBuffer<float> vertexBuffer : register( u0 );
|
2014-09-05 22:07:46 +00:00
|
|
|
Buffer<int> sizes : register( t1 );
|
|
|
|
Buffer<int> offsets : register( t2 );
|
|
|
|
Buffer<int> indices : register( t3 );
|
|
|
|
Buffer<float> weights : register( t4 );
|
2012-12-13 18:22:30 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
struct Vertex {
|
|
|
|
float vertexData[LENGTH];
|
2012-12-13 18:22:30 +00:00
|
|
|
};
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void clear(out Vertex v) {
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
2012-12-13 18:22:30 +00:00
|
|
|
v.vertexData[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Vertex readVertex(int index) {
|
2012-12-13 18:22:30 +00:00
|
|
|
Vertex v;
|
2014-09-05 22:07:46 +00:00
|
|
|
int vertexIndex = primvarOffset + index * STRIDE;
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
2014-05-09 00:20:54 +00:00
|
|
|
v.vertexData[i] = vertexBuffer[vertexIndex + i];
|
2012-12-13 18:22:30 +00:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void writeVertex(int index, Vertex v) {
|
|
|
|
int vertexIndex = primvarOffset + index * STRIDE;
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
2014-05-09 00:20:54 +00:00
|
|
|
vertexBuffer[vertexIndex + i] = v.vertexData[i];
|
2012-12-13 18:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void addWithWeight(inout Vertex v, const Vertex src, float weight) {
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
2012-12-13 18:22:30 +00:00
|
|
|
v.vertexData[i] += weight * src.vertexData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
// Stencil compute Kernel
|
|
|
|
class ComputeStencil : IComputeKernel {
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int placeholder;
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void runKernel( uint3 ID ) {
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int current = int(ID.x) + batchStart;
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (current>batchEnd) {
|
|
|
|
return;
|
|
|
|
}
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Vertex dst;
|
2012-12-13 18:22:30 +00:00
|
|
|
clear(dst);
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int offset = offsets[current],
|
|
|
|
size = sizes[current];
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int i=0; i<size; ++i) {
|
|
|
|
addWithWeight(dst, readVertex( indices[offset+i] ), weights[offset+i]);
|
|
|
|
}
|
2014-06-10 23:31:44 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// the vertex buffer contains our control vertices at the beginning: don't
|
|
|
|
// stomp on those !
|
|
|
|
writeVertex(numCVs+current, dst);
|
2014-06-10 23:31:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// Add place-holder stencil kernel or D3D11ShaderReflection::GetInterfaceSlots()
|
|
|
|
// returns 0
|
|
|
|
class PlaceHolder : IComputeKernel {
|
|
|
|
int placeholder;
|
|
|
|
|
|
|
|
void runKernel( uint3 ID ) {
|
2012-12-13 18:22:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//--------------------------------------------------------------------------------
|
2012-12-13 18:22:30 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
ComputeStencil computeStencil;
|
2012-12-13 18:22:30 +00:00
|
|
|
|
|
|
|
[numthreads(WORK_GROUP_SIZE, 1, 1)]
|
|
|
|
void cs_main( uint3 ID : SV_DispatchThreadID )
|
|
|
|
{
|
|
|
|
// call kernel
|
|
|
|
kernel.runKernel(ID);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|