Skip to content

Commit aba2731

Browse files
authored
Allow render-test to run inline ray tracing tests. (shader-slang#1903)
* Update VS projects to 2019. * Empty commit to trigger build * Implement gfx inline ray tracing on D3D12. * Allow render-test to run inline ray tracing tests. Co-authored-by: Yong He <yhe@nvidia.com>
1 parent 0995067 commit aba2731

9 files changed

+333
-6
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -use-dxil -profile sm_6_5 -render-feature ray-tracing
2+
//TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-tracing
3+
4+
//TEST_INPUT: set scene = AccelerationStructure
5+
uniform RaytracingAccelerationStructure scene;
6+
7+
//TEST_INPUT:set outputBuffer = out ubuffer(data=[0], stride=4)
8+
RWStructuredBuffer<float> outputBuffer;
9+
10+
bool traceRayClosestHit(
11+
float3 rayOrigin,
12+
float3 rayDir,
13+
out float t)
14+
{
15+
RayDesc ray;
16+
ray.Origin = rayOrigin;
17+
ray.TMin = 0.01f;
18+
ray.Direction = rayDir;
19+
ray.TMax = 1e4f;
20+
RayQuery<RAY_FLAG_NONE> q;
21+
let rayFlags = RAY_FLAG_NONE;
22+
23+
q.TraceRayInline(
24+
scene,
25+
rayFlags,
26+
0xff,
27+
ray);
28+
29+
q.Proceed();
30+
if(q.CommittedStatus() == COMMITTED_TRIANGLE_HIT)
31+
{
32+
t = q.CommittedRayT();
33+
//primitiveIndex = q.CommittedPrimitiveIndex();
34+
return true;
35+
}
36+
return false;
37+
}
38+
39+
[shader("compute")]
40+
[numthreads(1,1,1)]
41+
void computeMain(
42+
uint3 threadIdx : SV_DispatchThreadID)
43+
{
44+
float t = 0.0;
45+
traceRayClosestHit(float3(0.1, 0.1, 0.0), float3(0,0,1), t);
46+
outputBuffer[threadIdx.x] = t;
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type: float
2+
0.5

tools/gfx/d3d12/render-d3d12.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -4316,6 +4316,22 @@ Result D3D12Device::initialize(const Desc& desc)
43164316
auto minPrecisionSupport = options.MinPrecisionSupport;
43174317
}
43184318
}
4319+
// Check ray tracing support
4320+
{
4321+
D3D12_FEATURE_DATA_D3D12_OPTIONS5 options;
4322+
if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
4323+
D3D12_FEATURE_D3D12_OPTIONS5, &options, sizeof(options))))
4324+
{
4325+
if (options.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED)
4326+
{
4327+
m_features.add("ray-tracing");
4328+
}
4329+
if (options.RaytracingTier >= D3D12_RAYTRACING_TIER_1_1)
4330+
{
4331+
m_features.add("ray-query");
4332+
}
4333+
}
4334+
}
43194335
}
43204336

43214337
m_desc = desc;

tools/gfx/debug-layer.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void validateAccelerationStructureBuildInputs(
228228
default:
229229
GFX_DIAGNOSE_ERROR(
230230
"Unsupported IAccelerationStructure::TriangleDesc::indexFormat. Valid "
231-
"values are R_UInt32 or R_UInt16.");
231+
"values are Unknown, R_UInt32 or R_UInt16.");
232232
}
233233
if (!buildInputs.geometryDescs[i].content.triangles.indexData)
234234
{
@@ -237,6 +237,39 @@ void validateAccelerationStructureBuildInputs(
237237
"IAccelerationStructure::TriangleDesc::indexCount is not 0");
238238
}
239239
}
240+
if (buildInputs.geometryDescs[i].content.triangles.indexFormat != Format::Unknown)
241+
{
242+
if (buildInputs.geometryDescs[i].content.triangles.indexCount == 0)
243+
{
244+
GFX_DIAGNOSE_ERROR(
245+
"IAccelerationStructure::TriangleDesc::indexCount cannot be 0 if "
246+
"IAccelerationStructure::TriangleDesc::indexFormat is not Format::Unknown");
247+
}
248+
if (buildInputs.geometryDescs[i].content.triangles.indexData == 0)
249+
{
250+
GFX_DIAGNOSE_ERROR(
251+
"IAccelerationStructure::TriangleDesc::indexData cannot be null if "
252+
"IAccelerationStructure::TriangleDesc::indexFormat is not "
253+
"Format::Unknown");
254+
}
255+
}
256+
else
257+
{
258+
if (buildInputs.geometryDescs[i].content.triangles.indexCount != 0)
259+
{
260+
GFX_DIAGNOSE_ERROR(
261+
"IAccelerationStructure::TriangleDesc::indexCount must be 0 if "
262+
"IAccelerationStructure::TriangleDesc::indexFormat is "
263+
"Format::Unknown");
264+
}
265+
if (buildInputs.geometryDescs[i].content.triangles.indexData != 0)
266+
{
267+
GFX_DIAGNOSE_ERROR(
268+
"IAccelerationStructure::TriangleDesc::indexData must be null if "
269+
"IAccelerationStructure::TriangleDesc::indexFormat is "
270+
"Format::Unknown");
271+
}
272+
}
240273
if (!buildInputs.geometryDescs[i].content.triangles.vertexData)
241274
{
242275
GFX_DIAGNOSE_ERROR(

tools/gfx/vulkan/render-vk.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5552,6 +5552,7 @@ Result VKDevice::initVulkanInstanceAndDevice(bool useValidationLayer)
55525552
deviceCreateInfo.pNext = &rayQueryFeatures;
55535553
deviceExtensions.add(VK_KHR_RAY_QUERY_EXTENSION_NAME);
55545554
m_features.add("ray-query");
5555+
m_features.add("ray-tracing");
55555556
}
55565557

55575558
if (bufferDeviceAddressFeatures.bufferDeviceAddress)

tools/gfx/vulkan/vk-util.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ Result AccelerationStructureBuildGeometryInfoBuilder::build(
262262
case Format::R_UInt16:
263263
vkGeomData.triangles.indexType = VK_INDEX_TYPE_UINT16;
264264
break;
265+
case Format::Unknown:
266+
vkGeomData.triangles.indexType = VK_INDEX_TYPE_NONE_KHR;
267+
break;
265268
default:
266269
debugCallback->handleMessage(
267270
DebugMessageType::Error,

0 commit comments

Comments
 (0)