summaryrefslogtreecommitdiff
path: root/tools/render-test/d3d-util.h
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-06-28 11:14:48 -0700
committerGitHub <noreply@github.com>2018-06-28 11:14:48 -0700
commitdfe13b54286b27dd15f591455bbb86b7798285c2 (patch)
tree4a11f01feaae059b6c11bdfbe12a614228af6dd5 /tools/render-test/d3d-util.h
parent22033f06573f900dc030c487b2c30feddf3d8f16 (diff)
Share graphics API layer between tests/examples (#603)
The `render-test` project has an in-progress graphics API abstraction layer, and it makes sense to share this code with our examples rather than write a bunch of redundant code between examples and tests. Most of this change is just moving files from `tools/render-test/*` to a new library project at `tools/slang-graphics/`. The most complicated code change there is renaming from `render_test` to `slang_graphics`. The existing `hello` example was ported to use the graphics API layer instead of raw D3D11 API calls. It is still hard-coded to use the D3D11 back-end and the `SLANG_DXBC` target, so more work is needed if we want to actually support multiple APIs in the examples. I also went ahead and implemented an extremely rudimentary set of APIs to abstract over the Windows platform calls that were being made in the example, so that we could potentially run that same example on other platforms. I did *not* port `render-test` to use those APIs, and I also did not implement them for anything but Windows (my assumption is that for most other platforms we would just use SDL2, and require people to ensure it is installed to their machine before building Slang examples).
Diffstat (limited to 'tools/render-test/d3d-util.h')
-rw-r--r--tools/render-test/d3d-util.h61
1 files changed, 0 insertions, 61 deletions
diff --git a/tools/render-test/d3d-util.h b/tools/render-test/d3d-util.h
deleted file mode 100644
index b7a268fd8..000000000
--- a/tools/render-test/d3d-util.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// d3d-util.h
-#pragma once
-
-#include <stdint.h>
-
-#include "../../slang-com-helper.h"
-
-#include "../../slang-com-ptr.h"
-#include "../../source/core/list.h"
-
-#include "render.h"
-
-#include <D3Dcommon.h>
-#include <DXGIFormat.h>
-
-namespace renderer_test {
-
-class D3DUtil
-{
- public:
- enum UsageType
- {
- USAGE_UNKNOWN, ///< Generally used to mark an error
- USAGE_TARGET, ///< Format should be used when written as target
- USAGE_DEPTH_STENCIL, ///< Format should be used when written as depth stencil
- USAGE_SRV, ///< Format if being read as srv
- USAGE_COUNT_OF,
- };
- enum UsageFlag
- {
- USAGE_FLAG_MULTI_SAMPLE = 0x1, ///< If set will be used form multi sampling (such as MSAA)
- USAGE_FLAG_SRV = 0x2, ///< If set means will be used as a shader resource view (SRV)
- };
-
- /// Get primitive topology as D3D primitive topology
- static D3D_PRIMITIVE_TOPOLOGY getPrimitiveTopology(PrimitiveTopology prim);
-
- /// Calculate size taking into account alignment. Alignment must be a power of 2
- static UInt calcAligned(UInt size, UInt alignment) { return (size + alignment - 1) & ~(alignment - 1); }
-
- /// Compile HLSL code to DXBC
- static Slang::Result compileHLSLShader(char const* sourcePath, char const* source, char const* entryPointName, char const* dxProfileName, Slang::ComPtr<ID3DBlob>& shaderBlobOut);
-
- /// Given a slang pixel format returns the equivalent DXGI_ pixel format. If the format is not known, will return DXGI_FORMAT_UNKNOWN
- static DXGI_FORMAT getMapFormat(Format format);
-
- /// Given the usage, flags, and format will return the most suitable format. Will return DXGI_UNKNOWN if combination is not possible
- static DXGI_FORMAT calcFormat(UsageType usage, DXGI_FORMAT format);
- /// Calculate appropriate format for creating a buffer for usage and flags
- static DXGI_FORMAT calcResourceFormat(UsageType usage, Int usageFlags, DXGI_FORMAT format);
- /// True if the type is 'typeless'
- static bool isTypeless(DXGI_FORMAT format);
-
- /// Returns number of bits used for color channel for format (for channels with multiple sizes, returns smallest ie RGB565 -> 5)
- static Int getNumColorChannelBits(DXGI_FORMAT fmt);
-
- /// Append text in in, into wide char array
- static void appendWideChars(const char* in, Slang::List<wchar_t>& out);
-};
-
-} // renderer_test