2012-06-09 20:40:48 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-06-09 20:40:48 +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-06-09 20:40:48 +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-06-09 20:40:48 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-06-09 20:40:48 +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-06-09 20:40:48 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2012-06-09 20:40:48 +00:00
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
|
|
|
|
layout(local_size_x=WORK_GROUP_SIZE, local_size_y=1, local_size_z=1) in;
|
2015-09-21 15:58:28 +00:00
|
|
|
layout(std430) buffer;
|
2015-05-28 00:23:36 +00:00
|
|
|
|
|
|
|
// source and destination buffers
|
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
uniform int srcOffset = 0;
|
|
|
|
uniform int dstOffset = 0;
|
2015-05-19 17:16:56 +00:00
|
|
|
layout(binding=0) buffer src_buffer { float srcVertexBuffer[]; };
|
|
|
|
layout(binding=1) buffer dst_buffer { float dstVertexBuffer[]; };
|
2015-05-28 00:23:36 +00:00
|
|
|
|
|
|
|
// derivative buffers (if needed)
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_1ST_DERIVATIVES)
|
2015-05-28 00:23:36 +00:00
|
|
|
uniform ivec3 duDesc;
|
|
|
|
uniform ivec3 dvDesc;
|
|
|
|
layout(binding=2) buffer du_buffer { float duBuffer[]; };
|
|
|
|
layout(binding=3) buffer dv_buffer { float dvBuffer[]; };
|
|
|
|
#endif
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_2ND_DERIVATIVES)
|
|
|
|
uniform ivec3 duuDesc;
|
|
|
|
uniform ivec3 duvDesc;
|
|
|
|
uniform ivec3 dvvDesc;
|
|
|
|
layout(binding=10) buffer duu_buffer { float duuBuffer[]; };
|
|
|
|
layout(binding=11) buffer duv_buffer { float duvBuffer[]; };
|
|
|
|
layout(binding=12) buffer dvv_buffer { float dvvBuffer[]; };
|
|
|
|
#endif
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
// stencil buffers
|
|
|
|
|
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_KERNEL_EVAL_STENCILS)
|
|
|
|
|
|
|
|
uniform int batchStart = 0;
|
|
|
|
uniform int batchEnd = 0;
|
|
|
|
layout(binding=4) buffer stencilSizes { int _sizes[]; };
|
|
|
|
layout(binding=5) buffer stencilOffsets { int _offsets[]; };
|
|
|
|
layout(binding=6) buffer stencilIndices { int _indices[]; };
|
|
|
|
layout(binding=7) buffer stencilWeights { float _weights[]; };
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_1ST_DERIVATIVES)
|
2015-05-28 00:23:36 +00:00
|
|
|
layout(binding=8) buffer stencilDuWeights { float _duWeights[]; };
|
|
|
|
layout(binding=9) buffer stencilDvWeights { float _dvWeights[]; };
|
|
|
|
#endif
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_2ND_DERIVATIVES)
|
|
|
|
layout(binding=13) buffer stencilDuuWeights { float _duuWeights[]; };
|
|
|
|
layout(binding=14) buffer stencilDuvWeights { float _duvWeights[]; };
|
|
|
|
layout(binding=15) buffer stencilDvvWeights { float _dvvWeights[]; };
|
|
|
|
#endif
|
|
|
|
|
2015-05-28 00:23:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// patch buffers
|
|
|
|
|
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_KERNEL_EVAL_PATCHES)
|
|
|
|
|
|
|
|
struct PatchCoord {
|
|
|
|
int arrayIndex;
|
|
|
|
int patchIndex;
|
|
|
|
int vertIndex;
|
|
|
|
float s;
|
|
|
|
float t;
|
|
|
|
};
|
|
|
|
struct PatchParam {
|
2015-06-11 20:18:25 +00:00
|
|
|
uint field0;
|
|
|
|
uint field1;
|
2015-05-28 00:23:36 +00:00
|
|
|
float sharpness;
|
|
|
|
};
|
|
|
|
uniform ivec4 patchArray[2];
|
|
|
|
layout(binding=4) buffer patchCoord_buffer { PatchCoord patchCoords[]; };
|
|
|
|
layout(binding=5) buffer patchIndex_buffer { int patchIndexBuffer[]; };
|
|
|
|
layout(binding=6) buffer patchParam_buffer { PatchParam patchParamBuffer[]; };
|
|
|
|
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2012-06-09 20:40:48 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
struct Vertex {
|
|
|
|
float vertexData[LENGTH];
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
2012-06-09 20:40:48 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void clear(out Vertex v) {
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
2012-12-11 01:15:13 +00:00
|
|
|
v.vertexData[i] = 0;
|
|
|
|
}
|
2012-06-09 20:40:48 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
Vertex readVertex(int index) {
|
2012-06-09 20:40:48 +00:00
|
|
|
Vertex v;
|
2015-05-07 23:11:00 +00:00
|
|
|
int vertexIndex = srcOffset + index * SRC_STRIDE;
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
2015-05-07 23:11:00 +00:00
|
|
|
v.vertexData[i] = srcVertexBuffer[vertexIndex + i];
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-06-09 20:40:48 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
void writeVertex(int index, Vertex v) {
|
2015-05-07 23:11:00 +00:00
|
|
|
int vertexIndex = dstOffset + index * DST_STRIDE;
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
2015-05-07 23:11:00 +00:00
|
|
|
dstVertexBuffer[vertexIndex + i] = v.vertexData[i];
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-06-09 20:40:48 +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-11 01:15:13 +00:00
|
|
|
v.vertexData[i] += weight * src.vertexData[i];
|
|
|
|
}
|
2012-06-09 20:40:48 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_1ST_DERIVATIVES)
|
2015-05-28 00:23:36 +00:00
|
|
|
void writeDu(int index, Vertex du) {
|
|
|
|
int duIndex = duDesc.x + index * duDesc.z;
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
|
|
|
duBuffer[duIndex + i] = du.vertexData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeDv(int index, Vertex dv) {
|
|
|
|
int dvIndex = dvDesc.x + index * dvDesc.z;
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
|
|
|
dvBuffer[dvIndex + i] = dv.vertexData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_2ND_DERIVATIVES)
|
|
|
|
void writeDuu(int index, Vertex duu) {
|
|
|
|
int duuIndex = duuDesc.x + index * duuDesc.z;
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
|
|
|
duuBuffer[duuIndex + i] = duu.vertexData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeDuv(int index, Vertex duv) {
|
|
|
|
int duvIndex = duvDesc.x + index * duvDesc.z;
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
|
|
|
duvBuffer[duvIndex + i] = duv.vertexData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeDvv(int index, Vertex dvv) {
|
|
|
|
int dvvIndex = dvvDesc.x + index * dvvDesc.z;
|
|
|
|
for (int i = 0; i < LENGTH; ++i) {
|
|
|
|
dvvBuffer[dvvIndex + i] = dvv.vertexData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_KERNEL_EVAL_STENCILS)
|
|
|
|
|
2015-04-10 22:34:04 +00:00
|
|
|
void main() {
|
2012-06-09 20:40:48 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int current = int(gl_GlobalInvocationID.x) + batchStart;
|
2012-06-09 20:40:48 +00:00
|
|
|
|
2015-01-13 01:02:54 +00:00
|
|
|
if (current>=batchEnd) {
|
2014-09-05 22:07:46 +00:00
|
|
|
return;
|
2012-06-09 20:40:48 +00:00
|
|
|
}
|
2014-06-10 23:31:44 +00:00
|
|
|
|
|
|
|
Vertex dst;
|
|
|
|
clear(dst);
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
int offset = _offsets[current],
|
2015-05-19 17:16:56 +00:00
|
|
|
size = _sizes[current];
|
2015-04-10 22:34:04 +00:00
|
|
|
|
2015-05-27 15:57:47 +00:00
|
|
|
for (int stencil = 0; stencil < size; ++stencil) {
|
|
|
|
int vindex = offset + stencil;
|
|
|
|
addWithWeight(
|
|
|
|
dst, readVertex(_indices[vindex]), _weights[vindex]);
|
2014-06-10 23:31:44 +00:00
|
|
|
}
|
2012-06-09 20:40:48 +00:00
|
|
|
|
2015-05-07 23:11:00 +00:00
|
|
|
writeVertex(current, dst);
|
2015-05-28 00:23:36 +00:00
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_1ST_DERIVATIVES)
|
2015-05-28 00:23:36 +00:00
|
|
|
Vertex du, dv;
|
|
|
|
clear(du);
|
|
|
|
clear(dv);
|
|
|
|
for (int i=0; i<size; ++i) {
|
|
|
|
// expects the compiler optimizes readVertex out here.
|
|
|
|
Vertex src = readVertex(_indices[offset+i]);
|
|
|
|
addWithWeight(du, src, _duWeights[offset+i]);
|
|
|
|
addWithWeight(dv, src, _dvWeights[offset+i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (duDesc.y > 0) { // length
|
|
|
|
writeDu(current, du);
|
|
|
|
}
|
|
|
|
if (dvDesc.y > 0) {
|
|
|
|
writeDv(current, dv);
|
|
|
|
}
|
|
|
|
#endif
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_2ND_DERIVATIVES)
|
|
|
|
Vertex duu, duv, dvv;
|
|
|
|
clear(duu);
|
|
|
|
clear(duv);
|
|
|
|
clear(dvv);
|
|
|
|
for (int i=0; i<size; ++i) {
|
|
|
|
// expects the compiler optimizes readVertex out here.
|
|
|
|
Vertex src = readVertex(_indices[offset+i]);
|
|
|
|
addWithWeight(duu, src, _duuWeights[offset+i]);
|
|
|
|
addWithWeight(duv, src, _duvWeights[offset+i]);
|
|
|
|
addWithWeight(dvv, src, _dvvWeights[offset+i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (duuDesc.y > 0) { // length
|
|
|
|
writeDuu(current, duu);
|
|
|
|
}
|
|
|
|
if (duvDesc.y > 0) {
|
|
|
|
writeDuv(current, duv);
|
|
|
|
}
|
|
|
|
if (dvvDesc.y > 0) {
|
|
|
|
writeDvv(current, dvv);
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_KERNEL_EVAL_PATCHES)
|
|
|
|
|
|
|
|
// PERFORMANCE: stride could be constant, but not as significant as length
|
|
|
|
|
|
|
|
//struct PatchArray {
|
|
|
|
// int patchType;
|
|
|
|
// int numPatches;
|
|
|
|
// int indexBase; // an offset within the index buffer
|
|
|
|
// int primitiveIdBase; // an offset within the patch param buffer
|
|
|
|
//};
|
|
|
|
// # of patcharrays is 1 or 2.
|
|
|
|
|
|
|
|
uint getDepth(uint patchBits) {
|
2015-06-11 20:18:25 +00:00
|
|
|
return (patchBits & 0xf);
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float getParamFraction(uint patchBits) {
|
2015-06-11 20:18:25 +00:00
|
|
|
uint nonQuadRoot = (patchBits >> 4) & 0x1;
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
uint depth = getDepth(patchBits);
|
|
|
|
if (nonQuadRoot == 1) {
|
|
|
|
return 1.0f / float( 1 << (depth-1) );
|
|
|
|
} else {
|
|
|
|
return 1.0f / float( 1 << depth );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vec2 normalizePatchCoord(uint patchBits, vec2 uv) {
|
|
|
|
float frac = getParamFraction(patchBits);
|
|
|
|
|
|
|
|
uint iu = (patchBits >> 22) & 0x3ff;
|
|
|
|
uint iv = (patchBits >> 12) & 0x3ff;
|
|
|
|
|
|
|
|
// top left corner
|
|
|
|
float pu = float(iu*frac);
|
|
|
|
float pv = float(iv*frac);
|
|
|
|
|
|
|
|
// normalize u,v coordinates
|
|
|
|
return vec2((uv.x - pu) / frac, (uv.y - pv) / frac);
|
|
|
|
}
|
|
|
|
|
2016-09-29 16:56:15 +00:00
|
|
|
bool isRegular(uint patchBits) {
|
|
|
|
return (((patchBits >> 5) & 0x1u) != 0);
|
|
|
|
}
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
|
2016-09-29 16:56:15 +00:00
|
|
|
int getNumControlVertices(int patchType) {
|
|
|
|
return (patchType == 3) ? 4 :
|
|
|
|
(patchType == 6) ? 16 :
|
|
|
|
(patchType == 9) ? 20 : 0;
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
|
|
|
int current = int(gl_GlobalInvocationID.x);
|
|
|
|
|
|
|
|
PatchCoord coord = patchCoords[current];
|
|
|
|
int patchIndex = coord.patchIndex;
|
|
|
|
|
|
|
|
ivec4 array = patchArray[coord.arrayIndex];
|
|
|
|
|
2015-06-11 20:18:25 +00:00
|
|
|
uint patchBits = patchParamBuffer[patchIndex].field1;
|
2016-09-29 16:56:15 +00:00
|
|
|
int patchType = isRegular(patchBits) ? 6 : array.x;
|
|
|
|
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
vec2 uv = normalizePatchCoord(patchBits, vec2(coord.s, coord.t));
|
|
|
|
float dScale = float(1 << getDepth(patchBits));
|
2016-09-29 16:56:15 +00:00
|
|
|
int boundary = int((patchBits >> 8) & 0xfU);
|
|
|
|
|
|
|
|
float wP[20], wDs[20], wDt[20], wDss[20], wDst[20], wDtt[20];
|
|
|
|
|
|
|
|
int numControlVertices = 0;
|
|
|
|
if (patchType == 3) {
|
|
|
|
float wP4[4], wDs4[4], wDt4[4], wDss4[4], wDst4[4], wDtt4[4];
|
|
|
|
OsdGetBilinearPatchWeights(uv.s, uv.t, dScale, wP4, wDs4, wDt4, wDss4, wDst4, wDtt4);
|
|
|
|
numControlVertices = 4;
|
|
|
|
for (int i=0; i<numControlVertices; ++i) {
|
|
|
|
wP[i] = wP4[i];
|
|
|
|
wDs[i] = wDs4[i];
|
|
|
|
wDt[i] = wDt4[i];
|
2017-01-26 22:36:30 +00:00
|
|
|
wDss[i] = wDss4[i];
|
|
|
|
wDst[i] = wDst4[i];
|
|
|
|
wDtt[i] = wDtt4[i];
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
}
|
2016-09-29 16:56:15 +00:00
|
|
|
} else if (patchType == 6) {
|
|
|
|
float wP16[16], wDs16[16], wDt16[16], wDss16[16], wDst16[16], wDtt16[16];
|
|
|
|
OsdGetBSplinePatchWeights(uv.s, uv.t, dScale, boundary, wP16, wDs16, wDt16, wDss16, wDst16, wDtt16);
|
|
|
|
numControlVertices = 16;
|
|
|
|
for (int i=0; i<numControlVertices; ++i) {
|
|
|
|
wP[i] = wP16[i];
|
|
|
|
wDs[i] = wDs16[i];
|
|
|
|
wDt[i] = wDt16[i];
|
2017-01-26 22:36:30 +00:00
|
|
|
wDss[i] = wDss16[i];
|
|
|
|
wDst[i] = wDst16[i];
|
|
|
|
wDtt[i] = wDtt16[i];
|
2016-09-29 16:56:15 +00:00
|
|
|
}
|
|
|
|
} else if (patchType == 9) {
|
|
|
|
OsdGetGregoryPatchWeights(uv.s, uv.t, dScale, wP, wDs, wDt, wDss, wDst, wDtt);
|
|
|
|
numControlVertices = 20;
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
Vertex dst, du, dv, duu, duv, dvv;
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
clear(dst);
|
2015-05-28 00:23:36 +00:00
|
|
|
clear(du);
|
|
|
|
clear(dv);
|
2017-01-26 22:36:30 +00:00
|
|
|
clear(duu);
|
|
|
|
clear(duv);
|
|
|
|
clear(dvv);
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
|
2016-09-29 16:56:15 +00:00
|
|
|
int indexStride = getNumControlVertices(array.x);
|
|
|
|
int indexBase = array.z + indexStride * (patchIndex - array.w);
|
|
|
|
|
2015-05-27 15:57:47 +00:00
|
|
|
for (int cv = 0; cv < numControlVertices; ++cv) {
|
|
|
|
int index = patchIndexBuffer[indexBase + cv];
|
|
|
|
addWithWeight(dst, readVertex(index), wP[cv]);
|
2015-05-28 00:23:36 +00:00
|
|
|
addWithWeight(du, readVertex(index), wDs[cv]);
|
|
|
|
addWithWeight(dv, readVertex(index), wDt[cv]);
|
2017-01-26 22:36:30 +00:00
|
|
|
addWithWeight(duu, readVertex(index), wDss[cv]);
|
|
|
|
addWithWeight(duv, readVertex(index), wDst[cv]);
|
|
|
|
addWithWeight(dvv, readVertex(index), wDtt[cv]);
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
}
|
|
|
|
writeVertex(current, dst);
|
|
|
|
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_1ST_DERIVATIVES)
|
2015-05-28 00:23:36 +00:00
|
|
|
if (duDesc.y > 0) { // length
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
writeDu(current, du);
|
|
|
|
}
|
2015-05-28 00:23:36 +00:00
|
|
|
if (dvDesc.y > 0) {
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
writeDv(current, dv);
|
|
|
|
}
|
2015-05-28 00:23:36 +00:00
|
|
|
#endif
|
2017-01-26 22:36:30 +00:00
|
|
|
#if defined(OPENSUBDIV_GLSL_COMPUTE_USE_2ND_DERIVATIVES)
|
|
|
|
if (duuDesc.y > 0) { // length
|
|
|
|
writeDuu(current, duu);
|
|
|
|
}
|
|
|
|
if (duvDesc.y > 0) { // length
|
|
|
|
writeDuv(current, duv);
|
|
|
|
}
|
|
|
|
if (dvvDesc.y > 0) {
|
|
|
|
writeDvv(current, dvv);
|
|
|
|
}
|
|
|
|
#endif
|
Osd API refactor: EvalStencils and EvalPatches
Add EvalStencils and EvalPatches API for most of CPU and GPU evaluators.
with this change, Eval API in the osd layer consists of following parts:
- Evaluators (Cpu, Omp, Tbb, Cuda, CL, GLXFB, GLCompute, D3D11Compute)
implements EvalStencils and EvalPatches(*). Both supports derivatives
(not fully implemented though)
- Interop vertex buffer classes (optional, same as before)
Note that these classes are not necessary to use Evaluators.
All evaluators have EvalStencils/Patches which take device-specific
buffer objects. For example, GLXFBEvaluator can take GLuint directly
for both stencil tables and input primvars. Although using these
interop classes makes it easy to integrate osd into relatively
simple applications.
- device-dependent StencilTable and PatchTable (optional)
These are also optional, but can be used simply a substitute of
Far::StencilTable and Far::PatchTable for osd evaluators.
- PatchArray, PatchCoord, PatchParam
They are tiny structs used for GPU based patch evaluation.
(*) TODO and known issues:
- CLEvaluator and D3D11Evaluator's EvalPatches() have not been implemented.
- GPU Gregory patch evaluation has not been implemented in EvalPatches().
- CudaEvaluator::EvalPatches() is very unstable.
- All patch evaluation kernels have not been well optimized.
- Currently GLXFB kernel doesn't support derivative evaluation.
There's a technical difficulty for the multi-stream output.
2015-05-26 04:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|