-
Notifications
You must be signed in to change notification settings - Fork 758
[SER] Basic execution tests #7379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
simoll
wants to merge
15
commits into
microsoft:staging-sm6.9
Choose a base branch
from
simoll:ser_exectest_patch
base: staging-sm6.9
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6cb6843
[SER] Basic execution tests
simoll 6bcb151
Add SetShaderTableIndex+LoadLocalRootConstant tests / host code for l…
simoll 144a083
Uppercased vars for coding standards / added CreateDXRDevice helper /…
simoll 5a31d33
Merge remote-tracking branch 'msft/staging-sm6.9' into ser_exectest_p…
simoll c2e2dee
Test all MaybeReorderThread variants (in wave-incoherent execution)
simoll 6ab79fe
DynamicHitObjectArrayTest
simoll d31a0ad
Cleanup / fixes and update expected values based on changed geometry
simoll 8f1c598
WaveIncoherentHitTest
simoll e1df92b
SERReorderCoherentTest
simoll c6fce45
Fixed SERShaderTableIndexTest (not relying on is/ah any longer)
simoll c3c399f
Turn ShaderTable::Init into a ctor with initializer list
simoll 15140b1
Fix GetAttributesTest: procedural not contained in AABB / use integer…
simoll 6e42757
Fix SERWaveIncoherentHitTest: Use ray_flags to be independent of aabb…
simoll 0aee7ff
nfc: formatting
simoll 03e013a
Merge remote-tracking branch 'msft/staging-sm6.9' into ser_exectest_p…
simoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
//===------------ DXRUtil.h - DXR Utility Functions ------------*- C++ -*-===// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// DXRUtil.h // | ||
// Copyright (C) Nvidia Corporation. All rights reserved. // | ||
// This file is distributed under the University of Illinois Open Source // | ||
// License. See LICENSE.TXT for details. // | ||
// // | ||
// This file contains the utility functions for DXR execution tests. // | ||
// // | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
//= DXR Utility | ||
//============================================================================ | ||
#define SHADER_ID_SIZE_IN_BYTES 32 | ||
|
||
#ifndef ROUND_UP | ||
#define ROUND_UP(v, PowerOf2Alignment) \ | ||
(((v) + (PowerOf2Alignment)-1) & ~((PowerOf2Alignment)-1)) | ||
#endif | ||
struct SceneConsts { | ||
DirectX::XMFLOAT4 Eye; | ||
DirectX::XMFLOAT4 U; | ||
DirectX::XMFLOAT4 V; | ||
DirectX::XMFLOAT4 W; | ||
float SceneScale; | ||
unsigned WindowSize[2]; | ||
int RayFlags; | ||
}; | ||
|
||
struct Instance { | ||
D3D12_RAYTRACING_GEOMETRY_TYPE Type; | ||
DirectX::XMFLOAT4X4 Matrix; | ||
UINT GeometryCount; | ||
UINT BottomASIdx; | ||
UINT InstanceID; | ||
UINT Mask; | ||
UINT Flags; | ||
}; | ||
|
||
class ShaderTable { | ||
public: | ||
ShaderTable(ID3D12Device *Device, int RaygenCount, int MissCount, | ||
int HitGroupCount, int RayTypeCount, int RootTableDwords) | ||
: RayTypeCount(RayTypeCount), RaygenCount(RaygenCount), | ||
MissCount(MissCount * RayTypeCount), | ||
HitGroupCount(HitGroupCount * RayTypeCount), | ||
RootTableSizeInBytes(RootTableDwords * 4), | ||
ShaderRecordSizeInBytes( | ||
ROUND_UP(RootTableSizeInBytes + SHADER_ID_SIZE_IN_BYTES, | ||
D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT)), | ||
MissStartIdx(RaygenCount), HitGroupStartIdx(MissStartIdx + MissCount) { | ||
|
||
const int TotalSizeInBytes = | ||
(RaygenCount + MissCount + HitGroupCount) * ShaderRecordSizeInBytes; | ||
|
||
D3D12_RESOURCE_DESC Desc = CD3DX12_RESOURCE_DESC::Buffer( | ||
TotalSizeInBytes, D3D12_RESOURCE_FLAG_NONE, | ||
std::max(D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT, | ||
D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT)); | ||
CD3DX12_HEAP_PROPERTIES Heap = | ||
CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT); | ||
VERIFY_SUCCEEDED(Device->CreateCommittedResource( | ||
&Heap, D3D12_HEAP_FLAG_NONE, &Desc, | ||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, nullptr, | ||
IID_PPV_ARGS(&SBTResource))); | ||
SBTResource->SetName(L"SBT Resource Heap"); | ||
CD3DX12_HEAP_PROPERTIES Upload = | ||
CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD); | ||
VERIFY_SUCCEEDED(Device->CreateCommittedResource( | ||
&Upload, D3D12_HEAP_FLAG_NONE, &Desc, D3D12_RESOURCE_STATE_GENERIC_READ, | ||
nullptr, IID_PPV_ARGS(&SBTUploadResource))); | ||
SBTUploadResource->SetName(L"SBT Upload Heap"); | ||
|
||
VERIFY_SUCCEEDED(SBTUploadResource->Map(0, nullptr, (void **)&HostPtr)); | ||
} | ||
|
||
void Upload(ID3D12GraphicsCommandList *CmdList) { | ||
CD3DX12_RESOURCE_BARRIER Barrier = CD3DX12_RESOURCE_BARRIER::Transition( | ||
SBTResource, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, | ||
D3D12_RESOURCE_STATE_COPY_DEST); | ||
CmdList->ResourceBarrier(1, &Barrier); | ||
CmdList->CopyResource(SBTResource, SBTUploadResource); | ||
CD3DX12_RESOURCE_BARRIER Barrier2 = CD3DX12_RESOURCE_BARRIER::Transition( | ||
SBTResource, D3D12_RESOURCE_STATE_COPY_DEST, | ||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); | ||
CmdList->ResourceBarrier(1, &Barrier2); | ||
} | ||
|
||
int GetShaderRecordSizeInBytes() { return ShaderRecordSizeInBytes; } | ||
|
||
int GetRaygenShaderRecordIdx(int Idx) { return Idx; } | ||
int GetMissShaderRecordIdx(int Idx, int RayType) { | ||
return MissStartIdx + Idx * RayTypeCount + RayType; | ||
} | ||
int GetHitGroupShaderRecordIdx(int Idx, int RayType) { | ||
return HitGroupStartIdx + Idx * RayTypeCount + RayType; | ||
} | ||
|
||
void *GetRaygenShaderIdPtr(int Idx) { | ||
return HostPtr + GetRaygenShaderRecordIdx(Idx) * ShaderRecordSizeInBytes; | ||
} | ||
void *GetMissShaderIdPtr(int Idx, int RayType) { | ||
return HostPtr + | ||
GetMissShaderRecordIdx(Idx, RayType) * ShaderRecordSizeInBytes; | ||
} | ||
void *GetHitGroupShaderIdPtr(int Idx, int RayType) { | ||
return HostPtr + | ||
GetHitGroupShaderRecordIdx(Idx, RayType) * ShaderRecordSizeInBytes; | ||
} | ||
|
||
void *GetRaygenRootTablePtr(int Idx) { | ||
return (char *)GetRaygenShaderIdPtr(Idx) + SHADER_ID_SIZE_IN_BYTES; | ||
} | ||
void *GetMissRootTablePtr(int Idx, int RayType) { | ||
return (char *)GetMissShaderIdPtr(Idx, RayType) + SHADER_ID_SIZE_IN_BYTES; | ||
} | ||
void *GetHitGroupRootTablePtr(int Idx, int RayType) { | ||
return (char *)GetHitGroupShaderIdPtr(Idx, RayType) + | ||
SHADER_ID_SIZE_IN_BYTES; | ||
} | ||
|
||
int GetRaygenRangeInBytes() { return RaygenCount * ShaderRecordSizeInBytes; } | ||
int GetMissRangeInBytes() { return MissCount * ShaderRecordSizeInBytes; } | ||
int GetHitGroupRangeInBytes() { | ||
return HitGroupCount * ShaderRecordSizeInBytes; | ||
} | ||
|
||
D3D12_GPU_VIRTUAL_ADDRESS GetRaygenStartGpuVA() { | ||
return SBTResource->GetGPUVirtualAddress() + | ||
GetRaygenShaderRecordIdx(0) * ShaderRecordSizeInBytes; | ||
} | ||
D3D12_GPU_VIRTUAL_ADDRESS GetMissStartGpuVA() { | ||
return SBTResource->GetGPUVirtualAddress() + | ||
GetMissShaderRecordIdx(0, 0) * ShaderRecordSizeInBytes; | ||
} | ||
D3D12_GPU_VIRTUAL_ADDRESS GetHitGroupStartGpuVA() { | ||
return SBTResource->GetGPUVirtualAddress() + | ||
GetHitGroupShaderRecordIdx(0, 0) * ShaderRecordSizeInBytes; | ||
} | ||
|
||
private: | ||
CComPtr<ID3D12Resource> SBTResource; | ||
CComPtr<ID3D12Resource> SBTUploadResource; | ||
char *HostPtr = nullptr; | ||
int RayTypeCount = 0; | ||
int RaygenCount = 0; | ||
int MissCount = 0; | ||
int HitGroupCount = 0; | ||
int RootTableSizeInBytes = 0; | ||
int ShaderRecordSizeInBytes = 0; | ||
int MissStartIdx = 0; | ||
int HitGroupStartIdx = 0; | ||
}; | ||
|
||
//----------------------------------------------------------------------------- | ||
void AllocateBuffer( | ||
ID3D12Device *Device, UINT64 BufferSize, ID3D12Resource **Resource, | ||
bool AllowUAV = false, | ||
D3D12_RESOURCE_STATES InitialResourceState = D3D12_RESOURCE_STATE_COMMON, | ||
const wchar_t *ResourceName = nullptr) { | ||
auto UploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT); | ||
auto BufferDesc = CD3DX12_RESOURCE_DESC::Buffer( | ||
BufferSize, AllowUAV ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | ||
: D3D12_RESOURCE_FLAG_NONE); | ||
VERIFY_SUCCEEDED(Device->CreateCommittedResource( | ||
&UploadHeapProperties, D3D12_HEAP_FLAG_NONE, &BufferDesc, | ||
InitialResourceState, nullptr, IID_PPV_ARGS(Resource))); | ||
if (ResourceName) { | ||
(*Resource)->SetName(ResourceName); | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void ReallocScratchResource(ID3D12Device *Device, ID3D12Resource **Resource, | ||
UINT64 NBytes) { | ||
if (!(*Resource) || (*Resource)->GetDesc().Width < NBytes) { | ||
AllocateBuffer(Device, NBytes, Resource, true, | ||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, L"scratchResource"); | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void AllocateUploadBuffer(ID3D12Device *Device, const void *Data, | ||
UINT64 DataSize, ID3D12Resource **Resource, | ||
const wchar_t *ResourceName = nullptr) { | ||
auto UploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD); | ||
auto BufferDesc = CD3DX12_RESOURCE_DESC::Buffer(DataSize); | ||
VERIFY_SUCCEEDED(Device->CreateCommittedResource( | ||
&UploadHeapProperties, D3D12_HEAP_FLAG_NONE, &BufferDesc, | ||
D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(Resource))); | ||
if (ResourceName) { | ||
(*Resource)->SetName(ResourceName); | ||
} | ||
void *MappedData; | ||
VERIFY_SUCCEEDED((*Resource)->Map(0, nullptr, &MappedData)); | ||
memcpy(MappedData, Data, DataSize); | ||
(*Resource)->Unmap(0, nullptr); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void AllocateBufferFromUpload(ID3D12Device *Device, | ||
ID3D12GraphicsCommandList *CommandList, | ||
ID3D12Resource *UploadSource, | ||
ID3D12Resource **Resource, | ||
D3D12_RESOURCE_STATES TargetResourceState, | ||
const wchar_t *ResourceName = nullptr) { | ||
const bool AllowUAV = | ||
TargetResourceState == D3D12_RESOURCE_STATE_UNORDERED_ACCESS; | ||
AllocateBuffer(Device, UploadSource->GetDesc().Width, Resource, AllowUAV, | ||
D3D12_RESOURCE_STATE_COPY_DEST, ResourceName); | ||
CommandList->CopyResource(*Resource, UploadSource); | ||
CD3DX12_RESOURCE_BARRIER Barrier = CD3DX12_RESOURCE_BARRIER::Transition( | ||
*Resource, D3D12_RESOURCE_STATE_COPY_DEST, TargetResourceState); | ||
CommandList->ResourceBarrier(1, (const D3D12_RESOURCE_BARRIER *)&Barrier); | ||
} | ||
|
||
//= DXR Utility | ||
//============================================================================ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we getting max here? those are known values and the default is always going to be bigger.