瀏覽代碼

implement basic rendering with raytracing in DX12GraphicsApi

Kolja Strohm 4 周之前
父節點
當前提交
ddd1706364
共有 8 個文件被更改,包括 304 次插入241 次删除
  1. 2 2
      Common.hlsl
  2. 164 133
      DX12GraphicsApi.cpp
  3. 14 6
      DX12GraphicsApi.h
  4. 107 86
      DX12Shader.cpp
  5. 12 7
      DX12Shader.h
  6. 2 5
      DX12Texture.cpp
  7. 0 2
      DX12Texture.h
  8. 3 0
      Framework.vcxproj

+ 2 - 2
Common.hlsl

@@ -4,9 +4,9 @@
 // and that its size must be declared in the corresponding
 // D3D12_RAYTRACING_SHADER_CONFIG pipeline subobjet.
 
-struct HitInfo
+struct [raypayload] HitInfo
 {
-    float4 colorAndDistance;
+    float4 colorAndDistance : write(caller, closesthit, miss) : read(caller);
 };
 
 // Attributes output by the raytracing when hitting a surface,

+ 164 - 133
DX12GraphicsApi.cpp

@@ -10,6 +10,9 @@
 #include "DLLRegister.h"
 #include "DX12BLASModel.h"
 #include "DX12CommandQueue.h"
+#include "DX12HitShader.h"
+#include "DX12MissShader.h"
+#include "DX12RayGenShader.h"
 #include "DX12Shader.h"
 #include "DX12Texture.h"
 #include "DX12TLAS.h"
@@ -31,18 +34,12 @@ DirectX12::DirectX12()
       device(0),
       infoQueue(0),
       directCommandQueue(0),
-      copyCommandQueue(0),
-      computeCommandQueue(0),
       swapChain(0),
       rtvHeap(0),
-      dsvHeap(0),
-      depthBuffer(0),
       backBufferIndex(0),
       tearing(0),
       viewPort(0),
       allowedRenderArea(0),
-      vertexBufferView(0),
-      indexBufferView(0),
       signature(0),
       uiTexture(0),
       texturRegister(new TextureList()),
@@ -51,7 +48,10 @@ DirectX12::DirectX12()
       worldShaderBindingTables(0),
       lastTLASId(-1),
       lastModelId(-1),
-      defaultRenderTarget(0)
+      defaultRenderTarget(0),
+      globalDescriptorHeap(0),
+      defaultHitGroup(0),
+      defaultRayGenerationShaderFunction(0)
 {
     for (int i = 0; i < 2; i++)
         backBuffer[i] = 0;
@@ -84,29 +84,23 @@ DirectX12::~DirectX12()
         }
         delete[] worldShaderBindingTables;
     }
-    if (directCommandQueue)
+    if (globalDescriptorHeap)
     {
-        directCommandQueue->flush();
-        directCommandQueue->release();
+        globalDescriptorHeap->release();
     }
-    if (copyCommandQueue)
+    if (pipeline)
     {
-        copyCommandQueue->flush();
-        copyCommandQueue->release();
+        pipeline->release();
     }
-    if (computeCommandQueue)
+    if (directCommandQueue)
     {
-        computeCommandQueue->flush();
-        computeCommandQueue->release();
+        directCommandQueue->flush();
+        directCommandQueue->release();
     }
-    if (depthBuffer) depthBuffer->Release();
-    if (dsvHeap) dsvHeap->Release();
     texturRegister->release();
     if (uiTexture) uiTexture->release();
     if (defaultRenderTarget) defaultRenderTarget->release();
     if (signature) signature->Release();
-    delete indexBufferView;
-    delete vertexBufferView;
     delete allowedRenderArea;
     delete viewPort;
     for (int i = 0; i < 2; i++)
@@ -155,6 +149,10 @@ void DirectX12::updateBottomLevelAccelerationStructure()
 void Framework::DirectX12::renderKamera(
     Cam3D* zKamera, DX12Texture* zTarget, bool guiVisible)
 {
+    if (!pipeline)
+    {
+        setPipeline(new DX12Pipeline());
+    }
     // TODO
     // directCommandQueue->getCommandList()->RSSetViewports(
     //     1, (D3D12_VIEWPORT*)zKamera->zViewPort());
@@ -197,36 +195,110 @@ void Framework::DirectX12::renderKamera(
     sbt->startUpdate();
     int objectIndex = 0;
     int instanceIndex = 0;
-    w->render(
-        [this, &tlas, &objectIndex, &instanceIndex, &identity](Model3D* obj) {
-            obj->calculateMatrices(identity, matrixBuffer);
-            int modelId = obj->zModelData()->getId();
-            DX12BLASModel* blasModel = blasModels[modelId];
-            ArrayIterator<int> boneIds = blasModel->zBoneIds()->begin();
-            for (const DX12BLAS* blas : *blasModel->zBLAS())
-            {
-                D3D12_RAYTRACING_INSTANCE_DESC* desc = tlas->nextInstanceDesc();
-                desc->InstanceID = objectIndex;
-                desc->InstanceContributionToHitGroupIndex = objectIndex;
-                desc->Flags = D3D12_RAYTRACING_INSTANCE_FLAG_NONE;
-                desc->InstanceMask = 0xFF;
-                desc->AccelerationStructure
-                    = blas->zResultBuffer()->zBuffer()->GetGPUVirtualAddress();
-                memcpy(desc->Transform,
-                    &matrixBuffer[boneIds.val()],
-                    sizeof(float) * 12);
-                // TODO: sbt->setHitGroupShaderInputs(instanceIndex, ...)
-                boneIds++;
-                instanceIndex++;
-            }
-            objectIndex++;
-        });
+    w->render([this, &tlas, &objectIndex, &instanceIndex, &identity, &sbt](
+                  Model3D* obj) {
+        obj->calculateMatrices(identity, matrixBuffer);
+        int modelId = obj->zModelData()->getId();
+        DX12BLASModel* blasModel = blasModels[modelId];
+        ArrayIterator<int> boneIds = blasModel->zBoneIds()->begin();
+        for (const DX12BLAS* blas : *blasModel->zBLAS())
+        {
+            D3D12_RAYTRACING_INSTANCE_DESC* desc = tlas->nextInstanceDesc();
+            desc->InstanceID = objectIndex;
+            desc->InstanceContributionToHitGroupIndex = objectIndex;
+            desc->Flags = D3D12_RAYTRACING_INSTANCE_FLAG_NONE;
+            desc->InstanceMask = 0xFF;
+            desc->AccelerationStructure
+                = blas->zResultBuffer()->zBuffer()->GetGPUVirtualAddress();
+            memcpy(desc->Transform,
+                &matrixBuffer[boneIds.val()],
+                sizeof(float) * 12);
+            boneIds++;
+            instanceIndex++;
+        }
+        fillShaderBindingTable(sbt, obj, objectIndex);
+        objectIndex++;
+    });
     tlas->endUpdate();
-    // TODO: setup ray gen and miss params
+    if (defaultRayGenerationShaderFunction)
+    {
+        sbt->setShaderInputs(defaultRayGenerationShaderFunction,
+            {zTarget->zResource()->GetGPUVirtualAddress(),
+                tlas->zResultBuffer()->zBuffer()->GetGPUVirtualAddress()});
+    }
+    sbt->setGlobalDescriptorHeap(dynamic_cast<DX12GlobalDescriptorHeap*>(
+        globalDescriptorHeap->getThis()));
     sbt->endUpdate(device);
+    ID3D12DescriptorHeap* heaps[] = {globalDescriptorHeap->zDescriptorHeap()};
+    directCommandQueue->zCommandList()->SetDescriptorHeaps(1, heaps);
+
+    D3D12_DISPATCH_RAYS_DESC desc;
+    sbt->fillDispatchRaysDesc(&desc);
+    directCommandQueue->zCommandList()->SetPipelineState1(
+        pipeline->zPipelineState());
+    directCommandQueue->zCommandList()->DispatchRays(&desc);
     // TODO: call ray tracing
 }
 
+void Framework::DirectX12::initializePipeline()
+{
+    if (pipeline->getShaders().getEntryCount() == 0)
+    { // add default shaders
+        DX12Shader* rayGenShader
+            = new DX12Shader(DX12DefaultRayGenerationShaderBytes,
+                sizeof(DX12DefaultRayGenerationShaderBytes));
+        // RayGen from RayGen.hlsl
+        DX12ShaderSignature* rayGenSignature = new DX12ShaderSignature();
+        rayGenSignature->addRegisterUsageLinkedToShaderBindingTable(
+            DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, 0);
+        rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
+            0, DX12_SHADER_REGISTER_U_UNORDERED_ACCESS, 1);
+        rayGenSignature->addRegisterUsageLinkedToShaderBindingTable(
+            DX12_SHADER_REGISTER_T_SHADER_RESOURCE, 0);
+        defaultRayGenerationShaderFunction
+            = new DX12ShaderFunction("RayGen", rayGenSignature);
+        rayGenShader->addFunction(defaultRayGenerationShaderFunction);
+        pipeline->addShader(rayGenShader);
+
+        DX12Shader* missShader = new DX12Shader(
+            DX12DefaultMissShaderBytes, sizeof(DX12DefaultMissShaderBytes));
+        // Miss from Miss.hlsl
+        missShader->addFunction(
+            new DX12ShaderFunction("Miss", new DX12ShaderSignature()));
+        pipeline->addShader(missShader);
+
+        DX12Shader* hitShader = new DX12Shader(
+            DX12DefaultMissShaderBytes, sizeof(DX12DefaultMissShaderBytes));
+        // ClosestHit from Hit.hlsl
+        DX12ShaderFunction* closestHitFunction
+            = new DX12ShaderFunction("ClosestHit", new DX12ShaderSignature());
+        missShader->addFunction(closestHitFunction);
+        pipeline->addShader(hitShader);
+
+        defaultHitGroup = new DX12ShaderHitGroup("HitGroup");
+        defaultHitGroup->setClosestHitShaderFunction(closestHitFunction);
+        pipeline->addHitGroup(defaultHitGroup);
+    }
+}
+
+void Framework::DirectX12::initializeGlobalDescriptorHeap()
+{
+    globalDescriptorHeap->addTextureInput(
+        DX12_SHADER_REGISTER_T_SHADER_RESOURCE, uiTexture);
+}
+
+void Framework::DirectX12::fillShaderBindingTable(
+    DX12ShaderBindingTable* zShaderBindingTable,
+    Model3D* zModel,
+    int instanceIndex)
+{
+    if (defaultHitGroup)
+    {
+        zShaderBindingTable->setHitGroupShaderInputs(
+            instanceIndex, defaultHitGroup, {});
+    }
+}
+
 typedef HRESULT(__stdcall* CreateDXGIFactory2Function)(UINT, REFIID, void**);
 
 typedef HRESULT(__stdcall* D3D12CreateDeviceFunction)(
@@ -464,8 +536,6 @@ void DirectX12::initialize(
     }
 
     directCommandQueue = new DX12DirectCommandQueue(device);
-    copyCommandQueue = new DX12CopyCommandQueue(device);
-    computeCommandQueue = new DX12ComputeCommandQueue(device);
 
     IDXGIFactory5* fac5 = 0;
     factory->QueryInterface(__uuidof(IDXGIFactory5), (void**)&fac5);
@@ -593,72 +663,6 @@ void DirectX12::initialize(
     renderB->newImage(this->backBufferSize.x, this->backBufferSize.y, 0);
     uiTexture = createOrGetTexture("_f_Render_Image", renderB, RAM_TO_GPU);
 
-    vertexBufferView = new D3D12_VERTEX_BUFFER_VIEW();
-    vertexBufferView->StrideInBytes = sizeof(Vertex3D);
-
-    indexBufferView = new D3D12_INDEX_BUFFER_VIEW();
-    indexBufferView->Format = DXGI_FORMAT_R32_UINT;
-
-    D3D12_CLEAR_VALUE optimizedClearValue = {};
-    optimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT;
-    optimizedClearValue.DepthStencil = {1.0f, 0};
-    CD3DX12_HEAP_PROPERTIES heapProp
-        = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
-    CD3DX12_RESOURCE_DESC heapDesc
-        = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D32_FLOAT,
-            this->backBufferSize.x,
-            this->backBufferSize.y,
-            1,
-            0,
-            1,
-            0,
-            D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
-    res = device->CreateCommittedResource(&heapProp,
-        D3D12_HEAP_FLAG_NONE,
-        &heapDesc,
-        D3D12_RESOURCE_STATE_DEPTH_WRITE,
-        &optimizedClearValue,
-        __uuidof(ID3D12Resource),
-        (void**)&depthBuffer);
-    if (FAILED(res))
-    {
-        factory->Release();
-        Logging::error() << "ERROR: CreateCommittedResource returned " << res
-                         << "\n";
-        WMessageBox(fenster->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("CreateCommittedResource ist Fehlgeschlagen."),
-            MB_ICONERROR);
-        return;
-    }
-
-    D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
-    dsvHeapDesc.NumDescriptors = 1;
-    dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
-    dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
-    res = device->CreateDescriptorHeap(
-        &dsvHeapDesc, __uuidof(ID3D12DescriptorHeap), (void**)&dsvHeap);
-    if (FAILED(res))
-    {
-        factory->Release();
-        Logging::error() << "ERROR: CreateDescriptorHeap returned " << res
-                         << "\n";
-        WMessageBox(fenster->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("CreateDescriptorHeap ist Fehlgeschlagen."),
-            MB_ICONERROR);
-        return;
-    }
-
-    D3D12_DEPTH_STENCIL_VIEW_DESC dsv = {};
-    dsv.Format = DXGI_FORMAT_D32_FLOAT;
-    dsv.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
-    dsv.Texture2D.MipSlice = 0;
-    dsv.Flags = D3D12_DSV_FLAG_NONE;
-
-    device->CreateDepthStencilView(
-        depthBuffer, &dsv, dsvHeap->GetCPUDescriptorHandleForHeapStart());
-
     D3D12_FEATURE_DATA_ROOT_SIGNATURE featureData = {};
     featureData.HighestVersion = D3D_ROOT_SIGNATURE_VERSION_1_1;
     if (FAILED(device->CheckFeatureSupport(
@@ -816,6 +820,12 @@ void DirectX12::beginFrame(bool fill2D, bool fill3D, int fillColor)
     }
 
     uiTexture->updateTextur();
+
+    CD3DX12_RESOURCE_BARRIER transition
+        = CD3DX12_RESOURCE_BARRIER::Transition(defaultRenderTarget->zResource(),
+            D3D12_RESOURCE_STATE_COPY_SOURCE,
+            D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+    directCommandQueue->zCommandList()->ResourceBarrier(1, &transition);
 }
 
 void DirectX12::renderKamera(Cam3D* zKamera)
@@ -830,24 +840,33 @@ void Framework::DirectX12::renderKamera(Cam3D* zKamera, Texture* zTarget)
 
 void DirectX12::presentFrame()
 {
-    // TODO
-    // directCommandQueue->getCommandList()->RSSetViewports(1, viewPort);
-
-    viewAndProj[0] = Mat4<float>::identity();
-    viewAndProj[1] = Mat4<float>::identity();
-
-    D3D12_RESOURCE_BARRIER barrier;
-    ZeroMemory(&barrier, sizeof(barrier));
-    barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
-    barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
-    barrier.Transition.pResource = this->backBuffer[backBufferIndex];
-    barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
-    barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
-    barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+    CD3DX12_RESOURCE_BARRIER transition
+        = CD3DX12_RESOURCE_BARRIER::Transition(defaultRenderTarget->zResource(),
+            D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
+            D3D12_RESOURCE_STATE_COPY_SOURCE);
+    directCommandQueue->zCommandList()->ResourceBarrier(1, &transition);
+    transition
+        = CD3DX12_RESOURCE_BARRIER::Transition(backBuffer[backBufferIndex],
+            D3D12_RESOURCE_STATE_RENDER_TARGET,
+            D3D12_RESOURCE_STATE_COPY_DEST);
+    directCommandQueue->zCommandList()->ResourceBarrier(1, &transition);
+
+    directCommandQueue->zCommandList()->CopyResource(
+        backBuffer[backBufferIndex], defaultRenderTarget->zResource());
+
+    transition
+        = CD3DX12_RESOURCE_BARRIER::Transition(backBuffer[backBufferIndex],
+            D3D12_RESOURCE_STATE_COPY_DEST,
+            D3D12_RESOURCE_STATE_RENDER_TARGET);
+    directCommandQueue->zCommandList()->ResourceBarrier(1, &transition);
+
+    // Indicate that the back buffer will now be used to present.
+    transition
+        = CD3DX12_RESOURCE_BARRIER::Transition(backBuffer[backBufferIndex],
+            D3D12_RESOURCE_STATE_RENDER_TARGET,
+            D3D12_RESOURCE_STATE_PRESENT);
+    directCommandQueue->zCommandList()->ResourceBarrier(1, &transition);
 
-    // TODO
-    // directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
-    copyCommandQueue->execute();
     directCommandQueue->execute();
 
     swapChain->Present(0, 0);
@@ -869,12 +888,10 @@ Texture* DirectX12::createOrGetTexture(
         if (b) ret->setImageZ(b);
         return ret;
     }
-    Texture* ret
-        = new DX12Texture(device, copyCommandQueue, directCommandQueue, dir);
+    Texture* ret = new DX12Texture(device, directCommandQueue, dir);
     if (b) ret->setImageZ(b);
     texturRegister->addTexture(dynamic_cast<Texture*>(ret->getThis()), name);
     ret->updateTextur();
-    copyCommandQueue->execute();
     directCommandQueue->execute();
     return ret;
 }
@@ -896,6 +913,20 @@ void Framework::DirectX12::setPipeline(DX12Pipeline* pipeline)
         this->pipeline->release();
     }
     this->pipeline = pipeline;
+    if (pipeline)
+    {
+        initializePipeline();
+        if (!globalDescriptorHeap
+            || globalDescriptorHeap->zPipeline() != pipeline)
+        {
+            if (globalDescriptorHeap)
+            {
+                globalDescriptorHeap->release();
+            }
+            globalDescriptorHeap = pipeline->createGlobalDescriptorHeap();
+            initializeGlobalDescriptorHeap();
+        }
+    }
 }
 
 bool DirectX12::isAvailable()

+ 14 - 6
DX12GraphicsApi.h

@@ -38,6 +38,11 @@ namespace Framework
     class DX12TLAS;
     class DX12Texture;
     class DX12Pipeline;
+    class DX12GlobalDescriptorHeap;
+    class DX12ShaderBindingTable;
+    class Model3D;
+    class DX12ShaderHitGroup;
+    class DX12ShaderFunction;
 
     class DirectX12 : public GraphicsApi
     {
@@ -46,19 +51,13 @@ namespace Framework
         ID3D12Device5* device;
         ID3D12InfoQueue* infoQueue;
         DX12DirectCommandQueue* directCommandQueue;
-        DX12CopyCommandQueue* copyCommandQueue;
-        DX12ComputeCommandQueue* computeCommandQueue;
         IDXGISwapChain4* swapChain;
         ID3D12DescriptorHeap* rtvHeap;
-        ID3D12DescriptorHeap* dsvHeap;
-        ID3D12Resource* depthBuffer;
         ID3D12Resource* backBuffer[2];
         int backBufferIndex;
         int tearing;
         D3D12_VIEWPORT* viewPort;
         tagRECT* allowedRenderArea;
-        D3D12_VERTEX_BUFFER_VIEW* vertexBufferView;
-        D3D12_INDEX_BUFFER_VIEW* indexBufferView;
         ID3D12RootSignature* signature;
         Mat4<float> matrixBuffer[MAX_KNOCHEN_ANZ];
         Mat4<float> viewAndProj[2];
@@ -72,6 +71,9 @@ namespace Framework
         int lastModelId;
         DX12Texture* defaultRenderTarget;
         DX12Pipeline* pipeline;
+        DX12GlobalDescriptorHeap* globalDescriptorHeap;
+        DX12ShaderHitGroup* defaultHitGroup;
+        DX12ShaderFunction* defaultRayGenerationShaderFunction;
 
     public:
         DLLEXPORT DirectX12();
@@ -81,6 +83,12 @@ namespace Framework
         DLLEXPORT void updateBottomLevelAccelerationStructure();
         DLLEXPORT void renderKamera(
             Cam3D* zKamera, DX12Texture* zTarget, bool guiVisible);
+        DLLEXPORT void initializePipeline();
+        DLLEXPORT void initializeGlobalDescriptorHeap();
+        DLLEXPORT void fillShaderBindingTable(
+            DX12ShaderBindingTable* zShaderBindingTable,
+            Model3D* zModel,
+            int objectIndex);
 
     public:
         DLLEXPORT void initialize(NativeWindow* fenster,

+ 107 - 86
DX12Shader.cpp

@@ -252,7 +252,8 @@ D3D12_EXPORT_DESC* Framework::DX12ShaderFunction::zExportDesc() const
     return exportDesc;
 }
 
-Framework::DX12Shader::DX12Shader(const char* shaderBytes, int shaderBytesSize)
+Framework::DX12Shader::DX12Shader(
+    const unsigned char* shaderBytes, int shaderBytesSize)
     : ReferenceCounter(),
       shaderBytes(shaderBytes),
       shaderBytesSize(shaderBytesSize),
@@ -280,7 +281,7 @@ int Framework::DX12Shader::getShaderBytesSize() const
     return shaderBytesSize;
 }
 
-const char* Framework::DX12Shader::getShaderBytes() const
+const unsigned char* Framework::DX12Shader::getShaderBytes() const
 {
     return shaderBytes;
 }
@@ -439,42 +440,43 @@ void Framework::DX12ShaderHitGroup::setAnyHitShaderFunction(
 }
 
 void Framework::DX12ShaderHitGroup::setIntersectionShaderFunction(
-    DX12ShaderFunction* intersectionShaderFunction)
+    DX12ShaderFunction* zIntersectionShaderFunction)
 {
     if (closestHitShaderFunction
         && closestHitShaderFunction->zSignature()
-               != intersectionShaderFunction->zSignature())
+               != zIntersectionShaderFunction->zSignature())
     {
         Logging::error()
             << "Intersection shader function and closest-hit shader "
                "function must have the same root signature when they are "
                "combined in the same hit group. HitGroup Name: '"
             << name << "' Intersection Shader Function: '"
-            << intersectionShaderFunction->getFunctionName().getText()
+            << zIntersectionShaderFunction->getFunctionName().getText()
             << "' Closest Hit Shader Function: '"
             << closestHitShaderFunction->getFunctionName().getText() << "'";
         throw std::runtime_error("Incompatible root signatures in hit group");
     }
     if (anyHitShaderFunction
         && anyHitShaderFunction->zSignature()
-               != intersectionShaderFunction->zSignature())
+               != zIntersectionShaderFunction->zSignature())
     {
         Logging::error()
             << "Intersection shader function and any-hit shader "
                "function must have the same root signature when they are "
                "combined in the same hit group. HitGroup Name: '"
             << name << "' Intersection Shader Function: '"
-            << intersectionShaderFunction->getFunctionName().getText()
+            << zIntersectionShaderFunction->getFunctionName().getText()
             << "' Any Hit Shader Function: '"
             << anyHitShaderFunction->getFunctionName().getText() << "'";
         throw std::runtime_error("Incompatible root signatures in hit group");
     }
 
-    if (this->intersectionShaderFunction)
+    if (intersectionShaderFunction)
     {
-        this->intersectionShaderFunction->release();
+        intersectionShaderFunction->release();
     }
-    this->intersectionShaderFunction = intersectionShaderFunction;
+    intersectionShaderFunction = dynamic_cast<DX12ShaderFunction*>(
+        zIntersectionShaderFunction->getThis());
     hitGroupDesc->IntersectionShaderImport = 0;
     if (intersectionShaderFunction)
     {
@@ -1007,96 +1009,115 @@ void Framework::DX12GlobalDescriptorHeap::updateDescriptorHeap(
         switch (input->registerType)
         {
         case DX12_SHADER_REGISTER_B_CONST_BUFFER:
-            D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {};
-            if (!zBuffer)
             {
-                Logging::error()
-                    << "Expected a buffer resource for register type "
-                    << input->registerType;
-                throw std::logic_error(
-                    "Expected a buffer resource for register type "
-                    + std::to_string(input->registerType));
+                D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {};
+                if (!zBuffer)
+                {
+                    Logging::error()
+                        << "Expected a buffer resource for register type "
+                        << input->registerType;
+                    throw std::logic_error(
+                        "Expected a buffer resource for register type "
+                        + std::to_string(input->registerType));
+                }
+                cbvDesc.BufferLocation
+                    = zBuffer->zBuffer()->GetGPUVirtualAddress();
+                cbvDesc.SizeInBytes = (unsigned)zBuffer->getElementCount()
+                                    * zBuffer->getElementLength();
+                zDevice->CreateConstantBufferView(
+                    &cbvDesc, descriptorHeapHandle);
+                break;
             }
-            cbvDesc.BufferLocation = zBuffer->zBuffer()->GetGPUVirtualAddress();
-            cbvDesc.SizeInBytes
-                = zBuffer->getElementCount() * zBuffer->getElementLength();
-            zDevice->CreateConstantBufferView(&cbvDesc, descriptorHeapHandle);
-            break;
         case DX12_SHADER_REGISTER_T_SHADER_RESOURCE:
-            D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
-            srvDesc.Format = DXGI_FORMAT_UNKNOWN;
-            if (zTLAS)
-            {
-                srvDesc.ViewDimension
-                    = D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE;
-                srvDesc.RaytracingAccelerationStructure.Location
-                    = zTLAS->zResultBuffer()->zBuffer()->GetGPUVirtualAddress();
-            }
-            else if (zTexture)
-            {
-                srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
-                srvDesc.Texture2D.MipLevels = 0;
-                srvDesc.Texture2D.MostDetailedMip = 0;
-                srvDesc.Texture2D.PlaneSlice = 0;
-                srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;
-            }
-            else if (zBuffer)
             {
-                srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
-                srvDesc.Buffer.FirstElement = 0;
-                srvDesc.Buffer.NumElements = zBuffer->getElementCount();
-                srvDesc.Buffer.StructureByteStride
-                    = zBuffer->getElementLength();
-                srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
+                D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
+                srvDesc.Format = DXGI_FORMAT_UNKNOWN;
+                if (zTLAS)
+                {
+                    srvDesc.ViewDimension
+                        = D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE;
+                    srvDesc.RaytracingAccelerationStructure.Location
+                        = zTLAS->zResultBuffer()
+                              ->zBuffer()
+                              ->GetGPUVirtualAddress();
+                }
+                else if (zTexture)
+                {
+                    srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+                    srvDesc.Texture2D.MipLevels = 0;
+                    srvDesc.Texture2D.MostDetailedMip = 0;
+                    srvDesc.Texture2D.PlaneSlice = 0;
+                    srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;
+                }
+                else if (zBuffer)
+                {
+                    srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
+                    srvDesc.Buffer.FirstElement = 0;
+                    srvDesc.Buffer.NumElements
+                        = (unsigned)zBuffer->getElementCount();
+                    srvDesc.Buffer.StructureByteStride
+                        = zBuffer->getElementLength();
+                    srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
+                }
+                srvDesc.Shader4ComponentMapping
+                    = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+                zDevice->CreateShaderResourceView(
+                    zTexture ? zTexture->zResource()
+                             : (zBuffer ? zBuffer->zBuffer() : 0),
+                    &srvDesc,
+                    descriptorHeapHandle);
+                break;
             }
-            srvDesc.Shader4ComponentMapping
-                = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
-            zDevice->CreateShaderResourceView(
-                zTexture ? zTexture->zResource()
-                         : (zBuffer ? zBuffer->zBuffer() : 0),
-                &srvDesc,
-                descriptorHeapHandle);
-            break;
         case DX12_SHADER_REGISTER_U_UNORDERED_ACCESS:
-            D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
-            if (zTexture)
             {
-                uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
-                uavDesc.Format = DXGI_FORMAT_UNKNOWN;
-                uavDesc.Texture2D.MipSlice = 0;
-                uavDesc.Texture2D.PlaneSlice = 0;
-            }
-            else if (zBuffer)
-            {
-                uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
-                uavDesc.Buffer.FirstElement = 0;
-                uavDesc.Buffer.NumElements = zBuffer->getElementCount();
-                uavDesc.Buffer.StructureByteStride
-                    = zBuffer->getElementLength();
-                uavDesc.Buffer.CounterOffsetInBytes = 0;
-                uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
-            }
-            else
-            {
-                Logging::error() << "Expected a texture or buffer resource for "
-                                    "register type "
-                                 << input->registerType;
-                throw std::logic_error(
-                    "Expected a texture or buffer resource for register type "
-                    + std::to_string(input->registerType));
+                D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
+                if (zTexture)
+                {
+                    uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
+                    uavDesc.Format = DXGI_FORMAT_UNKNOWN;
+                    uavDesc.Texture2D.MipSlice = 0;
+                    uavDesc.Texture2D.PlaneSlice = 0;
+                }
+                else if (zBuffer)
+                {
+                    uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
+                    uavDesc.Buffer.FirstElement = 0;
+                    uavDesc.Buffer.NumElements
+                        = (unsigned)zBuffer->getElementCount();
+                    uavDesc.Buffer.StructureByteStride
+                        = zBuffer->getElementLength();
+                    uavDesc.Buffer.CounterOffsetInBytes = 0;
+                    uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
+                }
+                else
+                {
+                    Logging::error()
+                        << "Expected a texture or buffer resource for "
+                           "register type "
+                        << input->registerType;
+                    throw std::logic_error(
+                        "Expected a texture or buffer resource for register "
+                        "type "
+                        + std::to_string(input->registerType));
+                }
+                zDevice->CreateUnorderedAccessView(
+                    zTexture ? zTexture->zResource() : zBuffer->zBuffer(),
+                    0,
+                    &uavDesc,
+                    descriptorHeapHandle);
+                break;
             }
-            zDevice->CreateUnorderedAccessView(
-                zTexture ? zTexture->zResource() : zBuffer->zBuffer(),
-                0,
-                &uavDesc,
-                descriptorHeapHandle);
-            break;
         }
         descriptorHeapHandle.ptr += zDevice->GetDescriptorHandleIncrementSize(
             D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
     }
 }
 
+DX12Pipeline* Framework::DX12GlobalDescriptorHeap::zPipeline() const
+{
+    return pipeline;
+}
+
 ID3D12DescriptorHeap*
 Framework::DX12GlobalDescriptorHeap::zDescriptorHeap() const
 {

+ 12 - 7
DX12Shader.h

@@ -105,16 +105,16 @@ namespace Framework
     {
     private:
         RCArray<DX12ShaderFunction> functions;
-        const char* shaderBytes;
+        const unsigned char* shaderBytes;
         int shaderBytesSize;
         D3D12_DXIL_LIBRARY_DESC* libraryDesc;
 
     public:
-        DX12Shader(const char* shaderBytes, int shaderBytesSize);
+        DX12Shader(const unsigned char* shaderBytes, int shaderBytesSize);
         ~DX12Shader();
         void addFunction(DX12ShaderFunction* function);
         int getShaderBytesSize() const;
-        const char* getShaderBytes() const;
+        const unsigned char* getShaderBytes() const;
         const RCArray<DX12ShaderFunction>& getFunctions() const;
         D3D12_DXIL_LIBRARY_DESC* zLibraryDesc() const;
     };
@@ -134,10 +134,10 @@ namespace Framework
         DX12ShaderHitGroup(const Text name);
         ~DX12ShaderHitGroup();
         void setClosestHitShaderFunction(
-            DX12ShaderFunction* closestHitShaderFunction);
-        void setAnyHitShaderFunction(DX12ShaderFunction* anyHitShaderFunction);
+            DX12ShaderFunction* zClosestHitShaderFunction);
+        void setAnyHitShaderFunction(DX12ShaderFunction* zAnyHitShaderFunction);
         void setIntersectionShaderFunction(
-            DX12ShaderFunction* intersectionShaderFunction);
+            DX12ShaderFunction* zIntersectionShaderFunction);
         void setPayloadSize(int payloadSize);
         void setAttributeSize(int attributeSize);
         const Text& getName() const;
@@ -203,6 +203,7 @@ namespace Framework
         void addBufferInput(DX12ShaderRegister type, DXBuffer* zBuffer);
         void addTLASInput(DX12ShaderRegister type, DX12TLAS* zTLAS);
         void updateDescriptorHeap(ID3D12Device5* zDevice);
+        DX12Pipeline* zPipeline() const;
         ID3D12DescriptorHeap* zDescriptorHeap() const;
     };
 
@@ -211,6 +212,7 @@ namespace Framework
     private:
         DX12Pipeline* pipeline;
         DX12Buffer* shaderBindingTableBuffer;
+        DX12GlobalDescriptorHeap* globalDescriptorHeap;
         int rayGenRecordSize;
         int rayGenCount;
         int missRecordSize;
@@ -222,8 +224,11 @@ namespace Framework
     public:
         DX12ShaderBindingTable(DX12Pipeline* pipeline);
         ~DX12ShaderBindingTable();
-
+        void setGlobalDescriptorHeap(
+            DX12GlobalDescriptorHeap* zGlobalDescriptorHeap);
         void startUpdate();
+        void setShaderInputs(DX12ShaderFunction* zFunction,
+            std::initializer_list<unsigned __int64> gpuAddresses);
         void setHitGroupShaderInputs(int instanceIndex,
             DX12ShaderHitGroup* zHitGroup,
             std::initializer_list<unsigned __int64> gpuAddresses);

+ 2 - 5
DX12Texture.cpp

@@ -6,14 +6,11 @@
 
 using namespace Framework;
 
-DX12Texture::DX12Texture(ID3D12Device* device,
-    DX12CopyCommandQueue* copy,
-    DX12DirectCommandQueue* direct,
-    TextureDirection dir)
+DX12Texture::DX12Texture(
+    ID3D12Device* device, DX12DirectCommandQueue* direct, TextureDirection dir)
     : Texture(dir),
       buffer(0),
       device(device),
-      copy(copy),
       direct(direct)
 {}
 

+ 0 - 2
DX12Texture.h

@@ -15,12 +15,10 @@ namespace Framework
     private:
         ID3D12Resource* buffer;
         ID3D12Device* device;
-        DX12CopyCommandQueue* copy;
         DX12DirectCommandQueue* direct;
 
     public:
         DLLEXPORT DX12Texture(ID3D12Device* device,
-            DX12CopyCommandQueue* copy,
             DX12DirectCommandQueue* direct,
             TextureDirection dir);
         DLLEXPORT ~DX12Texture();

+ 3 - 0
Framework.vcxproj

@@ -486,6 +486,7 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
       <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Common.hlsl</AdditionalInputs>
       <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd "x64\Debug\DX12HitShader.pdb" %(AdditionalOptions)</AdditionalOptions>
       <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12DefaultHitShaderBytes</VariableName>
     </FxCompile>
     <FxCompile Include="Miss.hlsl">
       <EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -500,6 +501,7 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12MissShader.h</Outputs>
       <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Common.hlsl</AdditionalInputs>
       <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12DefaultMissShaderBytes</VariableName>
     </FxCompile>
     <FxCompile Include="RayGen.hlsl">
       <EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -514,6 +516,7 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12RayGenShader.h</Outputs>
       <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Common.hlsl</AdditionalInputs>
       <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12DefaultRayGenerationShaderBytes</VariableName>
     </FxCompile>
   </ItemGroup>
   <ItemGroup>