重构D3D12集成测试目录结构,每个测试独立子文件夹隔离资源
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(D3D12_Integration)
|
||||
|
||||
set(ENGINE_ROOT_DIR ${CMAKE_SOURCE_DIR}/../engine)
|
||||
set(ENGINE_ROOT_DIR ${CMAKE_SOURCE_DIR}/engine)
|
||||
|
||||
find_package(Python3 REQUIRED)
|
||||
|
||||
@@ -11,12 +11,11 @@ enable_testing()
|
||||
# Minimal test - just verifies initialization and render loop
|
||||
add_executable(D3D12_Minimal
|
||||
WIN32
|
||||
main_minimal.cpp
|
||||
minimal/main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(D3D12_Minimal PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/stbi
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/minimal
|
||||
${ENGINE_ROOT_DIR}/include
|
||||
)
|
||||
|
||||
@@ -25,12 +24,6 @@ target_compile_definitions(D3D12_Minimal PRIVATE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
target_include_directories(D3D12_Minimal PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${ENGINE_ROOT_DIR}/third_party
|
||||
${ENGINE_ROOT_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(D3D12_Minimal PRIVATE
|
||||
d3d12
|
||||
dxgi
|
||||
@@ -42,14 +35,13 @@ target_link_libraries(D3D12_Minimal PRIVATE
|
||||
# Render model test - complete rendering with model, shader, texture
|
||||
add_executable(D3D12_RenderModel
|
||||
WIN32
|
||||
main_render.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/stbi/stb_image.cpp
|
||||
render_model/main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(D3D12_RenderModel PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/stbi
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/render_model
|
||||
${ENGINE_ROOT_DIR}/include
|
||||
${ENGINE_ROOT_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(D3D12_RenderModel PRIVATE
|
||||
@@ -57,12 +49,6 @@ target_compile_definitions(D3D12_RenderModel PRIVATE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
target_include_directories(D3D12_RenderModel PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${ENGINE_ROOT_DIR}/third_party
|
||||
${ENGINE_ROOT_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(D3D12_RenderModel PRIVATE
|
||||
d3d12
|
||||
dxgi
|
||||
@@ -74,71 +60,58 @@ target_link_libraries(D3D12_RenderModel PRIVATE
|
||||
# Copy Res folder to output directory for Minimal test
|
||||
add_custom_command(TARGET D3D12_Minimal POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Res
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/Res
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/minimal/Res
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/Res
|
||||
)
|
||||
|
||||
# Copy Res folder to output directory for RenderModel test
|
||||
add_custom_command(TARGET D3D12_RenderModel POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Res
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/Res
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/render_model/Res
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/Res
|
||||
)
|
||||
|
||||
# Copy test scripts to output directory for Minimal test
|
||||
add_custom_command(TARGET D3D12_Minimal POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run.bat
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/run.bat
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/compare_ppm.py
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/compare_ppm.py
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GT.ppm
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/GT.ppm
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run_integration_test.py
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/
|
||||
)
|
||||
|
||||
# Copy test scripts to output directory for RenderModel test
|
||||
add_custom_command(TARGET D3D12_RenderModel POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run.bat
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/run.bat
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/compare_ppm.py
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/compare_ppm.py
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GT.ppm
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/GT.ppm
|
||||
)
|
||||
|
||||
# Copy run_integration_test.py to output directories
|
||||
add_custom_command(TARGET D3D12_Minimal POST_BUILD
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run_integration_test.py
|
||||
$<TARGET_FILE_DIR:D3D12_Minimal>/run_integration_test.py
|
||||
)
|
||||
|
||||
add_custom_command(TARGET D3D12_RenderModel POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run_integration_test.py
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/run_integration_test.py
|
||||
$<TARGET_FILE_DIR:D3D12_RenderModel>/
|
||||
)
|
||||
|
||||
# Register integration tests with CTest
|
||||
add_test(NAME D3D12_Minimal_Integration
|
||||
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/run_integration_test.py
|
||||
COMMAND ${Python3_EXECUTABLE} $<TARGET_FILE_DIR:D3D12_Minimal>/run_integration_test.py
|
||||
$<TARGET_FILE:D3D12_Minimal>
|
||||
minimal.ppm
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GT_minimal.ppm
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/minimal/GT_minimal.ppm
|
||||
5
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:D3D12_Minimal>
|
||||
)
|
||||
|
||||
add_test(NAME D3D12_RenderModel_Integration
|
||||
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/run_integration_test.py
|
||||
COMMAND ${Python3_EXECUTABLE} $<TARGET_FILE_DIR:D3D12_RenderModel>/run_integration_test.py
|
||||
$<TARGET_FILE:D3D12_RenderModel>
|
||||
screenshot.ppm
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GT.ppm
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/render_model/GT.ppm
|
||||
5
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:D3D12_RenderModel>
|
||||
)
|
||||
|
||||
|
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 189 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
99
tests/RHI/D3D12/integration/render_model/Res/Shader/gs.hlsl
Normal file
99
tests/RHI/D3D12/integration/render_model/Res/Shader/gs.hlsl
Normal file
@@ -0,0 +1,99 @@
|
||||
struct VertexData{
|
||||
float4 position:POSITION;
|
||||
float4 texcoord:TEXCOORD0;
|
||||
float4 normal:NORMAL;
|
||||
float4 tangent:TANGENT;
|
||||
};
|
||||
|
||||
struct VSOut{
|
||||
float4 position:SV_POSITION;
|
||||
float4 normal:NORMAL;
|
||||
float4 texcoord:TEXCOORD0;
|
||||
};
|
||||
|
||||
static const float PI=3.141592;
|
||||
cbuffer globalConstants:register(b0){
|
||||
float4 misc;
|
||||
};
|
||||
|
||||
Texture2D T_DiffuseTexture:register(t0);
|
||||
SamplerState samplerState:register(s0);
|
||||
|
||||
struct MaterialData{
|
||||
float r;
|
||||
};
|
||||
StructuredBuffer<MaterialData> materialData:register(t0,space1);
|
||||
cbuffer DefaultVertexCB:register(b1){
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 ViewMatrix;
|
||||
float4x4 ModelMatrix;
|
||||
float4x4 IT_ModelMatrix;
|
||||
float4x4 ReservedMemory[1020];
|
||||
};
|
||||
|
||||
VSOut MainVS(VertexData inVertexData){
|
||||
VSOut vo;
|
||||
vo.normal=mul(IT_ModelMatrix,inVertexData.normal);
|
||||
float4 positionWS=mul(ModelMatrix,inVertexData.position);
|
||||
float4 positionVS=mul(ViewMatrix,positionWS);
|
||||
vo.position=mul(ProjectionMatrix,positionVS);
|
||||
//vo.position=float4(positionWS.xyz+vo.normal.xyz*sin(misc.x)*0.2f,1.0f);
|
||||
vo.texcoord=inVertexData.texcoord;
|
||||
return vo;
|
||||
}
|
||||
|
||||
[maxvertexcount(4)]
|
||||
void MainGS(triangle VSOut inPoint[3],uint inPrimitiveID:SV_PrimitiveID,
|
||||
inout TriangleStream<VSOut> outTriangleStream){
|
||||
outTriangleStream.Append(inPoint[0]);
|
||||
outTriangleStream.Append(inPoint[1]);
|
||||
outTriangleStream.Append(inPoint[2]);
|
||||
/*VSOut vo;
|
||||
float3 positionWS=inPoint[0].position.xyz;
|
||||
float3 N=normalize(inPoint[0].normal.xyz);
|
||||
vo.normal=float4(N,0.0f);
|
||||
float3 helperVec=abs(N.y)>0.999?float3(0.0f,0.0f,1.0f):float3(0.0f,1.0f,0.0f);
|
||||
float3 tangent=normalize(cross(N,helperVec));//u
|
||||
float3 bitangent=normalize(cross(tangent,N));//v
|
||||
float scale=materialData[inPrimitiveID].r;
|
||||
|
||||
|
||||
float3 p0WS=positionWS-(bitangent*0.5f-tangent*0.5f)*scale;//left bottom
|
||||
float4 p0VS=mul(ViewMatrix,float4(p0WS,1.0f));
|
||||
vo.position=mul(ProjectionMatrix,p0VS);
|
||||
vo.texcoord=float4(0.0f,1.0f,0.0f,0.0f);
|
||||
outTriangleStream.Append(vo);
|
||||
|
||||
float3 p1WS=positionWS-(bitangent*0.5f+tangent*0.5f)*scale;//right bottom
|
||||
float4 p1VS=mul(ViewMatrix,float4(p1WS,1.0f));
|
||||
vo.position=mul(ProjectionMatrix,p1VS);
|
||||
vo.texcoord=float4(1.0f,1.0f,0.0f,0.0f);
|
||||
outTriangleStream.Append(vo);
|
||||
|
||||
float3 p2WS=positionWS+(bitangent*0.5f+tangent*0.5f)*scale;//left top
|
||||
float4 p2VS=mul(ViewMatrix,float4(p2WS,1.0f));
|
||||
vo.position=mul(ProjectionMatrix,p2VS);
|
||||
vo.texcoord=float4(0.0f,0.0f,0.0f,0.0f);
|
||||
outTriangleStream.Append(vo);
|
||||
|
||||
float3 p3WS=positionWS+(bitangent*0.5f-tangent*0.5f)*scale;//right top
|
||||
float4 p3VS=mul(ViewMatrix,float4(p3WS,1.0f));
|
||||
vo.position=mul(ProjectionMatrix,p3VS);
|
||||
vo.texcoord=float4(1.0f,0.0f,0.0f,0.0f);
|
||||
outTriangleStream.Append(vo);*/
|
||||
|
||||
}
|
||||
|
||||
float4 MainPS(VSOut inPSInput):SV_TARGET{
|
||||
float3 N=normalize(inPSInput.normal.xyz);
|
||||
float3 bottomColor=float3(0.1f,0.4f,0.6f);
|
||||
float3 topColor=float3(0.7f,0.7f,0.7f);
|
||||
float theta=asin(N.y);//-PI/2 ~ PI/2
|
||||
theta/=PI;//-0.5~0.5
|
||||
theta+=0.5f;//0.0~1.0
|
||||
float ambientColorIntensity=1.0;
|
||||
float3 ambientColor=lerp(bottomColor,topColor,theta)*ambientColorIntensity;
|
||||
float4 diffuseColor=T_DiffuseTexture.Sample(samplerState,inPSInput.texcoord.xy);
|
||||
float3 surfaceColor=diffuseColor.rgb;
|
||||
return float4(surfaceColor,1.0f);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
struct VertexData{
|
||||
float4 position:POSITION;
|
||||
float4 texcoord:TEXCOORD0;
|
||||
float4 normal:NORMAL;
|
||||
float4 tangent:TANGENT;
|
||||
};
|
||||
|
||||
struct VSOut{
|
||||
float4 position:SV_POSITION;
|
||||
float4 normal:NORMAL;
|
||||
float4 texcoord:TEXCOORD0;
|
||||
float4 positionWS:TEXCOORD1;
|
||||
};
|
||||
|
||||
static const float PI=3.141592;
|
||||
cbuffer globalConstants:register(b0){
|
||||
float4 misc;
|
||||
};
|
||||
|
||||
cbuffer DefaultVertexCB:register(b1){
|
||||
float4x4 ProjectionMatrix;
|
||||
float4x4 ViewMatrix;
|
||||
float4x4 ModelMatrix;
|
||||
float4x4 IT_ModelMatrix;
|
||||
float4x4 ReservedMemory[1020];
|
||||
};
|
||||
|
||||
VSOut MainVS(VertexData inVertexData){
|
||||
VSOut vo;
|
||||
vo.normal=mul(IT_ModelMatrix,inVertexData.normal);
|
||||
float3 positionMS=inVertexData.position.xyz+vo.normal*sin(misc.x);
|
||||
float4 positionWS=mul(ModelMatrix,float4(positionMS,1.0));
|
||||
float4 positionVS=mul(ViewMatrix,positionWS);
|
||||
vo.position=mul(ProjectionMatrix,positionVS);
|
||||
vo.positionWS=positionWS;
|
||||
vo.texcoord=inVertexData.texcoord;
|
||||
return vo;
|
||||
}
|
||||
|
||||
float4 MainPS(VSOut inPSInput):SV_TARGET{
|
||||
float3 N=normalize(inPSInput.normal.xyz);
|
||||
float3 bottomColor=float3(0.1f,0.4f,0.6f);
|
||||
float3 topColor=float3(0.7f,0.7f,0.7f);
|
||||
float theta=asin(N.y);//-PI/2 ~ PI/2
|
||||
theta/=PI;//-0.5~0.5
|
||||
theta+=0.5f;//0.0~1.0
|
||||
float ambientColorIntensity=0.2;
|
||||
float3 ambientColor=lerp(bottomColor,topColor,theta)*ambientColorIntensity;
|
||||
float3 L=normalize(float3(1.0f,1.0f,-1.0f));
|
||||
|
||||
float diffuseIntensity=max(0.0f,dot(N,L));
|
||||
float3 diffuseLightColor=float3(0.1f,0.4f,0.6f);
|
||||
float3 diffuseColor=diffuseLightColor*diffuseIntensity;
|
||||
|
||||
float3 specularColor=float3(0.0f,0.0f,0.0f);
|
||||
if(diffuseIntensity>0.0f){
|
||||
float3 cameraPositionWS=float3(0.0f,0.0f,0.0f);
|
||||
float3 V=normalize(cameraPositionWS.xyz-inPSInput.positionWS.xyz);
|
||||
float3 R=normalize(reflect(-L,N));
|
||||
float specularIntensity=pow(max(0.0f,dot(V,R)),128.0f);
|
||||
specularColor=float3(1.0f,1.0f,1.0f)*specularIntensity;
|
||||
}
|
||||
float3 surfaceColor=ambientColor+diffuseColor+specularColor;
|
||||
return float4(surfaceColor,1.0f);
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "XCEngine/Debug/ConsoleLogSink.h"
|
||||
#include "XCEngine/Debug/FileLogSink.h"
|
||||
#include "XCEngine/Containers/String.h"
|
||||
#include "stbi/stb_image.h"
|
||||
#include "third_party/stb/stb_image.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
using namespace XCEngine::Debug;
|
||||
@@ -1,2 +0,0 @@
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user