dzn: use dxil_validator
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15751>
This commit is contained in:

committed by
Marge Bot

parent
0c5d772b71
commit
09c2016d6b
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#include "glsl_types.h"
|
#include "glsl_types.h"
|
||||||
|
|
||||||
|
#include "dxil_validator.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -126,14 +128,8 @@ dzn_instance_destroy(dzn_instance *instance, const VkAllocationCallbacks *alloc)
|
|||||||
if (!instance)
|
if (!instance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (instance->dxc.validator)
|
if (instance->dxil_validator)
|
||||||
instance->dxc.validator->Release();
|
dxil_destroy_validator(instance->dxil_validator);
|
||||||
|
|
||||||
if (instance->dxc.library)
|
|
||||||
instance->dxc.library->Release();
|
|
||||||
|
|
||||||
if (instance->dxc.compiler)
|
|
||||||
instance->dxc.compiler->Release();
|
|
||||||
|
|
||||||
list_for_each_entry_safe(dzn_physical_device, pdev,
|
list_for_each_entry_safe(dzn_physical_device, pdev,
|
||||||
&instance->physical_devices, link) {
|
&instance->physical_devices, link) {
|
||||||
@@ -174,14 +170,10 @@ dzn_instance_create(const VkInstanceCreateInfo *pCreateInfo,
|
|||||||
instance->debug_flags =
|
instance->debug_flags =
|
||||||
parse_debug_string(getenv("DZN_DEBUG"), dzn_debug_options);
|
parse_debug_string(getenv("DZN_DEBUG"), dzn_debug_options);
|
||||||
|
|
||||||
instance->dxc.validator = dxil_get_validator();
|
instance->dxil_validator = dxil_create_validator(instance);
|
||||||
instance->dxc.library = dxc_get_library();
|
|
||||||
instance->dxc.compiler = dxc_get_compiler();
|
|
||||||
instance->d3d12.serialize_root_sig = d3d12_get_serialize_root_sig();
|
instance->d3d12.serialize_root_sig = d3d12_get_serialize_root_sig();
|
||||||
|
|
||||||
if (!instance->dxc.validator ||
|
if (!instance->dxil_validator ||
|
||||||
!instance->dxc.library ||
|
|
||||||
!instance->dxc.compiler ||
|
|
||||||
!instance->d3d12.serialize_root_sig) {
|
!instance->d3d12.serialize_root_sig) {
|
||||||
dzn_instance_destroy(instance, pAllocator);
|
dzn_instance_destroy(instance, pAllocator);
|
||||||
return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED);
|
return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED);
|
||||||
@@ -478,7 +470,7 @@ dzn_physical_device_get_d3d12_dev(dzn_physical_device *pdev)
|
|||||||
|
|
||||||
mtx_lock(&pdev->dev_lock);
|
mtx_lock(&pdev->dev_lock);
|
||||||
if (!pdev->dev) {
|
if (!pdev->dev) {
|
||||||
pdev->dev = d3d12_create_device(pdev->adapter, instance->dxc.validator == nullptr);
|
pdev->dev = d3d12_create_device(pdev->adapter, !instance->dxil_validator);
|
||||||
|
|
||||||
dzn_physical_device_cache_caps(pdev);
|
dzn_physical_device_cache_caps(pdev);
|
||||||
dzn_physical_device_init_memory(pdev);
|
dzn_physical_device_init_memory(pdev);
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "dxil_nir.h"
|
#include "dxil_nir.h"
|
||||||
#include "dxil_nir_lower_int_samplers.h"
|
#include "dxil_nir_lower_int_samplers.h"
|
||||||
|
#include "dxil_validator.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dzn_meta_compile_shader(dzn_device *device, nir_shader *nir,
|
dzn_meta_compile_shader(dzn_device *device, nir_shader *nir,
|
||||||
@@ -35,9 +36,6 @@ dzn_meta_compile_shader(dzn_device *device, nir_shader *nir,
|
|||||||
{
|
{
|
||||||
dzn_instance *instance =
|
dzn_instance *instance =
|
||||||
container_of(device->vk.physical->instance, dzn_instance, vk);
|
container_of(device->vk.physical->instance, dzn_instance, vk);
|
||||||
IDxcValidator *validator = instance->dxc.validator;
|
|
||||||
IDxcLibrary *library = instance->dxc.library;
|
|
||||||
IDxcCompiler *compiler = instance->dxc.compiler;
|
|
||||||
|
|
||||||
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
|
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
|
||||||
|
|
||||||
@@ -50,47 +48,37 @@ dzn_meta_compile_shader(dzn_device *device, nir_shader *nir,
|
|||||||
bool ret = nir_to_dxil(nir, &opts, &dxil_blob);
|
bool ret = nir_to_dxil(nir, &opts, &dxil_blob);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
dzn_shader_blob blob(dxil_blob.data, dxil_blob.size);
|
char *err;
|
||||||
ComPtr<IDxcOperationResult> result;
|
bool res = dxil_validate_module(instance->dxil_validator,
|
||||||
validator->Validate(&blob, DxcValidatorFlags_InPlaceEdit, &result);
|
dxil_blob.data,
|
||||||
|
dxil_blob.size, &err);
|
||||||
|
|
||||||
if ((instance->debug_flags & DZN_DEBUG_DXIL) &&
|
if ((instance->debug_flags & DZN_DEBUG_DXIL) &&
|
||||||
(instance->debug_flags & DZN_DEBUG_INTERNAL)) {
|
(instance->debug_flags & DZN_DEBUG_INTERNAL)) {
|
||||||
IDxcBlobEncoding *disassembly;
|
char *disasm = dxil_disasm_module(instance->dxil_validator,
|
||||||
compiler->Disassemble(&blob, &disassembly);
|
dxil_blob.data,
|
||||||
ComPtr<IDxcBlobEncoding> blobUtf8;
|
dxil_blob.size);
|
||||||
library->GetBlobAsUtf8(disassembly, blobUtf8.GetAddressOf());
|
if (disasm) {
|
||||||
char *disasm = reinterpret_cast<char*>(blobUtf8->GetBufferPointer());
|
fprintf(stderr,
|
||||||
disasm[blobUtf8->GetBufferSize() - 1] = 0;
|
"== BEGIN SHADER ============================================\n"
|
||||||
fprintf(stderr,
|
"%s\n"
|
||||||
"== BEGIN SHADER ============================================\n"
|
"== END SHADER ==============================================\n",
|
||||||
"%s\n"
|
disasm);
|
||||||
"== END SHADER ==============================================\n",
|
ralloc_free(disasm);
|
||||||
disasm);
|
|
||||||
disassembly->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT validationStatus;
|
|
||||||
result->GetStatus(&validationStatus);
|
|
||||||
if (FAILED(validationStatus)) {
|
|
||||||
if ((instance->debug_flags & DZN_DEBUG_DXIL) &&
|
|
||||||
(instance->debug_flags & DZN_DEBUG_INTERNAL)) {
|
|
||||||
ComPtr<IDxcBlobEncoding> printBlob, printBlobUtf8;
|
|
||||||
result->GetErrorBuffer(&printBlob);
|
|
||||||
library->GetBlobAsUtf8(printBlob.Get(), printBlobUtf8.GetAddressOf());
|
|
||||||
|
|
||||||
char *errorString;
|
|
||||||
if (printBlobUtf8) {
|
|
||||||
errorString = reinterpret_cast<char*>(printBlobUtf8->GetBufferPointer());
|
|
||||||
errorString[printBlobUtf8->GetBufferSize() - 1] = 0;
|
|
||||||
fprintf(stderr,
|
|
||||||
"== VALIDATION ERROR =============================================\n"
|
|
||||||
"%s\n"
|
|
||||||
"== END ==========================================================\n",
|
|
||||||
errorString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(!FAILED(validationStatus));
|
|
||||||
|
if ((instance->debug_flags & DZN_DEBUG_DXIL) &&
|
||||||
|
(instance->debug_flags & DZN_DEBUG_INTERNAL) &&
|
||||||
|
err) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"== VALIDATION ERROR =============================================\n"
|
||||||
|
"%s\n"
|
||||||
|
"== END ==========================================================\n",
|
||||||
|
err);
|
||||||
|
ralloc_free(err);
|
||||||
|
}
|
||||||
|
assert(res);
|
||||||
|
|
||||||
void *data;
|
void *data;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "spirv_to_dxil.h"
|
#include "spirv_to_dxil.h"
|
||||||
|
|
||||||
|
#include "dxil_validator.h"
|
||||||
|
|
||||||
#include "vk_alloc.h"
|
#include "vk_alloc.h"
|
||||||
#include "vk_util.h"
|
#include "vk_util.h"
|
||||||
#include "vk_format.h"
|
#include "vk_format.h"
|
||||||
@@ -32,13 +34,8 @@
|
|||||||
#include <directx/d3d12.h>
|
#include <directx/d3d12.h>
|
||||||
#include <dxguids/dxguids.h>
|
#include <dxguids/dxguids.h>
|
||||||
|
|
||||||
#include <dxcapi.h>
|
|
||||||
#include <wrl/client.h>
|
|
||||||
|
|
||||||
#include "util/u_debug.h"
|
#include "util/u_debug.h"
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
|
||||||
|
|
||||||
static dxil_spirv_shader_stage
|
static dxil_spirv_shader_stage
|
||||||
to_dxil_shader_stage(VkShaderStageFlagBits in)
|
to_dxil_shader_stage(VkShaderStageFlagBits in)
|
||||||
{
|
{
|
||||||
@@ -64,9 +61,6 @@ dzn_pipeline_compile_shader(dzn_device *device,
|
|||||||
{
|
{
|
||||||
dzn_instance *instance =
|
dzn_instance *instance =
|
||||||
container_of(device->vk.physical->instance, dzn_instance, vk);
|
container_of(device->vk.physical->instance, dzn_instance, vk);
|
||||||
IDxcValidator *validator = instance->dxc.validator;
|
|
||||||
IDxcLibrary *library = instance->dxc.library;
|
|
||||||
IDxcCompiler *compiler = instance->dxc.compiler;
|
|
||||||
const VkSpecializationInfo *spec_info = stage_info->pSpecializationInfo;
|
const VkSpecializationInfo *spec_info = stage_info->pSpecializationInfo;
|
||||||
VK_FROM_HANDLE(vk_shader_module, module, stage_info->module);
|
VK_FROM_HANDLE(vk_shader_module, module, stage_info->module);
|
||||||
struct dxil_spirv_object dxil_object;
|
struct dxil_spirv_object dxil_object;
|
||||||
@@ -148,45 +142,34 @@ dzn_pipeline_compile_shader(dzn_device *device,
|
|||||||
if (!success)
|
if (!success)
|
||||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
|
||||||
dzn_shader_blob blob(dxil_object.binary.buffer, dxil_object.binary.size);
|
char *err;
|
||||||
ComPtr<IDxcOperationResult> result;
|
bool res = dxil_validate_module(instance->dxil_validator,
|
||||||
validator->Validate(&blob, DxcValidatorFlags_InPlaceEdit, &result);
|
dxil_object.binary.buffer,
|
||||||
|
dxil_object.binary.size, &err);
|
||||||
|
|
||||||
if (instance->debug_flags & DZN_DEBUG_DXIL) {
|
if (instance->debug_flags & DZN_DEBUG_DXIL) {
|
||||||
IDxcBlobEncoding *disassembly;
|
char *disasm = dxil_disasm_module(instance->dxil_validator,
|
||||||
compiler->Disassemble(&blob, &disassembly);
|
dxil_object.binary.buffer,
|
||||||
ComPtr<IDxcBlobEncoding> blobUtf8;
|
dxil_object.binary.size);
|
||||||
library->GetBlobAsUtf8(disassembly, blobUtf8.GetAddressOf());
|
if (disasm) {
|
||||||
char *disasm = reinterpret_cast<char*>(blobUtf8->GetBufferPointer());
|
fprintf(stderr,
|
||||||
disasm[blobUtf8->GetBufferSize() - 1] = 0;
|
"== BEGIN SHADER ============================================\n"
|
||||||
fprintf(stderr, "== BEGIN SHADER ============================================\n"
|
"%s\n"
|
||||||
"%s\n"
|
"== END SHADER ==============================================\n",
|
||||||
"== END SHADER ==============================================\n",
|
disasm);
|
||||||
disasm);
|
ralloc_free(disasm);
|
||||||
disassembly->Release();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT validationStatus;
|
if (!res) {
|
||||||
result->GetStatus(&validationStatus);
|
if (err) {
|
||||||
if (FAILED(validationStatus)) {
|
fprintf(stderr,
|
||||||
if (instance->debug_flags & DZN_DEBUG_DXIL) {
|
"== VALIDATION ERROR =============================================\n"
|
||||||
ComPtr<IDxcBlobEncoding> printBlob, printBlobUtf8;
|
"%s\n"
|
||||||
result->GetErrorBuffer(&printBlob);
|
"== END ==========================================================\n",
|
||||||
library->GetBlobAsUtf8(printBlob.Get(), printBlobUtf8.GetAddressOf());
|
err);
|
||||||
|
ralloc_free(err);
|
||||||
char *errorString;
|
|
||||||
if (printBlobUtf8) {
|
|
||||||
errorString = reinterpret_cast<char*>(printBlobUtf8->GetBufferPointer());
|
|
||||||
|
|
||||||
errorString[printBlobUtf8->GetBufferSize() - 1] = 0;
|
|
||||||
fprintf(stderr,
|
|
||||||
"== VALIDATION ERROR =============================================\n"
|
|
||||||
"%s\n"
|
|
||||||
"== END ==========================================================\n",
|
|
||||||
errorString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,7 +55,6 @@
|
|||||||
|
|
||||||
#define D3D12_IGNORE_SDK_LAYERS
|
#define D3D12_IGNORE_SDK_LAYERS
|
||||||
#include <directx/d3d12.h>
|
#include <directx/d3d12.h>
|
||||||
#include <dxcapi.h>
|
|
||||||
#include <wrl/client.h>
|
#include <wrl/client.h>
|
||||||
|
|
||||||
#include "spirv_to_dxil.h"
|
#include "spirv_to_dxil.h"
|
||||||
@@ -71,6 +70,8 @@ using Microsoft::WRL::ComPtr;
|
|||||||
|
|
||||||
#define dzn_stub() unreachable("Unsupported feature")
|
#define dzn_stub() unreachable("Unsupported feature")
|
||||||
|
|
||||||
|
struct dxil_validator;
|
||||||
|
|
||||||
struct dzn_instance;
|
struct dzn_instance;
|
||||||
struct dzn_device;
|
struct dzn_device;
|
||||||
|
|
||||||
@@ -217,15 +218,6 @@ dzn_physical_device_get_mem_type_mask_for_resource(const dzn_physical_device *pd
|
|||||||
IDXGIFactory4 *
|
IDXGIFactory4 *
|
||||||
dxgi_get_factory(bool debug);
|
dxgi_get_factory(bool debug);
|
||||||
|
|
||||||
IDxcValidator *
|
|
||||||
dxil_get_validator(void);
|
|
||||||
|
|
||||||
IDxcLibrary *
|
|
||||||
dxc_get_library(void);
|
|
||||||
|
|
||||||
IDxcCompiler *
|
|
||||||
dxc_get_compiler(void);
|
|
||||||
|
|
||||||
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
|
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
|
||||||
d3d12_get_serialize_root_sig(void);
|
d3d12_get_serialize_root_sig(void);
|
||||||
|
|
||||||
@@ -675,24 +667,6 @@ enum dzn_register_space {
|
|||||||
DZN_REGISTER_SPACE_PUSH_CONSTANT,
|
DZN_REGISTER_SPACE_PUSH_CONSTANT,
|
||||||
};
|
};
|
||||||
|
|
||||||
class dzn_shader_blob : public IDxcBlob {
|
|
||||||
public:
|
|
||||||
dzn_shader_blob(void *buf, size_t sz) : data(buf), size(sz) {}
|
|
||||||
|
|
||||||
LPVOID STDMETHODCALLTYPE GetBufferPointer(void) override { return data; }
|
|
||||||
|
|
||||||
SIZE_T STDMETHODCALLTYPE GetBufferSize() override { return size; }
|
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**) override { return E_NOINTERFACE; }
|
|
||||||
|
|
||||||
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
|
|
||||||
|
|
||||||
ULONG STDMETHODCALLTYPE Release() override { return 0; }
|
|
||||||
|
|
||||||
void *data;
|
|
||||||
size_t size;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dzn_pipeline {
|
struct dzn_pipeline {
|
||||||
struct vk_object_base base;
|
struct vk_object_base base;
|
||||||
VkPipelineBindPoint type;
|
VkPipelineBindPoint type;
|
||||||
@@ -966,11 +940,7 @@ enum dzn_debug_flags {
|
|||||||
struct dzn_instance {
|
struct dzn_instance {
|
||||||
struct vk_instance vk;
|
struct vk_instance vk;
|
||||||
|
|
||||||
struct {
|
struct dxil_validator *dxil_validator;
|
||||||
IDxcValidator *validator;
|
|
||||||
IDxcLibrary *library;
|
|
||||||
IDxcCompiler *compiler;
|
|
||||||
} dxc;
|
|
||||||
struct {
|
struct {
|
||||||
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE serialize_root_sig;
|
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE serialize_root_sig;
|
||||||
} d3d12;
|
} d3d12;
|
||||||
|
@@ -152,26 +152,6 @@ d3d12_create_device(IUnknown *adapter, bool experimental_features)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDxcValidator *
|
|
||||||
dxil_get_validator(void)
|
|
||||||
{
|
|
||||||
IDxcValidator *ret = NULL;
|
|
||||||
|
|
||||||
HMODULE dxil_mod = LoadLibraryA("dxil.dll");
|
|
||||||
if (!dxil_mod) {
|
|
||||||
mesa_loge("failed to load dxil.dll\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
DxcCreateInstanceProc CreateInstance = (DxcCreateInstanceProc)
|
|
||||||
GetProcAddress(dxil_mod, "DxcCreateInstance");
|
|
||||||
HRESULT hr = CreateInstance(CLSID_DxcValidator, IID_PPV_ARGS(&ret));
|
|
||||||
if (FAILED(hr))
|
|
||||||
mesa_loge("DxcCreateInstance failed: %08x\n", hr);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
|
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
|
||||||
d3d12_get_serialize_root_sig(void)
|
d3d12_get_serialize_root_sig(void)
|
||||||
{
|
{
|
||||||
@@ -184,43 +164,3 @@ d3d12_get_serialize_root_sig(void)
|
|||||||
return (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)
|
return (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)
|
||||||
GetProcAddress(d3d12_mod, "D3D12SerializeVersionedRootSignature");
|
GetProcAddress(d3d12_mod, "D3D12SerializeVersionedRootSignature");
|
||||||
}
|
}
|
||||||
|
|
||||||
IDxcLibrary *
|
|
||||||
dxc_get_library(void)
|
|
||||||
{
|
|
||||||
IDxcLibrary *ret = NULL;
|
|
||||||
|
|
||||||
HMODULE dxil_mod = LoadLibraryA("dxcompiler.dll");
|
|
||||||
if (!dxil_mod) {
|
|
||||||
mesa_loge("failed to load dxcompiler.dll\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
DxcCreateInstanceProc CreateInstance = (DxcCreateInstanceProc)
|
|
||||||
GetProcAddress(dxil_mod, "DxcCreateInstance");
|
|
||||||
HRESULT hr = CreateInstance(CLSID_DxcLibrary, IID_PPV_ARGS(&ret));
|
|
||||||
if (FAILED(hr))
|
|
||||||
mesa_loge("DxcCreateInstance failed: %08x\n", hr);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
IDxcCompiler *
|
|
||||||
dxc_get_compiler(void)
|
|
||||||
{
|
|
||||||
IDxcCompiler *ret = NULL;
|
|
||||||
|
|
||||||
HMODULE dxil_mod = LoadLibraryA("dxcompiler.dll");
|
|
||||||
if (!dxil_mod) {
|
|
||||||
mesa_loge("failed to load dxcompiler.dll\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
DxcCreateInstanceProc CreateInstance = (DxcCreateInstanceProc)
|
|
||||||
GetProcAddress(dxil_mod, "DxcCreateInstance");
|
|
||||||
HRESULT hr = CreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&ret));
|
|
||||||
if (FAILED(hr))
|
|
||||||
mesa_loge("DxcCreateInstance failed: %08x\n", hr);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user