From af5a3688c57f0f0a9406fb1ea488e093d5822aea Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 19 Oct 2019 14:31:56 -0700 Subject: Updated submodules (API version 240033); Enabled bindless mode in Asteroid demo --- DiligentCore | 2 +- DiligentFX | 2 +- DiligentSamples | 2 +- DiligentTools | 2 +- Projects/Asteroids/CMakeLists.txt | 1 + Projects/Asteroids/src/asteroid_ps.hlsl | 8 +- Projects/Asteroids/src/asteroid_ps_d3d11.hlsl | 3 +- Projects/Asteroids/src/asteroid_ps_diligent.hlsl | 9 +- Projects/Asteroids/src/asteroid_vs.hlsl | 47 +++--- Projects/Asteroids/src/asteroids_DE.cpp | 139 +++++++++++++----- Projects/Asteroids/src/asteroids_DE.h | 2 + Projects/Asteroids/src/shader_common.h | 25 ++++ Tests/TestApp/assets/LuaTest.lua | 6 - Tests/TestApp/assets/TestComputeShaders.lua | 1 - Tests/TestApp/src/RenderScriptTest.cpp | 20 ++- Tests/TestApp/src/TestApp.cpp | 24 ++-- Tests/TestApp/src/TestDrawCommands.cpp | 159 +++++++++------------ .../PluginSource/src/SamplePlugin.cpp | 4 +- 18 files changed, 256 insertions(+), 200 deletions(-) create mode 100644 Projects/Asteroids/src/shader_common.h diff --git a/DiligentCore b/DiligentCore index 5a4e694..046a6fd 160000 --- a/DiligentCore +++ b/DiligentCore @@ -1 +1 @@ -Subproject commit 5a4e694df2c519ee6a81a2ce1428e65624a17dfd +Subproject commit 046a6fdcc82251bf6ae5118c5b5a410b1a976936 diff --git a/DiligentFX b/DiligentFX index 89b30b9..e6e67d6 160000 --- a/DiligentFX +++ b/DiligentFX @@ -1 +1 @@ -Subproject commit 89b30b961e04308486840227d6a0e90aca239588 +Subproject commit e6e67d64ce34e901c01e912a925a85ac986582ea diff --git a/DiligentSamples b/DiligentSamples index 16b05eb..06698e3 160000 --- a/DiligentSamples +++ b/DiligentSamples @@ -1 +1 @@ -Subproject commit 16b05eb0013e15173ffbd4ce6a1cb74b322aa6e9 +Subproject commit 06698e383e27a7a526abc189a5a09a2d2eaace76 diff --git a/DiligentTools b/DiligentTools index 03cd20e..62dbbec 160000 --- a/DiligentTools +++ b/DiligentTools @@ -1 +1 @@ -Subproject commit 03cd20ee3eaae97fdde0d662179bddfb5f8fd167 +Subproject commit 62dbbec16e3fbd9c6a7ab8943e727676d2ca5d20 diff --git a/Projects/Asteroids/CMakeLists.txt b/Projects/Asteroids/CMakeLists.txt index 4bb80c3..d932a61 100644 --- a/Projects/Asteroids/CMakeLists.txt +++ b/Projects/Asteroids/CMakeLists.txt @@ -87,6 +87,7 @@ if(WIN32) ${MEDIA} SDK/Include/d3dx12.h src/common_defines.h + src/shader_common.h readme.md ) set_target_properties(Asteroids PROPERTIES diff --git a/Projects/Asteroids/src/asteroid_ps.hlsl b/Projects/Asteroids/src/asteroid_ps.hlsl index c645486..5c5bfd3 100644 --- a/Projects/Asteroids/src/asteroid_ps.hlsl +++ b/Projects/Asteroids/src/asteroid_ps.hlsl @@ -1,5 +1,5 @@ -#include "asteroid_vs.hlsl" #include "common_defines.h" +#include "shader_common.h" // Apparently tools don't like unbounded/bindless texture arrays, so use the real constant for now Texture2DArray Tex[NUM_UNIQUE_TEXTURES] : register(t0); @@ -31,9 +31,9 @@ float4 asteroid_ps(in float4 position : SV_Position, // and forward substituting the above and then refusing to compile "divergent" // coordinates... float3 detailTex = 0.0f; - detailTex += blendWeights.x * Tex[mTextureIndex].Sample(Sampler, coords1).xyz; - detailTex += blendWeights.y * Tex[mTextureIndex].Sample(Sampler, coords2).xyz; - detailTex += blendWeights.z * Tex[mTextureIndex].Sample(Sampler, coords3).xyz; + detailTex += blendWeights.x * Tex[vs_output.textureId].Sample(Sampler, coords1).xyz; + detailTex += blendWeights.y * Tex[vs_output.textureId].Sample(Sampler, coords2).xyz; + detailTex += blendWeights.z * Tex[vs_output.textureId].Sample(Sampler, coords3).xyz; float wrap = 0.0f; float wrap_diffuse = saturate((dot(normal, normalize(lightPos)) + wrap) / (1.0f + wrap)); diff --git a/Projects/Asteroids/src/asteroid_ps_d3d11.hlsl b/Projects/Asteroids/src/asteroid_ps_d3d11.hlsl index f4987c9..8b58d09 100644 --- a/Projects/Asteroids/src/asteroid_ps_d3d11.hlsl +++ b/Projects/Asteroids/src/asteroid_ps_d3d11.hlsl @@ -1,5 +1,4 @@ -#include "asteroid_vs.hlsl" -#include "common_defines.h" +#include "shader_common.h" Texture2DArray Tex : register(t0); sampler Sampler : register(s0); diff --git a/Projects/Asteroids/src/asteroid_ps_diligent.hlsl b/Projects/Asteroids/src/asteroid_ps_diligent.hlsl index c2f6f0b..bd1ee1d 100644 --- a/Projects/Asteroids/src/asteroid_ps_diligent.hlsl +++ b/Projects/Asteroids/src/asteroid_ps_diligent.hlsl @@ -1,12 +1,5 @@ #include "common_defines.h" - -struct VSOut -{ - float3 positionModel : POSITIONMODEL; - float3 normalWorld : NORMAL; - float3 albedo : ALBEDO; // Alternatively, can pass just "ao" to PS and read cbuffer in PS - uint textureId : TEXTURE_ID; -}; +#include "shader_common.h" #ifdef BINDLESS diff --git a/Projects/Asteroids/src/asteroid_vs.hlsl b/Projects/Asteroids/src/asteroid_vs.hlsl index f19fe2c..3498d33 100644 --- a/Projects/Asteroids/src/asteroid_vs.hlsl +++ b/Projects/Asteroids/src/asteroid_vs.hlsl @@ -1,39 +1,46 @@ -cbuffer DrawConstantBuffer// : register(b0) -{ - float4x4 mWorld; - float4x4 mViewProjection; - float4 mSurfaceColor; - float4 mDeepColor; - uint mTextureIndex; -}; +#include "shader_common.h" + +#ifdef BINDLESS + +StructuredBuffer g_Data; -struct VSOut +#else + +cbuffer DrawConstantBuffer { - float3 positionModel : POSITIONMODEL; - float3 normalWorld : NORMAL; - float3 albedo : ALBEDO; // Alternatively, can pass just "ao" to PS and read cbuffer in PS - uint textureId : TEXTURE_ID; + AsteroidData g_Data; }; +#endif + float linstep(float min, float max, float s) { return saturate((s - min) / (max - min)); } -void asteroid_vs(in float3 in_pos : ATTRIB0, +void asteroid_vs(in float3 in_pos : ATTRIB0, in float3 in_normal : ATTRIB1, - out float4 position : SV_Position, +#ifdef BINDLESS + in uint AsteroidId : ATTRIB2, // SV_InstanceId is not affected by BaseInstance +#endif + out float4 position : SV_Position, out VSOut vs_output) { - float3 positionWorld = mul(mWorld, float4(in_pos, 1.0f)).xyz; - position = mul(mViewProjection, float4(positionWorld, 1.0f)); +#ifdef BINDLESS + AsteroidData Data = g_Data[AsteroidId]; +#else + AsteroidData Data = g_Data; +#endif + + float3 positionWorld = mul(Data.World, float4(in_pos, 1.0f)).xyz; + position = mul(Data.ViewProjection, float4(positionWorld, 1.0f)); vs_output.positionModel = in_pos; - vs_output.normalWorld = mul(mWorld, float4(in_normal, 0.0f)).xyz; // No non-uniform scaling + vs_output.normalWorld = mul(Data.World, float4(in_normal, 0.0f)).xyz; // No non-uniform scaling float depth = linstep(0.5f, 0.7f, length(in_pos.xyz)); - vs_output.albedo = lerp(mDeepColor.xyz, mSurfaceColor.xyz, depth); + vs_output.albedo = lerp(Data.DeepColor.xyz, Data.SurfaceColor.xyz, depth); - vs_output.textureId = mTextureIndex; + vs_output.textureId = Data.TextureIndex; } diff --git a/Projects/Asteroids/src/asteroids_DE.cpp b/Projects/Asteroids/src/asteroids_DE.cpp index 3cafba9..0b8408d 100644 --- a/Projects/Asteroids/src/asteroids_DE.cpp +++ b/Projects/Asteroids/src/asteroids_DE.cpp @@ -237,14 +237,47 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G std::vector Barriers; mBackBufferWidth = mSwapChain->GetDesc().Width; mBackBufferHeight = mSwapChain->GetDesc().Height; - // Create draw constant buffer + const auto MaxAsteroidsInSubset = (NUM_ASTEROIDS + mNumSubsets - 1) / mNumSubsets; + + if (m_BindingMode == BindingMode::Bindless) + { + { + BufferDesc desc; + desc.Name = "Instance ID buffer"; + desc.Usage = USAGE_STATIC; + desc.BindFlags = BIND_VERTEX_BUFFER; + desc.uiSizeInBytes = static_cast(sizeof(Uint32)) * MaxAsteroidsInSubset; + std::vector Ids(MaxAsteroidsInSubset); + for (Uint32 i=0; i < Ids.size(); ++i) + Ids[i] = i; + BufferData Data(Ids.data(), desc.uiSizeInBytes); + mDevice->CreateBuffer(desc, &Data, &mInstanceIDBuffer); + Barriers.emplace_back(mInstanceIDBuffer, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_VERTEX_BUFFER, true); + } + { + BufferDesc desc; + desc.Name = "Asteroids data buffer"; + desc.Usage = USAGE_DYNAMIC; + desc.BindFlags = BIND_SHADER_RESOURCE; + desc.Mode = BUFFER_MODE_STRUCTURED; + desc.CPUAccessFlags = CPU_ACCESS_WRITE; + desc.ElementByteStride = static_cast(sizeof(DrawConstantBuffer)); + desc.uiSizeInBytes = desc.ElementByteStride * MaxAsteroidsInSubset; + mAsteroidsDataBuffers.resize(mNumSubsets); + for(Uint32 i=0; i < mNumSubsets; ++i) + { + mDevice->CreateBuffer(desc, nullptr, &mAsteroidsDataBuffers[i]); + } + } + } + else { BufferDesc desc; - desc.Name = "draw constant buffer (dynamic)"; - desc.Usage = USAGE_DYNAMIC; - desc.uiSizeInBytes = (Uint32) sizeof(DrawConstantBuffer); - desc.BindFlags = BIND_UNIFORM_BUFFER; + desc.Name = "Asteroids constant buffer"; + desc.Usage = USAGE_DYNAMIC; desc.CPUAccessFlags = CPU_ACCESS_WRITE; + desc.BindFlags = BIND_UNIFORM_BUFFER; + desc.uiSizeInBytes = (Uint32) sizeof(DrawConstantBuffer); mDevice->CreateBuffer(desc, nullptr, &mDrawConstantBuffer); Barriers.emplace_back(mDrawConstantBuffer, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_CONSTANT_BUFFER, true); } @@ -255,11 +288,12 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G LayoutElement inputDesc[] = { LayoutElement{ 0, 0, 3, VT_FLOAT32, false, 0, sizeof(Vertex)}, - LayoutElement{ 1, 0, 3, VT_FLOAT32} + LayoutElement{ 1, 0, 3, VT_FLOAT32}, + LayoutElement{ 2, 1, 1, VT_UINT32, False, LayoutElement::FREQUENCY_PER_INSTANCE} }; PSODesc.GraphicsPipeline.InputLayout.LayoutElements = inputDesc; - PSODesc.GraphicsPipeline.InputLayout.NumElements = _countof(inputDesc); + PSODesc.GraphicsPipeline.InputLayout.NumElements = (m_BindingMode == BindingMode::Bindless) ? 3 : 2; PSODesc.GraphicsPipeline.DepthStencilDesc.DepthFunc = COMPARISON_FUNC_GREATER_EQUAL; @@ -273,6 +307,11 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G attribs.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; attribs.pShaderSourceStreamFactory = pShaderSourceFactory; attribs.UseCombinedTextureSamplers = true; + + ShaderMacro Macros[] = {{"BINDLESS", "1"}, {}}; + if (m_BindingMode == BindingMode::Bindless) + attribs.Macros = Macros; + mDevice->CreateShader(attribs, &vs); } @@ -286,17 +325,11 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G attribs.UseCombinedTextureSamplers = true; attribs.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; - if(m_BindingMode == BindingMode::Bindless) - { - ShaderMacro Macros[] = {{"BINDLESS", "1"}, {}}; + ShaderMacro Macros[] = {{"BINDLESS", "1"}, {}}; + if (m_BindingMode == BindingMode::Bindless) attribs.Macros = Macros; - mDevice->CreateShader(attribs, &ps); - attribs.Macros = nullptr; - } - else - { - mDevice->CreateShader(attribs, &ps); - } + + mDevice->CreateShader(attribs, &ps); } StaticSamplerDesc samDesc; @@ -317,13 +350,16 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G PSODesc.ResourceLayout.StaticSamplers = &samDesc; PSODesc.ResourceLayout.NumStaticSamplers = 1; - ShaderResourceVariableDesc Variables[] = + std::vector Variables = { {SHADER_TYPE_PIXEL, "Tex", m_BindingMode == BindingMode::Dynamic ? SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC : SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} }; + if (m_BindingMode == BindingMode::Bindless) + Variables.emplace_back(SHADER_TYPE_VERTEX, "g_Data", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE); + PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; - PSODesc.ResourceLayout.Variables = Variables; - PSODesc.ResourceLayout.NumVariables = _countof(Variables); + PSODesc.ResourceLayout.Variables = Variables.data(); + PSODesc.ResourceLayout.NumVariables = static_cast(Variables.size()); PSODesc.GraphicsPipeline.RTVFormats[0] = mSwapChain->GetDesc().ColorBufferFormat; PSODesc.GraphicsPipeline.NumRenderTargets = 1; @@ -350,10 +386,11 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G } else if(m_BindingMode == BindingMode::Bindless) { - NumSRBs = 1; + NumSRBs = mNumSubsets; } mDevice->CreatePipelineState(PSODesc, &mAsteroidsPSO); - mAsteroidsPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "DrawConstantBuffer")->Set(mDrawConstantBuffer); + if (m_BindingMode != BindingMode::Bindless) + mAsteroidsPSO->GetStaticVariableByName(SHADER_TYPE_VERTEX, "DrawConstantBuffer")->Set(mDrawConstantBuffer); mAsteroidsSRBs.resize(NumSRBs); for(size_t srb = 0; srb < mAsteroidsSRBs.size(); ++srb) @@ -564,7 +601,11 @@ Asteroids::Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, G IDeviceObject* SRVArray[NUM_UNIQUE_TEXTURES]; for(Uint32 t = 0; t < NUM_UNIQUE_TEXTURES; ++t) SRVArray[t] = mTextureSRVs[t]; - mAsteroidsSRBs[0]->GetVariableByName(SHADER_TYPE_PIXEL, "Tex")->SetArray(SRVArray, 0, NUM_UNIQUE_TEXTURES); + for(Uint32 i = 0; i < mNumSubsets; ++i) + { + mAsteroidsSRBs[i]->GetVariableByName(SHADER_TYPE_PIXEL, "Tex")->SetArray(SRVArray, 0, NUM_UNIQUE_TEXTURES); + mAsteroidsSRBs[i]->GetVariableByName(SHADER_TYPE_VERTEX, "g_Data")->Set(mAsteroidsDataBuffers[i]->GetDefaultView(BUFFER_VIEW_SHADER_RESOURCE)); + } } mDeviceCtxt->TransitionResourceStates(static_cast(Barriers.size()), Barriers.data()); } @@ -790,24 +831,41 @@ void Asteroids::RenderSubset(Diligent::Uint32 SubsetNum, pCtx->SetPipelineState(mAsteroidsPSO); { - IBuffer* ia_buffers[] = { mVertexBuffer }; - Uint32 ia_offsets[] = { 0 }; - pCtx->SetVertexBuffers(0, 1, ia_buffers, ia_offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_NONE); + IBuffer* ia_buffers[] = { mVertexBuffer, mInstanceIDBuffer }; + Uint32 ia_offsets[_countof(ia_buffers)] = {}; + pCtx->SetVertexBuffers(0, (m_BindingMode == BindingMode::Bindless) ? 2 : 1, ia_buffers, ia_offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_NONE); pCtx->SetIndexBuffer(mIndexBuffer, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY); } - auto pVar = m_BindingMode == BindingMode::Dynamic ? mAsteroidsSRBs[SubsetNum]->GetVariableByName(SHADER_TYPE_PIXEL, "Tex") : nullptr; - if( m_BindingMode == BindingMode::Bindless) + auto viewProjection = camera.ViewProjection(); + + if (m_BindingMode == BindingMode::Bindless) { - pCtx->CommitShaderResources(mAsteroidsSRBs[0], RESOURCE_STATE_TRANSITION_MODE_VERIFY); + { + MapHelper drawConstants(pCtx, mAsteroidsDataBuffers[SubsetNum], MAP_WRITE, MAP_FLAG_DISCARD); + UINT i=0; + for (UINT drawIdx = startIdx; drawIdx < startIdx+numAsteroids; ++drawIdx, ++i) + { + const auto staticData = &staticAsteroidData[drawIdx]; + const auto dynamicData = &dynamicAsteroidData[drawIdx]; + + XMStoreFloat4x4(&drawConstants[i].mWorld, dynamicData->world); + XMStoreFloat4x4(&drawConstants[i].mViewProjection, viewProjection); + drawConstants[i].mSurfaceColor = staticData->surfaceColor; + drawConstants[i].mDeepColor = staticData->deepColor; + drawConstants[i].mTextureIndex = staticData->textureIndex; + } + } + pCtx->CommitShaderResources(mAsteroidsSRBs[SubsetNum], RESOURCE_STATE_TRANSITION_MODE_TRANSITION); } - - auto viewProjection = camera.ViewProjection(); + + auto pVar = m_BindingMode == BindingMode::Dynamic ? mAsteroidsSRBs[SubsetNum]->GetVariableByName(SHADER_TYPE_PIXEL, "Tex") : nullptr; for (UINT drawIdx = startIdx; drawIdx < startIdx+numAsteroids; ++drawIdx) { - auto staticData = &staticAsteroidData[drawIdx]; - auto dynamicData = &dynamicAsteroidData[drawIdx]; + const auto staticData = &staticAsteroidData[drawIdx]; + const auto dynamicData = &dynamicAsteroidData[drawIdx]; + if( m_BindingMode != BindingMode::Bindless ) { MapHelper drawConstants(pCtx, mDrawConstantBuffer, MAP_WRITE, MAP_FLAG_DISCARD); XMStoreFloat4x4(&drawConstants->mWorld, dynamicData->world); @@ -816,6 +874,7 @@ void Asteroids::RenderSubset(Diligent::Uint32 SubsetNum, drawConstants->mDeepColor = staticData->deepColor; drawConstants->mTextureIndex = staticData->textureIndex; } + if( m_BindingMode == BindingMode::Dynamic ) { pVar->Set(mTextureSRVs[staticData->textureIndex]); @@ -830,10 +889,11 @@ void Asteroids::RenderSubset(Diligent::Uint32 SubsetNum, pCtx->CommitShaderResources(mAsteroidsSRBs[staticData->textureIndex], RESOURCE_STATE_TRANSITION_MODE_VERIFY); } - DrawAttribs attribs(dynamicData->indexCount, VT_UINT16, DRAW_FLAG_VERIFY_ALL); + DrawIndexedAttribs attribs(dynamicData->indexCount, VT_UINT16, DRAW_FLAG_VERIFY_ALL); attribs.FirstIndexLocation = dynamicData->indexStart; attribs.BaseVertex = staticData->vertexStart; - pCtx->Draw(attribs); + attribs.FirstInstanceLocation = drawIdx - startIdx; + pCtx->DrawIndexed(attribs); } } @@ -853,7 +913,7 @@ void Asteroids::Render(float frameTime, const OrbitCamera& camera, const Setting QueryPerformanceCounter((LARGE_INTEGER*)&currCounter); mUpdateTicks = currCounter; - auto SubsetSize = NUM_ASTEROIDS / (settings.multithreadedRendering ? mNumSubsets : 1); + auto SubsetSize = NUM_ASTEROIDS / mNumSubsets; if (settings.multithreadedRendering) { @@ -861,7 +921,9 @@ void Asteroids::Render(float frameTime, const OrbitCamera& camera, const Setting mUpdateSubsetsSignal.Trigger(true); } - mAsteroids->Update(frameTime, camera.Eye(), settings, 0, SubsetSize); + + for(Uint32 i=0; i < (!settings.multithreadedRendering ? mNumSubsets : 1); ++i) + mAsteroids->Update(frameTime, camera.Eye(), settings, SubsetSize * i, SubsetSize); if (settings.multithreadedRendering) { @@ -885,7 +947,8 @@ void Asteroids::Render(float frameTime, const OrbitCamera& camera, const Setting mRenderSubsetsSignal.Trigger(true); } - RenderSubset(0, mDeviceCtxt, camera, 0, SubsetSize); + for(Uint32 i=0; i < (!settings.multithreadedRendering ? mNumSubsets : 1); ++i) + RenderSubset(i, mDeviceCtxt, camera, SubsetSize * i, SubsetSize); if (settings.multithreadedRendering) { diff --git a/Projects/Asteroids/src/asteroids_DE.h b/Projects/Asteroids/src/asteroids_DE.h index 60a56cc..2857ac0 100644 --- a/Projects/Asteroids/src/asteroids_DE.h +++ b/Projects/Asteroids/src/asteroids_DE.h @@ -83,6 +83,8 @@ private: Diligent::RefCntAutoPtr mIndexBuffer; Diligent::RefCntAutoPtr mVertexBuffer; + Diligent::RefCntAutoPtr mInstanceIDBuffer; + std::vector> mAsteroidsDataBuffers; Diligent::RefCntAutoPtr mDrawConstantBuffer; Diligent::RefCntAutoPtr mSpriteVertexBuffer; Diligent::RefCntAutoPtr mSkyboxConstantBuffer; diff --git a/Projects/Asteroids/src/shader_common.h b/Projects/Asteroids/src/shader_common.h new file mode 100644 index 0000000..ced6a70 --- /dev/null +++ b/Projects/Asteroids/src/shader_common.h @@ -0,0 +1,25 @@ +#ifndef SHADER_COMMON_H +#define SHADER_COMMON_H + +struct VSOut +{ + float3 positionModel : POSITIONMODEL; + float3 normalWorld : NORMAL; + float3 albedo : ALBEDO; + uint textureId : TEXTURE_ID; +}; + +struct AsteroidData +{ + float4x4 World; + float4x4 ViewProjection; + float4 SurfaceColor; + float4 DeepColor; + + uint TextureIndex; + uint Padding0; + uint Padding1; + uint Padding2; +}; + +#endif diff --git a/Tests/TestApp/assets/LuaTest.lua b/Tests/TestApp/assets/LuaTest.lua index 92c61ea..b4ffc48 100644 --- a/Tests/TestApp/assets/LuaTest.lua +++ b/Tests/TestApp/assets/LuaTest.lua @@ -613,7 +613,6 @@ end TestDrawAttribs = DrawAttribs.Create{ NumIndices = 128, IndexType = "VT_UINT16", - IsIndexed = true, NumInstances = 32, BaseVertex = 48, IndirectDrawArgsOffset = 1024, @@ -625,7 +624,6 @@ TestDrawAttribs = DrawAttribs.Create{ } assert( TestDrawAttribs.NumIndices == 128 ) assert( TestDrawAttribs.IndexType == "VT_UINT16" ) -assert( TestDrawAttribs.IsIndexed == true ) assert( TestDrawAttribs.NumInstances == 32 ) assert( TestDrawAttribs.BaseVertex == 48 ) assert( TestDrawAttribs.IndirectDrawArgsOffset == 1024 ) @@ -636,7 +634,6 @@ assert( TestDrawAttribs.FirstInstanceLocation == 96 ) TestDrawAttribs.NumVertices = 92 TestDrawAttribs.IndexType = "VT_UINT32" -TestDrawAttribs.IsIndexed = false TestDrawAttribs.NumInstances = 19 TestDrawAttribs.BaseVertex = 498 TestDrawAttribs.IndirectDrawArgsOffset = 234 @@ -653,7 +650,6 @@ assert( TestDrawAttribs.pIndirectDrawAttribs.Name == TestDrawAttribs2.pIndirectD assert( TestDrawAttribs.NumIndices == 92 ) assert( TestDrawAttribs.NumVertices == 92 ) assert( TestDrawAttribs.IndexType == "VT_UINT32" ) -assert( TestDrawAttribs.IsIndexed == false ) assert( TestDrawAttribs.NumInstances == 19 ) assert( TestDrawAttribs.BaseVertex == 498 ) assert( TestDrawAttribs.IndirectDrawArgsOffset == 234 ) @@ -667,7 +663,6 @@ assert( TestDrawAttribs.IndirectAttribsBufferStateTransitionMode == "RESOURCE_ST assert( TestGlobalDrawAttribs.NumVertices == 123 ); assert( TestGlobalDrawAttribs.NumIndices == 123 ); assert( TestGlobalDrawAttribs.IndexType == "VT_UINT16" ); -assert( TestGlobalDrawAttribs.IsIndexed == true ); assert( TestGlobalDrawAttribs.NumInstances == 19 ); assert( TestGlobalDrawAttribs.BaseVertex == 97 ); assert( TestGlobalDrawAttribs.IndirectDrawArgsOffset == 120 ); @@ -678,7 +673,6 @@ function TestDrawAttribsArg(DrawAttrs) assert( DrawAttrs.NumVertices == 34 ); assert( DrawAttrs.NumIndices == 34 ); assert( DrawAttrs.IndexType == "VT_UINT16" ); - assert( DrawAttrs.IsIndexed == true ); assert( DrawAttrs.NumInstances == 139 ); assert( DrawAttrs.BaseVertex == 937 ); assert( DrawAttrs.IndirectDrawArgsOffset == 1205 ); diff --git a/Tests/TestApp/assets/TestComputeShaders.lua b/Tests/TestApp/assets/TestComputeShaders.lua index f69805d..863c8a5 100644 --- a/Tests/TestApp/assets/TestComputeShaders.lua +++ b/Tests/TestApp/assets/TestComputeShaders.lua @@ -312,7 +312,6 @@ UpdateDispatchArgsBuffSRB:InitializeStaticResources() RenderSRB:InitializeStaticResources() DrawAttrs = DrawAttribs.Create{ - IsIndexed = true, IndexType = "VT_UINT32", pIndirectDrawAttribs = IndirectDrawArgsBuffer, IndirectAttribsBufferStateTransitionMode = "RESOURCE_STATE_TRANSITION_MODE_TRANSITION", diff --git a/Tests/TestApp/src/RenderScriptTest.cpp b/Tests/TestApp/src/RenderScriptTest.cpp index 00000bd..270be4a 100644 --- a/Tests/TestApp/src/RenderScriptTest.cpp +++ b/Tests/TestApp/src/RenderScriptTest.cpp @@ -119,10 +119,9 @@ RenderScriptTest::RenderScriptTest( IRenderDevice *pRenderDevice, IDeviceContext } { - DrawAttribs GlobalDrawAttribs; + ScriptParser::CombinedDrawAttribs GlobalDrawAttribs; GlobalDrawAttribs.NumVertices = 123; GlobalDrawAttribs.IndexType = VT_UINT16; - GlobalDrawAttribs.IsIndexed = True; GlobalDrawAttribs.NumInstances = 19; GlobalDrawAttribs.BaseVertex = 97; GlobalDrawAttribs.IndirectDrawArgsOffset = 120; @@ -330,15 +329,14 @@ RenderScriptTest::RenderScriptTest( IRenderDevice *pRenderDevice, IDeviceContext } { - DrawAttribs DrawAttribs; - DrawAttribs.NumVertices = 34; - DrawAttribs.IndexType = VT_UINT16; - DrawAttribs.IsIndexed = True; - DrawAttribs.NumInstances = 139; - DrawAttribs.BaseVertex = 937; - DrawAttribs.IndirectDrawArgsOffset = 1205; - DrawAttribs.StartVertexLocation = 198; - pScript->Run( "TestDrawAttribsArg", DrawAttribs ); + ScriptParser::CombinedDrawAttribs Attribs; + Attribs.NumVertices = 34; + Attribs.IndexType = VT_UINT16; + Attribs.NumInstances = 139; + Attribs.BaseVertex = 937; + Attribs.IndirectDrawArgsOffset = 1205; + Attribs.StartVertexLocation = 198; + pScript->Run( "TestDrawAttribsArg", Attribs ); } { diff --git a/Tests/TestApp/src/TestApp.cpp b/Tests/TestApp/src/TestApp.cpp index 9f6fc27..0a5e738 100644 --- a/Tests/TestApp/src/TestApp.cpp +++ b/Tests/TestApp/src/TestApp.cpp @@ -691,17 +691,19 @@ void TestApp::Render() UniformData[3] = 0; } - DrawAttribs DrawAttrs; - DrawAttrs.NumVertices = 3; - DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pRenderScript->Run(m_pImmediateContext, "DrawTris", DrawAttrs); - - DrawAttrs.IsIndexed = true; - DrawAttrs.NumIndices = 3; - DrawAttrs.IndexType = VT_UINT32; - DrawAttrs.NumInstances = 3; - DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pRenderScript->Run(m_pImmediateContext, "DrawTris", DrawAttrs); + { + DrawAttribs DrawAttrs{3, DRAW_FLAG_VERIFY_ALL}; + m_pRenderScript->Run(m_pImmediateContext, "DrawTris", DrawAttrs); + } + + { + DrawIndexedAttribs DrawAttrs{}; + DrawAttrs.NumIndices = 3; + DrawAttrs.IndexType = VT_UINT32; + DrawAttrs.NumInstances = 3; + DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; + m_pRenderScript->Run(m_pImmediateContext, "DrawTris", DrawAttrs); + } m_pTestDrawCommands->Draw(); m_pTestBufferAccess->Draw((float)dCurrTime); diff --git a/Tests/TestApp/src/TestDrawCommands.cpp b/Tests/TestApp/src/TestDrawCommands.cpp index 75919c8..a4641a6 100644 --- a/Tests/TestApp/src/TestDrawCommands.cpp +++ b/Tests/TestApp/src/TestDrawCommands.cpp @@ -348,16 +348,16 @@ void TestDrawCommands::Draw() // 0,1 { - DrawAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles - m_pDeviceContext->Draw(DrawAttrs); + DrawIndexedAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 2,3: test index buffer offset m_pDeviceContext->SetIndexBuffer( m_pIndexBuff, 2 * 3 * sizeof( Uint32 ), RESOURCE_STATE_TRANSITION_MODE_VERIFY ); { - DrawAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles - m_pDeviceContext->Draw(DrawAttrs); + DrawIndexedAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles + m_pDeviceContext->DrawIndexed(DrawAttrs); } NumTestTrianglesInRow[1] = 4; @@ -371,18 +371,18 @@ void TestDrawCommands::Draw() // 0,1 { - DrawAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles + DrawIndexedAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles DrawAttrs.BaseVertex = 10; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 2,3: index buffer offset & Base Vertex m_pDeviceContext->SetIndexBuffer( m_pIndexBuff, 2 * 3 * sizeof( Uint32 ), RESOURCE_STATE_TRANSITION_MODE_VERIFY ); { - DrawAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles + DrawIndexedAttribs DrawAttrs(2*3, VT_UINT32, DRAW_FLAG_VERIFY_ALL);// Draw 2 triangles DrawAttrs.BaseVertex = 10; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } NumTestTrianglesInRow[2] = 4; @@ -444,7 +444,7 @@ void TestDrawCommands::Draw() // 0,1 { DrawAttribs DrawAttrs; - DrawAttrs.NumIndices = 3; // Draw 1 triangle + DrawAttrs.NumVertices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.FirstInstanceLocation = 0; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; @@ -454,7 +454,7 @@ void TestDrawCommands::Draw() // 2,3 { DrawAttribs DrawAttrs; - DrawAttrs.NumIndices = 3; // Draw 1 triangle + DrawAttrs.NumVertices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.FirstInstanceLocation = 2; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; @@ -466,7 +466,7 @@ void TestDrawCommands::Draw() m_pDeviceContext->SetVertexBuffers(0, 2, pBuffs, Offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_RESET); { DrawAttribs DrawAttrs; - DrawAttrs.NumIndices = 3; // Draw 1 triangle + DrawAttrs.NumVertices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.FirstInstanceLocation = 2; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; @@ -478,7 +478,7 @@ void TestDrawCommands::Draw() m_pDeviceContext->SetVertexBuffers(0, 2, pBuffs, Offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_RESET); { DrawAttribs DrawAttrs; - DrawAttrs.NumIndices = 3; // Draw 1 triangle + DrawAttrs.NumVertices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.FirstInstanceLocation = 2; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; @@ -496,63 +496,58 @@ void TestDrawCommands::Draw() m_pDeviceContext->SetIndexBuffer(m_pIndexBuff, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY); // 0,1 { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 2,3: test index buffer offset m_pDeviceContext->SetIndexBuffer( m_pIndexBuff, 2 * 3 * sizeof( Uint32 ), RESOURCE_STATE_TRANSITION_MODE_VERIFY ); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 4,5: test vertex buffer offset Offsets[0] += 2*3 * Strides[0]; m_pDeviceContext->SetVertexBuffers(0, 2, pBuffs, Offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_RESET); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 6,7: test instance buffer offset Offsets[1] += 2 * Strides[1]; m_pDeviceContext->SetVertexBuffers(0, 2, pBuffs, Offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_RESET); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 8,9: test first index location { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.FirstIndexLocation = 2*3; - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } NumTestTrianglesInRow[5] = 10; @@ -567,64 +562,59 @@ void TestDrawCommands::Draw() m_pDeviceContext->SetIndexBuffer(m_pIndexBuff, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY); // 0,1 { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 2,3 { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.FirstInstanceLocation = 2; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 4,5: test index buffer offset m_pDeviceContext->SetIndexBuffer( m_pIndexBuff, 2 * 3 * sizeof( Uint32 ), RESOURCE_STATE_TRANSITION_MODE_VERIFY ); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.FirstInstanceLocation = 2; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 6,7: test instance buffer offset Offsets[1] += Strides[1] * 2; m_pDeviceContext->SetVertexBuffers(0, 2, pBuffs, Offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_RESET); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.FirstInstanceLocation = 2; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 8,9: test first index location { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.FirstInstanceLocation = 2; DrawAttrs.FirstIndexLocation = 2*3; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } NumTestTrianglesInRow[6] = 10; @@ -638,65 +628,60 @@ void TestDrawCommands::Draw() m_pDeviceContext->SetIndexBuffer(m_pIndexBuff, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY); // 0,1 { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 2,3 { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.BaseVertex = 2*3; - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 4,5: test index buffer offset m_pDeviceContext->SetIndexBuffer( m_pIndexBuff, 2 * 3 * sizeof( Uint32 ), RESOURCE_STATE_TRANSITION_MODE_VERIFY ); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.BaseVertex = 2*3; - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 6,7: test instance buffer offset Offsets[1] += Strides[1] * 2; m_pDeviceContext->SetVertexBuffers(0, 2, pBuffs, Offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_RESET); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.BaseVertex = 2*3; - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 8,9: Test first index location { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances DrawAttrs.BaseVertex = 2*3; - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.FirstIndexLocation = 2*3; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } NumTestTrianglesInRow[7] = 10; @@ -710,69 +695,64 @@ void TestDrawCommands::Draw() m_pDeviceContext->SetIndexBuffer(m_pIndexBuff, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY); // 0,1 { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 2,3 { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.BaseVertex = 3; DrawAttrs.FirstInstanceLocation = 1; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 4,5: test index buffer offset m_pDeviceContext->SetIndexBuffer( m_pIndexBuff, 2 * 3 * sizeof( Uint32 ), RESOURCE_STATE_TRANSITION_MODE_VERIFY ); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.BaseVertex = 3; DrawAttrs.FirstInstanceLocation = 1; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 6,7: test instance buffer offset Offsets[1] += Strides[1] * 2; m_pDeviceContext->SetVertexBuffers(0, 2, pBuffs, Offsets, RESOURCE_STATE_TRANSITION_MODE_VERIFY, SET_VERTEX_BUFFERS_FLAG_RESET); { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.BaseVertex = 3; DrawAttrs.FirstInstanceLocation = 1; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } // 8,9: test first index location { - DrawAttribs DrawAttrs; + DrawIndexedAttribs DrawAttrs; DrawAttrs.NumIndices = 3; // Draw 1 triangle DrawAttrs.NumInstances = 2; // Draw 2 instances - DrawAttrs.IsIndexed = true; DrawAttrs.BaseVertex = 3; DrawAttrs.FirstInstanceLocation = 1; DrawAttrs.IndexType = VT_UINT32; DrawAttrs.FirstIndexLocation = 2*3; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexed(DrawAttrs); } NumTestTrianglesInRow[8] = 10; @@ -796,8 +776,8 @@ void TestDrawCommands::Draw() MappedData[3] = 0; // Start instance MappedData.Unmap(); - DrawAttribs DrawAttrs(m_pIndirectDrawArgs, DRAW_FLAG_VERIFY_ALL, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - m_pDeviceContext->Draw(DrawAttrs); + DrawIndirectAttribs DrawAttrs(DRAW_FLAG_VERIFY_ALL, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + m_pDeviceContext->DrawIndirect(DrawAttrs, m_pIndirectDrawArgs); } // 2,3: test first vertex location @@ -808,8 +788,8 @@ void TestDrawCommands::Draw() MappedData[2] = 3*2; // Start vertex MappedData[3] = 0; // Start instance MappedData.Unmap(); - DrawAttribs DrawAttrs(m_pIndirectDrawArgs, DRAW_FLAG_VERIFY_ALL, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - m_pDeviceContext->Draw(DrawAttrs); + DrawIndirectAttribs DrawAttrs(DRAW_FLAG_VERIFY_ALL, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + m_pDeviceContext->DrawIndirect(DrawAttrs, m_pIndirectDrawArgs); } // 4,5: test first instance location @@ -820,11 +800,10 @@ void TestDrawCommands::Draw() MappedData[2] = 3*2; // Start vertex MappedData[3] = 2; // Start instance MappedData.Unmap(); - DrawAttribs DrawAttrs; - DrawAttrs.pIndirectDrawAttribs = m_pIndirectDrawArgs; + DrawIndirectAttribs DrawAttrs; DrawAttrs.IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_VERIFY; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndirect(DrawAttrs, m_pIndirectDrawArgs); } NumTestTrianglesInRow[9] = 6; @@ -849,8 +828,8 @@ void TestDrawCommands::Draw() MappedData[4] = 0; // Start instance MappedData.Unmap(); - DrawAttribs DrawAttrs(m_pIndexedIndirectDrawArgs, VT_UINT32, DRAW_FLAG_VERIFY_ALL, RESOURCE_STATE_TRANSITION_MODE_VERIFY); - m_pDeviceContext->Draw(DrawAttrs); + DrawIndexedIndirectAttribs DrawAttrs(VT_UINT32, DRAW_FLAG_VERIFY_ALL, RESOURCE_STATE_TRANSITION_MODE_VERIFY); + m_pDeviceContext->DrawIndexedIndirect(DrawAttrs, m_pIndexedIndirectDrawArgs); } // 2,3: test start index location @@ -863,13 +842,11 @@ void TestDrawCommands::Draw() MappedData[4] = 0; // Start instance MappedData.Unmap(); - DrawAttribs DrawAttrs; - DrawAttrs.IsIndexed = true; + DrawIndexedIndirectAttribs DrawAttrs; DrawAttrs.IndexType = VT_UINT32; - DrawAttrs.pIndirectDrawAttribs = m_pIndexedIndirectDrawArgs; DrawAttrs.IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_VERIFY; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexedIndirect(DrawAttrs, m_pIndexedIndirectDrawArgs); } // 4,5: test base vertex @@ -882,13 +859,11 @@ void TestDrawCommands::Draw() MappedData[4] = 0; // Start instance MappedData.Unmap(); - DrawAttribs DrawAttrs; - DrawAttrs.IsIndexed = true; + DrawIndexedIndirectAttribs DrawAttrs; DrawAttrs.IndexType = VT_UINT32; - DrawAttrs.pIndirectDrawAttribs = m_pIndexedIndirectDrawArgs; DrawAttrs.IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_VERIFY; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexedIndirect(DrawAttrs, m_pIndexedIndirectDrawArgs); } // 6,7: test start instance @@ -901,13 +876,11 @@ void TestDrawCommands::Draw() MappedData[4] = 2; // Start instance MappedData.Unmap(); - DrawAttribs DrawAttrs; - DrawAttrs.IsIndexed = true; + DrawIndexedIndirectAttribs DrawAttrs; DrawAttrs.IndexType = VT_UINT32; - DrawAttrs.pIndirectDrawAttribs = m_pIndexedIndirectDrawArgs; DrawAttrs.IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_VERIFY; DrawAttrs.Flags = DRAW_FLAG_VERIFY_ALL; - m_pDeviceContext->Draw(DrawAttrs); + m_pDeviceContext->DrawIndexedIndirect(DrawAttrs, m_pIndexedIndirectDrawArgs); } NumTestTrianglesInRow[10] = 8; } diff --git a/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp b/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp index af356c1..05321af 100644 --- a/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp +++ b/unityplugin/GhostCubePlugin/PluginSource/src/SamplePlugin.cpp @@ -166,6 +166,6 @@ void SamplePlugin::Render(Diligent::IDeviceContext *pContext, const float4x4 &Vi pContext->SetPipelineState(m_PSO); pContext->CommitShaderResources(m_SRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - DrawAttribs DrawAttrs(36, VT_UINT32, DRAW_FLAG_VERIFY_ALL); - pContext->Draw(DrawAttrs); + DrawIndexedAttribs DrawAttrs(36, VT_UINT32, DRAW_FLAG_VERIFY_ALL); + pContext->DrawIndexed(DrawAttrs); } -- cgit v1.2.3