100% found this document useful (2 votes)
20 views

GPGPU Programming for Games and Science 1st Edition Eberly pdf download

GPGPU Programming for Games and Science by David H. Eberly focuses on general purpose GPU programming, emphasizing robustness, accuracy, and speed in software development. The book covers key concepts such as SIMD extensions, floating-point arithmetic, and practical GPU programming techniques using Direct3D 11 and HLSL. It includes numerous examples and applications relevant to both game and scientific programming.

Uploaded by

bowlinbaeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
20 views

GPGPU Programming for Games and Science 1st Edition Eberly pdf download

GPGPU Programming for Games and Science by David H. Eberly focuses on general purpose GPU programming, emphasizing robustness, accuracy, and speed in software development. The book covers key concepts such as SIMD extensions, floating-point arithmetic, and practical GPU programming techniques using Direct3D 11 and HLSL. It includes numerous examples and applications relevant to both game and scientific programming.

Uploaded by

bowlinbaeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

GPGPU Programming for Games and Science 1st

Edition Eberly download

https://ebookmeta.com/product/gpgpu-programming-for-games-and-
science-1st-edition-eberly/

Download more ebook from https://ebookmeta.com


GPGPU
Computer Game Programming Eberly

GPGPU Programming for Games


and Science
GPGPU Programming for Games and Science demonstrates how to achieve

Programming for Games


robustness, accuracy, speed, and/or easily maintained, reusable, and readable
source code to tackle practical problems in computer science and software
engineering. The book primarily addresses programming on a graphics processing
unit (GPU) while covering some material also relevant to programming on a central

and Science
processing unit (CPU). It discusses many concepts of general purpose GPU
(GPGPU) programming and presents several practical examples in game program-
ming and scientific programming.

The author first describes numerical issues that arise when computing with
floating-point arithmetic, including making trade-offs among robustness, accuracy,
and speed. He then shows how single instruction multiple data (SIMD) extensions
work on CPUs. The core of the book focuses on the GPU from the perspective of
Direct3D 11 (D3D11) and the High Level Shading Language (HLSL). The book goes
on to explore practical matters of programming a GPU and discusses vector and
matrix algebra, rotations and quaternions, and coordinate systems. The final
chapter gives several sample GPGPU applications on relatively advanced topics.

Features

• Presents SIMD extensions to the CPU as well as a large collection of


approximations for standard mathematics functions
• Provides examples of how to draw using a combination of vertex, geometry,
and pixel shaders and how to execute a compute shader
• Shows you how to copy data between CPU and GPU and offers guidance
on parallelizing data transfer
• Explains how to work with multiple GPUs regarding D3D11 adapter
enumeration and device creation
• Discusses IEEE floating-point support on a GPU
• Illustrates how to use the Geometric Tools Engine and the resource
types in D3D11, with the source code available on a supporting website

K20720
ISBN: 978-1-4665-9535-4
90000

9 781466 595354
David H. Eberly
GPGPU
Programming
for Games
and Science
GPGPU
Programming
for Games
and Science
David H. Eberly
G e o m e t r i c To o l s L L C , R e d m o n d , Wa s h i n g t o n , U S A

Boca Raton London New York

CRC Press is an imprint of the


Taylor & Francis Group, an informa business
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742

© 2015 by Taylor & Francis Group, LLC


CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works


Version Date: 20140709

International Standard Book Number-13: 978-1-4665-9536-1 (eBook - PDF)

This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but
the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to
trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained.
If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical,
or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without
written permission from the publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright.com/) or contact the Copyright
Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a
variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to
infringe.

Visit the Taylor & Francis Web site at


http://www.taylorandfrancis.com

and the CRC Press Web site at


http://www.crcpress.com
Contents

List of Figures xiii

List of Tables xv

Listings xvii

Preface xxv

Trademarks xxvii

1 Introduction 1

2 CPU Computing 5
2.1 Numerical Computing . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 The Curse: An Example from Games . . . . . . . . . . 5
2.1.2 The Curse: An Example from Science . . . . . . . . . 10
2.1.3 The Need to Understand Floating-Point Systems . . . 11
2.2 Balancing Robustness, Accuracy, and Speed . . . . . . . . . 14
2.2.1 Robustness . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2.1.1 Formal Definitions . . . . . . . . . . . . . . . 14
2.2.1.2 Algorithms and Implementations . . . . . . . 16
2.2.1.3 Practical Definitions . . . . . . . . . . . . . . 17
2.2.2 Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2.3 Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2.4 Computer Science Is a Study of Trade-offs . . . . . . . 20
2.3 IEEE Floating Point Standard . . . . . . . . . . . . . . . . . 22
2.4 Binary Scientific Notation . . . . . . . . . . . . . . . . . . . . 23
2.4.1 Conversion from Rational to Binary Scientific Numbers 24
2.4.2 Arithmetic Properties of Binary Scientific Numbers . . 27
2.4.2.1 Addition of Binary Scientific Numbers . . . . 28
2.4.2.2 Subtraction of Binary Scientific Numbers . . 28
2.4.2.3 Multiplication of Binary Scientific Numbers . 28
2.4.2.4 Division of Binary Scientific Numbers . . . . 29
2.4.3 Algebraic Properties of Binary Scientific Numbers . . 30
2.5 Floating-Point Arithmetic . . . . . . . . . . . . . . . . . . . . 31
2.5.1 Binary Encodings . . . . . . . . . . . . . . . . . . . . 32
2.5.1.1 8-bit Floating-Point Numbers . . . . . . . . . 33

v
vi Contents

2.5.1.2 16-Bit Floating-Point Numbers . . . . . . . . 36


2.5.1.3 32-Bit Floating-Point Numbers . . . . . . . . 39
2.5.1.4 64-Bit Floating-Point Numbers . . . . . . . . 41
2.5.1.5 n-Bit Floating-Point Numbers . . . . . . . . 42
2.5.1.6 Classifications of Floating-Point Numbers . . 45
2.5.2 Rounding and Conversions . . . . . . . . . . . . . . . 50
2.5.2.1 Rounding with Ties-to-Even . . . . . . . . . 51
2.5.2.2 Rounding with Ties-to-Away . . . . . . . . . 52
2.5.2.3 Rounding toward Zero . . . . . . . . . . . . . 52
2.5.2.4 Rounding toward Positive . . . . . . . . . . . 52
2.5.2.5 Rounding toward Negative . . . . . . . . . . 53
2.5.2.6 Rounding from Floating-Point to Integral
Floating-Point . . . . . . . . . . . . . . . . . 54
2.5.2.7 Conversion from Integer to Floating-Point . 60
2.5.2.8 Conversion from Floating-Point to Rational . 64
2.5.2.9 Conversion from Rational to Floating-Point . 67
2.5.2.10 Conversion to Wider Format . . . . . . . . . 70
2.5.2.11 Conversion to Narrower Format . . . . . . . 73
2.5.3 Arithmetic Operations . . . . . . . . . . . . . . . . . . 81
2.5.4 Mathematical Functions . . . . . . . . . . . . . . . . . 82
2.5.5 Floating-Point Oddities . . . . . . . . . . . . . . . . . 83
2.5.5.1 Where Have My Digits Gone? . . . . . . . . 83
2.5.5.2 Have a Nice Stay! . . . . . . . . . . . . . . . 88
2.5.5.3 The Best I Can Do Is That Bad? . . . . . . . 89
2.5.5.4 You Have Been More Than Helpful . . . . . 91
2.5.5.5 Hardware and Optimizing Compiler Issues . 92

3 SIMD Computing 93
3.1 Intel Streaming SIMD Extensions . . . . . . . . . . . . . . . 93
3.1.1 Shuffling Components . . . . . . . . . . . . . . . . . . 94
3.1.2 Single-Component versus All-Component Access . . . 95
3.1.3 Load and Store Instructions . . . . . . . . . . . . . . . 95
3.1.4 Logical Instructions . . . . . . . . . . . . . . . . . . . 98
3.1.5 Comparison Instructions . . . . . . . . . . . . . . . . . 99
3.1.6 Arithmetic Instructions . . . . . . . . . . . . . . . . . 100
3.1.7 Matrix Multiplication and Transpose . . . . . . . . . . 100
3.1.8 IEEE Floating-Point Support . . . . . . . . . . . . . . 103
3.1.9 Keep the Pipeline Running . . . . . . . . . . . . . . . 103
3.1.10 Flattening of Branches . . . . . . . . . . . . . . . . . . 104
3.2 SIMD Wrappers . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.3 Function Approximations . . . . . . . . . . . . . . . . . . . . 107
3.3.1 Minimax Approximations . . . . . . . . . . . . . . . . 107
3.3.2 Inverse Square Root Function Using Root Finding . . 110
3.3.3 Square Root Function . . . . . . . . . . . . . . . . . . 111
3.3.4 Inverse Square Root Using a Minimax Algorithm . . . 114
Contents vii

3.3.5 Sine Function . . . . . . . . . . . . . . . . . . . . . . . 116


3.3.6 Cosine Function . . . . . . . . . . . . . . . . . . . . . 116
3.3.7 Tangent Function . . . . . . . . . . . . . . . . . . . . . 117
3.3.8 Inverse Sine Function . . . . . . . . . . . . . . . . . . 117
3.3.9 Inverse Cosine Function . . . . . . . . . . . . . . . . . 119
3.3.10 Inverse Tangent Function . . . . . . . . . . . . . . . . 119
3.3.11 Exponential Functions . . . . . . . . . . . . . . . . . . 120
3.3.12 Logarithmic Functions . . . . . . . . . . . . . . . . . . 120

4 GPU Computing 123


4.1 Drawing a 3D Object . . . . . . . . . . . . . . . . . . . . . . 123
4.1.1 Model Space . . . . . . . . . . . . . . . . . . . . . . . 123
4.1.2 World Space . . . . . . . . . . . . . . . . . . . . . . . 123
4.1.3 View Space . . . . . . . . . . . . . . . . . . . . . . . . 124
4.1.4 Projection Space . . . . . . . . . . . . . . . . . . . . . 125
4.1.5 Window Space . . . . . . . . . . . . . . . . . . . . . . 129
4.1.6 Summary of the Transformations . . . . . . . . . . . . 130
4.1.7 Rasterization . . . . . . . . . . . . . . . . . . . . . . . 131
4.2 High Level Shading Language (HLSL) . . . . . . . . . . . . . 134
4.2.1 Vertex and Pixel Shaders . . . . . . . . . . . . . . . . 134
4.2.2 Geometry Shaders . . . . . . . . . . . . . . . . . . . . 138
4.2.3 Compute Shaders . . . . . . . . . . . . . . . . . . . . . 141
4.2.4 Compiling HLSL Shaders . . . . . . . . . . . . . . . . 144
4.2.4.1 Compiling the Vertex Coloring Shaders . . . 147
4.2.4.2 Compiling the Texturing Shaders . . . . . . 151
4.2.4.3 Compiling the Billboard Shaders . . . . . . . 152
4.2.4.4 Compiling the Gaussian Blurring Shaders . . 156
4.2.5 Reflecting HLSL Shaders . . . . . . . . . . . . . . . . 160
4.3 Devices, Contexts, and Swap Chains . . . . . . . . . . . . . . 168
4.3.1 Creating a Device and an Immediate Context . . . . . 168
4.3.2 Creating Swap Chains . . . . . . . . . . . . . . . . . . 170
4.3.3 Creating the Back Buffer . . . . . . . . . . . . . . . . 171
4.4 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
4.4.1 Resource Usage and CPU Access . . . . . . . . . . . . 174
4.4.2 Resource Views . . . . . . . . . . . . . . . . . . . . . . 175
4.4.3 Subresources . . . . . . . . . . . . . . . . . . . . . . . 178
4.4.4 Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
4.4.4.1 Constant Buffers . . . . . . . . . . . . . . . . 181
4.4.4.2 Texture Buffers . . . . . . . . . . . . . . . . 181
4.4.4.3 Vertex Buffers . . . . . . . . . . . . . . . . . 182
4.4.4.4 Index Buffers . . . . . . . . . . . . . . . . . . 184
4.4.4.5 Structured Buffers . . . . . . . . . . . . . . . 184
4.4.4.6 Raw Buffers . . . . . . . . . . . . . . . . . . 187
4.4.4.7 Indirect-Argument Buffers . . . . . . . . . . 189
4.4.5 Textures . . . . . . . . . . . . . . . . . . . . . . . . . . 189
viii Contents

4.4.5.1 1D Textures . . . . . . . . . . . . . . . . . . 192


4.4.5.2 2D Textures . . . . . . . . . . . . . . . . . . 193
4.4.5.3 3D Textures . . . . . . . . . . . . . . . . . . 194
4.4.6 Texture Arrays . . . . . . . . . . . . . . . . . . . . . . 195
4.4.6.1 1D Texture Arrays . . . . . . . . . . . . . . . 195
4.4.6.2 2D Texture Arrays . . . . . . . . . . . . . . . 196
4.4.6.3 Cubemap Textures . . . . . . . . . . . . . . . 197
4.4.6.4 Cubemap Texture Arrays . . . . . . . . . . . 198
4.4.7 Draw Targets . . . . . . . . . . . . . . . . . . . . . . . 198
4.5 States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
4.6 Shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
4.6.1 Creating Shaders . . . . . . . . . . . . . . . . . . . . . 202
4.6.2 Vertex, Geometry, and Pixel Shader Execution . . . . 202
4.6.3 Compute Shader Execution . . . . . . . . . . . . . . . 205
4.7 Copying Data between CPU and GPU . . . . . . . . . . . . 207
4.7.1 Mapped Writes for Dynamic Update . . . . . . . . . . 207
4.7.2 Staging Resources . . . . . . . . . . . . . . . . . . . . 210
4.7.3 Copy from CPU to GPU . . . . . . . . . . . . . . . . 211
4.7.4 Copy from GPU to CPU . . . . . . . . . . . . . . . . 212
4.7.5 Copy from GPU to GPU . . . . . . . . . . . . . . . . 213
4.8 Multiple GPUs . . . . . . . . . . . . . . . . . . . . . . . . . . 214
4.8.1 Enumerating the Adapters . . . . . . . . . . . . . . . 214
4.8.2 Copying Data between Multiple GPUs . . . . . . . . . 215
4.9 IEEE Floating-Point on the GPU . . . . . . . . . . . . . . . 217

5 Practical Matters 223


5.1 Engine Design and Architecture . . . . . . . . . . . . . . . . 223
5.1.1 A Simple Low-Level D3D11 Application . . . . . . . . 223
5.1.2 HLSL Compilation in Microsoft Visual Studio . . . . . 226
5.1.3 Design Goals for the Geometric Tools Engine . . . . . 227
5.1.3.1 An HLSL Factory . . . . . . . . . . . . . . . 227
5.1.3.2 Resource Bridges . . . . . . . . . . . . . . . . 228
5.1.3.3 Visual Effects . . . . . . . . . . . . . . . . . 230
5.1.3.4 Visual Objects and Scene Graphs . . . . . . 231
5.1.3.5 Cameras . . . . . . . . . . . . . . . . . . . . 231
5.2 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
5.2.1 Debugging on the CPU . . . . . . . . . . . . . . . . . 232
5.2.2 Debugging on the GPU . . . . . . . . . . . . . . . . . 233
5.2.3 Be Mindful of Your Surroundings . . . . . . . . . . . . 235
5.2.3.1 An Example of an HLSL Compiler Bug . . . 236
5.2.3.2 An Example of a Programmer Bug . . . . . . 239
5.3 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
5.3.1 Performance on the CPU . . . . . . . . . . . . . . . . 241
5.3.2 Performance on the GPU . . . . . . . . . . . . . . . . 243
5.3.3 Performance Guidelines . . . . . . . . . . . . . . . . . 247
Contents ix

5.4 Code Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . 249


5.4.1 Topics in Code Testing . . . . . . . . . . . . . . . . . . 250
5.4.2 Code Coverage and Unit Testing on the GPU . . . . . 254

6 Linear and Affine Algebra 257


6.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
6.1.1 Robust Length and Normalization Computations . . . 258
6.1.2 Orthogonality . . . . . . . . . . . . . . . . . . . . . . . 260
6.1.2.1 Orthogonality in 2D . . . . . . . . . . . . . . 260
6.1.2.2 Orthogonality in 3D . . . . . . . . . . . . . . 261
6.1.2.3 Orthogonality in 4D . . . . . . . . . . . . . . 262
6.1.2.4 Gram-Schmidt Orthonormalization . . . . . 263
6.1.3 Orthonormal Sets . . . . . . . . . . . . . . . . . . . . 264
6.1.3.1 Orthonormal Sets in 2D . . . . . . . . . . . . 265
6.1.3.2 Orthonormal Sets in 3D . . . . . . . . . . . . 265
6.1.3.3 Orthonormal Sets in 4D . . . . . . . . . . . . 267
6.1.4 Barycentric Coordinates . . . . . . . . . . . . . . . . . 269
6.1.5 Intrinsic Dimensionality . . . . . . . . . . . . . . . . . 270
6.2 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
6.2.1 Matrix Storage and Transfom Conventions . . . . . . 274
6.2.2 Base Class Matrix Operations . . . . . . . . . . . . . . 275
6.2.3 Square Matrix Operations in 2D . . . . . . . . . . . . 278
6.2.4 Square Matrix Operations in 3D . . . . . . . . . . . . 279
6.2.5 Square Matrix Operations in 4D . . . . . . . . . . . . 281
6.2.6 The Laplace Expansion Theorem . . . . . . . . . . . . 282
6.3 Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
6.3.1 Rotation in 2D . . . . . . . . . . . . . . . . . . . . . . 288
6.3.2 Rotation in 3D . . . . . . . . . . . . . . . . . . . . . . 289
6.3.3 Rotation in 4D . . . . . . . . . . . . . . . . . . . . . . 292
6.3.4 Quaternions . . . . . . . . . . . . . . . . . . . . . . . . 294
6.3.4.1 Algebraic Operations . . . . . . . . . . . . . 295
6.3.4.2 Relationship of Quaternions to Rotations . . 297
6.3.4.3 Spherical Linear Interpolation of Quaternions 299
6.3.5 Euler Angles . . . . . . . . . . . . . . . . . . . . . . . 305
6.3.5.1 World Coordinates versus Body Coordinates 306
6.3.6 Conversion between Representations . . . . . . . . . . 308
6.3.6.1 Quaternion to Matrix . . . . . . . . . . . . . 309
6.3.6.2 Matrix to Quaternion . . . . . . . . . . . . . 309
6.3.6.3 Axis-Angle to Matrix . . . . . . . . . . . . . 311
6.3.6.4 Matrix to Axis-Angle . . . . . . . . . . . . . 311
6.3.6.5 Axis-Angle to Quaternion . . . . . . . . . . . 312
6.3.6.6 Quaternion to Axis-Angle . . . . . . . . . . . 312
6.3.6.7 Euler Angles to Matrix . . . . . . . . . . . . 313
6.3.6.8 Matrix to Euler Angles . . . . . . . . . . . . 313
x Contents

6.3.6.9 Euler Angles to and from Quaternion or Axis-


Angle . . . . . . . . . . . . . . . . . . . . . . 317
6.4 Coordinate Systems . . . . . . . . . . . . . . . . . . . . . . . 318
6.4.1 Geometry and Affine Algebra . . . . . . . . . . . . . . 319
6.4.2 Transformations . . . . . . . . . . . . . . . . . . . . . 322
6.4.2.1 Composition of Affine Transformations . . . 322
6.4.2.2 Decomposition of Affine Transformations . . 327
6.4.2.3 A Simple Transformation Factory . . . . . . 330
6.4.3 Coordinate System Conventions . . . . . . . . . . . . 332
6.4.4 Converting between Coordinate Systems . . . . . . . . 336

7 Sample Applications 341


7.1 Video Streams . . . . . . . . . . . . . . . . . . . . . . . . . . 341
7.1.1 The VideoStream Class . . . . . . . . . . . . . . . . . . 341
7.1.2 The VideoStreamManager Class . . . . . . . . . . . . . . 342
7.2 Root Finding . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
7.2.1 Root Bounding . . . . . . . . . . . . . . . . . . . . . . 346
7.2.2 Bisection . . . . . . . . . . . . . . . . . . . . . . . . . 347
7.2.3 Newton’s Method . . . . . . . . . . . . . . . . . . . . . 348
7.2.4 Exhaustive Evaluation . . . . . . . . . . . . . . . . . . 350
7.2.4.1 CPU Root Finding Using a Single Thread . . 350
7.2.4.2 CPU Root Finding Using Multiple Threads . 351
7.2.4.3 GPU Root Finding . . . . . . . . . . . . . . 352
7.3 Least Squares Fitting . . . . . . . . . . . . . . . . . . . . . . 355
7.3.1 Fit a Line to 2D Points . . . . . . . . . . . . . . . . . 355
7.3.2 Fit a Plane to 3D Points . . . . . . . . . . . . . . . . . 358
7.3.3 Orthogonal Regression . . . . . . . . . . . . . . . . . . 359
7.3.3.1 Fitting with Lines . . . . . . . . . . . . . . . 359
7.3.3.2 Fitting with Planes . . . . . . . . . . . . . . 361
7.3.4 Estimation of Tangent Planes . . . . . . . . . . . . . . 362
7.4 Partial Sums . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
7.5 All-Pairs Triangle Intersection . . . . . . . . . . . . . . . . . 368
7.6 Shortest Path in a Weighted Graph . . . . . . . . . . . . . . 371
7.7 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
7.8 Median Filtering . . . . . . . . . . . . . . . . . . . . . . . . . 384
7.8.1 Median by Sorting . . . . . . . . . . . . . . . . . . . . 385
7.8.2 Median of 3 × 3 Using Min-Max Operations . . . . . . 387
7.8.3 Median of 5 × 5 Using Min-Max Operations . . . . . . 389
7.9 Level Surface Extraction . . . . . . . . . . . . . . . . . . . . 392
7.10 Mass-Spring Systems . . . . . . . . . . . . . . . . . . . . . . 398
7.11 Fluid Dynamics . . . . . . . . . . . . . . . . . . . . . . . . . 400
7.11.1 Numerical Methods . . . . . . . . . . . . . . . . . . . 401
7.11.2 Solving Fluid Flow in 2D . . . . . . . . . . . . . . . . 403
7.11.2.1 Initialization of State . . . . . . . . . . . . . 405
7.11.2.2 Initialization of External Forces . . . . . . . 406
Contents xi

7.11.2.3 Updating the State with Advection . . . . . 409


7.11.2.4 Applying the State Boundary Conditions . . 410
7.11.2.5 Computing the Divergence of Velocity . . . . 413
7.11.2.6 Solving the Poisson Equation . . . . . . . . . 413
7.11.2.7 Updating the Velocity to Be Divergence Free 414
7.11.2.8 Screen Captures from the Simulation . . . . 415
7.11.3 Solving Fluid Flow in 3D . . . . . . . . . . . . . . . . 416
7.11.3.1 Initialization of State . . . . . . . . . . . . . 418
7.11.3.2 Initialization of External Forces . . . . . . . 419
7.11.3.3 Updating the State with Advection . . . . . 422
7.11.3.4 Applying the State Boundary Conditions . . 424
7.11.3.5 Computing the Divergence of Velocity . . . . 425
7.11.3.6 Solving the Poisson Equation . . . . . . . . . 425
7.11.3.7 Updating the Velocity to Be Divergence Free 427
7.11.3.8 Screen Captures from the Simulation . . . . 427

Bibliography 429

Index 435
List of Figures

2.1 Colliding circles . . . . . . . . . . . . . . . . . . . . . . . . . 7


2.2 Circle interpenetration due to roundoff errors . . . . . . . . 8
2.3 Circles at last time of contact . . . . . . . . . . . . . . . . . 10
2.4 Convex hull update (in theory) . . . . . . . . . . . . . . . . 11
2.5 Convex hull update (in practice) . . . . . . . . . . . . . . . 12
2.6 Layout of 8-bit floating-point . . . . . . . . . . . . . . . . . 33
2.7 Distribution of binary8 numbers . . . . . . . . . . . . . . . . 36
2.8 Layout of 16-bit floating-point . . . . . . . . . . . . . . . . . 37
2.9 Layout of 32-bit floating-point . . . . . . . . . . . . . . . . . 39
2.10 Layout of 64-bit floating-point . . . . . . . . . . . . . . . . . 41
2.11 Rounding with ties-to-even . . . . . . . . . . . . . . . . . . . 51
2.12 Rounding with ties-to-away . . . . . . . . . . . . . . . . . . 52
2.13 Rounding toward zero . . . . . . . . . . . . . . . . . . . . . 52
2.14 Rounding toward positive . . . . . . . . . . . . . . . . . . . 53
2.15 Rounding toward negative . . . . . . . . . . . . . . . . . . . 53
2.16 Comparison of narrow and wide formats . . . . . . . . . . . 74

3.1 Initial plot of g(x) =√ 1 + x − p(x) . . . . . . . . . . . . . . 112
3.2 Final plot of g(x) = 1 + x − p(x) . . . . . . . . . . . . . . 114

4.1 Eyepoint and view frustum . . . . . . . . . . . . . . . . . . . 127


4.2 Symmetric view frustum and faces . . . . . . . . . . . . . . 128
4.3 1D pixel ownership . . . . . . . . . . . . . . . . . . . . . . . 132
4.4 2D pixel ownership . . . . . . . . . . . . . . . . . . . . . . . 132
4.5 Top-left rasterization rule . . . . . . . . . . . . . . . . . . . 133
4.6 Vertex coloring and texturing . . . . . . . . . . . . . . . . . 137
4.7 Billboards using geometry shaders . . . . . . . . . . . . . . . 141
4.8 Dispatch and group thread IDs . . . . . . . . . . . . . . . . 143
4.9 Blurring using compute shaders . . . . . . . . . . . . . . . . 144
4.10 Mipmaps as subresources . . . . . . . . . . . . . . . . . . . . 178
4.11 Texture arrays as subresources . . . . . . . . . . . . . . . . . 179
4.12 Copying data between processors . . . . . . . . . . . . . . . 208

6.1 Visualization of 3 × 3 determinant . . . . . . . . . . . . . . . 284


6.2 Visual of 4 × 4 expansion by row 0 . . . . . . . . . . . . . . 285
6.3 Visualization of 4 × 4 expansion by rows zero and one . . . 287

xiii
xiv List of Figures

6.4 Visualization of 3D rotation . . . . . . . . . . . . . . . . . . 289


6.5 Spherical linear interpolation of quaternions . . . . . . . . . 300
6.6 Illustration of affine algebra . . . . . . . . . . . . . . . . . . 320
6.7 Parallelogram law of affine algebra . . . . . . . . . . . . . . 321
6.8 Counterclockwise rotation in the plane . . . . . . . . . . . . 333
6.9 Left-handed versus right-handed coordinate systems . . . . 335
6.10 Conversion from right-handed to left-handed coordinates . . 337
6.11 Commutative diagram for change of basis . . . . . . . . . . 339

7.1 Binary expression tree for partial sums . . . . . . . . . . . . 365


7.2 DAG for partial sums of four numbers . . . . . . . . . . . . 366
7.3 DAG for partial sums of eight numbers . . . . . . . . . . . . 367
7.4 Intersection of a meshes for a cylinder and a torus . . . . . . 371
7.5 The directed edges from a point in the grid graph . . . . . . 373
7.6 The directed edges to a point in the grid graph . . . . . . . 374
7.7 The breadth-first update of distances in a 5 × 5 grid . . . . 374
7.8 A level surface for a single voxel . . . . . . . . . . . . . . . . 392
7.9 Triangle mesh configurations (part 1) . . . . . . . . . . . . . 394
7.10 Triangle mesh configurations (part 2) . . . . . . . . . . . . . 395
7.11 Surface extraction for two level values . . . . . . . . . . . . 397
7.12 2D fluid screen captures . . . . . . . . . . . . . . . . . . . . 416
7.13 3D fluid screen captures . . . . . . . . . . . . . . . . . . . . 428
Exploring the Variety of Random
Documents with Different Content
He looked up into her face for an instant.

"I've forgotten," he said.

"Sir Colvin wouldn't have suspected me," she added. "He knows no
more about a woman than ... than you do.

"I suppose that leaves him without much knowledge to boast of?" he
reflected.

"Yes," she said; "it does."

She tilted her head sideways to see, beyond her knee, on what his eyes
were fixed. She tossed her foot clear of the muslin flounces, and then with a
curious twist of the ankle brought it round into her view.

"What's wrong with it?" she asked.

He shook his head.

"How should I know?" he said thoughtfully. "It wasn't made for me."

She laughed, slowly twirling her foot, as though fascinated by its


suppleness, or by the gleaming creases of the silk that covered it. Then, with
a little jerk of her knee, she let it settle again into the froth of flounces.

"Really," she said, "for a man who says so little, you do say the strangest
things."

His eyes had wandered again to the square of open air, the picture in
azure and ochre and emerald which the window made in the wall. The
brown woman still sat swinging her bead in the shade of the chenar.
Terrington could see its glassy blueness as it dipped to and fro across a
splinter of sunlight.

Rose Chantry, with her eyes on his profile, asked him at what he was
looking.

He told her.
"I know!" she exclaimed. "Why is she always doing that?"

"She wants a child," he said.

"But she has one."

"Another then."

She gave a shudder.

"What strange things women are!" she cried.

His eyes came round to her, and she felt a coldness in them like the
green gleam of ice.

"Out here, you see," he said quietly, "women are still as fond of making
men as of making fools of them."

"Why do you say that?" she asked sharply.

"I could think of nothing better," he replied.

"Why did you say it to me?" she persisted.

"To whom else could I have said it?" he enquired blandly.

The blaze of anger seemed to fill her eyes with a floating sparkle of fresh
colours, and her lips closed tightly, as though to repress a desire to bite him.
Then she met his glance and laughed.

"I wonder why you dislike me so," she said.

"I don't dislike you," he replied.

"Oh, well!" she sighed, "why don't you dislike me, then; since you seem
too? You wish I wasn't here!"

"Very much," he admitted.


"Why? What harm do I do?"

"Haven't you told me that this morning?"

"No!" she cried. "You weren't thinking of that; you know you weren't.
You believe that would have happened anyhow. It was what you meant
about making fools of men."

"Well," he said, "don't you make fools of them?"

She shook her head softly.

"My mistake then," he said.

"Ah!" she sighed, "but you don't think so. I daresay you think something
much more horrid of me than you care to say. And it ought to have been
rather nice for you all, having me up here."

"Yes," he said, "I think it ought."

She looked at him doubtfully, crumpling her lips together in her fingers.

"But you do make mistakes," she went on retrospectively.

"Yes," he said, "one makes everything of them."

She regarded him for a moment in the light of the remark, before adding:

"You told me, the first time you saw me, I must give up riding."

"Yes," he admitted, smiling; "that was one of them. But I found that your
riding could be of use to us."

"Of use to you?" she exclaimed.

"Yes, in creating a false impression."

"An impression of what?"


"Of security: that we did not think you were in any danger."

"Though you thought I was?"

"I was sure of it," he said.

She was sitting upright now; her hands set upon the chair-arms; her face
changing stormily between anger and astonishment.

"You were sure I was in danger, yet you did nothing to prevent it!" she
cried. "Do you mean that?"

"What should I have done?" he enquired.

"Warned me!" she said

"But didn't I?"

"Oh, that!" she exclaimed impatiently.

"And would you have been warned?"

"I don't know. I can't say. That's got nothing to do with it. Or you could
have given me an escort."

He shook his head.

"That would have made you no safer, and would have spoilt you as an
advertisement."

"As an advertisement!" she protested hotly. "Do soldiers let a woman run
the risk of being murdered to make things safe far them? I think it's
contemptible!"

"Yes," he said quietly; "so I see: but you don't think enough."

He sat looking at her in a way she detested; as no other man seemed able
to look at her; as though she were a piece in a game he played.
"Did any one else know it wasn't safe for me?" she demanded.

He shook his head.

"Wouldn't you have been warned in that case?" he suggested.

"Yes," she returned warmly, "I'm quite certain I should."

"I think so too," he said. "Nothing in Sar would have been weighed
beside it."

"Except by you," she retorted.

"Except by me," he said. "You see I'm here to weigh things. I'm here to
look after you all. You think I should have told you of your danger, and shut
you up in the safety of Sar. But there is no safety in Sar. That's the mistake.
Your riding was a risk, but it helped our chance to make Sar safer; safer for
every one, safer for you."

"And suppose I had been killed?"

"Well," he said, "you can fancy what I should have paid for it. But the
safety would have been there, though it was only there for others. And it
was to make that that I am here."

She met his musing observation of her with hard clear eyes.

"Haven't you wasted an unusual lot of time talking to me this morning,


Captain Terrington?" she said.

He took the deep breath of a man whose heart is sick for sleep, and
threw back his shoulders.

"Yes," he smiled, rising; "I was quite exceptionally tired."


V

Terrington gave a practical shape to his forebodings as soon as the


Commissioner and his escort started for the Durbar.

The entire force was under arms; the Residency guard was trebled;
sappers were stationed in every room to break open the loopholes; others
waited with discs of guncotton to blow away the trees which masked the
polo ground; and the final connexions were made with the mine which was
to overthrow the courtyard wall.

Appearances were kept up by an attenuated fatigue party, which was as


markedly visible about the place as the rest of the garrison was not.

Terrington, who had changed for polo, also made a peacefully indifferent
figure as he strolled across to the mess-room and round the Residency
garden, with a loose coat drawn over his riding-shirt, whose blue and silver
showed in the scarf about his throat.

He had returned to his orderly-room in the Fort, when news of the


tragedy which was to wring from England a growl of vengeance was
brought to the sentries at the Residency gate by the handful of blood-
smeared horsemen who swept through it with broken and clotted lances and
a crimson lather on their horses' flanks.

Hussain Shah was holding Langford, mortally hurt, in the saddle, his
huge figure swinging limply to and fro, and more than half that remnant of
the escort reeled as they drew rein before the Residency door.

Terrington was not the first to hear of the disaster, but he heard it in the
most dramatic fashion; from Mrs. Chantry's lips.

She had torn across the compound as the Lancers came to a blundering
halt before the mess-room entrance, and dashed breathless into the orderly
room, waiting no confirmation of the story that was told by their plight.

She caught at her side, clutching with the other hand at the table, and for
an instant panted, speechless, her face white as jasmine, above a big bow of
creamy lace.

Then, with a hard gasp of breath:

"They're killed!" she cried.

Terrington had sprung to his feet as she burst in upon him.

"Who are?" he demanded.

"Lewis and Sir Colvin," she panted, "and ... and most of the others. All
but six or seven of them. Mr. Langford's there, but he's simply hacked; and
all the men are streaming."

A long thin wail broke from her with the horror of what she had seen,
and she covered her eyes with both her hands.

Terrington had stepped towards the doorway as he realized the


significance of what she had seen. She put herself sharply in front of him,
her head flung fiercely back.

"What are you going to do?" she demanded. "You let them go like that,
you made them go like that! That's what's done it all! You wouldn't let them
take the men! Aren't you going to try to save them? They mayn't be dead!
Don't you think they mayn't be dead? If only you'll go at once; this moment!
Take every one and smash them. Don't you think it's possible; just possible?
And it wasn't I who did it, was it? was it really?"

He laid a hand upon her shoulder to put her aside.

"No, child," he said gently; "you had nothing to do with it."

As he would have passed out, leaping footsteps sounded on the stairs,


and Captain Walcot almost dashed into his arms.

"Have you heard?" he cried.

"What?" asked Terrington


Walcot glanced with deprecation at Mrs. Chantry's figure.

"Say what you know!" said Terrington.

"Sir Colvin and Chantry have been murdered at the Durbar, and all the
men they took in with them."

"Who told you?" said Terrington.

"Hussain Shah," replied the other excitedly. "Langford was in the


courtyard with half the escort, when a yelling began inside the hall, and a
swarm of those brown swine poured out shouting that Sir Colvin was killed,
and attacked him. Langford charged, and tried to jam them in the doorway;
but the crowd joined in behind, and when Langford was shot through the
body Hussain retired 'em, and they had to cut their way through till they
were clear of the Bazaar. Every man of them was wounded, and they've lost
five and Langford's dying."

"Is Clones with him?"

Walcot nodded.

Terrington remained a moment without speaking, gazing almost absently


through the window in the thick mud wall at the green grove of chenar. In
his loose racing-coat above polo boots and breeches, and with the gay silk
scarf at his throat, he suggested anything but a man suddenly met by a great
emergency.

"Tell Subadar Afzul Singh," he said slowly, "to post the Fort guard,
break out the loopholes and put the place at once in a state of defence. You
will parade every other available man in the courtyard within half an hour,
in marching order a hundred and fifty rounds a man. Dore will take over
Langford's Sikhs and Dogras; the Bakót levies will reinforce the Fort guard.
Send Risaldar Hussain Shah to me here."

Rose Chantry held her sobbing breath in astonishment at the note of


control which had come into the man's voice. It was lower and softer than
she had ever heard it, but it spoke with a quiet and assured authority which
seemed to master her even while it addressed another.

Walcot felt it too. He was the elder of the two men, and but a few months
junior in the service; they had lived together for some time on terms of
perfect equality, yet now, though Terrington had made no reference to a
change in their relations, Walcot's heels came together while the other was
speaking, and his hand went to his cap with a "Very good, sir" as Nevile
ended.

The phrase, the sudden change of relation, Walcot's retreating figure,


disciplined and subordinate, produced on Rose Chantry a very curious
effect.

"Are you going to take over the command?" she said to Terrington, who
had seated himself at his desk and was writing rapidly.

He turned his head and looked at her, his mind evidently occupied with
an interrupted thought.

"I have taken it over," he said quietly, turning again to his pen.

She watched him for a moment. His silence, his unconcern, his power,
were all alike beyond her.

"Are you going to the Palace?" she asked at length.

He looked round at her again, as clearly preoccupied as before, but


without irritation.

"You will save them, won't you, if you can?" she went on imploringly, to
force the subject into his mind.

"Yes," he said slowly, "I'm going to the Palace." Then after a pause, but
with his eyes still upon her, "Mr. Clones would probably be very glad of
some help with the wounded."

"The wounded!" she repeated with a little shudder.


"Yes," he said; "you'll see a good deal of them during the next few days,
and it's as well to be of use. If you'll take this to him," he went on, folding
up a note, "he'll show you what to do. It's only the making up of bandages,"
he continued, as she held back; "the time left us is very short."

Something scornful had come into his voice, though ever so faintly, and
something compelling as well. She took the note when he held it out to her,
unable, despite her will, to do anything else. As she passed the doorway
Hussain Shah appeared on the landing beyond it, the folds of the turban
above his temple stiff with blood. She paused an instant to hear Terrington's
greeting, but the greeting was in Pukhtu, which she did not understand. Had
she understood, her opinion of Terrington's hardness would have been
confirmed, for no reference was made to the wounded man's condition until
he had received his orders.

"Are you fit for duty?" said Terrington simply.

"I am unhurt, sir," replied the other as he saluted.

Half an hour later every available man in the force was paraded in the
courtyard of the Fort. Walcot with his Lancers in front; then, behind
Terrington, the Sikhs and Dogras that could be spared from the Fort, the
Guides bringing up the rear. The Maxim had been hoisted on to the roof of
the Eastern Tower, whence it covered for a certain distance an advance on
the Palace. In the silence the blow of a pick could be heard, and the falling
stones from the last loopholes in the walls.

Terrington sat his horse immovably, waiting for the signal from Afzul
Singh which should open the gates. He was burning with a dull anger
against the circumstance in which he had been placed, and against the folly
of the men who had created it. He knew that in marching on the Palace to
demand the men who had entered it that morning he was imperilling the
safety of his entire force; yet he knew, too, that sentimental England would
never forgive his sanity in declining the risk should any of Sir Colvin's
party happen to be still alive. He had no hope of their safety. He was too
well acquainted with the temper in which they had been attacked. That he
viewed with no resentment whatever. It had been a piece of the foulest
treachery, but treachery was a virtue in Sar, and he was quite able to accept,
and even to respect, alien standards of conduct.

What did anger him was the stolid British arrogance which declined to
make allowance for any prejudices but its own, and thought beneath its
dignity all considerations which were not in the terms of its own
intelligence. Rose Chantry watched him from the orderly-room window
which overlooked the courtyard. She had been in the surgery helping
Clones to make up first-aid bandages, but the tramp of laden men down the
long passages, and the roll, like a soft volley, of grounded butts in the dust
as the men fell in, so wrought on her excitement that she left her work and
ran up the narrow twisted stairs to the room from which half an hour earlier
Terrington had sent her.

She watched him now, with her shoulder pressed against the yellow
chunam wall and her head drawn back in order not to be seen, wondering
how a man of his dominant authority could wait impassively at such a
moment the arrangements of a subordinate.

Her eyes, dry and hot, seemed almost to repudiate resentfully the tears
which she had shed; a pulse throbbed like the flutter of a moth at her throat;
her uneasy fingers seemed to crave to be closed, and yet when she clenched
her fist they ached to be opened. She longed to tear about, to give orders, to
rouse enthusiasm. She would have liked to ride beside Terrington to the
Palace and carry a flag: and the thought of how he would regard such a
proposal moved her not to a sense of its humour but to renewed irritation
with the man who could ride as indifferently to death as he would to a
dinner.

Her whole being was in disorder owing to the uncertainty of her


husband's fate. At the first shock and accepted inference of his death tears
had burst from her in the weak wretchedness of bereavement, the sense of
widowhood, and grief at the dying of one so near to her in the pride of his
youth. It was perhaps the very nearness of death's-knife, the cutting off of
the one who was one with her, who had scarcely gone from her arms, which
gave her the keenest shudder. The sword which had been thrust through him
seemed almost to have pricked her breast. Not that she feared for her own
safety; she never imagined that it was compromised. She had the supreme
British scorn for her country's foes, and thought it was only a question of
policy whether Terrington with his handful of men would not at once burn
the Palace to the ground, carry off the Khan in chains, and ravage the whole
country with sword and fire.

It was death in the shadow which had stabbed and was gone which made
her shiver. A thing so swift, so sudden, so unforeseen mocked the
comfortable security of life.

But with the fitting out of the expedition and speculation on the possible
safety of those in the Palace, her emotions became dreadfully perplexed.
She had perforce to cease mourning a husband who might be still alive, and
with the disappearance of a reason for her sorrow she began to wonder what
had caused it.

Had she cried because she loved him or because he was killed? She had
not a doubt while she thought him dead, but the chance of his being alive
seemed to have altered everything. Last night she would have disowned
indignantly the idea that she did not love him. She had accepted him as
naturally in the order of needful things as food and clothing. He was her
husband and so had everything that husbands have, did everything that
husbands do. She had never thought about it as a personal matter. One had a
husband as one had a cold in the head; one didn't always quite know why;
but having him one accepted him for the sort of thing he was.

Lewis had taken her from a life already wearily dull, and with every
prospect of becoming duller. He had come suddenly into her existence—a
quite unlooked-for excitement; and had transplanted her into surroundings
more exciting still; full of men, and dangers, and pageants and great affairs.
It was so full indeed, that in the press of things to do he was a good deal
crowded out. His work, his fresh appointments—for he had been
tremendously in demand—gave him rather the air of continually arranging
new scenes and effects in which she played the leading lady.

She didn't in the least so consciously regard him; she had not even
noticed how much his work kept him out of the occasions which she most
enjoyed; he seemed just a part of the delightful movement, a sort of dashing
high-spirited hot-tempered ambitious concentration of it all. He was the
man who had made it all possible for her, being her husband. That was how,
gratefully, she most often thought of him.

His death wrenched her by its treacherous horror; but it had put no
awkward questions. The questions came with the doubt if he were dead.
How much did she care for him? Did she care for him at all? Had she ever
cared for him as a husband? Right on the heels of that, answering it to her
astounded perception, came a shrinking of disgust that she had lived three
years with a man as his wife without loving him; without even discovering
that she did not love him. It was that which seared the tears in her eyes, and
left her with a sense of shame and self-disdain and loneliness indescribable.

It was that too in a curious reflected fashion which increased her anger at
Terrington's quiet indifference to the ways of Fate. She could picture Lewis
Chantry's raging vehemence under a like provocation.

As she watched the silent mass of men in the courtyard—the dull yellow
of the field-service kit lightened by the gay alkalaks of the Lancers, the
orange and white of their pennons, the glistening of the sun upon lance-
head and bayonet, the silence broken only by the clink of a bridoon as some
impatient horse flung up its head—there was a burst of blue and red above
the eastern tower and the Union Jack flew out above the Fort.

It was the signal that Afzul Singh had completed his defences. Walcot
rode back to Terrington and saluted. Terrington nodded. With a sparkle of
light on their lances, the horsemen were in the saddle, the rifles leapt to the
'carry,' and were swung on to the shoulder, cresting the infantry with the
shimmer of steel; the gates were thrown open, the Lancers passed through
and extended, the Sikhs and Dogras wheeled outwards after them in column
of fours, followed by the Guides.

As the gates closed behind the last section a sharp explosion rang out,
followed by others in quick succession.

Rose Chantry started and stood quivering in tense excitement; then


darted across the room to the further window, which looked towards the
polo ground through a green fringe of chenar.
As she reached it there was another rending uproar almost under her feet,
and a tree leapt into the air from beneath the window and fell with a
crashing ruin of its branches towards the river.

Afzul Singh was converting the screen of chenar into an abattis with
discs of gun cotton, but to Rose the trees seemed to be falling before the
enemy's shells, and she ran hurriedly to the eastern tower to get a view of
the besiegers, and found there Afzul Singh himself, who explained her
mistake.

A sand-bag revetment crowned the top of the tower, and the loopholes on
either side of the Maxim were manned by picked shots. All were intently
watching the occasional glimpse of colour or gleam of steel which marked
the progress of Terrington's force through the Bazaar.

Now that the din of the detonations had ceased not a sound broke the
silence; the city lay listless and without a sign of life in the haze of its
noontide heat. The dust rose on the heels of the column as it emerged from
the Bazaar and filtered through the collection of low mud buildings beyond
it. Clear of these, Terrington swung his right at once on to the river, and the
whole of his little force could be seen for the first time as it extended and
moved forward across the space of open ground to the east of the Palace. It
looked painfully small for its job, like an ant attacking a mouse, even
though Terrington made it as imposing as he could without sacrificing its
compactness. The ground, flat as a floor from the river to the foot-hills,
gave no command for rifle fire over the centre of the town, and Terrington
had no choice but to march straight at the wall which surrounded the Khan's
buildings, and chance their being defended. It was a dangerous piece of
work, and Afzul Singh never lowered his glasses till the doubtful part of it
was done.

But Terrington showed at once the temper in which he had undertaken it.
His cavalry wheeled to the left, leaving the front open, and, advancing,
formed a screen which covered the skirts of the town. The river protected
the other flank, and, with the Guides in the centre as reserve, the Sikhs went
straight for the eastern gate, while the Dogra detachment advanced half
right upon the Palace stables where the wall ran down to the river. The
guards on the gate allowed themselves to be taken, the stables were
occupied without resistance, and a command was thus obtained of the
Palace compound which was seen to be invitingly empty. But Terrington
was the last man to be tempted by such an invitation. He had obtained a
foothold from which to enforce his demands, and did not intend to go a step
further.

He could not hope to carry the Palace, filled as it doubtless was with the
Khan's guards; he had no guns to batter it; but he could now, if his hand was
forced, make life very uncomfortable for those within its walls. So he began
to parley.

What passed was hidden by the Palace wall from the watchers on the
tower, but after three hours of apprehension they could see that the force
was preparing to retire, and presently some of the Khan's bearers appeared
through the gateway carrying charpoys. Afzul Singh guessed what was on
them, and his grave consideration made no disguise with Mrs. Chantry. He
had no hope that any of those who had been trapped in the Palace would
return alive, and he held out none to her.

"None come," he said, lowering his glasses; "they are all carried."

Terrington had requested the return of Sir Colvin and his escort, and, on
the reply that they were killed, had demanded their bodies.

Mir Khan, informed by his spies that the Fort had been loop-holed,
provisions stored, the trees levelled and every preparation made for a
prolonged siege, foresaw with a chuckle the very imminent destruction of
the British force in Sar, and was far too astute to hurry a game which was
going his own way.

So he tendered the bodies with every mark of respect and the most
profound apologies for the passions of his subjects which he had been
unable to keep under control.

Terrington had replied acknowledging the arrival of the charpoys and


announcing that he was for the present the British representative in Sar, and
would, on receiving instructions from his Government, acquaint the Khan
what reparation was demanded for the murder at a friendly Durbar of Her
Majesty's Commissioner.

The old man, when the message was read to him, rubbed his foot and
smiled with child-like craftiness. He admired the daring which had flung
that handful of the Sirkar's men without an hour's hesitation against his
Palace; admired it the more since it seemed to prove that Terrington was
after all but a swine-headed fighter like the rest of his kind.

VI

Terrington brought back his men with an undiminished precaution, Mir


Khan's affability merely increasing his distrust, and Afzul Singh, his equal
in subtlety and in knowledge of the foe, had prepared a sally should the
force require assistance in getting out of the Bazaar. Mir Khan, however, to
his own everlasting regret, held his hand, so that the little expedition
returned without a shot fired, and the gates of the Fort were shut and barred
behind it. Afzul Singh had been already entrusted with the duty of putting
every alien out of the Fort, but to prevent more securely the escape of
information, the guards were strengthened, and sentries patrolled the entire
front of the Fort with orders to shoot any man attempting to enter or leave it
before dawn.

When the men were dismissed Terrington called Walcot and Dore into
the women's durbar hall and sent for Hussain Shah and Afzul Singh, who
were the two senior native officers.

"I should like to break the news to Mrs. Chantry if I may," said Walcot in
the doorway.

"The news?" enquired Terrington.

"Of her husband's death," Walcot explained.


Terrington's face showed a certain blankness of apprehension. He had
forgotten that there was any one in the Fort, whose hopes or fears could be
affected by the confirmation obtained of that morning's tragedy.

"Oh, certainly," he said.

The room was a long gloomy one on the ground floor, used by Langford
partly as an office, partly as a store. Bales and boxes still filled two of its
corners, and the space in front of them was littered with Sir Colvin's and the
Chantrys' belongings, which were being removed from the Residency with
ostentation. One dark window in the further wall lent what dim light the
room had, and the table at which Terrington seated himself was drawn
somewhat towards it.

He was writing when the two native officers entered, and he assigned to
them the two seats on his right, with the grave silent courtesy with which
the East had coloured so curiously his English manner. Dore, nervously
tired by the excitement of the morning, had dropped limply on to a bale of
clothing, and lit a cigarette, but the two Sikhs sat erect and impassive beside
the table. Clones came in to requisition some stores, and reported Langford
to be insensible and sinking.

"If you can spare a few moments you might spend them here," said
Terrington.

The doctor nodded, and sat down on a packing-case beside Dore, rising
again at once as Mrs. Chantry, followed by Walcot, entered the room.

She was wearing still the frock of creamy lace in which she was to have
watched the polo that afternoon. Her face looked listless and white and
faded above it like a broken flower. Her eyes sought Terrington's in the dim
room with a sort of frightened submissiveness.

"May I come in?" she said.

"Of course," he answered, getting out of his chair to hand it to her; but
Walcot had already drawn forward a seat of Sari rush from the relics of the
Residency, and she dropped into it limply, with a nod of acknowledgment to
Terrington, amid all the crushed and huddled fragments of her own lost
little home. Walcot sat down on a box beside her. A tiny jade god slid down
the pile of rugs and bowls and cushions, and lay at her feet with a severed
arm. He had been for years the very dearest of her household treasures, and
now to find him maimed and friendless moved in her a despondent misery
which she had not felt at her husband's death. She hid the little broken body
in the hollow of her hand, and sat there, her head bent over it, shaking with
sobs. It was the very smallness of the grief that brought her tears.

Terrington blotted the notes he had written and laid down his pen. He
made no sort of preamble: for anything in his manner the occasion might
have been the most ordinary in the world.

"I wish," he said, "to explain my plans. Some of us may not come
through the next few weeks, and I don't want those who do to be saddled
with my mistakes. So I'll enter any protest, to cover you in case I'm not with
you at the finish. We leave Sar to-night."

Even the two dark impassive faces on his right reflected the
unexpectedness of his announcement, and Walcot half rose to his feet.

"Abandon the Fort?" he exclaimed.

"Abandon the Fort, and everything we cannot carry, and retire by the
Palári upon Rashát," said Terrington quietly.

"But I understood, if you'll excuse me," continued Walcot, trying to


control his excitement, "that all the defences of the Fort which we've been
at for the last month were your idea."

"They were," said Terrington.

"Have you changed your mind then?" asked the other sharply.

"No," said Terrington slowly, "but I've changed my position. I've only so
far had to decide how to make the Fort defensible if it had to be defended."
"Yes, but!" Walcot objected, "the clearing of the Residency, the blowing
down of these trees; all that has taken place since! What's been the object of
that if you didn't mean to stay?"

"In war," said Terrington quietly, "it's sometimes as well to keep your
intentions from the enemy."

"Did Sir Colvin mean us to stay here, sir?" enquired Dore.

"Yes," said Terrington. "Sir Colvin intended to hold out in Sar if


anything went wrong till a relieving force could get up here from Sampur."

"You absolutely disagree with him, then?" Walcot rapped out.

Terrington looked at him thoughtfully.

"I have another point of view," he said.

"And what's that?" snapped the other.

"He was a political officer and I am a soldier," said Terrington simply.

Dore turned his shoulder upon Walcot, with a wrinkle of annoyance at


his carping note.

"Don't you think we could hold Sar, sir?" he asked with boyish eagerness
for a stand-up fight.

"Yes," said Terrington, kindling sympathetically at the thought of the


fight he too had longed for, "I think we just could, though it might be a near
thing. I've decided to clear out," he went on, addressing the others, "because
the value of being penned up here doesn't impress me politically, and
because digging us out of this in mid-winter would mean a horrible waste of
life. There are only a few hundred of us to be wiped out at the worst, but it
might take thousands of the men who came to save us. These little sieges
are often very costly things."

"I shouldn't think our retirement will be very popular at home," Clones
suggested.
"I don't suppose it will," said Terrington; "at home they're rather fond of
a siege; it makes the paper more interesting."

"And how about the intentions of the Government, Colonel," Clones


continued in his reasonable way; "I suppose you were sent up here to carry
them out."

"No doubt," said Terrington with his grave smile, "but without being told
what its intentions were. Consequently one rather seems to be here to make
intentions for the Government, and I'm very possibly making them all
wrong. But that's their fault for not having sent a better man."

"There's one point, Terrington, you don't seem to have considered,"


Walcot interjected; "that you've got to take a woman over passes which
even the natives won't cross at this time of year."

"I haven't considered it for a moment," said Terrington shortly.

Walcot's face curdled with anger.

"That's hardly been the habit of Englishmen hitherto out here," he


exclaimed.

"I dare say not," said Terrington with dry indifference.

Rose Chantry, with her hand still closed about the little broken god in
her lap, looked up at him through the tears that hung across her eyes.
Beyond the cool darkness of the entrance door, against the far wall of the
blazing courtyard she could see the row of charpoys with their burden of
dead men, mere rolls of sallow dungari cloth, waiting till the grave being
dug beside the Residency gate should be wide enough to hold them. It was
the most dreadful moment of her life, when she needed above all to be
petted and comforted into a sense of her importance, but the man who
should have done it was indifferent even to her safety. She had already
begun to cheer herself with the thought of a siege; the delicacy of her
position; the solicitous homage of all the men; her cheerful and inspiring
effect upon them; the excitement in England so intensified by the presence
of a woman among the besieged; the accounts of her in the papers, made
more touching by her loss; and then the thrill of the relief—she took the
relief for granted—the sound of the guns, the fight through the streets of
Sar, the cheers of the British troops, the ardent congratulations, the soft
abandonment of that moment at the end of the suspense, and herself the one
woman in a British army. And the coming home after such an experience;
the woman of the moment, every one wanting to meet her; perhaps a
command from the Queen.

All her dream was shattered by Terrington's implacable decree. She


looked at him with despairing hate. She thought of the reckless sacrifices
Englishmen had made for women during the Mutiny, and hated him the
more. She felt sure that she could never live through the snows of those
passes about which she had heard such awful stories. The cold would kill
her; the cold always shrivelled her up; and she had nothing to wear, nothing
warmer than was wanted for an Indian winter.

And that very morning, only a few hours back, as the party started for
the Durbar, she had exulted in her triumph over him, she whose folly had
given everything into his hand!

What ages it seemed since Lewis had swung buoyantly into his saddle,
and Sir Colvin, ruddy and cheery, had waved her an "au revoir." Now they
were rolls of yellow dungari lying out there in the sun.

In her absorption of self-pity she scarcely heard Captain Walcot's


expressions of dissent from his leader's plans, which were more forcible
than soldierly. He was seething with wrath at Terrington's treatment of her,
and Terrington, aware of his excitement, but quite at fault as to its cause,
heard him with determined patience.

"And by which pass do you mean to retire?" he exclaimed at last, unable


to shake Terrington's resolve.

"By the Palári," said the other.

"The Palári!" cried Walcot derisively. "Why, it's the worst pass on this
side of the Pamir. May I ask why you've chosen it?"
"Have you been through the Palári or Darai?" Terrington enquired.

"No."

"Then you can hardly appreciate why I've chosen it," said Terrington
quietly. "The Palári is the only one which we've a chance of reaching
without being cut off; it's the only one not commanded from above at this
time of year, and Freddy Gale, holding this end of it at Rashát, is absolutely
done for unless we dig him out."

His reasons were listened to by the room in absorbing silence. Then


Walcot blurted out:

"Is this a council of war?"

"No," said Terrington; "it's an opportunity for protest. I wished to put


your advice on record, but I didn't propose to take it."

Walcot thereupon declared himself emphatically in favour of remaining


in Sar; Dore followed him less assertively. Clones gave a shrug of his
shoulders.

"It's all one to me where I doctor you," he smiled.

Terrington turned to the two men beside him, who had sat, immovably
attentive, throughout the discussion.

"We are as the print of thy footsteps," said Afzul Shah, and Hussain
nodded.

Terrington wrote for some moments, then read aloud his own
dispositions and the objections which had been urged against retirement.
His own plans and reasons were very bluntly outlined, but he gave the case
for the occupation of Sar with a fulness and cogency that astonished its
advocates, who did not suspect how dear the scheme had been to his
ambition, nor what its abandonment had cost him.

He handed the paper to Walcot.


"Will you sign it?" he said.

The best that was in the other man responded instinctively to such
treatment:

"You've put it a long way stronger than I could myself," he said, taking
up the pen.

VII

Langford came back to consciousness an hour before he died, and


Terrington sat beside him to the end, writing instructions to cover every
detail of the departure while he spoke and listened to the dying man.
Langford was a fine horseman and a very capable soldier, and the only one
of his subordinates on whose decision Terrington could rely. He had left in
India an uncompleted love affair but he spoke of nothing in his last
moments but the safety of the force.

"You'll have to watch those Bakót chaps," he murmured, "there's no fight


in 'em." And again with more difficulty. "Those beggars 'll cut you off at the
Sorágh Gul; get round by the Bewal road. You'll have to smash 'em there."
His mind was evidently away with the retreating troops. His grip tightened
on Terrington's hand. "If only I could go along with you, old man. Oh, it's
hard to come to grief at the first hurdle."

He shut his eyes with that inconsolable sigh, and it was his unconscious
soul that whispered, "Give my love to Helen," with the last beats of his
heart.

Terrington went on writing as Langford's head fell back, then he


loosened the dead man's fingers from his hand, and left the room. The sheer
pressure of thought seemed to have squeezed out of him the power of
feeling.

You might also like