adding D3D11 unit tests, removing raw HLSL support

This commit is contained in:
2025-09-12 00:54:15 +02:00
parent 6dd129cf35
commit 62beb8d316
27 changed files with 381 additions and 106 deletions

View File

@@ -10,15 +10,12 @@
#pragma comment(lib,"d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#ifndef PULSE_D3D11_COMPILER_UNAVAILABLE
#pragma comment(lib,"d3dcompiler.lib")
#endif
PulseBackendFlags Direct3D11CheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used)
{
if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_D3D11) == 0)
return PULSE_BACKEND_INVALID;
if((shader_formats_used & PULSE_SHADER_FORMAT_DXBC_BIT) == 0 && (shader_formats_used & PULSE_SHADER_FORMAT_HLSL_BIT) == 0)
if((shader_formats_used & PULSE_SHADER_FORMAT_DXBC_BIT) == 0)
return PULSE_BACKEND_INVALID;
return PULSE_BACKEND_D3D11;
}
@@ -62,6 +59,6 @@ PulseBackendHandler D3D11Driver = {
.PFN_UnloadBackend = Direct3D11UnloadBackend,
.PFN_CreateDevice = Direct3D11CreateDevice,
.backend = PULSE_BACKEND_D3D11,
.supported_shader_formats = PULSE_SHADER_FORMAT_DXBC_BIT | PULSE_SHADER_FORMAT_HLSL_BIT,
.supported_shader_formats = PULSE_SHADER_FORMAT_DXBC_BIT,
.driver_data = PULSE_NULLPTR
};

View File

@@ -7,55 +7,6 @@
#include "D3D11.h"
#include "D3D11Device.h"
#include "D3D11ComputePipeline.h"
#include <string.h>
#ifndef PULSE_D3D11_COMPILER_UNAVAILABLE
#include <d3dcompiler.h>
static HRESULT CompileComputeShader(PulseDevice device, const unsigned char* src, uint32_t src_size, const char* entry_point, ID3DBlob** blob)
{
if(!src || !entry_point || !device || !blob)
return E_INVALIDARG;
Direct3D11Device* d3d11_device = D3D11_RETRIEVE_DRIVER_DATA_AS(device, Direct3D11Device*);
*blob = PULSE_NULLPTR;
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(device->backend))
flags |= D3DCOMPILE_DEBUG;
// We generally prefer to use the higher CS shader profile when possible as CS 5.0 is better performance on 11-class hardware
LPCSTR profile = (ID3D11Device_GetFeatureLevel(d3d11_device->device) >= D3D_FEATURE_LEVEL_11_0) ? "cs_5_0" : "cs_4_0";
ID3DBlob* shader_blob = PULSE_NULLPTR;
ID3DBlob* error_blob = PULSE_NULLPTR;
HRESULT hr = D3DCompile(src, src_size, PULSE_NULLPTR, PULSE_NULLPTR, PULSE_NULLPTR, entry_point, profile, flags, 0, &shader_blob, &error_blob);
if(FAILED(hr))
{
if(error_blob)
{
if(PULSE_IS_BACKEND_LOW_LEVEL_DEBUG(device->backend))
PulseLogInfoFmt(device->backend, "(D3D11) failed to compile HLSL shader. %s", ID3D10Blob_GetBufferPointer(error_blob));
ID3D10Blob_Release(error_blob);
}
if(shader_blob)
ID3D10Blob_Release(shader_blob);
return hr;
}
*blob = shader_blob;
return hr;
}
#else
static HRESULT CompileComputeShader(PulseDevice device, const unsigned char* src, uint32_t src_size, const char* entry_point, ID3DBlob** blob)
{
if(PULSE_IS_BACKEND_LOW_LEVEL_DEBUG(device->backend))
PulseLogInfo(device->backend, "(D3D11) on-the-fly shader compilation is not available");
PulseSetInternalError(PULSE_ERROR_INITIALIZATION_FAILED);
return D3DERR_INVALIDCALL;
}
#endif
PulseComputePipeline Direct3D11CreateComputePipeline(PulseDevice device, const PulseComputePipelineCreateInfo* info)
{
@@ -69,25 +20,7 @@ PulseComputePipeline Direct3D11CreateComputePipeline(PulseDevice device, const P
pipeline->driver_data = d3d11_pipeline;
void* bytecode_data = PULSE_NULLPTR;
size_t bytecode_size;
if(info->format & PULSE_SHADER_FORMAT_HLSL_BIT)
{
ID3D10Blob* blob = PULSE_NULLPTR;
CHECK_D3D11_RETVAL(device->backend, CompileComputeShader(device, info->code, info->code_size, info->entrypoint, &blob), PULSE_ERROR_INITIALIZATION_FAILED, PULSE_NULL_HANDLE);
bytecode_size = ID3D10Blob_GetBufferSize(blob);
memcpy(bytecode_data, ID3D10Blob_GetBufferPointer(blob), bytecode_size);
ID3D10Blob_Release(blob);
}
if(bytecode_data == PULSE_NULLPTR)
{
bytecode_data = (void*)info->code;
bytecode_size = info->code_size;
}
CHECK_D3D11_RETVAL(device->backend, ID3D11Device_CreateComputeShader(d3d11_device->device, bytecode_data, bytecode_size, PULSE_NULLPTR, &d3d11_pipeline->shader), PULSE_ERROR_INITIALIZATION_FAILED, PULSE_NULL_HANDLE);;
CHECK_D3D11_RETVAL(device->backend, ID3D11Device_CreateComputeShader(d3d11_device->device, (void*)info->code, info->code_size, PULSE_NULLPTR, &d3d11_pipeline->shader), PULSE_ERROR_INITIALIZATION_FAILED, PULSE_NULL_HANDLE);;
if(PULSE_IS_BACKEND_HIGH_LEVEL_DEBUG(device->backend))
PulseLogInfoFmt(device->backend, "(D3D11) created new compute pipeline %p", pipeline);

View File

@@ -35,4 +35,7 @@ bool Direct3D11BlitImage(PulseCommandList cmd, const PulseImageRegion* src, cons
void Direct3D11DestroyImage(PulseDevice device, PulseImage image)
{
Direct3D11Image* d3d11_image = D3D11_RETRIEVE_DRIVER_DATA_AS(image, Direct3D11Image*);
free(d3d11_image);
free(image);
}