Skip to content

Commit

Permalink
dxPtexViewer fixes:
Browse files Browse the repository at this point in the history
 - changed ptex layout data types in shaders to match srv format
 - changed ptex srv type to unorm format for uchar data
 - fixed hlsl compiler warning: initialized edgeDistance of OutputVertex struct in domain shader even if we are not in wireframe mode
 - added directx debug device and enabled automatic break points to easily spot dx errors
  • Loading branch information
hsdk committed Jan 9, 2015
1 parent 1de732e commit 7c73cf0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
33 changes: 32 additions & 1 deletion examples/dxPtexViewer/dxPtexViewer.cpp
Expand Up @@ -1417,8 +1417,12 @@ initD3D11(HWND hWnd) {
D3D_FEATURE_LEVEL hFeatureLevel = D3D_FEATURE_LEVEL_11_0;
for(UINT driverTypeIndex=0; driverTypeIndex < numDriverTypes; driverTypeIndex++){
hDriverType = driverTypes[driverTypeIndex];
unsigned int deviceFlags = 0;
#ifndef NDEBUG
deviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
hr = D3D11CreateDeviceAndSwapChain(NULL,
hDriverType, NULL, 0, NULL, 0,
hDriverType, NULL, deviceFlags, NULL, 0,
D3D11_SDK_VERSION, &hDXGISwapChainDesc,
&g_pSwapChain, &g_pd3dDevice,
&hFeatureLevel, &g_pd3dDeviceContext);
Expand All @@ -1432,6 +1436,33 @@ initD3D11(HWND hWnd) {
return false;
}

#ifndef NDEBUG
// set break points on directx errors
ID3D11Debug *d3dDebug = nullptr;
hr = g_pd3dDevice->QueryInterface(__uuidof(ID3D11Debug), (void**)&d3dDebug);
if (SUCCEEDED(hr)) {

ID3D11InfoQueue *d3dInfoQueue = nullptr;
hr = d3dDebug->QueryInterface(__uuidof(ID3D11InfoQueue), (void**)&d3dInfoQueue);
if (SUCCEEDED(hr)) {

d3dInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
d3dInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
d3dInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);

D3D11_MESSAGE_ID denied[] = { D3D11_MESSAGE_ID_SETPRIVATEDATA_CHANGINGPARAMS };
D3D11_INFO_QUEUE_FILTER filter;
memset(&filter, 0, sizeof(filter));
filter.DenyList.NumIDs = _countof(denied);
filter.DenyList.pIDList = denied;
d3dInfoQueue->AddStorageFilterEntries(&filter);

d3dInfoQueue->Release();
}
d3dDebug->Release();
}
#endif

// create rasterizer
D3D11_RASTERIZER_DESC rasterDesc;
ZeroMemory(&rasterDesc, sizeof(rasterDesc));
Expand Down
9 changes: 5 additions & 4 deletions examples/dxPtexViewer/shader.hlsl
Expand Up @@ -79,7 +79,7 @@ int OsdPrimitiveIdBase()
|| defined(NORMAL_BIQUADRATIC_WG)

Texture2DArray textureDisplace_Data : register(t6);
Buffer<int> textureDisplace_Packing : register(t7);
Buffer<uint> textureDisplace_Packing : register(t7);
#endif

#if defined(DISPLACEMENT_HW_BILINEAR) \
Expand Down Expand Up @@ -358,22 +358,23 @@ edgeColor(float4 Cfill, float4 edgeDistance)
// Pixel Shader
// ---------------------------------------------------------------------------


#if defined(COLOR_PTEX_NEAREST) || \
defined(COLOR_PTEX_HW_BILINEAR) || \
defined(COLOR_PTEX_BILINEAR) || \
defined(COLOR_PTEX_BIQUADRATIC)
Texture2DArray textureImage_Data : register(t4);
Buffer<int> textureImage_Packing : register(t5);
Buffer<uint> textureImage_Packing : register(t5);
#endif

#ifdef USE_PTEX_OCCLUSION
Texture2DArray textureOcclusion_Data : register(t8);
Buffer<int> textureOcclusion_Packing : register(t9);
Buffer<uint> textureOcclusion_Packing : register(t9);
#endif

#ifdef USE_PTEX_SPECULAR
Texture2DArray textureSpecular_Data : register(t10);
Buffer<int> textureSpecular_Packing : register(t11);
Buffer<uint> textureSpecular_Packing : register(t11);
#endif

void
Expand Down
6 changes: 3 additions & 3 deletions opensubdiv/osd/d3d11PtexMipmapTexture.cpp
Expand Up @@ -140,10 +140,10 @@ D3D11PtexMipmapTexture::Create(ID3D11DeviceContext *deviceContext,
break;
default:
switch (numChannels) {
case 1: format = DXGI_FORMAT_R8_UINT; break;
case 2: format = DXGI_FORMAT_R8G8_UINT; break;
case 1: format = DXGI_FORMAT_R8_UNORM; break;
case 2: format = DXGI_FORMAT_R8G8_UNORM; break;
case 3: assert(false); break;
case 4: format = DXGI_FORMAT_R8G8B8A8_UINT; break;
case 4: format = DXGI_FORMAT_R8G8B8A8_UNORM; break;
}
bpp = numChannels;
break;
Expand Down
2 changes: 1 addition & 1 deletion opensubdiv/osd/hlslPatchBSpline.hlsl
Expand Up @@ -332,7 +332,7 @@ void ds_main_patches(
OSD_COMPUTE_PTEX_COORD_DOMAIN_SHADER;

OSD_DISPLACEMENT_CALLBACK;

output.edgeDistance = 0;
output.positionOut = mul(OsdProjectionMatrix(),
float4(output.position.xyz, 1.0f));
}
2 changes: 1 addition & 1 deletion opensubdiv/osd/hlslPatchCommon.hlsl
Expand Up @@ -136,7 +136,7 @@ float TessAdaptive(float3 p0, float3 p1)
#define OSD_DISPLACEMENT_CALLBACK
#endif

Buffer<int2> OsdPatchParamBuffer : register( t3 );
Buffer<uint2> OsdPatchParamBuffer : register( t3 );

#define GetPatchLevel(primitiveID) \
(OsdPatchParamBuffer[GetPrimitiveID(primitiveID)].y & 0xf)
Expand Down
2 changes: 2 additions & 0 deletions opensubdiv/osd/hlslPatchGregory.hlsl
Expand Up @@ -637,6 +637,8 @@ void ds_main_patches(

output.patchCoord = patch[0].patchCoord;
output.patchCoord.xy = float2(v, u);

output.edgeDistance = 0;

OSD_COMPUTE_PTEX_COORD_DOMAIN_SHADER;

Expand Down
20 changes: 10 additions & 10 deletions opensubdiv/osd/hlslPtexCommon.hlsl
Expand Up @@ -36,7 +36,7 @@ struct PtexPacking {
int height;
};

PtexPacking getPtexPacking(Buffer<int> packings, int faceID)
PtexPacking getPtexPacking(Buffer<uint> packings, int faceID)
{
PtexPacking packing;
packing.page = packings[faceID*6+0].x;
Expand Down Expand Up @@ -72,7 +72,7 @@ int computeMipmapOffsetV(int h, int level)
return (m & x) + (level&~1);
}

PtexPacking getPtexPacking(Buffer<int> packings, int faceID, int level)
PtexPacking getPtexPacking(Buffer<uint> packings, int faceID, int level)
{
PtexPacking packing;
packing.page = packings[faceID*6+0].x;
Expand Down Expand Up @@ -112,7 +112,7 @@ void evalQuadraticBSpline(float u, out float B[3], out float BU[3])

float4 PtexLookupNearest(float4 patchCoord,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
float2 uv = patchCoord.xy;
int faceID = int(patchCoord.w);
Expand All @@ -125,7 +125,7 @@ float4 PtexLookupNearest(float4 patchCoord,
float4 PtexLookupNearest(float4 patchCoord,
int level,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
float2 uv = patchCoord.xy;
int faceID = int(patchCoord.w);
Expand All @@ -138,7 +138,7 @@ float4 PtexLookupNearest(float4 patchCoord,
float4 PtexLookup(float4 patchCoord,
int level,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
float2 uv = patchCoord.xy;
int faceID = int(patchCoord.w);
Expand Down Expand Up @@ -172,7 +172,7 @@ float4 PtexLookupQuadratic(out float4 du,
float4 patchCoord,
int level,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
float2 uv = patchCoord.xy;
int faceID = int(patchCoord.w);
Expand Down Expand Up @@ -238,7 +238,7 @@ float4 PtexLookupQuadratic(out float4 du,
float4 PtexMipmapLookupNearest(float4 patchCoord,
int level,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
#if defined(SEAMLESS_MIPMAP)
// diff level
Expand All @@ -262,7 +262,7 @@ float4 PtexMipmapLookupNearest(float4 patchCoord,
float4 PtexMipmapLookup(float4 patchCoord,
float level,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
#if defined(SEAMLESS_MIPMAP)
// diff level
Expand All @@ -288,7 +288,7 @@ float4 PtexMipmapLookupQuadratic(out float4 du,
float4 patchCoord,
float level,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
#if defined(SEAMLESS_MIPMAP)
// diff level
Expand Down Expand Up @@ -318,7 +318,7 @@ float4 PtexMipmapLookupQuadratic(out float4 du,
float4 PtexMipmapLookupQuadratic(float4 patchCoord,
float level,
Texture2DArray data,
Buffer<int> packings)
Buffer<uint> packings)
{
float4 du, dv;
return PtexMipmapLookupQuadratic(du, dv, patchCoord, level, data, packings);
Expand Down

0 comments on commit 7c73cf0

Please sign in to comment.